TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / Start2.py
blob02c01daf869dc97b61b435f41d443833b201eb5a
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 #this is essentially Start.py from the SoA game, except for a very small change
20 import GemRB
21 import GUICommon
23 StartWindow = 0
24 TutorialWindow = 0
25 QuitWindow = 0
26 ExitButton = 0
27 SinglePlayerButton = 0
28 OptionsButton = 0
29 MultiPlayerButton = 0
30 MoviesButton = 0
31 BackButton = 0
33 def OnLoad():
34 global StartWindow, TutorialWindow, QuitWindow
35 global ExitButton, OptionsButton, MultiPlayerButton, MoviesButton, SinglePlayerButton, BackButton
36 global SinglePlayerButton
38 skip_videos = GemRB.GetVar ("SkipIntroVideos")
40 GemRB.LoadWindowPack("START", 640, 480)
41 #tutorial subwindow
42 TutorialWindow = GemRB.LoadWindow (5)
43 TextAreaControl = TutorialWindow.GetControl (1)
44 CancelButton = TutorialWindow.GetControl (11)
45 PlayButton = TutorialWindow.GetControl (10)
46 TextAreaControl.SetText (44200)
47 CancelButton.SetText (13727)
48 PlayButton.SetText (33093)
49 PlayButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PlayPress)
50 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, CancelTut)
51 PlayButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
52 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
53 #quit subwindow
54 QuitWindow = GemRB.LoadWindow (3)
55 QuitTextArea = QuitWindow.GetControl (0)
56 CancelButton = QuitWindow.GetControl (2)
57 ConfirmButton = QuitWindow.GetControl (1)
58 QuitTextArea.SetText (19532)
59 CancelButton.SetText (13727)
60 ConfirmButton.SetText (15417)
61 ConfirmButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ExitConfirmed)
62 CancelButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ExitCancelled)
63 ConfirmButton.SetFlags (IE_GUI_BUTTON_DEFAULT, OP_OR)
64 CancelButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
65 #main window
66 StartWindow = GemRB.LoadWindow (0)
67 StartWindow.SetFrame ()
68 #this is the ToB specific part of Start.py
69 if GemRB.GetVar("oldgame")==1:
70 if GUICommon.HasTOB():
71 StartWindow.SetPicture("STARTOLD")
72 if not skip_videos:
73 GemRB.PlayMovie ("INTRO15F", 1)
74 else:
75 if not skip_videos:
76 GemRB.PlayMovie ("INTRO", 1)
78 #end ToB specific part
79 SinglePlayerButton = StartWindow.GetControl (0)
80 ExitButton = StartWindow.GetControl (3)
81 OptionsButton = StartWindow.GetControl (4)
82 MultiPlayerButton = StartWindow.GetControl (1)
83 MoviesButton = StartWindow.GetControl (2)
84 BackButton = StartWindow.GetControl (5)
85 StartWindow.CreateLabel(0x0fff0000, 0,450,640,30, "REALMS", "", 1)
86 Label=StartWindow.GetControl (0x0fff0000)
87 Label.SetText (GEMRB_VERSION)
88 if not GUICommon.HasTOB():
89 BackButton.SetState (IE_GUI_BUTTON_DISABLED)
90 BackButton.SetText ("")
91 else:
92 BackButton.SetState (IE_GUI_BUTTON_ENABLED)
93 BackButton.SetText (15416)
94 SinglePlayerButton.SetState (IE_GUI_BUTTON_ENABLED)
95 ExitButton.SetState (IE_GUI_BUTTON_ENABLED)
96 OptionsButton.SetState (IE_GUI_BUTTON_ENABLED)
97 MultiPlayerButton.SetState (IE_GUI_BUTTON_ENABLED)
98 MoviesButton.SetState (IE_GUI_BUTTON_ENABLED)
99 SinglePlayerButton.SetText (15413)
100 ExitButton.SetText (15417)
101 OptionsButton.SetText (13905)
102 MultiPlayerButton.SetText (15414)
103 MoviesButton.SetText (15415)
104 SinglePlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SinglePlayerPress)
105 ExitButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ExitPress)
106 OptionsButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OptionsPress)
107 MultiPlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MultiPlayerPress)
108 MoviesButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MoviesPress)
109 BackButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, Restart)
110 ExitButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
111 QuitWindow.SetVisible (WINDOW_INVISIBLE)
112 TutorialWindow.SetVisible (WINDOW_INVISIBLE)
113 StartWindow.SetVisible (WINDOW_VISIBLE)
114 MusicTable = GemRB.LoadTable ("songlist")
115 # the table has useless rownames, so we can't search for BG2Theme
116 theme = MusicTable.GetValue ("33", "RESOURCE")
117 GemRB.LoadMusicPL (theme, 1)
118 return
120 def SinglePlayerPress():
122 SinglePlayerButton.SetText (13728)
123 SinglePlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, NewSingle)
125 MultiPlayerButton.SetText (13729)
126 MultiPlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, LoadSingle)
128 if GemRB.GetVar("oldgame")==1:
129 MoviesButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, Tutorial)
130 MoviesButton.SetText (33093)
131 else:
132 MoviesButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ImportGame)
133 MoviesButton.SetText (71175)
135 ExitButton.SetText (15416)
136 ExitButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BackToMain)
138 OptionsButton.SetText ("")
139 OptionsButton.SetState (IE_GUI_BUTTON_DISABLED)
141 BackButton.SetText ("")
142 BackButton.SetState (IE_GUI_BUTTON_DISABLED)
143 return
145 def MultiPlayerPress():
147 OptionsButton.SetText ("")
148 SinglePlayerButton.SetText (20642)
149 ExitButton.SetText (15416)
150 MultiPlayerButton.SetText ("")
151 MoviesButton.SetText (11825)
152 MultiPlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, None)
153 SinglePlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ConnectPress)
154 MoviesButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, PregenPress)
155 ExitButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, BackToMain)
156 MultiPlayerButton.SetState (IE_GUI_BUTTON_DISABLED)
157 OptionsButton.SetState (IE_GUI_BUTTON_DISABLED)
158 return
160 def ConnectPress():
161 #well...
162 #GemRB.SetVar("PlayMode",2)
163 return
165 def PregenPress():
166 if StartWindow:
167 StartWindow.Unload()
168 if QuitWindow:
169 QuitWindow.Unload()
170 if TutorialWindow:
171 TutorialWindow.Unload()
172 #do not start game after chargen
173 GemRB.SetVar("PlayMode",-1) #will allow export
174 GemRB.SetVar("Slot",0)
175 GemRB.LoadGame(None)
176 GemRB.SetNextScript ("CharGen")
177 return
179 def LoadSingle():
180 if StartWindow:
181 StartWindow.Unload()
182 if QuitWindow:
183 QuitWindow.Unload()
184 if TutorialWindow:
185 TutorialWindow.Unload()
186 if GemRB.GetVar ("oldgame") == 0:
187 GemRB.SetVar ("PlayMode", 2)
188 GemRB.SetVar ("SaveDir", 1)
189 else:
190 GemRB.SetVar ("PlayMode", 0)
191 GemRB.SetVar ("SaveDir", 0)
193 GemRB.SetNextScript ("GUILOAD")
194 return
196 def NewSingle():
197 if StartWindow:
198 StartWindow.Unload()
199 if QuitWindow:
200 QuitWindow.Unload()
201 if TutorialWindow:
202 TutorialWindow.Unload()
203 if GemRB.GetVar ("oldgame") == 0:
204 GemRB.SetVar ("PlayMode", 2)
205 GemRB.SetVar ("SaveDir", 1)
206 else:
207 GemRB.SetVar ("PlayMode", 0)
208 GemRB.SetVar ("SaveDir", 0)
209 GemRB.SetVar("Slot",1)
210 GemRB.LoadGame(None)
211 GemRB.SetNextScript ("CharGen")
212 return
214 def ImportGame():
215 if StartWindow:
216 StartWindow.Unload()
217 if QuitWindow:
218 QuitWindow.Unload()
219 if TutorialWindow:
220 TutorialWindow.Unload()
221 #now this is tricky, we need to load old games, but set up the expansion
222 GemRB.SetVar ("PlayMode", 0)
223 GemRB.SetVar ("SaveDir", 0)
224 GemRB.SetNextScript ("GUILOAD")
225 return
227 def Tutorial():
228 StartWindow.SetVisible (WINDOW_INVISIBLE)
229 TutorialWindow.SetVisible (WINDOW_VISIBLE)
230 return
232 def PlayPress():
233 if StartWindow:
234 StartWindow.Unload()
235 if QuitWindow:
236 QuitWindow.Unload()
237 if TutorialWindow:
238 TutorialWindow.Unload()
239 GemRB.SetVar("PlayMode",1) #tutorial
240 GemRB.SetVar("SaveDir",0)
241 GemRB.SetVar("Slot",1)
242 GemRB.LoadGame(None)
243 GemRB.SetNextScript ("CharGen")
244 return
246 def CancelTut():
247 TutorialWindow.SetVisible (WINDOW_INVISIBLE)
248 StartWindow.SetVisible (WINDOW_VISIBLE)
249 return
251 def ExitPress():
252 StartWindow.SetVisible (WINDOW_INVISIBLE)
253 QuitWindow.SetVisible (WINDOW_VISIBLE)
254 return
256 def ExitConfirmed():
257 GemRB.Quit()
258 return
260 def OptionsPress():
261 #apparently the order is important
262 if StartWindow:
263 StartWindow.Unload()
264 if QuitWindow:
265 QuitWindow.Unload()
266 if TutorialWindow:
267 TutorialWindow.Unload()
268 GemRB.SetNextScript ("StartOpt")
269 return
271 def MoviesPress():
272 #apparently the order is important
273 if StartWindow:
274 StartWindow.Unload()
275 if QuitWindow:
276 QuitWindow.Unload()
277 if TutorialWindow:
278 TutorialWindow.Unload()
279 GemRB.SetNextScript ("GUIMOVIE")
280 return
282 def ExitCancelled():
283 QuitWindow.SetVisible (WINDOW_INVISIBLE)
284 StartWindow.SetVisible (WINDOW_VISIBLE)
285 return
287 def BackToMain():
288 SinglePlayerButton.SetState (IE_GUI_BUTTON_ENABLED)
289 OptionsButton.SetState (IE_GUI_BUTTON_ENABLED)
290 MultiPlayerButton.SetState (IE_GUI_BUTTON_ENABLED)
291 BackButton.SetState (IE_GUI_BUTTON_ENABLED)
292 SinglePlayerButton.SetText (15413)
293 ExitButton.SetText (15417)
294 OptionsButton.SetText (13905)
295 MultiPlayerButton.SetText (15414)
296 MoviesButton.SetText (15415)
297 BackButton.SetText (15416)
298 SinglePlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, SinglePlayerPress)
299 ExitButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, ExitPress)
300 OptionsButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, OptionsPress)
301 MultiPlayerButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MultiPlayerPress)
302 MoviesButton.SetEvent (IE_GUI_BUTTON_ON_PRESS, MoviesPress)
303 QuitWindow.SetVisible (WINDOW_INVISIBLE)
304 StartWindow.SetVisible (WINDOW_VISIBLE)
305 return
307 def Restart():
308 StartWindow.Unload()
309 QuitWindow.Unload()
310 GemRB.SetNextScript ("Start")
311 return