fixed the rest of the functions that needed globalid capabilities
[gemrb.git] / gemrb / GUIScripts / bg2 / GUIMA.py
blobd4ccd1b626f05f68c840c8b28dea8a2cb1209405
1 # -*-python-*-
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 ###################################################
25 import GemRB
26 from GUIDefines import *
27 import GUICommon
29 MapWindow = None
30 NoteWindow = None
31 WorldMapWindow = None
32 WorldMapControl = None
33 PortraitWindow = None
34 OldPortraitWindow = None
35 OptionsWindow = None
36 OldOptionsWindow = None
38 def RevealMap ():
39 import GUICommonWindows
40 global MapWindow
41 global OldPortraitWindow, OldOptionsWindow
43 if GUICommon.CloseOtherWindow (ShowMap):
44 if MapWindow:
45 MapWindow.Unload ()
46 if OptionsWindow:
47 OptionsWindow.Unload ()
48 if PortraitWindow:
49 PortraitWindow.Unload ()
51 MapWindow = None
52 #this window type should block the game
53 GemRB.SetVar ("OtherWindow", -1)
54 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
55 GemRB.UnhideGUI ()
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)
65 GemRB.GamePause (0,0)
66 return
68 ###################################################
69 # for farsight effect
70 ###################################################
71 def ShowMap ():
72 import GUICommonWindows
73 global MapWindow, OptionsWindow, PortraitWindow
74 global OldPortraitWindow, OldOptionsWindow
76 if GUICommon.CloseOtherWindow (ShowMap):
77 if MapWindow:
78 MapWindow.Unload ()
79 if OptionsWindow:
80 OptionsWindow.Unload ()
81 if PortraitWindow:
82 PortraitWindow.Unload ()
84 MapWindow = None
85 #this window type should block the game
86 GemRB.SetVar ("OtherWindow", -1)
87 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
88 GemRB.UnhideGUI ()
89 GUICommonWindows.PortraitWindow = OldPortraitWindow
90 OldPortraitWindow = None
91 GUICommonWindows.OptionsWindow = OldOptionsWindow
92 OldOptionsWindow = None
93 return
95 GemRB.HideGUI ()
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 ()
110 # World Map
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)
119 Label.SetText ("")
121 # Map Control
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)
135 return
137 ###################################################
138 def OpenMapWindow ():
139 import GUICommonWindows
140 global MapWindow, OptionsWindow, PortraitWindow
141 global OldPortraitWindow, OldOptionsWindow
143 if GUICommon.CloseOtherWindow (OpenMapWindow):
144 if MapWindow:
145 MapWindow.Unload ()
146 if OptionsWindow:
147 OptionsWindow.Unload ()
148 if PortraitWindow:
149 PortraitWindow.Unload ()
151 MapWindow = None
152 #this window type should block the game
153 GemRB.SetVar ("OtherWindow", -1)
154 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
155 GemRB.UnhideGUI ()
156 GUICommonWindows.PortraitWindow = OldPortraitWindow
157 OldPortraitWindow = None
158 GUICommonWindows.OptionsWindow = OldOptionsWindow
159 OldOptionsWindow = None
160 return
162 GemRB.HideGUI ()
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 ()
178 # World Map
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)
185 # Is this an option?
186 GemRB.SetVar ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES)
187 Button.SetVarAssoc ("ShowMapNotes", IE_GUI_MAP_VIEW_NOTES)
189 Label = Window.GetControl (0x10000003)
190 Label.SetText ("")
192 # Map Control
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)
202 return
204 def LeftDoublePressMap ():
205 #close the map on doubleclick
206 OpenMapWindow()
207 return
209 def CloseNoteWindow ():
210 if NoteWindow:
211 NoteWindow.Unload ()
212 MapWindow.SetVisible (WINDOW_VISIBLE)
213 return
215 def RemoveMapNote ():
216 PosX = GemRB.GetVar ("MapControlX")
217 PosY = GemRB.GetVar ("MapControlY")
218 GemRB.SetMapnote (PosX, PosY, 0, "")
219 CloseNoteWindow ()
220 return
222 def SetMapNote ():
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)
229 CloseNoteWindow ()
230 return
232 def SetFocusBack ():
233 NoteLabel.SetStatus (IE_GUI_CONTROL_FOCUSED)
234 return
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)
244 for i in range(8):
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)
252 #set
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)
258 #cancel
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)
264 #remove
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)
271 return
273 def OpenWorldMapWindowInside ():
274 global MapWindow
276 OpenMapWindow () #closes mapwindow
277 MapWindow = -1
278 print "MapWindow=",MapWindow
279 WorldMapWindowCommon (-1)
280 return
282 def OpenWorldMapWindow ():
283 WorldMapWindowCommon (GemRB.GetVar ("Travel"))
284 return
286 def MoveToNewArea ():
287 global WorldMapWindow, WorldMapControl
289 tmp = WorldMapControl.GetDestinationArea (1)
290 if tmp["Distance"]==-1:
291 print "Invalid target", tmp
292 return
294 CloseWorldMapWindow ()
295 GemRB.CreateMovement (tmp["Destination"], tmp["Entrance"], tmp["Direction"])
296 return
298 def ChangeTooltip ():
299 global WorldMapWindow, WorldMapControl
300 global str
302 tmp = WorldMapControl.GetDestinationArea ()
303 if (tmp):
304 str = "%s: %d"%(GemRB.GetString(23084),tmp["Distance"])
305 else:
306 str=""
308 WorldMapControl.SetTooltip (str)
309 return
311 def CloseWorldMapWindow ():
312 global WorldMapWindow, WorldMapControl
314 print "CloseWorldMapWindow found Mapwindow = ",MapWindow
315 if MapWindow:
316 # reopen map window
317 if WorldMapWindow:
318 WorldMapWindow.Unload ()
319 WorldMapWindow = None
320 WorldMapControl = None
321 OpenMapWindow ()
322 return
324 if WorldMapWindow:
325 WorldMapWindow.Unload ()
326 WorldMapWindow = None
327 WorldMapControl = None
328 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
329 GemRB.UnhideGUI ()
330 return
332 def WorldMapWindowCommon (Travel):
333 global WorldMapWindow, WorldMapControl
335 if WorldMapWindow:
336 CloseWorldMapWindow ()
337 return
339 GemRB.HideGUI ()
340 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
342 GemRB.LoadWindowPack ("GUIWMAP", 640, 480)
343 WorldMapWindow = Window = GemRB.LoadWindow (0)
344 #saving the original portrait window
345 Window.SetFrame ()
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)
353 #north
354 Button = Window.GetControl (1)
355 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapN)
357 #south
358 Button = Window.GetControl (2)
359 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapS)
361 #northwest
362 Button = Window.GetControl (8)
363 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapNW)
365 #northeast
366 Button = Window.GetControl (9)
367 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapNE)
369 #west
370 Button = Window.GetControl (10)
371 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapW)
373 #center
374 Button = Window.GetControl (11)
375 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapC)
377 #east
378 Button = Window.GetControl (12)
379 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapE)
381 #southwest
382 Button = Window.GetControl (13)
383 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapSW)
385 #southeast
386 Button = Window.GetControl (14)
387 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapSE)
389 # Done
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)
394 MapC()
395 return
397 def MapN():
398 WorldMapControl.AdjustScrolling (0, -10)
399 return
401 def MapNE():
402 WorldMapControl.AdjustScrolling (10, -10)
403 return
405 def MapE():
406 WorldMapControl.AdjustScrolling (10, 0)
407 return
409 def MapSE():
410 WorldMapControl.AdjustScrolling (10, 10)
411 return
413 def MapS():
414 WorldMapControl.AdjustScrolling (0, 10)
415 return
417 def MapSW():
418 WorldMapControl.AdjustScrolling (-10, 10)
419 return
421 def MapW():
422 WorldMapControl.AdjustScrolling (-10, 0)
423 return
425 def MapNW():
426 WorldMapControl.AdjustScrolling (-10, -10)
427 return
429 def MapC():
430 WorldMapControl.AdjustScrolling (0, 0)
431 return
433 ###################################################
434 # End of file GUIMA.py