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 window
23 ###################################################
28 from GUIDefines
import *
38 def OpenSaveWindow ():
39 global SaveWindow
, TextAreaControl
, Games
, ScrollBar
41 if GUICommon
.CloseOtherWindow (OpenSaveWindow
):
46 GUICommon
.GameWindow
.SetVisible(WINDOW_INVISIBLE
)
48 GemRB
.LoadWindowPack ("GUISAVE", 640, 480)
49 Window
= SaveWindow
= GemRB
.LoadWindow (0)
51 CancelButton
=Window
.GetControl (34)
52 CancelButton
.SetText (13727)
53 CancelButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, OpenSaveWindow
)
54 CancelButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
55 GemRB
.SetVar ("LoadIdx",0)
58 Button
= Window
.GetControl (26+i
)
59 Button
.SetText (15588)
60 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, SavePress
)
61 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
62 Button
.SetVarAssoc ("LoadIdx",i
)
64 Button
= Window
.GetControl (30+i
)
65 Button
.SetText (13957)
66 Button
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DeleteGamePress
)
67 Button
.SetState (IE_GUI_BUTTON_DISABLED
)
68 Button
.SetVarAssoc ("LoadIdx",i
)
71 Button
= Window
.GetControl (1+i
)
72 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
73 Button
.SetFlags(IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE
,OP_SET
)
76 for j
in range(PARTY_SIZE
):
77 Button
= Window
.GetControl (40+i
*PARTY_SIZE
+j
)
78 Button
.SetState (IE_GUI_BUTTON_LOCKED
)
79 Button
.SetFlags(IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE
,OP_SET
)
81 ScrollBar
=Window
.GetControl (25)
82 ScrollBar
.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE
, ScrollBarPress
)
83 Games
=GemRB
.GetSaveGames ()
84 TopIndex
= max (0, len(Games
) - 4 + 1) #one more for the 'new game'
85 GemRB
.SetVar ("TopIndex",TopIndex
)
86 ScrollBar
.SetVarAssoc ("TopIndex", TopIndex
+1)
87 ScrollBar
.SetDefaultScrollBar ()
89 Window
.SetVisible (WINDOW_VISIBLE
)
95 #draw load game portraits
96 Pos
= GemRB
.GetVar ("TopIndex")
100 Button1
= Window
.GetControl (26+i
)
101 Button2
= Window
.GetControl (30+i
)
102 if ActPos
<=len(Games
):
103 Button1
.SetState (IE_GUI_BUTTON_ENABLED
)
105 Button1
.SetState (IE_GUI_BUTTON_DISABLED
)
107 if ActPos
<len(Games
):
108 Slotname
= Games
[ActPos
].GetName()
109 Button2
.SetState (IE_GUI_BUTTON_ENABLED
)
110 elif ActPos
== len(Games
):
112 Button2
.SetState (IE_GUI_BUTTON_DISABLED
)
115 Button2
.SetState (IE_GUI_BUTTON_DISABLED
)
117 Label
= Window
.GetControl (0x10000008+i
)
118 Label
.SetText (Slotname
)
120 if ActPos
<len(Games
):
121 Slotname
= Games
[ActPos
].GetGameDate()
124 Label
= Window
.GetControl (0x10000010+i
)
125 Label
.SetText (Slotname
)
127 Button
=Window
.GetControl (1+i
)
128 if ActPos
<len(Games
):
129 Button
.SetSprite2D(Games
[ActPos
].GetPreview())
131 Button
.SetPicture("")
132 for j
in range(PARTY_SIZE
):
133 Button
=Window
.GetControl (40+i
*PARTY_SIZE
+j
)
134 if ActPos
<len(Games
):
135 Button
.SetSprite2D(Games
[ActPos
].GetPortrait(j
))
137 Button
.SetPicture("")
140 def AbortedSaveGame():
142 ConfirmWindow
.Unload ()
143 SaveWindow
.SetVisible (WINDOW_VISIBLE
)
146 def ConfirmedSaveGame():
149 Pos
= GemRB
.GetVar ("TopIndex")+GemRB
.GetVar ("LoadIdx")
150 Label
= ConfirmWindow
.GetControl (3)
151 Slotname
= Label
.QueryText ()
152 LoadScreen
.StartLoadScreen()
154 GemRB
.SaveGame(Games
[Pos
], Slotname
)
156 GemRB
.SaveGame(None, Slotname
)
158 ConfirmWindow
.Unload ()
159 SaveWindow
.SetVisible (WINDOW_VISIBLE
)
163 global ConfirmWindow
, NameField
, SaveButton
165 Pos
= GemRB
.GetVar ("TopIndex")+GemRB
.GetVar ("LoadIdx")
166 ConfirmWindow
= GemRB
.LoadWindow (1)
170 Slotname
= Games
[Pos
].GetName()
175 NameField
= ConfirmWindow
.GetControl (3)
176 NameField
.SetText (Slotname
)
177 NameField
.SetEvent (IE_GUI_EDIT_ON_CHANGE
, EditChange
)
179 #game hours (should be generated from game)
181 Slotname
= Games
[Pos
].GetGameDate()
184 Label
= ConfirmWindow
.GetControl (0x10000004)
185 Label
.SetText (Slotname
)
188 Button
=ConfirmWindow
.GetControl (0)
190 Button
.SetSprite2D(Games
[Pos
].GetPreview())
192 Button
.SetPicture("")
195 for j
in range(PARTY_SIZE
):
196 Button
=ConfirmWindow
.GetControl (40+j
)
198 Button
.SetSprite2D(Games
[Pos
].GetPortrait(j
))
200 Button
.SetPicture("")
203 SaveButton
=ConfirmWindow
.GetControl (7)
204 SaveButton
.SetText (save_strref
)
205 SaveButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, ConfirmedSaveGame
)
206 SaveButton
.SetFlags (IE_GUI_BUTTON_DEFAULT
, OP_OR
)
207 #SaveButton.SetState (IE_GUI_BUTTON_DISABLED)
209 SaveButton
.SetState (IE_GUI_BUTTON_DISABLED
)
212 CancelButton
=ConfirmWindow
.GetControl (8)
213 CancelButton
.SetText (13727)
214 CancelButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, AbortedSaveGame
)
215 CancelButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
217 ConfirmWindow
.SetVisible (WINDOW_VISIBLE
)
218 NameField
.SetStatus (IE_GUI_CONTROL_FOCUSED
)
222 Name
= NameField
.QueryText ()
224 SaveButton
.SetState (IE_GUI_BUTTON_DISABLED
)
226 SaveButton
.SetState (IE_GUI_BUTTON_ENABLED
)
229 def DeleteGameConfirm():
232 TopIndex
= GemRB
.GetVar ("TopIndex")
233 Pos
= TopIndex
+GemRB
.GetVar ("LoadIdx")
234 GemRB
.DeleteSaveGame(Games
[Pos
])
236 GemRB
.SetVar ("TopIndex",TopIndex
-1)
238 ScrollBar
.SetVarAssoc ("TopIndex", len(Games
))
241 ConfirmWindow
.Unload ()
242 SaveWindow
.SetVisible (WINDOW_VISIBLE
)
245 def DeleteGameCancel():
247 ConfirmWindow
.Unload ()
248 SaveWindow
.SetVisible (WINDOW_VISIBLE
)
251 def DeleteGamePress():
254 SaveWindow
.SetVisible (WINDOW_INVISIBLE
)
255 ConfirmWindow
=GemRB
.LoadWindow (2)
256 Text
=ConfirmWindow
.GetControl (0)
258 DeleteButton
=ConfirmWindow
.GetControl (1)
259 DeleteButton
.SetText (13957)
260 DeleteButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DeleteGameConfirm
)
261 CancelButton
=ConfirmWindow
.GetControl (2)
262 CancelButton
.SetText (13727)
263 CancelButton
.SetEvent (IE_GUI_BUTTON_ON_PRESS
, DeleteGameCancel
)
264 CancelButton
.SetFlags (IE_GUI_BUTTON_CANCEL
, OP_OR
)
266 ConfirmWindow
.SetVisible (WINDOW_VISIBLE
)
269 def CloseSaveWindow ():
272 if GemRB
.GetVar ("QuitAfterSave"):
274 GemRB
.SetNextScript ("Start")
277 GUICommon
.GameWindow
.SetVisible(WINDOW_VISIBLE
) #enabling the game control screen
278 GemRB
.UnhideGUI () #enabling the other windows