Advertisement
RaffaeL_RsK

ui.py-changes

Jul 4th, 2020 (edited)
2,731
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.73 KB | None | 0 0
  1. # ui.py
  2. #before:
  3. class Board (Window)
  4. #add this:
  5. #Take note that for some weird reasons, there are plenty of spaces random in code, in floats and between self an the rest of the deffinitons, but I'm too lazy to correct it... All I've made here was indentation correction, so the code isn't mine.
  6. class DynamicGauge (Gauge):
  7.     dynamicGaugePerc =  None
  8.     newGaugePerc =  0
  9.     def  __init__ ( self ):
  10.         Gauge. __init__ ( self )
  11.     def  __del__ ( self ):
  12.         Gauge. __del__ ( self )
  13.  
  14.     def MakeGauge ( self , width, color1, color2):
  15.         Gauge.MakeGauge ( self , width, color2)
  16.  
  17.         imgGauge2 = ExpandedImageBox ()
  18.         imgGauge2.SetParent ( self )
  19.         imgGauge2.LoadImage ( "d: / ymir work / ui / pattern / gauge_"  + color1 +  ".tga" )
  20.         imgGauge2.Show ()
  21.         imgGauge2.SetRenderingRect ( 0.0 , 0.0 , 0.0 , 0.0 )
  22.         imgGauge2.SetPosition ( self .GAUGE_TEMPORARY_PLACE, 0 )
  23.  
  24.         self .imgGauge2 = imgGauge2
  25.  
  26.     def SetPercentage ( self , curValue, maxValue):
  27.         # PERCENTAGE_MAX_VALUE_ZERO_DIVISION_ERROR
  28.         if maxValue > 0.0:
  29.             percentage = min ( 1.0, float(curValue) / float(maxValue))
  30.         else :
  31.             percentage = 0.0
  32.         # END_OF_PERCENTAGE_MAX_VALUE_ZERO_DIVISION_ERROR
  33.         gaugeSize = -1.0 + float(self.width - self.GAUGE_TEMPORARY_PLACE * 2) * percentage / self .GAUGE_WIDTH
  34.  
  35.         if  self .dynamicGaugePerc = =  None :
  36.             self .imgGauge.SetRenderingRect ( 0 . 0 , 0 . 0 , ( - 1 . 0  + float ( self .width -  self .GAUGE_TEMPORARY_PLACE * 2 ) * percentage /  self .GAUGE_WIDTH), 0 . 0 )
  37.             self .dynamicGaugePerc = percentage
  38.         elif  self .dynamicGaugePerc + 0 . 2  <  self .newGaugePerc:
  39.             self .imgGauge.SetRenderingRect ( 0 . 0 , 0 . 0 , ( - 1 . 0  + float ( self .width -  self .GAUGE_TEMPORARY_PLACE * 2 ) *  self .newGaugePerc /  self .GAUGE_WIDTH), 0 . 0 )
  40.             self .dynamicGaugePerc =  self .newGaugePerc
  41.  
  42.         self .newGaugePerc = percentage
  43.         self .imgGauge2.SetRenderingRect ( 0 . 0 , 0 . 0 , gaugeSize, 0 . 0 )
  44.         if percentage = =  0 :
  45.             self .imgGauge.Hide ()
  46.         else :
  47.             self .imgGauge.Show ()
  48.  
  49.     def OnUpdate ( self ):
  50.         if  self .dynamicGaugePerc >  self .newGaugePerc:
  51.             self .dynamicGaugePerc =  self .dynamicGaugePerc -  0 . 005
  52.             self .imgGauge.SetRenderingRect ( 0 . 0 , 0 . 0 , ( - 1 . 0  + float ( self .width -  self .GAUGE_TEMPORARY_PLACE * 2 ) *  self .dynamicGaugePerc /  self .GAUGE_WIDTH), 0 . 0 )
  53.         elif  self .dynamicGaugePerc <  self .newGaugePerc:
  54.             self .dynamicGaugePerc =  self .newGaugePerc
  55.             self .imgGauge.SetRenderingRect ( 0 . 0 , 0 . 0 , ( - 1 . 0  + float ( self .width -  self .GAUGE_TEMPORARY_PLACE * 2 ) *  self .dynamicGaugePerc /  self .GAUGE_WIDTH), 0 . 0 )
  56.  
  57. # uitarget.py
  58. #search:
  59. hpGauge.MakeGauge ( 130 , "red" )
  60. #replace:
  61. hpGauge.MakeGauge ( 130 , "red" , "blue" )
  62. #search
  63. ui.Gauge
  64. #replace:
  65. ui.DynamicGauge
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement