factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / GUIScripts / bg1 / GUILOAD.py
blob316ec8403bf3f6491221a2df380defb4b4022fb9
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.LoadWindowPack ("GUILOAD", 640, 480)
38 LoadWindow = GemRB.LoadWindow (0)
39 LoadWindow.SetFrame ()
41 CancelButton=LoadWindow.GetControl (34)
42 CancelButton.SetText (13727)
43 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CancelPress)
44 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
46 GemRB.SetVar ("LoadIdx",0)
47 for i in range (4):
48 Button = LoadWindow.GetControl (26+i)
49 Button.SetText (15590)
50 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, LoadGamePress)
51 Button.SetState (IE_GUI_BUTTON_DISABLED)
52 Button.SetVarAssoc ("LoadIdx",i)
54 Button = LoadWindow.GetControl (30+i)
55 Button.SetText (13957)
56 Button.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGamePress)
57 Button.SetState (IE_GUI_BUTTON_DISABLED)
58 Button.SetVarAssoc ("LoadIdx",i)
60 #area previews
61 Button = LoadWindow.GetControl (1+i)
62 Button.SetState (IE_GUI_BUTTON_LOCKED)
63 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
65 #PC portraits
66 for j in range (PARTY_SIZE):
67 Button = LoadWindow.GetControl (40 + i*PARTY_SIZE + j)
68 Button.SetState (IE_GUI_BUTTON_LOCKED)
69 Button.SetFlags (IE_GUI_BUTTON_NO_IMAGE|IE_GUI_BUTTON_PICTURE,OP_SET)
71 ScrollBar=LoadWindow.GetControl (25)
72 ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, ScrollBarPress)
73 Games=GemRB.GetSaveGames ()
74 TopIndex = max (0, len(Games) - 4)
75 GemRB.SetVar ("TopIndex",TopIndex)
76 ScrollBar.SetVarAssoc ("TopIndex", TopIndex+1)
77 ScrollBarPress ()
78 LoadWindow.SetVisible (WINDOW_VISIBLE)
79 return
81 def ScrollBarPress ():
82 #draw load game portraits
83 Pos = GemRB.GetVar ("TopIndex")
84 for i in range (4):
85 ActPos = Pos + i
87 Button1 = LoadWindow.GetControl (26+i)
88 Button2 = LoadWindow.GetControl (30+i)
89 if ActPos<len(Games):
90 Button1.SetState (IE_GUI_BUTTON_ENABLED)
91 Button2.SetState (IE_GUI_BUTTON_ENABLED)
92 else:
93 Button1.SetState (IE_GUI_BUTTON_DISABLED)
94 Button2.SetState (IE_GUI_BUTTON_DISABLED)
96 if ActPos<len(Games):
97 Slotname = Games[ActPos].GetName()
98 else:
99 Slotname = ""
100 Label = LoadWindow.GetControl (0x10000008+i)
101 Label.SetText (Slotname)
103 if ActPos<len(Games):
104 Slotname = Games[ActPos].GetDate()
105 else:
106 Slotname = ""
107 Label = LoadWindow.GetControl (0x10000010+i)
108 Label.SetText (Slotname)
110 Button=LoadWindow.GetControl (1+i)
111 if ActPos<len(Games):
112 Button.SetSprite2D(Games[ActPos].GetPreview())
113 else:
114 Button.SetPicture ("")
115 for j in range (PARTY_SIZE):
116 Button=LoadWindow.GetControl (40 + i*PARTY_SIZE + j)
117 if ActPos<len(Games):
118 Button.SetSprite2D(Games[ActPos].GetPortrait(j))
119 else:
120 Button.SetPicture ("")
121 return
123 def LoadGamePress ():
124 if LoadWindow:
125 LoadWindow.Unload ()
126 Pos = GemRB.GetVar ("TopIndex")+GemRB.GetVar ("LoadIdx")
127 LoadScreen.StartLoadScreen()
128 GemRB.LoadGame (Games[Pos]) #loads and enters savegame
129 GemRB.EnterGame ()
130 return
132 def DeleteGameConfirm():
133 global Games
135 TopIndex = GemRB.GetVar ("TopIndex")
136 Pos = TopIndex +GemRB.GetVar ("LoadIdx")
137 GemRB.DeleteSaveGame(Games[Pos])
138 if TopIndex>0:
139 GemRB.SetVar ("TopIndex",TopIndex-1)
140 del Games[Pos]
141 ScrollBar.SetVarAssoc ("TopIndex", len(Games))
142 ScrollBarPress ()
143 if ConfirmWindow:
144 ConfirmWindow.Unload ()
145 LoadWindow.SetVisible (WINDOW_VISIBLE)
146 return
148 def DeleteGameCancel ():
149 if ConfirmWindow:
150 ConfirmWindow.Unload ()
151 LoadWindow.SetVisible (WINDOW_VISIBLE)
152 return
154 def DeleteGamePress ():
155 global ConfirmWindow
157 LoadWindow.SetVisible (WINDOW_INVISIBLE)
158 ConfirmWindow=GemRB.LoadWindow (1)
159 Text=ConfirmWindow.GetControl (0)
160 Text.SetText (15305)
161 DeleteButton=ConfirmWindow.GetControl (1)
162 DeleteButton.SetText (13957)
163 DeleteButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGameConfirm)
164 CancelButton=ConfirmWindow.GetControl (2)
165 CancelButton.SetText (13727)
166 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, DeleteGameCancel)
167 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
169 ConfirmWindow.SetVisible (WINDOW_VISIBLE)
170 return
172 def CancelPress ():
173 if LoadWindow:
174 LoadWindow.Unload ()
175 GemRB.SetNextScript ("Start")
176 return