factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / bg1 / GUIMA.py
blobb69eb7df64cc31f44193514bd1972eddf29ac049
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 GUICommon
27 import GUICommonWindows
28 from GUIDefines import *
30 MapWindow = None
31 WorldMapWindow = None
32 WorldMapControl = None
33 PortraitWindow = None
34 OldPortraitWindow = None
35 OptionsWindow = None
36 OldOptionsWindow = None
38 def RevealMap ():
39 global MapWindow
40 global OldPortraitWindow, OldOptionsWindow
42 if GUICommon.CloseOtherWindow (ShowMap):
43 if MapWindow:
44 MapWindow.Unload ()
45 if OptionsWindow:
46 OptionsWindow.Unload ()
47 if PortraitWindow:
48 PortraitWindow.Unload ()
50 MapWindow = None
51 #this window type should block the game
52 GemRB.SetVar ("OtherWindow", -1)
53 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
54 GemRB.UnhideGUI ()
55 GUICommonWindows.PortraitWindow = OldPortraitWindow
56 OldPortraitWindow = None
57 GUICommonWindows.OptionsWindow = OldOptionsWindow
58 OldOptionsWindow = None
60 PosX = GemRB.GetVar ("MapControlX")
61 PosY = GemRB.GetVar ("MapControlY")
63 GemRB.RevealArea (PosX, PosY, 30, 1)
64 GemRB.GamePause (0,0)
65 return
67 ###################################################
68 # for farsight effect
69 ###################################################
70 def ShowMap ():
71 global MapWindow, OptionsWindow, PortraitWindow
72 global OldPortraitWindow, OldOptionsWindow
74 if GUICommon.CloseOtherWindow (ShowMap):
75 if MapWindow:
76 MapWindow.Unload ()
77 if OptionsWindow:
78 OptionsWindow.Unload ()
79 if PortraitWindow:
80 PortraitWindow.Unload ()
82 MapWindow = None
83 #this window type should block the game
84 GemRB.SetVar ("OtherWindow", -1)
85 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
86 GemRB.UnhideGUI ()
87 GUICommonWindows.PortraitWindow = OldPortraitWindow
88 OldPortraitWindow = None
89 GUICommonWindows.OptionsWindow = OldOptionsWindow
90 OldOptionsWindow = None
91 return
93 GemRB.HideGUI ()
94 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
96 GemRB.LoadWindowPack ("GUIMAP", 640, 480)
97 MapWindow = Window = GemRB.LoadWindow (2)
98 #this window type blocks the game normally, but map window doesn't
99 GemRB.SetVar ("OtherWindow", MapWindow.ID)
100 #saving the original portrait window
101 OldOptionsWindow = GUICommonWindows.OptionsWindow
102 OptionsWindow = GemRB.LoadWindow (0)
103 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, ShowMap)
104 OldPortraitWindow = GUICommonWindows.PortraitWindow
105 PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
106 OptionsWindow.SetFrame ()
108 # World Map
109 Button = Window.GetControl (1)
110 Button.SetState (IE_GUI_BUTTON_LOCKED)
112 # Map Control
113 Window.CreateMapControl (2, 0, 0, 0, 0)
114 Map = Window.GetControl (2)
115 Map.SetEvent (IE_GUI_MAP_ON_PRESS, RevealMap)
116 Window.SetVisible (WINDOW_VISIBLE)
117 OptionsWindow.SetVisible (WINDOW_GRAYED)
118 PortraitWindow.SetVisible (WINDOW_GRAYED)
119 OptionsWindow.SetVisible (WINDOW_FRONT)
120 PortraitWindow.SetVisible (WINDOW_FRONT)
121 Window.SetVisible (WINDOW_FRONT)
122 Map.SetStatus (IE_GUI_CONTROL_FOCUSED)
123 GemRB.GamePause (0,0)
124 return
126 ###################################################
127 def OpenMapWindow ():
128 global MapWindow, OptionsWindow, PortraitWindow
129 global OldPortraitWindow, OldOptionsWindow
131 if GUICommon.CloseOtherWindow (OpenMapWindow):
132 if MapWindow:
133 MapWindow.Unload ()
134 if OptionsWindow:
135 OptionsWindow.Unload ()
136 if PortraitWindow:
137 PortraitWindow.Unload ()
139 MapWindow = None
140 #this window type should block the game
141 GemRB.SetVar ("OtherWindow", -1)
142 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
143 #OldOptionsWindow.SetVisible (WINDOW_VISIBLE)
144 #OldPortraitWindow.SetVisible (WINDOW_VISIBLE)
145 GemRB.UnhideGUI ()
146 GUICommonWindows.PortraitWindow = OldPortraitWindow
147 OldPortraitWindow = None
148 GUICommonWindows.OptionsWindow = OldOptionsWindow
149 OldOptionsWindow = None
150 return
152 GemRB.HideGUI ()
153 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
155 GemRB.LoadWindowPack ("GUIMAP", 640, 480)
156 MapWindow = Window = GemRB.LoadWindow (2)
157 #this window type blocks the game normally, but map window doesn't
158 GemRB.SetVar ("OtherWindow", MapWindow.ID)
159 #saving the original portrait window
160 OldOptionsWindow = GUICommonWindows.OptionsWindow
161 OptionsWindow = GemRB.LoadWindow (0)
162 GUICommonWindows.MarkMenuButton (OptionsWindow)
163 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 0, OpenMapWindow)
164 OldPortraitWindow = GUICommonWindows.PortraitWindow
165 PortraitWindow = GUICommonWindows.OpenPortraitWindow (0)
166 OptionsWindow.SetFrame ()
168 # World Map
169 Button = Window.GetControl (1)
170 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, OpenWorldMapWindowInside)
172 # Map Control
173 Window.CreateMapControl (2, 0, 0, 0, 0)
174 Map = Window.GetControl (2)
175 Map.SetEvent (IE_GUI_MAP_ON_DOUBLE_PRESS, LeftDoublePressMap)
176 #OldOptionsWindow.SetVisible (WINDOW_INVISIBLE)
177 #OldPortraitWindow.SetVisible (WINDOW_INVISIBLE)
178 OptionsWindow.SetVisible (WINDOW_VISIBLE)
179 Window.SetVisible (WINDOW_VISIBLE)
180 PortraitWindow.SetVisible (WINDOW_VISIBLE)
181 Map.SetStatus (IE_GUI_CONTROL_FOCUSED)
183 def LeftDoublePressMap ():
184 OpenMapWindow()
185 return
187 def OpenWorldMapWindowInside ():
188 global MapWindow
190 OpenMapWindow () #closes mapwindow
191 MapWindow = -1
192 print "MapWindow=",MapWindow
193 WorldMapWindowCommon (-1)
194 return
196 def OpenWorldMapWindow ():
197 WorldMapWindowCommon (GemRB.GetVar ("Travel"))
198 return
200 def MoveToNewArea ():
201 global WorldMapWindow, WorldMapControl
203 tmp = WorldMapControl.GetDestinationArea (1)
204 if tmp["Distance"]==-1:
205 print "Invalid target", tmp
206 return
208 CloseWorldMapWindow ()
209 GemRB.CreateMovement (tmp["Destination"], tmp["Entrance"], tmp["Direction"])
210 return
212 def ChangeTooltip ():
213 global WorldMapWindow, WorldMapControl
214 global str
216 tmp = WorldMapControl.GetDestinationArea ()
217 if (tmp):
218 str = "%s: %d"%(GemRB.GetString(23084),tmp["Distance"])
219 else:
220 str=""
222 WorldMapControl.SetTooltip (str)
223 return
225 def CloseWorldMapWindow ():
226 global WorldMapWindow, WorldMapControl
228 print "CloseWorldMapWindow found Mapwindow = ",MapWindow
229 if MapWindow:
230 # reopen map window
231 if WorldMapWindow:
232 WorldMapWindow.Unload ()
233 WorldMapWindow = None
234 WorldMapControl = None
235 OpenMapWindow ()
236 return
238 if WorldMapWindow:
239 WorldMapWindow.Unload ()
240 WorldMapWindow = None
241 WorldMapControl = None
242 GUICommon.GameWindow.SetVisible(WINDOW_VISIBLE)
243 GemRB.UnhideGUI ()
244 return
246 def WorldMapWindowCommon (Travel):
247 global WorldMapWindow, WorldMapControl
249 if WorldMapWindow:
250 CloseWorldMapWindow ()
251 return
253 GemRB.HideGUI ()
254 GUICommon.GameWindow.SetVisible(WINDOW_INVISIBLE)
256 GemRB.LoadWindowPack ("GUIWMAP", 640, 480)
257 WorldMapWindow = Window = GemRB.LoadWindow (0)
258 #saving the original portrait window
259 Window.SetFrame ()
261 Window.CreateWorldMapControl (4, 0, 62, 640, 418, Travel, "toolfont")
262 WorldMapControl = Window.GetControl (4)
263 WorldMapControl.SetAnimation ("WMDAG")
264 WorldMapControl.SetEvent (IE_GUI_WORLDMAP_ON_PRESS, MoveToNewArea)
265 WorldMapControl.SetEvent (IE_GUI_MOUSE_ENTER_WORLDMAP, ChangeTooltip)
266 #center on current area
267 WorldMapControl.AdjustScrolling (0, 0)
269 #north
270 Button = Window.GetControl (1)
271 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapN)
273 #south
274 Button = Window.GetControl (2)
275 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, MapS)
277 # Done
278 Button = Window.GetControl (0)
279 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, CloseWorldMapWindow)
280 Button.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
281 Window.SetVisible (WINDOW_VISIBLE)
282 return
284 def MapN():
285 WorldMapControl.AdjustScrolling (0, -10)
286 return
288 def MapS():
289 WorldMapControl.AdjustScrolling (0, 10)
290 return
293 ###################################################
294 # End of file GUIMA.py