NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

uiSettingUtil.py (3064B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\structureSettings\uiSettingUtil.py
      2 from carbonui import const as uiconst
      3 from carbonui.control.singlelineedits.singleLineEditFloat import SingleLineEditFloat
      4 from carbonui.control.singlelineedits.singleLineEditInteger import SingleLineEditInteger
      5 from localization import GetByLabel
      6 import structures
      7 from carbon.common.script.util.format import FmtAmt
      8 
      9 def GetUnit(settingType):
     10     if settingType == structures.SETTINGS_TYPE_PERCENTAGE:
     11         return '%'
     12     if settingType == structures.SETTINGS_TYPE_ISK:
     13         return ' %s' % GetByLabel('UI/Common/ISK')
     14     return ''
     15 
     16 
     17 def AddValueEdit(parent, sgController, callback):
     18     settingType = sgController.GetSettingType()
     19     unit = GetUnit(settingType)
     20     hint = GetByLabel('UI/StructureSettingWnd/PerOzoneUnitConsumed') if sgController.GetSettingID() == structures.SETTING_JUMP_BRIDGE_ACTIVATION else ''
     21     settingInfo = sgController.GetSettingInfo()
     22     valueRange = settingInfo.valueRange
     23     minValue, maxValue = valueRange
     24     value = sgController.GetValue()
     25     if settingType in (structures.SETTINGS_TYPE_INT, structures.SETTINGS_TYPE_ISK):
     26         amountEdit = SinglelineEditIntegerWithUnit(name='amountEdit', parent=parent, align=uiconst.CENTERRIGHT, OnChange=callback, unit=unit, hint=hint, minValue=minValue, maxValue=maxValue, pos=(4, 0, 60, 0))
     27         value = int(value)
     28         decimals = 0
     29     else:
     30         decimals = 1
     31         if settingInfo.decimals is not None:
     32             decimals = settingInfo.decimals
     33         amountEdit = SinglelineEditFloatWithUnit(name='amountEdit', parent=parent, align=uiconst.CENTERRIGHT, OnChange=callback, unit=unit, hint=hint, minValue=minValue, maxValue=maxValue, pos=(4, 0, 60, 0), decimalPlaces=decimals)
     34         value = float(value)
     35     amountEdit.SetValue(value)
     36     labelClass = amountEdit.textLabel.__class__
     37     maxText = '%s %s' % (FmtAmt(float(maxValue), showFraction=decimals), unit)
     38     labelWidth, labelHeight = labelClass.MeasureTextSize(maxText)
     39     maxWidth = labelWidth + 2 * amountEdit._textClipper.padLeft + 20
     40     newWidth = max(maxWidth, amountEdit.width)
     41     amountEdit.width = newWidth
     42     return amountEdit
     43 
     44 
     45 class SinglelineEditFloatWithUnit(SingleLineEditFloat):
     46 
     47     def ApplyAttributes(self, attributes):
     48         self.unit = attributes.unit
     49         super(SinglelineEditFloatWithUnit, self).ApplyAttributes(attributes)
     50 
     51     def SetText(self, text, format = True):
     52         super(SinglelineEditFloatWithUnit, self).SetText(text, format)
     53         if self.unit:
     54             self.textLabel.text += ' %s ' % self.unit
     55 
     56 
     57 class SinglelineEditIntegerWithUnit(SingleLineEditInteger):
     58 
     59     def ApplyAttributes(self, attributes):
     60         self.unit = attributes.unit
     61         super(SinglelineEditIntegerWithUnit, self).ApplyAttributes(attributes)
     62 
     63     def SetText(self, text, format = True):
     64         super(SinglelineEditIntegerWithUnit, self).SetText(text, format)
     65         if self.unit:
     66             self.textLabel.text += '%s' % self.unit