GUIScript: Split GetSaveGameAttrib into separate functions.
[gemrb.git] / gemrb / GUIScripts / bg1 / GUILOAD.py
blob3ae3f867b3c9b14a5c4c0541aefdbfaaf9dd21e4
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 from LoadScreen import *
28 LoadWindow = 0
29 TextAreaControl = 0
30 GameCount = 0
31 ScrollBar = 0
33 def OnLoad ():
34 global LoadWindow, TextAreaControl, GameCount, ScrollBar
36 GemRB.LoadWindowPack ("GUILOAD", 640, 480)
37 LoadWindow = GemRB.LoadWindowObject (0)
38 LoadWindow.SetFrame ()
40 CancelButton=LoadWindow.GetControl (34)
41 CancelButton.SetText (13727)
42 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "CancelPress")
43 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
45 GemRB.SetVar ("LoadIdx",0)
46 for i in range (4):
47 Button = LoadWindow.GetControl (26+i)
48 Button.SetText (15590)
49 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "LoadGamePress")
50 Button.SetState (IE_GUI_BUTTON_DISABLED)
51 Button.SetVarAssoc ("LoadIdx",i)
53 Button = LoadWindow.GetControl (30+i)
54 Button.SetText (13957)
55 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, "DeleteGamePress")
56 Button.SetState (IE_GUI_BUTTON_DISABLED)
57 Button.SetVarAssoc ("LoadIdx",i)
59 #area previews
60 Button = LoadWindow.GetControl (1+i)
61 Button.SetState (IE_GUI_BUTTON_LOCKED)
62 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
64 #PC portraits
65 for j in range (PARTY_SIZE):
66 Button = LoadWindow.GetControl (40 + i*PARTY_SIZE + j)
67 Button.SetState (IE_GUI_BUTTON_LOCKED)
68 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
70 ScrollBar=LoadWindow.GetControl (25)
71 ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, "ScrollBarPress")
72 GameCount=GemRB.GetSaveGameCount () #count of games in save folder?
73 if GameCount>4:
74 TopIndex = GameCount-4
75 else:
76 TopIndex = 0
77 GemRB.SetVar ("TopIndex",TopIndex)
78 ScrollBar.SetVarAssoc ("TopIndex", TopIndex+1)
79 ScrollBarPress ()
80 LoadWindow.SetVisible (WINDOW_VISIBLE)
81 return
83 def ScrollBarPress ():
84 #draw load game portraits
85 Pos = GemRB.GetVar ("TopIndex")
86 for i in range (4):
87 ActPos = Pos + i
89 Button1 = LoadWindow.GetControl (26+i)
90 Button2 = LoadWindow.GetControl (30+i)
91 if ActPos<GameCount:
92 Button1.SetState (IE_GUI_BUTTON_ENABLED)
93 Button2.SetState (IE_GUI_BUTTON_ENABLED)
94 else:
95 Button1.SetState (IE_GUI_BUTTON_DISABLED)
96 Button2.SetState (IE_GUI_BUTTON_DISABLED)
98 if ActPos<GameCount:
99 Slotname = GemRB.GetSaveGameName(ActPos)
100 else:
101 Slotname = ""
102 Label = LoadWindow.GetControl (0x10000008+i)
103 Label.SetText (Slotname)
105 if ActPos<GameCount:
106 Slotname = GemRB.GetSaveGameDate(ActPos)
107 else:
108 Slotname = ""
109 Label = LoadWindow.GetControl (0x10000010+i)
110 Label.SetText (Slotname)
112 Button=LoadWindow.GetControl (1+i)
113 if ActPos<GameCount:
114 Button.SetSprite2D(GemRB.GetSaveGamePreview(ActPos))
115 else:
116 Button.SetPicture ("")
117 for j in range (PARTY_SIZE):
118 Button=LoadWindow.GetControl (40 + i*PARTY_SIZE + j)
119 if ActPos<GameCount:
120 Button.SetSprite2D(GemRB.GetSaveGamePortrait(ActPos, j))
121 else:
122 Button.SetPicture ("")
123 return
125 def LoadGamePress ():
126 if LoadWindow:
127 LoadWindow.Unload ()
128 Pos = GemRB.GetVar ("TopIndex")+GemRB.GetVar ("LoadIdx")
129 StartLoadScreen()
130 GemRB.LoadGame (Pos) #loads and enters savegame
131 GemRB.EnterGame ()
132 return
134 def DeleteGameConfirm():
135 global GameCount
137 TopIndex = GemRB.GetVar ("TopIndex")
138 Pos = TopIndex +GemRB.GetVar ("LoadIdx")
139 GemRB.DeleteSaveGame (Pos)
140 if TopIndex>0:
141 GemRB.SetVar ("TopIndex",TopIndex-1)
142 GameCount=GemRB.GetSaveGameCount () #count of games in save folder?
143 ScrollBar.SetVarAssoc ("TopIndex", GameCount)
144 ScrollBarPress ()
145 if ConfirmWindow:
146 ConfirmWindow.Unload ()
147 LoadWindow.SetVisible (WINDOW_VISIBLE)
148 return
150 def DeleteGameCancel ():
151 if ConfirmWindow:
152 ConfirmWindow.Unload ()
153 LoadWindow.SetVisible (WINDOW_VISIBLE)
154 return
156 def DeleteGamePress ():
157 global ConfirmWindow
159 LoadWindow.SetVisible (WINDOW_INVISIBLE)
160 ConfirmWindow=GemRB.LoadWindowObject (1)
161 Text=ConfirmWindow.GetControl (0)
162 Text.SetText (15305)
163 DeleteButton=ConfirmWindow.GetControl (1)
164 DeleteButton.SetText (13957)
165 DeleteButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "DeleteGameConfirm")
166 CancelButton=ConfirmWindow.GetControl (2)
167 CancelButton.SetText (13727)
168 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, "DeleteGameCancel")
169 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
171 ConfirmWindow.SetVisible (WINDOW_VISIBLE)
172 return
174 def CancelPress ():
175 if LoadWindow:
176 LoadWindow.Unload ()
177 GemRB.SetNextScript ("Start")
178 return