shipsView.py (7174B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation\empireTechnologyViews\shipsView.py 2 import blue 3 from carbon.common.script.util.timerstuff import AutoTimer 4 from carbonui import uiconst 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.sprite import Sprite 7 from carbonui.uicore import uicore 8 from charactercreator.client.scalingUtils import GetScaleFactor, SMALL_PANEL_WIDTH, SMALL_PANEL_HEIGHT, GetMainPanelWidth, GetMainPanelHeight, GetTopNavHeight, PANEL_HEADER_HEIGHT, GetBannerHeaderHeight 9 from eve.client.script.ui.login.charcreation.empireTechnologyViews.shipsViewData import ShipData 10 from eve.client.script.ui.login.charcreation.empireTechnologyViews.technologyView import TechnologyViewWithCentralPic 11 from eve.client.script.ui.login.charcreation.empireui.empireThemedTooltip import EmpireThemedTooltip, get_tooltip_width 12 from eve.common.lib.appConst import raceAmarr, raceCaldari, raceGallente, raceMinmatar 13 COLOR_CODE_MAP_BY_RACE = {raceAmarr: 'res:/UI/Texture/classes/EmpireSelection/Ships/fleetAmarr_colormap.png', 14 raceCaldari: 'res:/UI/Texture/classes/EmpireSelection/Ships/fleetCaldari_colormap.png', 15 raceGallente: 'res:/UI/Texture/classes/EmpireSelection/Ships/fleetGallente_colormap.png', 16 raceMinmatar: 'res:/UI/Texture/classes/EmpireSelection/Ships/fleetMinmatar_colormap.png'} 17 NO_COLOR = (0.0, 0.0, 0.0, 0.0) 18 COLOR_MAP_WIDTH = 1280 19 COLOR_MAP_HEIGHT = 800 20 HOVER_FREQUENCY = 250 21 X_SCALE_FACTOR_COLOR_MAP = float(COLOR_MAP_WIDTH) / float(SMALL_PANEL_WIDTH) 22 Y_SCALE_FACTOR_COLOR_MAP = float(COLOR_MAP_HEIGHT) / float(SMALL_PANEL_HEIGHT - PANEL_HEADER_HEIGHT) 23 TOOLTIP_MARGIN = 5 24 MOUSE_OVER_SHIP_SOUND = 'ui_es_ship_mouse_over_play' 25 MOUSE_EXIT_SHIP_SOUND = 'ui_es_ship_mouse_over_stop' 26 CENTRAL_VIEW_FADE_IN_DURATION = 2.0 27 28 class ShipsView(TechnologyViewWithCentralPic): 29 default_state = uiconst.UI_NORMAL 30 31 def ApplyAttributes(self, attributes): 32 self.is_ready = False 33 TechnologyViewWithCentralPic.ApplyAttributes(self, attributes) 34 self.tooltips = {} 35 self.hovered_ship_order_current = None 36 self.hover_x_new = None 37 self.hover_y_new = None 38 self.hover_thread = None 39 self.audio_svc = sm.GetService('audio') 40 self.ship_data = ShipData(self.technology, self.raceID).get_ship_data() 41 self.calculate_static_offsets() 42 self.calculate_proportions() 43 self.build_tooltips() 44 self.color_code_map = blue.resMan.GetResource(COLOR_CODE_MAP_BY_RACE[self.raceID], 'raw') 45 self.build_ship_by_color_code() 46 TechnologyViewWithCentralPic.ShowMainView(self) 47 self.is_ready = True 48 49 def Close(self): 50 self.hover_thread = None 51 TechnologyViewWithCentralPic.Close(self) 52 53 def clear_tooltips(self): 54 for tooltip in self.tooltips.values(): 55 tooltip.close() 56 57 self.tooltips = {} 58 59 def build_tooltips(self): 60 self.clear_tooltips() 61 for ship_order, ship_info in self.ship_data.iteritems(): 62 panel_width = GetMainPanelWidth() 63 margin = (uicore.desktop.width - panel_width) / 2 64 tooltip_left = ship_info['tooltip_left'] * self.scale_factor 65 tooltip_top = ship_info['tooltip_top'] * self.scale_factor 66 tooltip_width = get_tooltip_width() 67 if tooltip_left - TOOLTIP_MARGIN < -margin: 68 tooltip_left = -margin + TOOLTIP_MARGIN 69 elif tooltip_left + TOOLTIP_MARGIN + tooltip_width > panel_width + margin: 70 tooltip_left = panel_width + margin - tooltip_width - TOOLTIP_MARGIN 71 self.tooltips[ship_order] = EmpireThemedTooltip(name='Ship%d_%s' % (ship_order, ship_info['title']), parent=self, raceID=self.raceID, icon=ship_info['icon'], title=ship_info['title'], text=ship_info['subtitle'], left=tooltip_left, top=tooltip_top) 72 73 def build_ship_by_color_code(self): 74 self.ship_by_color_code = {} 75 for ship_order, ship_info in self.ship_data.iteritems(): 76 color_code = ship_info['color_code'] 77 self.ship_by_color_code[color_code] = ship_order 78 79 def calculate_static_offsets(self): 80 self.x_scale_factor_map = float(COLOR_MAP_WIDTH) / float(SMALL_PANEL_WIDTH) 81 self.y_scale_factor_map = float(COLOR_MAP_HEIGHT) / float(SMALL_PANEL_HEIGHT - PANEL_HEADER_HEIGHT) 82 83 def calculate_proportions(self): 84 self.x_offset = self.displayX + int(round((uicore.desktop.width - GetMainPanelWidth()) / 2)) 85 self.y_offset = self.displayY + int(round(GetTopNavHeight())) 86 self.scale_factor = GetScaleFactor() 87 viewWidthMinRes = SMALL_PANEL_WIDTH 88 viewWidth = GetMainPanelWidth() 89 viewHeightMinRes = SMALL_PANEL_HEIGHT - PANEL_HEADER_HEIGHT 90 viewHeight = GetMainPanelHeight() - GetBannerHeaderHeight() 91 self.scale_x = float(viewWidthMinRes) / float(viewWidth) 92 self.scale_y = float(viewHeightMinRes) / float(viewHeight) 93 94 def find_ship_from_color_map(self, x, y): 95 if self.hover_x_new is None or self.hover_y_new is None: 96 return 97 x_in_view = x - self.x_offset 98 y_in_view = y - self.y_offset 99 min_res_x_in_view = int(round(x_in_view * self.scale_x)) 100 min_res_y_in_view = int(round(y_in_view * self.scale_y)) 101 map_x = int(round(min_res_x_in_view * self.x_scale_factor_map)) 102 map_y = int(round(min_res_y_in_view * self.y_scale_factor_map)) 103 color_code = self.color_code_map.GetPixelColor(map_x, map_y) 104 ship_order = self.ship_by_color_code.get(color_code, None) 105 return ship_order 106 107 def OnMouseMove(self, *args): 108 if not self.is_ready: 109 return 110 self.hover_x_new = uicore.uilib.x 111 self.hover_y_new = uicore.uilib.y 112 self.show_ship_hover() 113 114 def OnMouseExit(self, *args): 115 if not self.is_ready: 116 return 117 self.hover_x_new = None 118 self.hover_y_new = None 119 self.show_ship_hover() 120 121 def show_ship_hover(self): 122 if not self.hover_thread: 123 self.hover_thread = AutoTimer(HOVER_FREQUENCY, self.show_ship_hover_timed) 124 125 def show_ship_hover_timed(self): 126 try: 127 if self.destroyed: 128 return 129 hovered_ship_order = self.find_ship_from_color_map(x=self.hover_x_new, y=self.hover_y_new) 130 if self.hovered_ship_order_current == hovered_ship_order: 131 return 132 if self.hovered_ship_order_current is not None: 133 self.tooltips[self.hovered_ship_order_current].set_visibility(False) 134 self.audio_svc.SendUIEvent(MOUSE_EXIT_SHIP_SOUND) 135 self.hovered_ship_order_current = hovered_ship_order 136 if self.hovered_ship_order_current is None: 137 return 138 self.tooltips[self.hovered_ship_order_current].set_visibility(True) 139 self.audio_svc.SendUIEvent(MOUSE_OVER_SHIP_SOUND) 140 finally: 141 self.hover_thread = None 142 143 def _OnResize(self, *args): 144 self.is_ready = False 145 self.calculate_proportions() 146 self.build_tooltips() 147 self.is_ready = True