2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2004 The GemRB Project
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 # GUIMA.py - scripts to control map windows from the GUIMA and GUIWMAP winpacks
23 ###################################################
26 from GUIDefines
import *
32 WorldMapControl
= None
34 OldPortraitWindow
= None
36 OldOptionsWindow
= None
39 import GUICommonWindows
41 global OldPortraitWindow
, OldOptionsWindow
43 if GUICommon
.CloseOtherWindow (ShowMap
):
47 OptionsWindow
.Unload ()
49 PortraitWindow
.Unload ()
52 #this window type should block the game
53 GemRB
.SetVar ("OtherWindow", -1)
54 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
56 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
57 OldPortraitWindow
= None
58 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
59 OldOptionsWindow
= None
61 PosX
= GemRB
.GetVar ("MapControlX")
62 PosY
= GemRB
.GetVar ("MapControlY")
64 GemRB
.RevealArea (PosX
, PosY
, 30, 1)
68 ###################################################
70 ###################################################
72 import GUICommonWindows
73 global MapWindow
, OptionsWindow
, PortraitWindow
74 global OldPortraitWindow
, OldOptionsWindow
76 if GUICommon
.CloseOtherWindow (ShowMap
):
80 OptionsWindow
.Unload ()
82 PortraitWindow
.Unload ()
85 #this window type should block the game
86 GemRB
.SetVar ("OtherWindow", -1)
87 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
89 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
90 OldPortraitWindow
= None
91 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
92 OldOptionsWindow
= None
96 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
98 GemRB
.LoadWindowPack ("GUIMAP", 640, 480)
99 MapWindow
= Window
= GemRB
.LoadWindow (2)
100 #this window type blocks the game normally, but map window doesn't
101 GemRB
.SetVar ("OtherWindow", MapWindow
.ID
)
102 #saving the original portrait window
103 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
104 OptionsWindow
= GemRB
.LoadWindow (0)
105 GUICommonWindows
.SetupMenuWindowControls (OptionsWindow
, 0, ShowMap
)
106 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
107 PortraitWindow
= GUICommonWindows
.OpenPortraitWindow (0)
108 OptionsWindow
.SetFrame ()
111 Button
= Window
.GetControl (1)
112 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
114 # Hide or Show mapnotes
115 Button
= Window
.GetControl (3)
116 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
118 Label
= Window
.GetControl (0x10000003)
122 Window
.CreateMapControl (2, 0, 0, 0, 0, 0x10000003, "FLAG1")
123 Map
= Window
.GetControl (2)
124 GemRB
.SetVar ("ShowMapNotes",IE_GUI_MAP_REVEAL_MAP
)
125 Map
.SetVarAssoc ("ShowMapNotes", IE_GUI_MAP_REVEAL_MAP
)
126 Map
.SetEvent (IE_GUI_MAP_ON_PRESS
, RevealMap
)
127 Window
.SetVisible (WINDOW_VISIBLE
)
128 OptionsWindow
.SetVisible (WINDOW_GRAYED
)
129 PortraitWindow
.SetVisible (WINDOW_GRAYED
)
130 OptionsWindow
.SetVisible (WINDOW_FRONT
)
131 PortraitWindow
.SetVisible (WINDOW_FRONT
)
132 Window
.SetVisible (WINDOW_FRONT
)
133 Map
.SetStatus (IE_GUI_CONTROL_FOCUSED
)
134 GemRB
.GamePause (0,0)
137 ###################################################
138 def OpenMapWindow ():
139 import GUICommonWindows
140 global MapWindow
, OptionsWindow
, PortraitWindow
141 global OldPortraitWindow
, OldOptionsWindow
143 if GUICommon
.CloseOtherWindow (OpenMapWindow
):
147 OptionsWindow
.Unload ()
149 PortraitWindow
.Unload ()
152 #this window type should block the game
153 GemRB
.SetVar ("OtherWindow", -1)
154 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
156 GUICommonWindows
.PortraitWindow
= OldPortraitWindow
157 OldPortraitWindow
= None
158 GUICommonWindows
.OptionsWindow
= OldOptionsWindow
159 OldOptionsWindow
= None
163 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
165 GemRB
.LoadWindowPack ("GUIMAP", 640, 480)
166 MapWindow
= Window
= GemRB
.LoadWindow (2)
167 #this window type blocks the game normally, but map window doesn't
168 GemRB
.SetVar ("OtherWindow", MapWindow
.ID
)
169 #saving the original portrait window
170 OldOptionsWindow
= GUICommonWindows
.OptionsWindow
171 OptionsWindow
= GemRB
.LoadWindow (0)
172 GUICommonWindows
.MarkMenuButton (OptionsWindow
)
173 GUICommonWindows
.SetupMenuWindowControls (OptionsWindow
, 0, OpenMapWindow
)
174 OldPortraitWindow
= GUICommonWindows
.PortraitWindow
175 PortraitWindow
= GUICommonWindows
.OpenPortraitWindow (0)
176 OptionsWindow
.SetFrame ()
179 Button
= Window
.GetControl (1)
180 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenWorldMapWindowInside
)
182 # Hide or Show mapnotes
183 Button
= Window
.GetControl (3)
184 Button
.SetFlags (IE_GUI_BUTTON_CHECKBOX
, OP_OR
)
186 GemRB
.SetVar ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES
)
187 Button
.SetVarAssoc ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES
)
189 Label
= Window
.GetControl (0x10000003)
193 Window
.CreateMapControl (2, 0, 0, 0, 0, 0x10000003, "FLAG1")
194 Map
= Window
.GetControl (2)
195 Map
.SetVarAssoc ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES
)
196 Map
.SetEvent (IE_GUI_MAP_ON_RIGHT_PRESS
, AddNoteWindow
)
197 Map
.SetEvent (IE_GUI_MAP_ON_DOUBLE_PRESS
, LeftDoublePressMap
)
198 OptionsWindow
.SetVisible (WINDOW_VISIBLE
)
199 Window
.SetVisible (WINDOW_VISIBLE
)
200 PortraitWindow
.SetVisible (WINDOW_VISIBLE
)
201 Map
.SetStatus (IE_GUI_CONTROL_FOCUSED
)
204 def LeftDoublePressMap ():
205 #close the map on doubleclick
209 def CloseNoteWindow ():
212 MapWindow
.SetVisible (WINDOW_VISIBLE
)
215 def RemoveMapNote ():
216 PosX
= GemRB
.GetVar ("MapControlX")
217 PosY
= GemRB
.GetVar ("MapControlY")
218 GemRB
.SetMapnote (PosX
, PosY
, 0, "")
223 PosX
= GemRB
.GetVar ("MapControlX")
224 PosY
= GemRB
.GetVar ("MapControlY")
225 Label
= NoteWindow
.GetControl (1)
226 Text
= Label
.QueryText ()
227 Color
= GemRB
.GetVar ("Color")
228 GemRB
.SetMapnote (PosX
, PosY
, Color
, Text
)
233 NoteLabel
.SetStatus (IE_GUI_CONTROL_FOCUSED
)
236 def AddNoteWindow ():
237 global NoteWindow
, NoteLabel
239 Label
= MapWindow
.GetControl (0x10000003)
240 Text
= Label
.QueryText ()
241 NoteWindow
= GemRB
.LoadWindow (5)
242 NoteLabel
= NoteWindow
.GetControl (1)
243 NoteLabel
.SetText (Text
)
245 Label
= NoteWindow
.GetControl (4+i
)
246 #the .chu is crappy, we have to reset the flags
247 Label
.SetSprites ("FLAG1", i
,0,1,2,0)
248 Label
.SetFlags (IE_GUI_BUTTON_RADIOBUTTON
, OP_SET
)
249 Label
.SetVarAssoc ("Color", i
)
250 Label
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SetFocusBack
)
253 Label
= NoteWindow
.GetControl (0)
254 Label
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SetMapNote
)
255 Label
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
256 Label
.SetText (11973)
259 Label
= NoteWindow
.GetControl (2)
260 Label
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseNoteWindow
)
261 Label
.SetText (13727)
262 Label
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
265 Label
= NoteWindow
.GetControl (3)
266 Label
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, RemoveMapNote
)
267 Label
.SetText (13957)
269 NoteWindow
.ShowModal (MODAL_SHADOW_GRAY
)
270 NoteLabel
.SetStatus (IE_GUI_CONTROL_FOCUSED
)
273 def OpenWorldMapWindowInside ():
276 OpenMapWindow () #closes mapwindow
278 print "MapWindow=",MapWindow
279 WorldMapWindowCommon (-1)
282 def OpenWorldMapWindow ():
283 WorldMapWindowCommon (GemRB
.GetVar ("Travel"))
286 def MoveToNewArea ():
287 global WorldMapWindow
, WorldMapControl
289 tmp
= WorldMapControl
.GetDestinationArea (1)
290 if tmp
["Distance"]==-1:
291 print "Invalid target", tmp
294 CloseWorldMapWindow ()
295 GemRB
.CreateMovement (tmp
["Destination"], tmp
["Entrance"], tmp
["Direction"])
298 def ChangeTooltip ():
299 global WorldMapWindow
, WorldMapControl
302 tmp
= WorldMapControl
.GetDestinationArea ()
304 str = "%s: %d"%(GemRB
.GetString(23084),tmp
["Distance"])
308 WorldMapControl
.SetTooltip (str)
311 def CloseWorldMapWindow ():
312 global WorldMapWindow
, WorldMapControl
314 print "CloseWorldMapWindow found Mapwindow = ",MapWindow
318 WorldMapWindow
.Unload ()
319 WorldMapWindow
= None
320 WorldMapControl
= None
325 WorldMapWindow
.Unload ()
326 WorldMapWindow
= None
327 WorldMapControl
= None
328 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
)
332 def WorldMapWindowCommon (Travel
):
333 global WorldMapWindow
, WorldMapControl
336 CloseWorldMapWindow ()
340 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
342 GemRB
.LoadWindowPack ("GUIWMAP", 640, 480)
343 WorldMapWindow
= Window
= GemRB
.LoadWindow (0)
344 #saving the original portrait window
347 Window
.CreateWorldMapControl (4, 0, 62, 640, 418, Travel
, "floattxt")
348 WorldMapControl
= Window
.GetControl (4)
349 WorldMapControl
.SetAnimation ("WMDAG")
350 WorldMapControl
.SetEvent (IE_GUI_WORLDMAP_ON_PRESS
, MoveToNewArea
)
351 WorldMapControl
.SetEvent (IE_GUI_MOUSE_ENTER_WORLDMAP
, ChangeTooltip
)
354 Button
= Window
.GetControl (1)
355 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapN
)
358 Button
= Window
.GetControl (2)
359 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapS
)
362 Button
= Window
.GetControl (8)
363 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapNW
)
366 Button
= Window
.GetControl (9)
367 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapNE
)
370 Button
= Window
.GetControl (10)
371 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapW
)
374 Button
= Window
.GetControl (11)
375 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapC
)
378 Button
= Window
.GetControl (12)
379 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapE
)
382 Button
= Window
.GetControl (13)
383 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapSW
)
386 Button
= Window
.GetControl (14)
387 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, MapSE
)
390 Button
= Window
.GetControl (0)
391 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, CloseWorldMapWindow
)
392 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
393 Window
.SetVisible (WINDOW_VISIBLE
)
398 WorldMapControl
.AdjustScrolling (0, -10)
402 WorldMapControl
.AdjustScrolling (10, -10)
406 WorldMapControl
.AdjustScrolling (10, 0)
410 WorldMapControl
.AdjustScrolling (10, 10)
414 WorldMapControl
.AdjustScrolling (0, 10)
418 WorldMapControl
.AdjustScrolling (-10, 10)
422 WorldMapControl
.AdjustScrolling (-10, 0)
426 WorldMapControl
.AdjustScrolling (-10, -10)
430 WorldMapControl
.AdjustScrolling (0, 0)
433 ###################################################
434 # End of file GUIMA.py