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

mapViewLegend.py (11000B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\mapView\controls\mapViewLegend.py
      2 import math
      3 import eve.client.script.ui.shared.pointerTool.pointerToolConst as pConst
      4 import eveicon
      5 from carbonui.control.buttonIcon import ButtonIcon
      6 from carbonui.primitives.container import Container
      7 from carbonui import const as uiconst, Align, TextColor
      8 from carbonui.text.styles import TextBody
      9 from carbonui.primitives.containerAutoSize import ContainerAutoSize
     10 from carbonui.primitives.fill import Fill
     11 from carbonui.primitives.gradientSprite import GradientSprite
     12 from carbonui.primitives.sprite import Sprite
     13 from carbonui.primitives.stretchspritevertical import StretchSpriteVertical
     14 from eve.client.script.ui import eveColor
     15 from eve.client.script.ui.shared.mapView.controls.mapViewLegendConst import HeatmapLegendDefinition, AbsoluteLegendDefinition, COLOR_RANGE_DEUTER
     16 BAR_ENTRY_HEIGHT = 20
     17 
     18 class MapViewLegend(ContainerAutoSize):
     19     default_align = Align.BOTTOMLEFT
     20     default_width = 300
     21     default_alignMode = uiconst.TOBOTTOM
     22 
     23     def __init__(self, open_settings_callback, *args, **kwargs):
     24         super(MapViewLegend, self).__init__(*args, **kwargs)
     25         self._open_settings_callback = open_settings_callback
     26         self.legend_type = None
     27         self.legend_data = None
     28         self.color_bar_container = None
     29         self.labels_container = None
     30         self.settings_container = None
     31         self.construct_layout()
     32 
     33     def construct_layout(self):
     34         self._bottom_cont = Container(name='bottom_cont', parent=self, align=uiconst.TOBOTTOM, height=22, padTop=4)
     35         self._content_cont = ContainerAutoSize(name='content_cont', parent=self, align=uiconst.TOBOTTOM, alignMode=uiconst.BOTTOMLEFT, padLeft=4)
     36         self._top_cont = Container(name='top_cont', parent=self, align=uiconst.TOBOTTOM, height=32, padding=(0, 0, 0, 4))
     37         self._color_bar_cont = ContainerAutoSize(name='color_bar_cont', parent=self._content_cont, align=uiconst.BOTTOMLEFT, width=8)
     38         self._labels_cont = ContainerAutoSize(name='labels_cont', parent=self._content_cont, align=uiconst.BOTTOMLEFT, left=12)
     39         self._legend_label = TextBody(parent=self._bottom_cont, text='Legend', align=uiconst.BOTTOMLEFT, bold=True)
     40         self._settings_button = ButtonIcon(parent=self._top_cont, texturePath=eveicon.tune, align=uiconst.BOTTOMLEFT, pos=(0, 4, 16, 16), func=self.on_settings_clicked, color=TextColor.NORMAL, uniqueUiName=pConst.UNIQUE_NAME_MAP_COLOR_SETTINGS)
     41 
     42     def construct_test_data(self):
     43         test_data = HeatmapLegendDefinition(label='Hotness', max_value=100, color_range_id=COLOR_RANGE_DEUTER)
     44         self.update_legend(test_data)
     45 
     46     def on_filter_updated(self, filter):
     47         self._clear_legend()
     48         if hasattr(filter, 'GetLegend'):
     49             legend_def = filter.GetLegend()
     50             if legend_def:
     51                 self.update_legend(legend_def)
     52                 if filter.has_filter_settings:
     53                     self._settings_button.Show()
     54                 else:
     55                     self._settings_button.Hide()
     56                 self.Show()
     57                 return
     58         self.Hide()
     59 
     60     def update_height(self):
     61         height = self._bottom_cont.height + self._top_cont.height
     62         height += max(self._color_bar_cont.height, self._labels_cont.height)
     63 
     64     def update_legend(self, definition):
     65         if definition.label:
     66             self._legend_label.Show()
     67             self._legend_label.text = definition.label
     68         else:
     69             self._legend_label.Hide()
     70         if isinstance(definition, HeatmapLegendDefinition):
     71             self.update_heatmap_legend(definition.abs_min_value, definition.abs_max_value, definition.min_value, definition.max_value, definition.color_range)
     72         elif isinstance(definition, AbsoluteLegendDefinition):
     73             self.update_absolute_legend(definition.value_color_pairs)
     74 
     75     def update_heatmap_legend(self, abs_min_value, abs_max_value, min_value, max_value, color_range):
     76         self.legend_type = 'heatmap'
     77         self.legend_data = {'abs_min_value': abs_min_value,
     78          'abs_max_value': abs_max_value,
     79          'min_value': min_value,
     80          'max_value': max_value,
     81          'colors': color_range}
     82         self._render_heatmap()
     83 
     84     def update_absolute_legend(self, value_color_pairs):
     85         self.legend_type = 'absolute'
     86         self.legend_data = value_color_pairs
     87         self._render_absolute()
     88 
     89     def _render_heatmap(self):
     90         self._clear_legend()
     91         self._settings_button.Show()
     92         abs_min = self.legend_data['abs_min_value']
     93         abs_max = self.legend_data['abs_max_value']
     94         min_value = self.legend_data['min_value']
     95         max_value = self.legend_data['max_value']
     96         colors = self.legend_data['colors']
     97         num = float(len(colors.range) - 1)
     98         rgbData = []
     99         alphaData = []
    100         for idx, color in enumerate(colors.range):
    101             val = idx / num
    102             col = color[:3]
    103             rgbData.append((val, col))
    104             alphaData.append((val, color[3]))
    105 
    106         initial_height = 132
    107         height_remaining = initial_height
    108         text_height_remaining = initial_height
    109         max_value_is_abs_max = max_value == abs_max
    110         if not max_value_is_abs_max:
    111             height_remaining -= BAR_ENTRY_HEIGHT
    112             text_height_remaining -= BAR_ENTRY_HEIGHT
    113             StretchSpriteVertical(parent=self._color_bar_cont, color=colors.max_color, align=uiconst.TOTOP, height=BAR_ENTRY_HEIGHT, topEdgeSize=4, bottomEdgeSize=0, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_top.png')
    114             TextBody(parent=ContainerAutoSize(parent=self._labels_cont, align=uiconst.TOPLEFT, height=BAR_ENTRY_HEIGHT, top=0), text='{:.0f}+'.format(abs_max), align=uiconst.TOPLEFT, left=8)
    115         else:
    116             height_remaining -= 4
    117             Sprite(parent=self._color_bar_cont, align=uiconst.TOTOP, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_top_hat.png', color=colors.range[-1], height=4)
    118         if min_value != abs_min:
    119             height_remaining -= BAR_ENTRY_HEIGHT
    120             text_height_remaining -= BAR_ENTRY_HEIGHT
    121         else:
    122             height_remaining -= 4
    123         GradientSprite(name='gradient', align=uiconst.TOTOP, parent=self._color_bar_cont, width=8, height=height_remaining, rgbData=rgbData, rotation=math.pi / 2)
    124         if max_value_is_abs_max:
    125             maxText = u'{:.0f}+'.format(max_value)
    126             maxTop = 0
    127         else:
    128             maxText = u'{:.0f}'.format(max_value)
    129             maxTop = BAR_ENTRY_HEIGHT
    130         heatmap_label_cont = Container(name='gradient_border', parent=self._labels_cont, align=uiconst.TOPLEFT, height=text_height_remaining, width=200, top=maxTop)
    131         TextBody(parent=heatmap_label_cont, text=maxText, align=uiconst.TOPLEFT, left=8, top=0)
    132         TextBody(parent=heatmap_label_cont, text='{:.0f}'.format(min_value), align=uiconst.BOTTOMLEFT, left=8, top=0)
    133         if min_value != abs_min:
    134             StretchSpriteVertical(parent=self._color_bar_cont, color=colors.min_color, align=uiconst.TOTOP, height=BAR_ENTRY_HEIGHT, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_bottom.png', topEdgeSize=0, bottomEdgeSize=4)
    135             TextBody(parent=ContainerAutoSize(parent=self._labels_cont, align=uiconst.TOPLEFT, height=BAR_ENTRY_HEIGHT, top=initial_height - BAR_ENTRY_HEIGHT), text=abs_min, align=uiconst.TOPLEFT, left=8)
    136         else:
    137             Sprite(parent=self._color_bar_cont, align=uiconst.TOTOP, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_bottom_hat.png', color=colors.range[0][:3] + (1.0,), height=4)
    138 
    139     def _render_absolute(self):
    140         self._clear_legend()
    141         height_total = 0
    142         for idx, (label, color) in enumerate(self.legend_data):
    143             is_first = idx == 0
    144             is_last = idx == len(self.legend_data) - 1
    145             if isinstance(color, list):
    146                 self._render_gradient_entry(label, color, is_first, is_last, height_total)
    147                 height_total += BAR_ENTRY_HEIGHT * 2
    148             else:
    149                 self._render_single_color_entry(label, color, is_first, is_last, height_total)
    150                 height_total += BAR_ENTRY_HEIGHT
    151 
    152     def _render_gradient_entry(self, label, color_range, is_first, is_last, height_offset):
    153         height_remaining = BAR_ENTRY_HEIGHT * 2
    154         if is_first:
    155             height_remaining -= 4
    156             Sprite(parent=self._color_bar_cont, align=uiconst.TOTOP, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_top_hat.png', color=color_range[-1], height=4)
    157         if is_last:
    158             height_remaining -= 4
    159         rgbData = []
    160         for idx, color in enumerate(color_range):
    161             rgbData.append((float(idx) / (len(color_range) - 1), color[:3]))
    162 
    163         GradientSprite(name='gradient', align=uiconst.TOTOP, parent=self._color_bar_cont, width=8, height=height_remaining, rgbData=rgbData, rotation=math.pi / 2)
    164         TextBody(parent=Container(parent=self._labels_cont, align=uiconst.TOPLEFT, height=BAR_ENTRY_HEIGHT * 2, width=100, top=height_offset), text=label, align=uiconst.CENTERLEFT, left=8)
    165         if is_last:
    166             Sprite(parent=self._color_bar_cont, align=uiconst.TOTOP, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_bottom_hat.png', color=color_range[0][:3] + (1.0,), height=4)
    167 
    168     def _render_single_color_entry(self, label, color, is_first, is_last, height_offset):
    169         cornerSize = 0
    170         if is_first and is_last:
    171             StretchSpriteVertical(parent=self._color_bar_cont, color=color, align=uiconst.TOTOP, height=BAR_ENTRY_HEIGHT, topEdgeSize=4, bottomEdgeSize=4, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_bar.png', cornerSize=cornerSize)
    172         elif is_first:
    173             StretchSpriteVertical(parent=self._color_bar_cont, color=color, align=uiconst.TOTOP, height=BAR_ENTRY_HEIGHT, topEdgeSize=4, bottomEdgeSize=0, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_top.png', cornerSize=cornerSize)
    174         elif is_last:
    175             StretchSpriteVertical(parent=self._color_bar_cont, color=color, align=uiconst.TOTOP, height=BAR_ENTRY_HEIGHT, topEdgeSize=0, bottomEdgeSize=4, texturePath='res:/UI/Texture/classes/MapView/Legend/legend_bottom.png', cornerSize=cornerSize)
    176         else:
    177             Fill(parent=self._color_bar_cont, color=color, align=uiconst.TOTOP, height=BAR_ENTRY_HEIGHT)
    178         TextBody(parent=ContainerAutoSize(parent=self._labels_cont, align=uiconst.TOPLEFT, height=BAR_ENTRY_HEIGHT, top=height_offset), text=label, align=uiconst.TOPLEFT, left=8)
    179 
    180     def _clear_legend(self):
    181         if self._color_bar_cont:
    182             self._color_bar_cont.Flush()
    183         if self._labels_cont:
    184             self._labels_cont.Flush()
    185 
    186     def clear(self):
    187         self.legend_type = None
    188         self.legend_data = None
    189         self._clear_legend()
    190 
    191     def on_settings_clicked(self, *args, **kwargs):
    192         self._open_settings_callback()