TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / MessageWindow.py
blob93eb0cc6e33aafb338cd46628506c3041cd6f0ec
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003-2005 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.
20 # MessageWindow.py - scripts and GUI for the main (walk) window
22 ###################################################
24 import GemRB
25 import GUICommon
26 import GUICommonWindows
27 import CommonWindow
28 import GUIClasses
29 import CommonTables
30 from GUIDefines import *
31 from CharGenEnd import GiveEquipment
33 MessageWindow = 0
34 PortraitWindow = 0
35 OptionsWindow = 0
36 ExpandButton = 0
37 ContractButton = 0
39 def OnLoad():
40 global PortraitWindow, OptionsWindow
42 GemRB.GameSetPartySize(PARTY_SIZE)
43 GemRB.GameSetProtagonistMode(1)
44 GemRB.LoadWindowPack(GUICommon.GetWindowPack())
46 GUICommonWindows.PortraitWindow = None
47 GUICommonWindows.ActionsWindow = None
48 GUICommonWindows.OptionsWindow = None
50 OptionsWindow = GemRB.LoadWindow(0)
51 GUICommonWindows.SetupMenuWindowControls (OptionsWindow, 1, None)
52 PortraitWindow = GUICommonWindows.OpenPortraitWindow(1)
54 Button=OptionsWindow.GetControl(10)
55 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, MinimizeOptions)
56 Button=PortraitWindow.GetControl(8)
57 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, GUICommonWindows.MinimizePortraits)
59 ActionsWindow = GemRB.LoadWindow(3)
60 GUICommonWindows.OpenActionsWindowControls (ActionsWindow)
61 Button=ActionsWindow.GetControl(60)
62 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, MaximizeOptions)
63 Button=ActionsWindow.GetControl(61)
64 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, MaximizePortraits)
66 GemRB.SetVar("PortraitWindow", PortraitWindow.ID)
67 GemRB.SetVar("ActionsWindow", ActionsWindow.ID)
68 GemRB.SetVar("OptionsWindow", OptionsWindow.ID)
69 GemRB.SetVar("TopWindow", -1)
70 GemRB.SetVar("OtherWindow", -1)
71 GemRB.SetVar("FloatWindow", -1)
72 GemRB.SetVar("PortraitPosition", 2) #Right
73 GemRB.SetVar("ActionsPosition", 4) #BottomAdded
74 GemRB.SetVar("OptionsPosition", 0) #Left
75 GemRB.SetVar("MessagePosition", 4) #BottomAdded
76 GemRB.SetVar("OtherPosition", 5) #Inactivating
77 GemRB.SetVar("TopPosition", 5) #Inactivating
79 UpdateControlStatus()
81 def MinimizeOptions():
82 GemRB.GameSetScreenFlags(GS_OPTIONPANE, OP_OR)
84 def MaximizeOptions():
85 GemRB.GameSetScreenFlags(GS_OPTIONPANE, OP_NAND)
87 # MinimizePortraits is in GUICommonWindows for dependency reasons
89 def MaximizePortraits():
90 GemRB.GameSetScreenFlags(GS_PORTRAITPANE, OP_NAND)
92 def TogglePartyAI():
93 GemRB.GameSetScreenFlags(GS_PARTYAI, OP_XOR)
95 def UpdateControlStatus():
96 global MessageWindow, ExpandButton, ContractButton
98 TMessageWindow = 0
99 TMessageTA = 0
100 GSFlags = GemRB.GetMessageWindowSize()
101 Expand = GSFlags&GS_DIALOGMASK
102 Override = GSFlags&GS_DIALOG
103 GSFlags = GSFlags-Expand
105 #a dialogue is running, setting messagewindow size to maximum
106 if Override:
107 Expand = GS_LARGEDIALOG
109 MessageWindow = GemRB.GetVar("MessageWindow")
111 GemRB.LoadWindowPack(GUICommon.GetWindowPack())
113 if Expand == GS_MEDIUMDIALOG:
114 TMessageWindow = GemRB.LoadWindow(12)
115 TMessageTA = TMessageWindow.GetControl(1)
116 ExpandButton = TMessageWindow.GetControl(0)
117 ExpandButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CommonWindow.OnIncreaseSize)
118 ContractButton = TMessageWindow.GetControl(3)
119 ContractButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CommonWindow.OnDecreaseSize)
121 elif Expand == GS_LARGEDIALOG:
122 TMessageWindow = GemRB.LoadWindow(7)
123 TMessageTA = TMessageWindow.GetControl(1)
124 ContractButton = TMessageWindow.GetControl(0)
125 ContractButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CommonWindow.OnDecreaseSize)
126 else:
127 TMessageWindow = GemRB.LoadWindow(4)
128 TMessageTA = TMessageWindow.GetControl(3)
129 ExpandButton = TMessageWindow.GetControl(2)
130 ExpandButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CommonWindow.OnIncreaseSize)
132 TMessageTA.SetFlags(IE_GUI_TEXTAREA_AUTOSCROLL|IE_GUI_TEXTAREA_SPEAKER)
133 TMessageTA.SetHistory(100)
134 hideflag = GemRB.HideGUI()
135 MessageTA = GUIClasses.GTextArea(MessageWindow,GemRB.GetVar("MessageTextArea"))
136 if MessageWindow>0 and MessageWindow!=TMessageWindow.ID:
137 MessageTA.MoveText(TMessageTA)
138 GUIClasses.GWindow(MessageWindow).Unload()
140 GemRB.SetVar("MessageWindow", TMessageWindow.ID)
141 GemRB.SetVar("MessageTextArea", TMessageTA.ID)
142 if Override:
143 TMessageTA.SetStatus (IE_GUI_CONTROL_FOCUSED)
144 else:
145 GUICommon.GameControl.SetStatus(IE_GUI_CONTROL_FOCUSED)
147 if GSFlags & GS_OPTIONPANE:
148 GemRB.SetVar("OptionsWindow", -1)
149 else:
150 GemRB.SetVar("OptionsWindow", OptionsWindow.ID)
152 if GSFlags & GS_PORTRAITPANE:
153 GemRB.SetVar("PortraitWindow", -1)
154 else:
155 GemRB.SetVar("PortraitWindow", PortraitWindow.ID)
157 if hideflag:
158 GemRB.UnhideGUI()
159 return
161 def RemoveYoshimo( idx):
162 GemRB.DisplayString(72046, 0xF5F596)
163 #WARNING:multiple strings are executed in reverse order
164 GemRB.ExecuteString('ApplySpellRES("destself",myself)', idx)
165 GemRB.ExecuteString('GivePartyAllEquipment()', idx)
166 return
168 def RemoveImoen( idx):
169 GemRB.DisplayString(72047, 0xF5F596)
170 GemRB.ExecuteString('ApplySpellRES("destself",myself)', idx)
171 GemRB.ExecuteString('GivePartyAllEquipment()', idx)
172 return
174 def FixEdwin( idx):
175 GemRB.ApplySpell(idx, "SPIN661")
176 return
178 def FixAnomen( idx):
179 #lawful neutral
180 if (GemRB.GetPlayerStat(idx, IE_ALIGNMENT) == 0x12):
181 GemRB.ApplySpell(idx, "SPIN678")
182 return
184 #do all the stuff not done yet
185 def FixProtagonist( idx):
187 Class = GemRB.GetPlayerStat (idx, IE_CLASS)
188 ClassIndex = CommonTables.Classes.FindValue (5, Class)
189 ClassName = CommonTables.Classes.GetRowName (ClassIndex)
190 KitIndex = GUICommon.GetKitIndex (idx)
191 GiveEquipment(idx, ClassName, KitIndex)
192 return
194 #upgrade savegame to next version
195 def GameExpansion():
197 version = GemRB.GameGetExpansion()
198 if version<3:
199 GemRB.GameSetReputation(100)
201 if not GUICommon.HasTOB():
202 return
204 if GemRB.GetVar("oldgame"):
205 #upgrade SoA to ToB/SoA
206 if GemRB.GameSetExpansion(4):
207 GemRB.AddNewArea("xnewarea")
208 return
210 if not GemRB.GameSetExpansion(5):
211 return
213 #upgrade to ToB only
214 GemRB.SetMasterScript("BALDUR25","WORLDM25")
215 GemRB.SetGlobal("INTOB","GLOBAL",1)
216 GemRB.SetGlobal("HADELLESIMEDREAM1","GLOBAL", 1)
217 GemRB.SetGlobal("HADELLESIMEDREAM2","GLOBAL", 1)
218 GemRB.SetGlobal("HADIMOENDREAM1","GLOBAL", 1)
219 GemRB.SetGlobal("HADSLAYERDREAM","GLOBAL", 1)
220 GemRB.SetGlobal("HADJONDREAM1","GLOBAL", 1)
221 GemRB.SetGlobal("HADJONDREAM2","GLOBAL", 1)
222 idx = GemRB.GetPartySize()
224 while idx:
225 name = GemRB.GetPlayerName(idx, 2) #scripting name
226 if name == "yoshimo":
227 RemoveYoshimo(idx)
228 elif name == "imoen":
229 RemoveImoen(idx)
230 elif name == "edwin":
231 FixEdwin(idx)
232 elif name == "anomen":
233 FixAnomen(idx)
234 elif name == "none":
235 FixProtagonist(idx)
236 GemRB.GameSelectPC (idx, True, SELECT_REPLACE)
237 idx=idx-1
238 return