TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / iwd / GUILOAD.py
blobf8d10bdf5f37a11b6d5936fc738da8889918d066
1 # -*-python-*-
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 # GUILOAD.py - Load window
23 ###################################################
25 import GemRB
26 import LoadScreen
27 from GUIDefines import *
29 LoadWindow = 0
30 TextAreaControl = 0
31 Games = ()
32 ScrollBar = 0
34 def OnLoad ():
35 global LoadWindow, TextAreaControl, Games, ScrollBar
37 GemRB.SetVar ("PlayMode",0) #iwd is always using 'mpsave'
38 GemRB.SetVar ("SaveDir",1) #iwd is always using 'mpsave'
39 GemRB.LoadWindowPack ("GUILOAD", 640, 480)
40 LoadWindow = GemRB.LoadWindow (0)
41 LoadWindow.SetFrame ()
42 CancelButton=LoadWindow.GetControl (34)
43 CancelButton.SetText (13727)
44 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CancelPress)
45 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
47 GemRB.SetVar ("LoadIdx",0)
48 for i in range (4):
49 Button = LoadWindow.GetControl (26+i)
50 Button.SetText (15590)
51 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, LoadGamePress)
52 Button.SetState (IE_GUI_BUTTON_DISABLED)
53 Button.SetVarAssoc ("LoadIdx",i)
55 Button = LoadWindow.GetControl (30+i)
56 Button.SetText (13957)
57 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGamePress)
58 Button.SetState (IE_GUI_BUTTON_DISABLED)
59 Button.SetVarAssoc ("LoadIdx",i)
61 #area previews
62 Button = LoadWindow.GetControl (1+i)
63 Button.SetState (IE_GUI_BUTTON_LOCKED)
64 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
66 #PC portraits
67 for j in range (PARTY_SIZE):
68 Button = LoadWindow.GetControl (40 + i*PARTY_SIZE + j)
69 Button.SetState (IE_GUI_BUTTON_LOCKED)
70 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
72 ScrollBar=LoadWindow.GetControl (25)
73 ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ScrollBarPress)
74 Games=GemRB.GetSaveGames ()
75 TopIndex = max (0, len(Games) - 4)
76 GemRB.SetVar ("TopIndex",TopIndex)
77 ScrollBar.SetVarAssoc ("TopIndex", TopIndex+1)
78 ScrollBarPress ()
79 LoadWindow.SetVisible (WINDOW_VISIBLE)
80 return
82 def ScrollBarPress ():
83 #draw load game portraits
84 Pos = GemRB.GetVar ("TopIndex")
85 for i in range (4):
86 ActPos = Pos + i
88 Button1 = LoadWindow.GetControl (26+i)
89 Button2 = LoadWindow.GetControl (30+i)
90 if ActPos<len(Games):
91 Button1.SetState (IE_GUI_BUTTON_ENABLED)
92 Button2.SetState (IE_GUI_BUTTON_ENABLED)
93 else:
94 Button1.SetState (IE_GUI_BUTTON_DISABLED)
95 Button2.SetState (IE_GUI_BUTTON_DISABLED)
97 if ActPos<len(Games):
98 Slotname = Games[ActPos].GetName()
99 else:
100 Slotname = ""
101 Label = LoadWindow.GetControl (0x10000008+i)
102 Label.SetText (Slotname)
104 if ActPos<len(Games):
105 Slotname = Games[ActPos].GetGameDate()
106 else:
107 Slotname = ""
108 Label = LoadWindow.GetControl (0x10000010+i)
109 Label.SetText (Slotname)
111 Button=LoadWindow.GetControl (1+i)
112 if ActPos<len(Games):
113 Button.SetSprite2D(Games[ActPos].GetPreview())
114 else:
115 Button.SetPicture ("")
116 for j in range (PARTY_SIZE):
117 Button=LoadWindow.GetControl (40 + i*PARTY_SIZE + j)
118 if ActPos<len(Games):
119 Button.SetSprite2D(Games[ActPos].GetPortrait(j))
120 else:
121 Button.SetPicture ("")
122 return
124 def LoadGamePress ():
125 if LoadWindow:
126 LoadWindow.Unload ()
127 Pos = GemRB.GetVar ("TopIndex")+GemRB.GetVar ("LoadIdx")
128 LoadScreen.StartLoadScreen()
129 GemRB.LoadGame(Games[Pos]) #loads and enters savegame
130 GemRB.SetNextScript ("PartyFormation")
131 return
133 def DeleteGameConfirm():
134 global Games
136 TopIndex = GemRB.GetVar ("TopIndex")
137 Pos = TopIndex +GemRB.GetVar ("LoadIdx")
138 GemRB.DeleteSaveGame(Games[Pos])
139 if TopIndex>0:
140 GemRB.SetVar ("TopIndex",TopIndex-1)
141 del Games[Pos]
142 ScrollBar.SetVarAssoc ("TopIndex", len(Games))
143 ScrollBarPress ()
144 if ConfirmWindow:
145 ConfirmWindow.Unload ()
146 LoadWindow.SetVisible (WINDOW_VISIBLE)
147 return
149 def DeleteGameCancel ():
150 if ConfirmWindow:
151 ConfirmWindow.Unload ()
152 LoadWindow.SetVisible (WINDOW_VISIBLE)
153 return
155 def DeleteGamePress ():
156 global ConfirmWindow
158 LoadWindow.SetVisible (WINDOW_INVISIBLE)
159 ConfirmWindow=GemRB.LoadWindow (1)
160 Text=ConfirmWindow.GetControl (0)
161 Text.SetText (15305)
162 DeleteButton=ConfirmWindow.GetControl (1)
163 DeleteButton.SetText (13957)
164 DeleteButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGameConfirm)
165 CancelButton=ConfirmWindow.GetControl (2)
166 CancelButton.SetText (13727)
167 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGameCancel)
168 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
170 ConfirmWindow.SetVisible (WINDOW_VISIBLE)
171 return
173 def CancelPress ():
174 if LoadWindow:
175 LoadWindow.Unload ()
176 GemRB.SetNextScript ("Start")
177 return