Button: Add separate event handler for dropping portraits.
[gemrb.git] / gemrb / GUIScripts / bg2 / GUICG15.py
blob52824b493d8c1c574c5fb7a8539346a3f1ab8f65
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 GUICommon import *
23 RaceWindow = 0
24 TextAreaControl = 0
25 DoneButton = 0
26 RaceTable = 0
27 RaceCount = 0
28 TopIndex = 0
29 MyChar = 0
30 #the size of the selection list
31 LISTSIZE = 11
33 def DisplayRaces():
34 global TopIndex
36 TopIndex=GemRB.GetVar("TopIndex")
37 for i in range(LISTSIZE):
38 Button = RaceWindow.GetControl(i+6)
39 Val = RaceTable.GetValue(i+TopIndex,0)
40 if Val==0:
41 Button.SetText("")
42 Button.SetState(IE_GUI_BUTTON_DISABLED)
43 else:
44 Button.SetText(Val)
45 Button.SetState(IE_GUI_BUTTON_ENABLED)
46 Button.SetEvent(IE_GUI_BUTTON_ON_PRESS,"RacePress")
47 Button.SetVarAssoc("HatedRace",RaceTable.GetValue(i+TopIndex,1) )
48 return
50 def OnLoad():
51 global RaceWindow, TextAreaControl, DoneButton
52 global RaceTable, RaceCount, TopIndex, MyChar
54 MyChar = GemRB.GetVar ("Slot")
55 Class = GemRB.GetPlayerStat (MyChar, IE_CLASS)
56 Class = ClassTable.FindValue (5, Class)
57 ClassName = ClassTable.GetRowName(Class)
58 TableName = ClassSkillsTable.GetValue(ClassName, "HATERACE")
59 if TableName == "*":
60 GemRB.SetNextScript("GUICG7")
61 return
62 GemRB.LoadWindowPack("GUICG", 640, 480)
63 RaceWindow = GemRB.LoadWindowObject(15)
64 RaceTable = GemRB.LoadTableObject(TableName)
65 RaceCount = RaceTable.GetRowCount()-LISTSIZE+1
66 if RaceCount<0:
67 RaceCount=0
69 TopIndex = 0
70 GemRB.SetVar("TopIndex", 0)
71 ScrollBarControl = RaceWindow.GetControl(1)
72 ScrollBarControl.SetVarAssoc("TopIndex", RaceCount)
73 ScrollBarControl.SetEvent(IE_GUI_SCROLLBAR_ON_CHANGE, "DisplayRaces")
74 ScrollBarControl.SetDefaultScrollBar ()
76 for i in range(LISTSIZE):
77 Button = RaceWindow.GetControl(i+6)
78 Button.SetFlags(IE_GUI_BUTTON_RADIOBUTTON,OP_OR)
80 GemRB.SetVar("HatedRace",0)
82 BackButton = RaceWindow.GetControl(4)
83 BackButton.SetText(15416)
84 BackButton.SetFlags (IE_GUI_BUTTON_CANCEL, OP_OR)
85 DoneButton = RaceWindow.GetControl(5)
86 DoneButton.SetText(11973)
87 DoneButton.SetFlags(IE_GUI_BUTTON_DEFAULT,OP_OR)
88 DoneButton.SetState(IE_GUI_BUTTON_DISABLED)
90 TextAreaControl = RaceWindow.GetControl(2)
91 TextAreaControl.SetText(17256)
93 DoneButton.SetEvent(IE_GUI_BUTTON_ON_PRESS,"NextPress")
94 BackButton.SetEvent(IE_GUI_BUTTON_ON_PRESS,"BackPress")
95 RaceWindow.SetVisible(WINDOW_VISIBLE)
96 DisplayRaces()
97 return
99 def RacePress():
100 Race = GemRB.GetVar("HatedRace")
101 Row = RaceTable.FindValue(1, Race)
102 TextAreaControl.SetText(RaceTable.GetValue(Row, 2) )
103 DoneButton.SetState(IE_GUI_BUTTON_ENABLED)
104 return
106 def BackPress():
107 if RaceWindow:
108 RaceWindow.Unload()
109 GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, 0) #scrapping the race value
110 GemRB.SetNextScript("CharGen6")
111 return
113 def NextPress():
114 if RaceWindow:
115 RaceWindow.Unload()
116 # save the hated race
117 GemRB.SetPlayerStat (MyChar, IE_HATEDRACE, GemRB.GetVar ("HatedRace"))
119 GemRB.SetNextScript("GUICG7") #mage spells
120 return