TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG15.py
blob5f98247ad1fbbb7efc1b036f9460c9f49af0b895
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 #character generation, racial enemy (GUICG15)
20 import GemRB
21 import CommonTables
22 from GUIDefines import *
23 from ie_stats import *
25 RaceWindow = 0
26 TextAreaControl = 0
27 DoneButton = 0
28 RaceTable = 0
29 RaceCount = 0
30 TopIndex = 0
31 MyChar = 0
32 #the size of the selection list
33 LISTSIZE = 11
35 def DisplayRaces():
36 global TopIndex
38 TopIndex=GemRB.GetVar("TopIndex")
39 for i in range(LISTSIZE):
40 Button = RaceWindow.GetControl(i+6)
41 Val = RaceTable.GetValue(i+TopIndex,0)
42 if Val==0:
43 Button.SetText("")
44 Button.SetState(IE_GUI_BUTTON_DISABLED)
45 else:
46 Button.SetText(Val)
47 Button.SetState(IE_GUI_BUTTON_ENABLED)
48 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, RacePress)
49 Button.SetVarAssoc("HatedRace",RaceTable.GetValue(i+TopIndex,1) )
50 return
52 def OnLoad():
53 global RaceWindow, TextAreaControl, DoneButton
54 global RaceTable, RaceCount, TopIndex, MyChar
56 MyChar = GemRB.GetVar ("Slot")
57 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
58 Class = CommonTables.Classes.FindValue (5, Class)
59 ClassName = CommonTables.Classes.GetRowName(Class)
60 TableName = CommonTables.ClassSkills.GetValue(ClassName, "HATERACE")
61 if TableName == "*":
62 GemRB.SetNextScript("GUICG7")
63 return
64 GemRB.LoadWindowPack("GUICG", 640, 480)
65 RaceWindow = GemRB.LoadWindow(15)
66 RaceTable = GemRB.LoadTable(TableName)
67 RaceCount = RaceTable.GetRowCount()-LISTSIZE+1
68 if RaceCount<0:
69 RaceCount=0
71 TopIndex = 0
72 GemRB.SetVar("TopIndex", 0)
73 ScrollBarControl = RaceWindow.GetControl(1)
74 ScrollBarControl.SetVarAssoc("TopIndex", RaceCount)
75 ScrollBarControl.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, DisplayRaces)
76 ScrollBarControl.SetDefaultScrollBar ()
78 for i in range(LISTSIZE):
79 Button = RaceWindow.GetControl(i+6)
80 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
82 GemRB.SetVar("HatedRace",0)
84 BackButton = RaceWindow.GetControl(4)
85 BackButton.SetText(15416)
86 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
87 DoneButton = RaceWindow.GetControl(5)
88 DoneButton.SetText(11973)
89 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
90 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
92 TextAreaControl = RaceWindow.GetControl(2)
93 TextAreaControl.SetText(17256)
95 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
96 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, BackPress)
97 RaceWindow.SetVisible(WINDOW_VISIBLE)
98 DisplayRaces()
99 return
101 def RacePress():
102 Race = GemRB.GetVar("HatedRace")
103 Row = RaceTable.FindValue(1, Race)
104 TextAreaControl.SetText(RaceTable.GetValue(Row, 2) )
105 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
106 return
108 def BackPress():
109 if RaceWindow:
110 RaceWindow.Unload()
111 GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, 0) #scrapping the race value
112 GemRB.SetNextScript("CharGen6")
113 return
115 def NextPress():
116 if RaceWindow:
117 RaceWindow.Unload()
118 # save the hated race
119 GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, GemRB.GetVar ("HatedRace"))
121 GemRB.SetNextScript("GUICG7") #mage spells
122 return