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

comparableAttribute.py (6860B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\comparison\comparableAttribute.py
      2 from carbon.common.script.sys.serviceConst import ROLE_GML
      3 from carbonui import TextColor
      4 from carbonui.control.contextMenu.menuData import MenuData
      5 from dogma import data as dogma_data
      6 import dogma.const as dogma_const
      7 from dogma.attributes.format import GetFormatAndValue, FormatUnit
      8 from eve.client.script.ui import eveColor
      9 from eve.common.lib import appConst
     10 from evelink.client import type_link
     11 from evelink.client.handlers.show_info.link import group_link
     12 from fsdBuiltData.common.iconIDs import GetIcon
     13 from inventorycommon import typeHelpers
     14 from localization import GetByLabel, GetByMessageID
     15 from localization.formatters import numericFormatters
     16 import blue
     17 
     18 def get_attribute_value(attribute_id, value, type_id):
     19     if attribute_id == appConst.attributeBaseWarpSpeed:
     20         multiplier = dogma_data.get_type_attribute(type_id, appConst.attributeWarpSpeedMultiplier, 1)
     21         return value * multiplier * appConst.AU
     22     elif attribute_id == appConst.attributeEstimatedPrice:
     23         return typeHelpers.GetAveragePrice(type_id)
     24     else:
     25         return value
     26 
     27 
     28 class BaseComparableAttribute(object):
     29 
     30     def __init__(self):
     31         self.is_best = False
     32         self.is_worst = False
     33 
     34     def set_best(self):
     35         self.is_best = True
     36 
     37     def set_worst(self):
     38         self.is_worst = True
     39 
     40     def clear_best_and_worst(self):
     41         self.is_best = False
     42         self.is_worst = False
     43 
     44     @property
     45     def attribute_id(self):
     46         raise NotImplementedError
     47 
     48     @property
     49     def name(self):
     50         raise NotImplementedError
     51 
     52     @property
     53     def value(self):
     54         raise NotImplementedError
     55 
     56     @property
     57     def unit_id(self):
     58         raise NotImplementedError
     59 
     60     @property
     61     def unit_name(self):
     62         return FormatUnit(self.unit_id)
     63 
     64     @property
     65     def texture_path(self):
     66         raise NotImplementedError
     67 
     68     @property
     69     def is_visible(self):
     70         return True
     71 
     72     @property
     73     def is_linear(self):
     74         return True
     75 
     76     @property
     77     def high_is_good(self):
     78         return True
     79 
     80     @property
     81     def is_link(self):
     82         return self.unit_id in (dogma_const.unitTypeID, dogma_const.unitGroupID)
     83 
     84     def get_value_text(self):
     85         if self.value is None:
     86             return GetByLabel('UI/Generic/NotAvailableShort')
     87         return self._get_value_text()
     88 
     89     def _get_value_text(self):
     90         return numericFormatters.FormatNumeric(self.value, useGrouping=True)
     91 
     92     def get_color(self):
     93         if self.is_linear and self.is_best:
     94             return eveColor.LIME_GREEN_HEX
     95         elif self.is_linear and self.is_worst and self.value:
     96             return eveColor.WARNING_ORANGE_HEX
     97         elif not self.value:
     98             return TextColor.DISABLED
     99         else:
    100             return TextColor.HIGHLIGHT
    101 
    102     def get_value_text_formatted(self):
    103         text = self.get_value_text()
    104         color = self.get_color()
    105         if color:
    106             return u'<color={}>{}</color>'.format(color, text)
    107         else:
    108             return text
    109 
    110     def get_tooltip_title(self):
    111         pass
    112 
    113     def get_tooltip_description(self):
    114         pass
    115 
    116     def get_menu(self):
    117         pass
    118 
    119 
    120 class ComparableAttribute(BaseComparableAttribute):
    121 
    122     def __init__(self, attribute_id, name, value, unit_id = None, texture_path = None):
    123         super(ComparableAttribute, self).__init__()
    124         self._attribute_id = attribute_id
    125         self._name = name
    126         self._value = value
    127         self._unit_id = unit_id
    128         self._texture_path = texture_path
    129 
    130     @property
    131     def attribute_id(self):
    132         return self._attribute_id
    133 
    134     @property
    135     def name(self):
    136         return self._name
    137 
    138     @property
    139     def value(self):
    140         return self._value
    141 
    142     @property
    143     def unit_id(self):
    144         return self._unit_id
    145 
    146     @property
    147     def texture_path(self):
    148         return self._texture_path
    149 
    150 
    151 class DogmaComparableAttribute(BaseComparableAttribute):
    152 
    153     def __init__(self, attribute_id, type_id):
    154         super(DogmaComparableAttribute, self).__init__()
    155         self.attribute = dogma_data.get_attribute(attribute_id)
    156         self.type_id = type_id
    157         self._value = dogma_data.get_type_attribute(type_id, attribute_id)
    158 
    159     @property
    160     def attribute_id(self):
    161         return self.attribute.attributeID
    162 
    163     @property
    164     def name(self):
    165         return GetByMessageID(self.attribute.displayNameID)
    166 
    167     @property
    168     def value(self):
    169         return get_attribute_value(self.attribute_id, self._value, self.type_id)
    170 
    171     @property
    172     def unit_id(self):
    173         return self.attribute.unitID
    174 
    175     @property
    176     def texture_path(self):
    177         icon = GetIcon(self.attribute.iconID)
    178         if icon:
    179             return icon.iconFile
    180 
    181     @property
    182     def is_visible(self):
    183         if not self.value and not self.attribute.displayWhenZero:
    184             return False
    185         if self.attribute.unitID == appConst.unitInverseAbsolutePercent and self.value == 1.0:
    186             return False
    187         return self.attribute.published
    188 
    189     @property
    190     def high_is_good(self):
    191         return self.attribute.highIsGood
    192 
    193     @property
    194     def is_linear(self):
    195         return self.unit_id not in dogma_const.non_linear_units
    196 
    197     def _get_value_text(self):
    198         text = GetFormatAndValue(dogma_data.get_attribute(self.attribute_id), self.value)
    199         if self.unit_id == dogma_const.unitTypeID:
    200             text = type_link(int(self.value), text)
    201         elif self.unit_id == dogma_const.unitGroupID:
    202             text = group_link(group_id=int(self.value), link_text=text)
    203         return text
    204 
    205     def get_tooltip_description(self):
    206         return dogma_data.get_attribute_tooltip_description(self.attribute_id)
    207 
    208     def get_menu(self):
    209         m = MenuData()
    210         if session.role & ROLE_GML > 0:
    211             m.AddEntry('GM - attributeID: %s' % self.attribute_id, lambda : blue.pyos.SetClipboardData(str(self.attribute_id)))
    212             name = self.attribute.name
    213             name = name[0].upper() + name[1:]
    214             name = '%s = %s' % ('attribute' + name, str(self.attribute_id))
    215             m.AddEntry(name, lambda : blue.pyos.SetClipboardData(name))
    216             import webbrowser
    217             m.AddEntry('Edit in FSD Editor', lambda : webbrowser.open('http://localhost:8000/dogma/attributes/{}/edit'.format(self.attribute_id)))
    218         return m
    219 
    220 
    221 class CanBeFittedToShipComparableAttribute(DogmaComparableAttribute):
    222 
    223     def __init__(self, attribute_ids, type_id):
    224         super(CanBeFittedToShipComparableAttribute, self).__init__(attribute_ids[0], type_id)
    225         self.attribute_ids = attribute_ids
    226 
    227     def get_value_text(self):
    228         ret = '\n'.join([ DogmaComparableAttribute(a_id, self.type_id).get_value_text() for a_id in self.attribute_ids ])
    229         return ret