GUICommon: Define a GameWindow variable.
[gemrb.git] / gemrb / GUIScripts / bg1 / GUIMA.py
blob0622c25f52f74ed9d4852686634050c0523ba158
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 import GUICommonWindows
27 from GUIDefines import *
28 from GUICommon import CloseOtherWindow
29 from GUICommon import GameWindow
30 from GUICommonWindows import *
32 MapWindow = None
33 WorldMapWindow = None
34 WorldMapControl = None
35 PortraitWindow = None
36 OldPortraitWindow = None
37 OptionsWindow = None
38 OldOptionsWindow = None
40 def RevealMap ():
41 global MapWindow
42 global OldPortraitWindow, OldOptionsWindow
44 if CloseOtherWindow (ShowMap):
45 if MapWindow:
46 MapWindow.Unload ()
47 if OptionsWindow:
48 OptionsWindow.Unload ()
49 if PortraitWindow:
50 PortraitWindow.Unload ()
52 MapWindow = None
53 #this window type should block the game
54 GemRB.SetVar ("OtherWindow", -1)
55 GameWindow.SetVisible(WINDOW_VISIBLE)
56 GemRB.UnhideGUI ()
57 GUICommonWindows.PortraitWindow = OldPortraitWindow
58 OldPortraitWindow = None
59 GUICommonWindows.OptionsWindow = OldOptionsWindow
60 OldOptionsWindow = None
62 PosX = GemRB.GetVar ("MapControlX")
63 PosY = GemRB.GetVar ("MapControlY")
65 GemRB.RevealArea (PosX, PosY, 30, 1)
66 GemRB.GamePause (0,0)
67 return
69 ###################################################
70 # for farsight effect
71 ###################################################
72 def ShowMap ():
73 global MapWindow, OptionsWindow, PortraitWindow
74 global OldPortraitWindow, OldOptionsWindow
76 if 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 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 GameWindow.SetVisible(WINDOW_INVISIBLE)
98 GemRB.LoadWindowPack ("GUIMAP", 640, 480)
99 MapWindow = Window = GemRB.LoadWindowObject (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.LoadWindowObject (0)
105 SetupMenuWindowControls (OptionsWindow, 0, "ShowMap")
106 OldPortraitWindow = GUICommonWindows.PortraitWindow
107 PortraitWindow = OpenPortraitWindow (0)
108 OptionsWindow.SetFrame ()
110 # World Map
111 Button = Window.GetControl (1)
112 Button.SetState (IE_GUI_BUTTON_LOCKED)
114 # Map Control
115 Window.CreateMapControl (2, 0, 0, 0, 0)
116 Map = Window.GetControl (2)
117 Map.SetEvent (IE_GUI_MAP_ON_PRESS, "RevealMap")
118 Window.SetVisible (WINDOW_VISIBLE)
119 OptionsWindow.SetVisible (WINDOW_GRAYED)
120 PortraitWindow.SetVisible (WINDOW_GRAYED)
121 OptionsWindow.SetVisible (WINDOW_FRONT)
122 PortraitWindow.SetVisible (WINDOW_FRONT)
123 Window.SetVisible (WINDOW_FRONT)
124 Map.SetStatus (IE_GUI_CONTROL_FOCUSED)
125 GemRB.GamePause (0,0)
126 return
128 ###################################################
129 def OpenMapWindow ():
130 global MapWindow, OptionsWindow, PortraitWindow
131 global OldPortraitWindow, OldOptionsWindow
133 if CloseOtherWindow (OpenMapWindow):
134 if MapWindow:
135 MapWindow.Unload ()
136 if OptionsWindow:
137 OptionsWindow.Unload ()
138 if PortraitWindow:
139 PortraitWindow.Unload ()
141 MapWindow = None
142 #this window type should block the game
143 GemRB.SetVar ("OtherWindow", -1)
144 GameWindow.SetVisible(WINDOW_VISIBLE)
145 #OldOptionsWindow.SetVisible (WINDOW_VISIBLE)
146 #OldPortraitWindow.SetVisible (WINDOW_VISIBLE)
147 GemRB.UnhideGUI ()
148 GUICommonWindows.PortraitWindow = OldPortraitWindow
149 OldPortraitWindow = None
150 GUICommonWindows.OptionsWindow = OldOptionsWindow
151 OldOptionsWindow = None
152 return
154 GemRB.HideGUI ()
155 GameWindow.SetVisible(WINDOW_INVISIBLE)
157 GemRB.LoadWindowPack ("GUIMAP", 640, 480)
158 MapWindow = Window = GemRB.LoadWindowObject (2)
159 #this window type blocks the game normally, but map window doesn't
160 GemRB.SetVar ("OtherWindow", MapWindow.ID)
161 #saving the original portrait window
162 OldOptionsWindow = GUICommonWindows.OptionsWindow
163 OptionsWindow = GemRB.LoadWindowObject (0)
164 MarkMenuButton (OptionsWindow)
165 SetupMenuWindowControls (OptionsWindow, 0, "OpenMapWindow")
166 OldPortraitWindow = GUICommonWindows.PortraitWindow
167 PortraitWindow = OpenPortraitWindow (0)
168 OptionsWindow.SetFrame ()
170 # World Map
171 Button = Window.GetControl (1)
172 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "OpenWorldMapWindowInside")
174 # Map Control
175 Window.CreateMapControl (2, 0, 0, 0, 0)
176 Map = Window.GetControl (2)
177 Map.SetEvent (IE_GUI_MAP_ON_DOUBLE_PRESS, "LeftDoublePressMap")
178 #OldOptionsWindow.SetVisible (WINDOW_INVISIBLE)
179 #OldPortraitWindow.SetVisible (WINDOW_INVISIBLE)
180 OptionsWindow.SetVisible (WINDOW_VISIBLE)
181 Window.SetVisible (WINDOW_VISIBLE)
182 PortraitWindow.SetVisible (WINDOW_VISIBLE)
183 Map.SetStatus (IE_GUI_CONTROL_FOCUSED)
185 def LeftDoublePressMap ():
186 #OpenMapWindow()
187 print "MoveToPoint"
188 return
190 def OpenWorldMapWindowInside ():
191 global MapWindow
193 OpenMapWindow () #closes mapwindow
194 MapWindow = -1
195 print "MapWindow=",MapWindow
196 WorldMapWindowCommon (-1)
197 return
199 def OpenWorldMapWindow ():
200 WorldMapWindowCommon (GemRB.GetVar ("Travel"))
201 return
203 def MoveToNewArea ():
204 global WorldMapWindow, WorldMapControl
206 tmp = WorldMapControl.GetDestinationArea (1)
207 if tmp["Distance"]==-1:
208 print "Invalid target", tmp
209 return
211 CloseWorldMapWindow ()
212 GemRB.CreateMovement (tmp["Destination"], tmp["Entrance"], tmp["Direction"])
213 return
215 def ChangeTooltip ():
216 global WorldMapWindow, WorldMapControl
217 global str
219 tmp = WorldMapControl.GetDestinationArea ()
220 if (tmp):
221 str = "%s: %d"%(GemRB.GetString(23084),tmp["Distance"])
222 else:
223 str=""
225 WorldMapControl.SetTooltip (str)
226 return
228 def CloseWorldMapWindow ():
229 global WorldMapWindow, WorldMapControl
231 print "CloseWorldMapWindow found Mapwindow = ",MapWindow
232 if MapWindow:
233 # reopen map window
234 if WorldMapWindow:
235 WorldMapWindow.Unload ()
236 WorldMapWindow = None
237 WorldMapControl = None
238 OpenMapWindow ()
239 return
241 if WorldMapWindow:
242 WorldMapWindow.Unload ()
243 WorldMapWindow = None
244 WorldMapControl = None
245 GameWindow.SetVisible(WINDOW_VISIBLE)
246 GemRB.UnhideGUI ()
247 return
249 def WorldMapWindowCommon (Travel):
250 global WorldMapWindow, WorldMapControl
252 if WorldMapWindow:
253 CloseWorldMapWindow ()
254 return
256 GemRB.HideGUI ()
257 GameWindow.SetVisible(WINDOW_INVISIBLE)
259 GemRB.LoadWindowPack ("GUIWMAP", 640, 480)
260 WorldMapWindow = Window = GemRB.LoadWindowObject (0)
261 #saving the original portrait window
262 Window.SetFrame ()
264 Window.CreateWorldMapControl (4, 0, 62, 640, 418, Travel, "toolfont")
265 WorldMapControl = Window.GetControl (4)
266 WorldMapControl.SetAnimation ("WMDAG")
267 WorldMapControl.SetEvent (IE_GUI_WORLDMAP_ON_PRESS, "MoveToNewArea")
268 WorldMapControl.SetEvent (IE_GUI_MOUSE_ENTER_WORLDMAP, "ChangeTooltip")
270 #north
271 Button = Window.GetControl (1)
272 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "MapN")
274 #south
275 Button = Window.GetControl (2)
276 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "MapS")
278 # Done
279 Button = Window.GetControl (0)
280 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "CloseWorldMapWindow")
281 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
282 Window.SetVisible (WINDOW_VISIBLE)
283 return
285 def MapN():
286 WorldMapControl.AdjustScrolling (0, -10)
287 return
289 def MapS():
290 WorldMapControl.AdjustScrolling (0, 10)
291 return
294 ###################################################
295 # End of file GUIMA.py