TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / bg1 / GUICG15.py
blob5c3173724cf6ab0ac5809e7fe6f6792345040cc4
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 from GUIDefines import *
22 from ie_stats import *
23 import CharGenCommon
24 import GUICommon
25 import CommonTables
27 RaceWindow = 0
28 TextAreaControl = 0
29 DoneButton = 0
30 RacialEnemyTable = 0
31 RaceCount = 0
32 TopIndex = 0
33 #the size of the selection list
34 LISTSIZE = 6
36 def DisplayRaces():
37 global TopIndex
39 TopIndex=GemRB.GetVar("TopIndex")
40 for i in range(LISTSIZE):
41 Button = RaceWindow.GetControl(i+2)
42 Val = RacialEnemyTable.GetValue(i+TopIndex,0)
43 if Val==0:
44 Button.SetText("")
45 Button.SetState(IE_GUI_BUTTON_DISABLED)
46 else:
47 Button.SetText(Val)
48 Button.SetState(IE_GUI_BUTTON_ENABLED)
49 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS, RacePress)
50 Button.SetVarAssoc("HatedRace",RacialEnemyTable.GetValue(i+TopIndex,1) )
51 return
53 def OnLoad():
54 global RaceWindow, TextAreaControl, DoneButton
55 global RacialEnemyTable, RaceCount, TopIndex
57 if GUICommon.CloseOtherWindow (OnLoad):
58 if(RaceWindow):
59 RaceWindow.Unload()
60 RaceWindow = None
61 return
63 GemRB.SetVar ("HatedRace",0)
65 ClassRow = GemRB.GetVar("Class")-1
66 Class = CommonTables.Classes.GetValue(ClassRow, 5)
67 ClassName = CommonTables.ClassSkills.GetRowName(Class)
68 TableName = CommonTables.ClassSkills.GetValue(ClassName, "HATERACE")
70 GemRB.LoadWindowPack("GUICG")
71 RaceWindow = GemRB.LoadWindow(15)
72 RacialEnemyTable = GemRB.LoadTable(TableName)
73 RaceCount = RacialEnemyTable.GetRowCount()-LISTSIZE+1
74 if RaceCount<0:
75 RaceCount=0
77 for i in range(LISTSIZE):
78 Button = RaceWindow.GetControl(i+2)
79 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
80 Button.SetSprites("GUIHRC",i,0,1,2,3)
82 BackButton = RaceWindow.GetControl(10)
83 BackButton.SetText(15416)
84 DoneButton = RaceWindow.GetControl(11)
85 DoneButton.SetText(11973)
86 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
87 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
89 TextAreaControl = RaceWindow.GetControl(8)
90 TextAreaControl.SetText(17256)
91 TopIndex = 0
92 GemRB.SetVar("TopIndex",0)
93 ScrollBarControl = RaceWindow.GetControl(1)
94 ScrollBarControl.SetVarAssoc("TopIndex",RaceCount)
95 ScrollBarControl.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, DisplayRaces)
97 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, NextPress)
98 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS, CharGenCommon.BackPress)
99 RaceWindow.ShowModal(MODAL_SHADOW_NONE)
100 DisplayRaces()
101 return
103 def RacePress():
104 Race = GemRB.GetVar("HatedRace")
105 Row = RacialEnemyTable.FindValue(1, Race)
106 TextAreaControl.SetText(RacialEnemyTable.GetValue(Row, 2) )
107 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
108 return
110 def NextPress():
111 MyChar = GemRB.GetVar ("Slot")
112 GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, GemRB.GetVar ("HatedRace") )
113 CharGenCommon.next()