fixed the rest of the functions that needed globalid capabilities
[gemrb.git] / gemrb / GUIScripts / bg2 / GUILOAD.py
blob12049ee2bb91c3de3710b98d8fc5b96b111e611a
1 # GemRB - Infinity Engine Emulator
2 # Copyright (C) 2003 The GemRB Project
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #load window
20 import GemRB
21 import LoadScreen
23 LoadWindow = 0
24 TextAreaControl = 0
25 Games = ()
26 ScrollBar = 0
28 def OnLoad():
29 global LoadWindow, TextAreaControl, Games, ScrollBar
31 GemRB.LoadWindowPack("GUILOAD", 640, 480)
32 LoadWindow = GemRB.LoadWindow(0)
33 LoadWindow.SetFrame ()
34 CancelButton=LoadWindow.GetControl(34)
35 CancelButton.SetText(13727)
36 CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CancelPress)
37 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
38 GemRB.SetVar("LoadIdx",0)
40 for i in range(4):
41 Button = LoadWindow.GetControl(26+i)
42 Button.SetText(15590)
43 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, LoadGamePress)
44 Button.SetState(IE_GUI_BUTTON_DISABLED)
45 Button.SetVarAssoc("LoadIdx",i)
47 Button = LoadWindow.GetControl(30+i)
48 Button.SetText(13957)
49 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, DeleteGamePress)
50 Button.SetState(IE_GUI_BUTTON_DISABLED)
51 Button.SetVarAssoc("LoadIdx",i)
53 #area previews
54 Button = LoadWindow.GetControl(1+i)
55 Button.SetState(IE_GUI_BUTTON_LOCKED)
56 Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
58 #PC portraits
59 for j in range(PARTY_SIZE):
60 Button = LoadWindow.GetControl(40+i*PARTY_SIZE+j)
61 Button.SetState(IE_GUI_BUTTON_LOCKED)
62 Button.SetFlags(IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
64 ScrollBar=LoadWindow.GetControl(25)
65 ScrollBar.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, ScrollBarPress)
66 Games=GemRB.GetSaveGames()
67 TopIndex = max (0, len(Games) - 4)
68 GemRB.SetVar ("TopIndex",TopIndex)
69 ScrollBar.SetVarAssoc ("TopIndex", TopIndex+1)
70 ScrollBarPress ()
71 LoadWindow.SetVisible (WINDOW_VISIBLE)
72 return
74 def ScrollBarPress():
75 #draw load game portraits
76 Pos = GemRB.GetVar("TopIndex")
77 for i in range(4):
78 ActPos = Pos + i
80 Button1 = LoadWindow.GetControl(26+i)
81 Button2 = LoadWindow.GetControl(30+i)
82 if ActPos<len(Games):
83 Button1.SetState(IE_GUI_BUTTON_ENABLED)
84 Button2.SetState(IE_GUI_BUTTON_ENABLED)
85 else:
86 Button1.SetState(IE_GUI_BUTTON_DISABLED)
87 Button2.SetState(IE_GUI_BUTTON_DISABLED)
89 if ActPos<len(Games):
90 Slotname = Games[ActPos].GetName()
91 else:
92 Slotname = ""
93 Label = LoadWindow.GetControl(0x10000008+i)
94 Label.SetText(Slotname)
96 if ActPos<len(Games):
97 Slotname = Games[ActPos].GetGameDate()
98 else:
99 Slotname = ""
100 Label = LoadWindow.GetControl(0x10000010+i)
101 Label.SetText(Slotname)
103 Button=LoadWindow.GetControl(1+i)
104 if ActPos<len(Games):
105 Button.SetSprite2D(Games[ActPos].GetPreview())
106 else:
107 Button.SetPicture("")
108 for j in range(PARTY_SIZE):
109 Button=LoadWindow.GetControl(40+i*PARTY_SIZE+j)
110 if ActPos<len(Games):
111 Button.SetSprite2D(Games[ActPos].GetPortrait(j))
112 else:
113 Button.SetPicture("")
114 return
116 def LoadGamePress():
117 if LoadWindow:
118 LoadWindow.Unload()
119 Pos = GemRB.GetVar("TopIndex")+GemRB.GetVar("LoadIdx")
120 LoadScreen.StartLoadScreen()
121 #loads savegame
122 GemRB.LoadGame(Games[Pos])
123 #performs conversion to ToB
124 if (GemRB.GetVar("oldgame")==0) and GemRB.GetVar("expansion")==1:
125 GemRB.GameSetExpansion()
127 #enters game
128 GemRB.EnterGame() #it will close windows, including the loadscreen
129 return
131 def DeleteGameConfirm():
132 global Games
134 TopIndex = GemRB.GetVar("TopIndex")
135 Pos = TopIndex +GemRB.GetVar("LoadIdx")
136 GemRB.DeleteSaveGame(Games[Pos])
137 if TopIndex>0:
138 GemRB.SetVar("TopIndex",TopIndex-1)
139 del Games[Pos]
140 ScrollBar.SetVarAssoc("TopIndex", len(Games))
141 ScrollBarPress()
142 if ConfirmWindow:
143 ConfirmWindow.Unload()
144 LoadWindow.SetVisible(WINDOW_VISIBLE)
145 return
147 def DeleteGameCancel():
148 if ConfirmWindow:
149 ConfirmWindow.Unload()
150 LoadWindow.SetVisible(WINDOW_VISIBLE)
151 return
153 def DeleteGamePress():
154 global ConfirmWindow
156 LoadWindow.SetVisible(WINDOW_INVISIBLE)
157 ConfirmWindow=GemRB.LoadWindow(1)
158 Text=ConfirmWindow.GetControl(0)
159 Text.SetText(15305)
160 DeleteButton=ConfirmWindow.GetControl(1)
161 DeleteButton.SetText(13957)
162 DeleteButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DeleteGameConfirm)
163 CancelButton=ConfirmWindow.GetControl(2)
164 CancelButton.SetText(13727)
165 CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, DeleteGameCancel)
166 ConfirmWindow.SetVisible(WINDOW_VISIBLE)
167 return
169 def CancelPress():
170 if LoadWindow:
171 LoadWindow.Unload()
172 GemRB.SetNextScript("Start")
173 return