TickHook: Fix crash when TickHook isn't set.
[gemrb.git] / gemrb / GUIScripts / iwd / Portrait.py
blob709407ee3089c173e4eae9ff4bd55b4c5e2f7200
1 # -*-python-*-
2 # GemRB - Infinity Engine Emulator
3 # Copyright (C) 2003 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.
22 # Portrait.py - scripts to control portrait selection and scrolling
23 ###################################################
25 import GemRB
27 ###################################################
29 PortraitCount = 0
30 PortraitsTable = None
31 Gender = None
33 # initializes gender and portrait table
34 # PortraitGender: 1 Male
35 # 2 Female
36 def Init (PortraitGender):
37 global PortraitsTable, PortraitCount, Gender
39 if PortraitsTable is None:
40 PortraitsTable = GemRB.LoadTable ("PICTURES")
42 PortraitCount = 0
43 Gender = PortraitGender
45 # sets index to given protraitname
46 def Set (PortraitName):
47 global PortraitCount
49 # removes l or s character at the end
50 PortraitName = PortraitName.rstrip ("[ls]")
52 # capitalize PortraitName
53 PortraitName = PortraitName.upper ()
55 # search table
56 for i in range(0, PortraitsTable.GetRowCount ()):
57 if PortraitName == PortraitsTable.GetRowName (i).upper ():
58 PortraitCount = i
59 break;
61 return
63 # returns next portrait name
64 def Next ():
65 global PortraitCount
67 while True:
68 PortraitCount = PortraitCount + 1
69 if PortraitCount == PortraitsTable.GetRowCount ():
70 PortraitCount = 0
71 if PortraitsTable.GetValue (PortraitCount, 0) == Gender:
72 return Name ()
74 # return previous portrait name
75 def Previous ():
76 global PortraitCount
78 while True:
79 PortraitCount = PortraitCount - 1
80 if PortraitCount < 0:
81 PortraitCount = PortraitsTable.GetRowCount () - 1
82 if PortraitsTable.GetValue (PortraitCount, 0) == Gender:
83 return Name ()
85 # gets current portrait name
86 def Name ():
87 global PortraitCount
89 # if portrait matches not current gender, it will be skipped to
90 # the next portrait that matches
91 while PortraitsTable.GetValue (PortraitCount, 0) != Gender:
92 PortraitCount = PortraitCount + 1
94 PortraitName = PortraitsTable.GetRowName (PortraitCount)
95 return PortraitName