single_campaign_panel.py (8226B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\theatersOfWar\campaigns\panels\single_campaign_panel.py 2 import carbonui.const as uiconst 3 import eveicon 4 import logging 5 import uthread2 6 from carbonui import Align, TextColor, PickState 7 from carbonui.control.buttonIcon import ButtonIcon 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.containerAutoSize import ContainerAutoSize 10 from carbonui.text.styles import TextDetail 11 from carbonui.uianimations import animations 12 from carbonui.uiconst import ANIM_LINEAR, UI_NORMAL 13 from carbonui.uicore import uicore 14 from collections import OrderedDict 15 from eve.client.script.ui.shared.theatersOfWar.campaigns.panels.briefing_panel import CampaignBriefing 16 from eve.client.script.ui.shared.theatersOfWar.campaigns.panels.geography_panel import CampaignGeography 17 from eve.client.script.ui.shared.theatersOfWar.campaigns.panels.overview_panel import CampaignOverview 18 from eve.client.script.ui.shared.theatersOfWar.campaigns.panels.page_selector import PageSelector 19 from eve.client.script.ui.shared.theatersOfWar.campaigns.panels.panel_const import PANEL_ID_OVERVIEW, PANEL_ID_OBJECTIVES, PANEL_ID_DAYS_BRIEFING, PANEL_ID_GEOGRAPHY, PANEL_LEFT_PADDING 20 from eveexceptions import ExceptionEater 21 from eveui import Mouse 22 from localization.formatters.timeIntervalFormatters import GetByLabel 23 logger = logging.getLogger(__name__) 24 25 class SingleCampaignPanel(Container): 26 default_name = 'singleCampaignPanel' 27 default_align = Align.TOALL 28 default_state = uiconst.UI_NORMAL 29 30 def ApplyAttributes(self, attributes): 31 self.current_campaign_id = None 32 self.panels = {} 33 self.recommended_section = None 34 super(SingleCampaignPanel, self).ApplyAttributes(attributes) 35 self.campaignPanelController = attributes.campaignPanelController 36 campaign_controller = self.campaignPanelController.selected_campaign_controller 37 pages_dict = OrderedDict() 38 pages_dict[PANEL_ID_OVERVIEW] = GetByLabel('UI/Campaigns/OverviewPage') 39 if not campaign_controller.is_expired: 40 pages_dict[PANEL_ID_OBJECTIVES] = GetByLabel('UI/Campaigns/ObjectivesPage') 41 pages_dict[PANEL_ID_DAYS_BRIEFING] = GetByLabel('UI/Campaigns/BriefingPage') 42 pages_dict[PANEL_ID_GEOGRAPHY] = GetByLabel('UI/Campaigns/GeographyPage') 43 selected_page_id = self.campaignPanelController.selected_campaign_page_id 44 if selected_page_id not in pages_dict: 45 selected_page_id = pages_dict.keys()[0] 46 self.campaignPanelController.selected_campaign_page_id = selected_page_id 47 self.page_selector = PageSelector(parent=self, pages=pages_dict, align=Align.CENTERRIGHT, left=32, selected_page_id=selected_page_id) 48 self._construct_back_button() 49 self.content_cont = ContainerAutoSize(parent=self, align=Align.TOTOP) 50 w, height = self.GetAbsoluteSize() 51 self.panels = {PANEL_ID_OVERVIEW: CampaignOverview(parent=self.content_cont, campaignPanelController=self.campaignPanelController, height=height), 52 PANEL_ID_DAYS_BRIEFING: CampaignBriefing(parent=self.content_cont, campaignPanelController=self.campaignPanelController, height=height), 53 PANEL_ID_GEOGRAPHY: CampaignGeography(parent=self.content_cont, campaignPanelController=self.campaignPanelController, height=height)} 54 self.reload_panels() 55 self.connect_signals() 56 57 def _construct_back_button(self): 58 self.back_cont = ContainerAutoSize(name='back_cont', parent=self, align=Align.TOTOP_NOPUSH, left=PANEL_LEFT_PADDING) 59 ButtonAndText(parent=self.back_cont, text=GetByLabel('UI/Campaigns/BackToCampaignSelection'), texture_path=eveicon.navigate_back, onclick_callback=self.go_back) 60 61 def go_back(self, *args): 62 self.campaignPanelController.selected_campaign_id = None 63 64 def reload_panels(self): 65 self.current_campaign_id = self.campaignPanelController.selected_campaign_id 66 for p in self.panels.itervalues(): 67 p.load_ui() 68 69 def is_selected_campaign_loaded(self): 70 return self.current_campaign_id == self.campaignPanelController.selected_campaign_id 71 72 def connect_signals(self): 73 self.page_selector.on_page_selected.connect(self.on_page_selected) 74 75 def disconnect_signals(self): 76 self.page_selector.on_page_selected.disconnect(self.on_page_selected) 77 78 def OnMouseWheel(self, *args): 79 self.page_selector.on_mouse_wheel(*args) 80 81 def on_page_selected(self, new_page_id, current_page_id): 82 self.campaignPanelController.selected_campaign_page_id = new_page_id 83 self.change_page(new_page_id, current_page_id) 84 85 def ClickButton(self, button): 86 self.Browse(1) 87 88 def Browse(self, direction = 1): 89 self.page_selector.browse(direction) 90 91 def change_page(self, new_page_id, old_page_id): 92 if new_page_id == old_page_id: 93 return 94 w, height = self.GetAbsoluteSize() 95 duration = 1.0 96 y_offset = self._get_y_offset(new_page_id, height) 97 animations.MorphScalar(self.content_cont, 'top', self.content_cont.top, -y_offset, duration=duration, curveType=ANIM_LINEAR, callback=lambda *args: self._stop_on_page(y_offset)) 98 self.page_selector.show_page_page_as_selected(new_page_id) 99 for p in self.panels.itervalues(): 100 p.change_page(new_page_id, old_page_id) 101 102 self.animate_back() 103 104 def animate_back(self): 105 self.back_cont.opacity = 0.0 106 animations.FadeIn(self.back_cont, duration=2.0) 107 108 def _get_y_offset(self, new_page_id, height): 109 if new_page_id in (PANEL_ID_OVERVIEW, PANEL_ID_OBJECTIVES): 110 y_offset = 0 111 else: 112 page_idx = self.page_selector.get_idx_for_page_id(new_page_id) 113 if self.page_selector.is_page_in_selector(PANEL_ID_OBJECTIVES): 114 y_offset = (page_idx - 1) * height 115 else: 116 y_offset = page_idx * height 117 return y_offset 118 119 def _stop_on_page(self, top): 120 self.content_cont.top = -top 121 122 def _OnSizeChange_NoBlock(self, width, height): 123 current_page_id = self.campaignPanelController.selected_campaign_page_id or 0 124 for p in self.panels.itervalues(): 125 p.height = height 126 p._on_size_changed(width, height) 127 128 self.content_cont.top = -self._get_y_offset(current_page_id, height) 129 130 def Close(self): 131 super(SingleCampaignPanel, self).Close() 132 with ExceptionEater('Failed to disconnect in SingleCampaignPanel'): 133 self.disconnect_signals() 134 135 136 class ButtonAndText(ContainerAutoSize): 137 default_state = UI_NORMAL 138 139 def ApplyAttributes(self, attributes): 140 super(ButtonAndText, self).ApplyAttributes(attributes) 141 texture_path = attributes.texture_path 142 text = attributes.text 143 inner_cont = ContainerAutoSize(parent=self, padding=(0, 0, 8, 8)) 144 self.onclick_callback = attributes.onclick_callback 145 self.btn = ButtonIcon(name='btn', parent=inner_cont, align=uiconst.CENTERLEFT, iconSize=16, pos=(0, 0, 16, 16), texturePath=texture_path, opacity_enabled=TextColor.SECONDARY.opacity, pickState=PickState.OFF) 146 self.label = TextDetail(parent=inner_cont, align=Align.CENTERLEFT, text=text, color=TextColor.SECONDARY, left=24) 147 148 def OnMouseEnter(self, *args): 149 self._update_mouseover_state() 150 151 def OnMouseExit(self, *args): 152 self._update_mouseover_state() 153 154 def OnMouseDown(self, button): 155 self._update_mouseover_state() 156 157 def OnMouseUp(self, button): 158 self._update_mouseover_state() 159 160 def _update_mouseover_state(self): 161 if uicore.uilib.mouseOver == self: 162 if Mouse.left.is_down: 163 glow_amount = 1.0 164 text_opacity = 1.0 165 else: 166 glow_amount = 0.5 167 text_opacity = 0.75 168 else: 169 glow_amount = 0.0 170 text_opacity = TextColor.SECONDARY.opacity 171 animations.MorphScalar(self.btn.icon, 'glowBrightness', endVal=glow_amount, duration=0.2) 172 self.label.opacity = text_opacity 173 174 def OnClick(self, *args): 175 self.onclick_callback()