2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 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 # GUISAVE.py - Save game screen from GUISAVE winpack
23 ###################################################
26 from GUIDefines
import *
27 from LoadScreen
import *
28 from GUIClasses
import GWindow
31 SaveDetailWindow
= None
37 def OpenSaveWindow ():
38 global SaveWindow
, OptionsWindow
, Games
, ScrollBar
43 if SaveDetailWindow
: OpenSaveDetailWindow ()
49 GemRB
.SetVar ("OtherWindow", OptionsWindow
.ID
)
55 GemRB
.LoadWindowPack ("GUISAVE", 640, 480)
56 SaveWindow
= Window
= GemRB
.LoadWindow (0)
57 OptionsWindow
= GWindow( GemRB
.GetVar ("OtherWindow") )
58 GemRB
.SetVar ("OtherWindow", SaveWindow
.ID
)
61 CancelButton
= Window
.GetControl (46)
62 CancelButton
.SetText (4196)
63 CancelButton
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "CancelPress")
64 CancelButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
65 GemRB
.SetVar ("SaveIdx", 0)
68 Button
= Window
.GetControl (14 + i
)
69 Button
.SetText (28645)
70 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "SaveGamePress")
71 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
72 Button
.SetVarAssoc ("SaveIdx", i
)
74 Button
= Window
.GetControl (18 + i
)
75 Button
.SetText (28640)
76 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "DeleteGamePress")
77 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
78 Button
.SetVarAssoc ("SaveIdx", i
)
81 Button
= Window
.GetControl (1 + i
)
82 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE
, OP_SET
)
86 Button
= Window
.GetControl (22 + i
*6 + j
)
87 Button
.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE
, OP_SET
)
89 ScrollBar
= Window
.GetControl(13)
90 ScrollBar
.SetEventByName(IE_GUI_SCROLLBAR_ON_CHANGE
, "ScrollBarPress")
91 Games
= GemRB
.GetSaveGames()
92 TopIndex
= max (0, len(Games
) - 4 + 1) #one more for the 'new game'
94 GemRB
.SetVar ("TopIndex",TopIndex
)
95 ScrollBar
.SetVarAssoc ("TopIndex", len(Games
))
101 def ScrollBarPress():
103 # draw load game portraits
104 Pos
= GemRB
.GetVar ("TopIndex")
108 Button1
= Window
.GetControl (14 + i
)
109 Button2
= Window
.GetControl (18 + i
)
110 if ActPos
<= len(Games
):
111 Button1
.SetState(IE_GUI_BUTTON_ENABLED
)
113 Button1
.SetState(IE_GUI_BUTTON_DISABLED
)
115 if ActPos
< len(Games
):
116 Slotname
= Games
[ActPos
].GetName()
117 Slottime
= Games
[ActPos
].GetDate()
118 Button2
.SetState(IE_GUI_BUTTON_ENABLED
)
119 elif ActPos
== len(Games
):
120 Slotname
= 28647 # "Empty"
122 Button2
.SetState(IE_GUI_BUTTON_DISABLED
)
126 Button2
.SetState(IE_GUI_BUTTON_DISABLED
)
128 Label
= Window
.GetControl (0x10000004+i
)
129 Label
.SetText (Slotname
)
131 Label
= Window
.GetControl (0x10000008 + i
)
132 Label
.SetText (Slottime
)
134 Button
= Window
.GetControl (1 + i
)
135 if ActPos
< len(Games
):
136 Button
.SetSprite2D(Games
[ActPos
].GetPreview())
138 Button
.SetPicture ("")
141 Button
= Window
.GetControl (22 + i
*6 + j
)
142 if ActPos
< len(Games
):
143 Button
.SetSprite2D(Games
[ActPos
].GetPortrait(j
))
145 Button
.SetPicture ("")
148 def SaveGamePress ():
149 OpenSaveDetailWindow ()
152 def DeleteGameConfirm():
155 TopIndex
= GemRB
.GetVar("TopIndex")
156 Pos
= TopIndex
+GemRB
.GetVar("SaveIdx")
157 GemRB
.DeleteSaveGame(Games
[Pos
])
159 GemRB
.SetVar("TopIndex",TopIndex
-1)
161 ScrollBar
.SetVarAssoc("TopIndex", len(Games
))
164 ConfirmWindow
.Unload()
165 SaveWindow
.SetVisible(WINDOW_VISIBLE
)
168 def DeleteGameCancel():
170 ConfirmWindow
.Unload()
171 SaveWindow
.SetVisible(WINDOW_VISIBLE
)
174 def DeleteGamePress():
177 SaveWindow
.SetVisible(WINDOW_INVISIBLE
)
178 ConfirmWindow
=GemRB
.LoadWindow(1)
180 Text
=ConfirmWindow
.GetControl(0)
183 DeleteButton
=ConfirmWindow
.GetControl(1)
184 DeleteButton
.SetText(13957)
185 DeleteButton
.SetEventByName(IE_GUI_BUTTON_ON_PRESS
, "DeleteGameConfirm")
186 DeleteButton
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
188 CancelButton
=ConfirmWindow
.GetControl(2)
189 CancelButton
.SetText(4196)
190 CancelButton
.SetEventByName(IE_GUI_BUTTON_ON_PRESS
, "DeleteGameCancel")
191 CancelButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
193 ConfirmWindow
.SetVisible(WINDOW_VISIBLE
)
200 def OpenSaveDetailWindow ():
201 global SaveDetailWindow
205 if SaveDetailWindow
!= None:
207 SaveDetailWindow
.Unload ()
208 SaveDetailWindow
= None
209 GemRB
.SetVar ("FloatWindow", -1)
214 SaveDetailWindow
= Window
= GemRB
.LoadWindow (1)
215 GemRB
.SetVar ("FloatWindow", SaveDetailWindow
.ID
)
218 Pos
= GemRB
.GetVar ("TopIndex") + GemRB
.GetVar ("SaveIdx")
222 Button
= Window
.GetControl (4)
224 Button
.SetText (28644) # Overwrite
226 Button
.SetText (28645) # Save
227 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "ConfirmedSaveGame")
228 Button
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
231 Button
= Window
.GetControl (5)
232 Button
.SetText (4196)
233 Button
.SetEventByName (IE_GUI_BUTTON_ON_PRESS
, "OpenSaveDetailWindow")
234 Button
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
238 Slotname
= Games
[Pos
].GetName()
239 Slottime
= Games
[Pos
].GetGameDate()
244 Edit
= Window
.GetControl (1)
245 Edit
.SetText (Slotname
)
246 Edit
.SetEventByName (IE_GUI_EDIT_ON_CHANGE
, "CheckSaveName")
247 Edit
.SetEventByName (IE_GUI_EDIT_ON_DONE
, "ConfirmedSaveGame")
249 Label
= Window
.GetControl (0x10000002)
250 Label
.SetText (Slottime
)
254 Button
= Window
.GetControl (0)
255 Button
.SetSprite2D(GemRB
.GetGamePreview())
258 for j
in range (PARTY_SIZE
):
259 Button
= Window
.GetControl (6 + j
)
260 Button
.SetSprite2D(GemRB
.GetGamePortraitPreview(j
))
265 Window
.ShowModal (MODAL_SHADOW_GRAY
)
266 Edit
.SetStatus (IE_GUI_CONTROL_FOCUSED
) # ShowModal will happily reset this..
269 # Disable Save/Overwrite button if the save slotname is empty,
271 def CheckSaveName ():
272 Window
= SaveDetailWindow
273 Button
= Window
.GetControl (4)
274 Edit
= Window
.GetControl (1)
275 Name
= Edit
.QueryText ()
278 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
280 Button
.SetState (IE_GUI_BUTTON_ENABLED
)
284 # User entered save name and pressed save/overwrite.
285 # Display progress bar screen and save the game, close the save windows
286 def ConfirmedSaveGame ():
287 Window
= SaveDetailWindow
289 Pos
= GemRB
.GetVar ("TopIndex") + GemRB
.GetVar ("SaveIdx")
290 Label
= Window
.GetControl (1)
291 Slotname
= Label
.QueryText ()
293 # Empty save name. We can get here if user presses Enter key
297 # We have to close floating window first
298 OpenSaveDetailWindow ()
299 StartLoadScreen (LS_TYPE_SAVING
)
301 GemRB
.SaveGame(Games
[Pos
], Slotname
)
303 GemRB
.SaveGame(None, Slotname
)
307 # Exit either back to game or to the Start window
308 def CloseSaveWindow ():
310 if GemRB
.GetVar ("QuitAfterSave"):
312 GemRB
.SetNextScript ("Start")
315 GemRB
.RunEventHandler ("OpenOptionsWindow")