TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg1 / GUIMP.py
blob209d30a9928fa4eaeec56b79197b7699f0209ce7
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 #Single Player Party Formation
20 import GemRB
21 from GUIDefines import *
23 PartyFormationWindow = 0
24 ExitWindow = 0
26 def OnLoad():
27 global PartyFormationWindow
28 GemRB.LoadWindowPack("GUIMP")
30 PartyFormationWindow = GemRB.LoadWindow(0)
32 ExitButton = PartyFormationWindow.GetControl(30)
33 ExitButton.SetText(13906)
34 ExitButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ExitPress)
35 ExitButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)
37 ModifyCharactersButton = PartyFormationWindow.GetControl(43)
38 ModifyCharactersButton.SetText(18816)
39 ModifyCharactersButton.SetState(IE_GUI_BUTTON_DISABLED)
40 #TODO: implement ModifyCharacters
41 #ModifyCharactersButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ModifyCharactersPress)
43 DoneButton = PartyFormationWindow.GetControl(28)
44 DoneButton.SetText(11973)
45 Portraits = 0
47 for i in range(18,24):
48 Label = PartyFormationWindow.GetControl(0x10000012+i)
49 #removing this label, it just disturbs us
50 Label.SetSize(0, 0)
51 Button = PartyFormationWindow.GetControl(i-12)
52 ResRef = GemRB.GetPlayerPortrait(i-17, 1)
53 if ResRef == "":
54 Button.SetFlags(IE_GUI_BUTTON_NORMAL,OP_SET)
55 else:
56 Button.SetPicture(ResRef)
57 Button.SetFlags(IE_GUI_BUTTON_PICTURE, OP_OR)
58 Portraits = Portraits+1
60 Button.SetVarAssoc("Slot",i-17)
61 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GeneratePress)
63 Button = PartyFormationWindow.GetControl(i)
64 Button.SetVarAssoc("Slot",i-17)
65 if ResRef == "":
66 Button.SetText(10264)
67 else:
68 Button.SetText(GemRB.GetPlayerName(i-17,0) )
70 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GeneratePress)
72 if Portraits == 0:
73 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
74 else:
75 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
76 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, EnterGamePress)
78 PartyFormationWindow.SetVisible(WINDOW_VISIBLE)
79 return
81 def ExitPress():
82 global PartyFormationWindow, ExitWindow
83 PartyFormationWindow.SetVisible(WINDOW_INVISIBLE)
84 ExitWindow = GemRB.LoadWindow(7)
86 TextArea = ExitWindow.GetControl(0)
87 TextArea.SetText(11329)
89 CancelButton = ExitWindow.GetControl(2)
90 CancelButton.SetText(13727)
91 CancelButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ExitCancelPress)
92 CancelButton.SetFlags(IE_GUI_BUTTON_CANCEL, OP_OR)
94 DoneButton = ExitWindow.GetControl(1)
95 DoneButton.SetText(11973)
96 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, ExitDonePress)
97 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT, OP_OR)
99 ExitWindow.SetVisible(WINDOW_VISIBLE)
100 return
102 def ExitDonePress():
103 global PartyFormationWindow, ExitWindow
104 if ExitWindow:
105 ExitWindow.Unload()
106 if PartyFormationWindow:
107 PartyFormationWindow.Unload()
108 GemRB.SetNextScript("Start")
109 return
111 def ExitCancelPress():
112 global PartyFormationWindow, ExitWindow
113 if ExitWindow:
114 ExitWindow.Unload()
115 PartyFormationWindow.SetVisible(WINDOW_VISIBLE)
116 return
118 def GeneratePress():
119 global PartyFormationWindow
120 slot = GemRB.GetVar("Slot")
121 ResRef = GemRB.GetPlayerPortrait(slot, 0)
122 if ResRef:
123 print "Already existing slot, we should drop it"
124 if PartyFormationWindow:
125 PartyFormationWindow.Unload()
126 GemRB.SetNextScript("CharGen")
127 return
129 def EnterGamePress():
130 GemRB.EnterGame()
131 return