all_offers_page.py (6974B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\omega\upsell\pages\all_offers_page.py 2 import uthread2 3 from carbon.common.script.util.format import FmtAmt 4 from carbonui import Align, TextColor 5 from carbonui.text.styles import TextHeadline, TextBody 6 from carbonui.control.scrollContainer import ScrollContainer 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.flowcontainer import FlowContainer 10 from carbonui.uianimations import animations 11 from eve.client.script.ui import eveColor 12 from eve.client.script.ui.control.eveLoadingWheel import LoadingWheel 13 from player_messaging.client.ui_message import message_player 14 from eve.client.script.ui.omega.upsell import omegaUpsellSignals 15 from eve.client.script.ui.omega.upsell.components.currency_toggle import CurrencyToggle 16 from eve.client.script.ui.omega.upsell.components.icons import PlexInfoIcon 17 from eve.client.script.ui.omega.upsell.components.offer_card import OfferCard 18 from plex.client.api.repository import get_repository 19 from plex.client.api.signal import on_balance_changed 20 from vgs.client.currency import CURRENCY_SYMBOL, CURRENCY_TEXT 21 from localization import GetByLabel 22 from stackless_response_router.exceptions import TimeoutException 23 from store.client.offers.offer_provider_svc import get_offer_provider_svc 24 25 class AllOffersPage(Container): 26 card_spacing = 32 27 28 def __init__(self, *args, **kwargs): 29 super(AllOffersPage, self).__init__(*args, **kwargs) 30 self._update_thread = None 31 self.construct_layout() 32 self.update() 33 34 def Close(self): 35 try: 36 self.kill_update_thread() 37 finally: 38 super(AllOffersPage, self).Close() 39 40 def kill_update_thread(self): 41 if self._update_thread is not None: 42 self._update_thread.kill() 43 self._update_thread = None 44 45 def construct_layout(self): 46 scroll_container = ScrollContainer(name='scroll_container', parent=self, padBottom=64) 47 self.flow_container = FlowContainer(name='flow_container', parent=scroll_container, align=Align.TOTOP, centerContent=True, contentSpacing=(self.card_spacing, self.card_spacing), padTop=12) 48 self.loading_wheel = LoadingWheel(name='loading_wheel', parent=self, align=Align.CENTER) 49 self.bottom_container = Container(name='bottom_container', parent=self, align=Align.TOPLEFT_PROP, pos=(0.5, 0.98, 636, 56)) 50 self.construct_currency_toggle() 51 self.plex_balance = PlexBalance(name='plex_balance', parent=self.bottom_container, align=Align.CENTERBOTTOM, opacity=0.0) 52 53 def construct_currency_toggle(self): 54 self.currency_container = ContainerAutoSize(name='currency_container', parent=self.bottom_container, align=Align.CENTERTOP, height=40, opacity=0.0) 55 self.currency_label = TextHeadline(name='currency_label', parent=self.currency_container, align=Align.TOLEFT, color=TextColor.HIGHLIGHT, padTop=4) 56 currency_toggle_container = Container(name='currency_toggle_container', parent=self.currency_container, align=Align.TOLEFT, width=38, padding=(8, 0, 8, 0)) 57 self.currency_toggle = CurrencyToggle(name='currency_toggle', parent=currency_toggle_container, align=Align.CENTER) 58 self.currency_toggle.on_switch_changed.connect(self.on_show_price_in_plex_change) 59 self.currency_toggle.Disable() 60 TextHeadline(name='plex_label', parent=self.currency_container, align=Align.TOLEFT, text=GetByLabel('UI/Common/PLEX'), color=eveColor.PLEX_YELLOW, padTop=4) 61 PlexInfoIcon(name='plex_icon', parent=self.currency_container, align=Align.TOLEFT, width=30, height=30, padding=(2, -2, 0, 0)) 62 63 def on_show_price_in_plex_change(self, toggle, is_checked): 64 if is_checked: 65 animations.FadeIn(self.plex_balance) 66 else: 67 animations.FadeOut(self.plex_balance) 68 omegaUpsellSignals.on_show_price_in_plex_change(is_checked) 69 70 def update(self): 71 self.kill_update_thread() 72 self._update_thread = uthread2.start_tasklet(self.update_async) 73 74 def update_async(self): 75 offers = self.load_offers() 76 if not offers: 77 return 78 sorted_offers = sorted(offers.items(), key=lambda offer: (offer[1].schedule_data.cycle_duration if offer[1].schedule_data else 0)) 79 self.update_currency(sorted_offers) 80 self.update_flow_container(sorted_offers) 81 self.update_cards(sorted_offers) 82 83 def load_offers(self): 84 try: 85 offers = get_offer_provider_svc().get_all_omega_subscription_offers() 86 animations.FadeOut(self.loading_wheel) 87 return offers 88 except TimeoutException: 89 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 90 except Exception: 91 message_player(GetByLabel('UI/Common/CannotConnectToServer')) 92 raise 93 94 def update_currency(self, offers): 95 currency_code = offers[0][1].price_before_tax.currency_code 96 currency_symbol = CURRENCY_SYMBOL.get(currency_code, currency_code) 97 currency_text = CURRENCY_TEXT.get(currency_code, currency_code) 98 self.currency_label.text = '%s %s' % (currency_symbol, currency_text) 99 self.currency_toggle.Enable() 100 animations.FadeIn(self.currency_container) 101 102 def update_flow_container(self, offers): 103 total_card_width = OfferCard.default_width * len(offers) 104 total_spacing_width = self.card_spacing * len(offers) - 1 105 self.flow_container.width = total_card_width + total_spacing_width 106 107 def update_cards(self, offers): 108 self.flow_container.Flush() 109 for offer_id, offer in offers: 110 OfferCard(parent=self.flow_container, offer_id=offer_id, offer=offer) 111 112 113 class PlexBalance(ContainerAutoSize): 114 default_height = 18 115 116 def __init__(self, *args, **kwargs): 117 super(PlexBalance, self).__init__(*args, **kwargs) 118 self.construct_layout() 119 self.update() 120 self.connect_signals() 121 122 def Close(self): 123 try: 124 self.disconnect_signals() 125 finally: 126 super(PlexBalance, self).Close() 127 128 def connect_signals(self): 129 on_balance_changed.connect(self.on_plex_balance_changed) 130 131 def disconnect_signals(self): 132 on_balance_changed.disconnect(self.on_plex_balance_changed) 133 134 def construct_layout(self): 135 TextBody(parent=self, align=Align.TOLEFT, text='%s:' % GetByLabel('UI/Neocom/PlexVault')) 136 icon_container = Container(parent=self, align=Align.TOLEFT, width=18, padTop=2, padLeft=4) 137 PlexInfoIcon(name='plex_icon', parent=icon_container, align=Align.CENTER, width=18, height=18) 138 self.balance_label = TextBody(parent=self, align=Align.TOLEFT) 139 140 def update(self): 141 self.balance_label.text = FmtAmt(get_repository().get_balance()) 142 143 def on_plex_balance_changed(self, *args): 144 self.update()