From 4c26c1b6ea9dd14dc65747b1c9a439d153b14dd1 Mon Sep 17 00:00:00 2001 From: Jaka Kranjc Date: Sat, 20 Nov 2010 13:47:56 +0100 Subject: [PATCH] GUICommon: fixed ceil to care about all the decimals and made it return an int --- gemrb/GUIScripts/GUICommon.py | 11 ++++++----- gemrb/GUIScripts/LUSpellSelection.py | 8 ++++---- gemrb/GUIScripts/bg2/LUHLASelection.py | 2 +- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gemrb/GUIScripts/GUICommon.py b/gemrb/GUIScripts/GUICommon.py index 241adbc35..e5ce4558a 100644 --- a/gemrb/GUIScripts/GUICommon.py +++ b/gemrb/GUIScripts/GUICommon.py @@ -895,16 +895,17 @@ def SetupDamageInfo (pc, Button): return ratio_str # redefine ceil, so we don't need to import the math module (which isn't available on all platforms) +# returns int instead of float def ceil (value): - dec = (value * 10) % 10 - if value > 0 and dec: - return float(int(value) + 1) + diff = value - int(value) + if value > 0 and diff > 0: + return int(value) + 1 else: - return float(int(value)) # just truncate + return int(value) # just truncate # unit test: #import math #for i in 1, 0, -1, 1.2, 0.2, -1.2, 1.8, 0.8, -1.8: -# if ceil (i) - math.ceil (i): +# if ceil (i) - int(math.ceil (i)): # print i, ceil (i), math.ceil (i) GameWindow = GUIClasses.GWindow(0) diff --git a/gemrb/GUIScripts/LUSpellSelection.py b/gemrb/GUIScripts/LUSpellSelection.py index ebcd10ec8..280c7411f 100644 --- a/gemrb/GUIScripts/LUSpellSelection.py +++ b/gemrb/GUIScripts/LUSpellSelection.py @@ -186,9 +186,9 @@ def OpenSpellsWindow (actor, table, level, diff, kit=0, gen=0, recommend=True): if len (Spells[i]) > ( 24 + ExtraSpellButtons() ): HideUnhideScrollBar(0) if chargen: - ScrollBar.SetVarAssoc ("SpellTopIndex", int ( GUICommon.ceil ( ( len (Spells[i])-24 ) / 6.0 ) ) + 1 ) + ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceil ( ( len (Spells[i])-24 ) / 6.0 ) + 1 ) else: #there are five rows of 5 spells in level up of sorcs - ScrollBar.SetVarAssoc ("SpellTopIndex", int ( GUICommon.ceil ( ( len (Spells[i])-25 ) / 5.0 ) ) + 1 ) + ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceil ( ( len (Spells[i])-25 ) / 5.0 ) + 1 ) else: ScrollBar.SetVarAssoc ("SpellTopIndex", 0) HideUnhideScrollBar(1) @@ -235,9 +235,9 @@ def SpellsDonePress (): if len (Spells[i]) > ( 24 + ExtraSpellButtons() ): HideUnhideScrollBar(0) if chargen: - ScrollBar.SetVarAssoc ("SpellTopIndex", int ( GUICommon.ceil ( ( len (Spells[i])-24 ) / 6.0 ) ) + 1 ) + ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceil ( ( len (Spells[i])-24 ) / 6.0 ) + 1 ) else: - ScrollBar.SetVarAssoc ("SpellTopIndex", int ( GUICommon.ceil ( ( len (Spells[i])-25 ) / 5.0 ) ) + 1 ) + ScrollBar.SetVarAssoc ("SpellTopIndex", GUICommon.ceil ( ( len (Spells[i])-25 ) / 5.0 ) + 1 ) else: ScrollBar.SetVarAssoc ("SpellTopIndex", 0) HideUnhideScrollBar(1) diff --git a/gemrb/GUIScripts/bg2/LUHLASelection.py b/gemrb/GUIScripts/bg2/LUHLASelection.py index 41bb156e9..ab12ee167 100644 --- a/gemrb/GUIScripts/bg2/LUHLASelection.py +++ b/gemrb/GUIScripts/bg2/LUHLASelection.py @@ -88,7 +88,7 @@ def OpenHLAWindow (actor, numclasses, classes, levels): ScrollBar.SetSprites ("GUISCRCW", 0, 0,1,2,3,5,4) ScrollBar.SetEvent (IE_GUI_SCROLLBAR_ON_CHANGE, HLAShowAbilities) #with enhanced GUI we have 5 rows of 5 abilities (the last one is 'the extra slot') - ScrollBar.SetVarAssoc ("HLATopIndex", int ( GUICommon.ceil ( ( len (HLAAbilities)-25 ) / 5.0 ) ) + 1 ) + ScrollBar.SetVarAssoc ("HLATopIndex", GUICommon.ceil ( ( len (HLAAbilities)-25 ) / 5.0 ) + 1 ) ScrollBar.SetDefaultScrollBar () # draw our HLAs and show the window -- 2.11.4.GIT