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

confirmApplyWnd.py (7147B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\cosmetics\structure\confirmApplyWnd.py
      2 import trinity
      3 import uthread2
      4 from carbon.common.script.util.format import FmtAmt
      5 from carbonui import uiconst, TextColor
      6 from carbonui.button.group import ButtonGroup
      7 from carbonui.control.button import Button
      8 from carbonui.control.window import Window
      9 from carbonui.primitives.container import Container
     10 from carbonui.primitives.line import Line
     11 from carbonui.primitives.sprite import Sprite, StreamingVideoSprite
     12 from carbonui.uianimations import animations
     13 from cosmetics.common.structures.exceptions import StructurePaintError, InvalidDataError, InsufficientRolesError, InsufficientBalanceError, ForbiddenRequestError
     14 from eve.client.script.ui.control.eveLabel import EveLabelLarge, EveLabelMedium
     15 from eve.client.script.ui.control.loadingContainer import LoadingSpriteSize
     16 from player_messaging.client.ui_message import message_player
     17 from localization import GetByLabel
     18 
     19 class ConfirmApplyWnd(Window):
     20     default_width = 450
     21     default_height = 240
     22     default_windowID = 'confirmApplyWnd'
     23     default_useDefaultPos = True
     24     default_caption = GetByLabel('UI/Personalization/PaintTool/PurchaseSummary')
     25     default_iconNum = 'res:/UI/Texture/WindowIcons/paint_tool.png'
     26 
     27     def __init__(self, paintwork, structure_ids, duration_days = 0, total_em_cost = 0, *args, **kwargs):
     28         super(ConfirmApplyWnd, self).__init__(*args, **kwargs)
     29         self._paintwork = paintwork
     30         self._structure_ids = structure_ids
     31         self._duration_days = duration_days
     32         self._total_em_cost = total_em_cost
     33         self._loading_thread = None
     34         self._loading_sprite = None
     35         self.show_window_controls = False
     36         self.MakeUnResizeable()
     37         self.DefineButtons(buttons=uiconst.OKCANCEL, okLabel=GetByLabel('UI/Personalization/PaintTool/BuyAndActivate'), okFunc=self._on_confirm_button_click, cancelLabel=GetByLabel('UI/Common/Buttons/Cancel'), cancelFunc=self._on_cancel_button_click)
     38         self._construct_layout()
     39 
     40     def Close(self, *args, **kwargs):
     41         if self._loading_thread:
     42             self._loading_thread.kill()
     43             self._loading_thread = None
     44         super(ConfirmApplyWnd, self).Close(*args, **kwargs)
     45 
     46     def _construct_layout(self):
     47         self._contents_cont = Container(parent=self.content, name='contentsCont')
     48         EveLabelLarge(name='license_type_label', parent=self._contents_cont, align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/LicenseType', description_color=TextColor.SECONDARY, duration_color=TextColor.HIGHLIGHT, duration_days=self._duration_days), padTop=20)
     49         EveLabelLarge(name='number_of_structures_label', parent=self._contents_cont, align=uiconst.TOTOP, text=GetByLabel('UI/Personalization/PaintTool/NumberOfStructures', description_color=TextColor.SECONDARY, amount_color=TextColor.HIGHLIGHT, amount=len(self._structure_ids)), padTop=4)
     50         currency_icon_size = 20
     51         total_cost_container = Container(name='total_cost_container', parent=self._contents_cont, align=uiconst.TOTOP, padTop=4, height=currency_icon_size)
     52         EveLabelLarge(name='total_cost_label', parent=total_cost_container, align=uiconst.TOLEFT, text=GetByLabel('UI/Personalization/PaintTool/TotalCost'), color=TextColor.SECONDARY)
     53         Sprite(name='evermarks_icon', parent=total_cost_container, align=uiconst.TOLEFT, texturePath='res:/UI/Texture/Icons/evermarks.png', width=currency_icon_size, height=currency_icon_size)
     54         EveLabelLarge(name='total_cost_currency', parent=total_cost_container, align=uiconst.TOLEFT, text=FmtAmt(self._total_em_cost), color=TextColor.HIGHLIGHT)
     55         loading_sprite_size = LoadingSpriteSize.MEDIUM
     56         self._loading_sprite = StreamingVideoSprite(name='loading_sprite', parent=self.content, align=uiconst.CENTER, state=uiconst.UI_DISABLED, width=loading_sprite_size, height=loading_sprite_size, videoPath='res:/video/shared/loading_sprite_%s.webm' % loading_sprite_size, videoLoop=True, blendMode=trinity.TR2_SBM_ADD, spriteEffect=trinity.TR2_SFX_COPY, opacity=0.0)
     57         self._error_message = EveLabelMedium(parent=self.content, name='errorMessage', align=uiconst.TOALL, opacity=0.0, padTop=20)
     58         Line(parent=self._contents_cont, align=uiconst.TOBOTTOM, padBottom=20)
     59 
     60     def _on_confirm_button_click(self, _button):
     61         if self._loading_thread is None:
     62             self._loading_thread = uthread2.start_tasklet(self._send_apply_request)
     63 
     64     def _send_apply_request(self):
     65         try:
     66             self._on_apply_request_begin()
     67             cosmetics_license_svc = sm.GetService('cosmeticsLicenseSvc')
     68             cosmetics_license_svc.request_license_for_structures(structure_ids=self._structure_ids, paintwork=self._paintwork, duration=self._duration_days * 86400)
     69             self._on_apply_request_end()
     70             self.SetModalResult(uiconst.ID_OK)
     71         except StructurePaintError:
     72             self._show_error_message(GetByLabel('UI/Personalization/PaintTool/IssueRequestErrorDescription'))
     73         except InvalidDataError:
     74             self._show_error_message(GetByLabel('UI/Personalization/PaintTool/IssueRequestErrorDescription'))
     75         except InsufficientRolesError:
     76             self._show_error_message(GetByLabel('UI/Personalization/PaintTool/IssueRequestRolesErrorDescription'))
     77         except InsufficientBalanceError:
     78             self._show_error_message(GetByLabel('UI/Personalization/PaintTool/IssueRequestBalanceErrorDescription'))
     79         except ForbiddenRequestError:
     80             self._show_error_message(GetByLabel('UI/Personalization/PaintTool/IssueRequestErrorDescription'))
     81         except Exception:
     82             self._show_error_message(GetByLabel('UI/Personalization/PaintTool/IssueRequestErrorDescription'))
     83         finally:
     84             self._on_apply_request_end()
     85 
     86     def _on_apply_request_begin(self):
     87         for component in self.sr.bottom.children:
     88             if isinstance(component, ButtonGroup):
     89                 for btn in component.buttons:
     90                     btn.enabled = False
     91 
     92         animations.FadeTo(self._loading_sprite, self._loading_sprite.opacity, 1.0, duration=0.1)
     93         animations.FadeTo(self._contents_cont, self._contents_cont.opacity, 0.0, duration=0.1)
     94         animations.FadeTo(self._error_message, self._error_message.opacity, 0.0, duration=0.1)
     95 
     96     def _on_apply_request_end(self):
     97         self._loading_thread = None
     98         for component in self.sr.bottom.children:
     99             if isinstance(component, ButtonGroup):
    100                 for btn in component.buttons:
    101                     btn.enabled = True
    102 
    103     def _show_error_message(self, msg):
    104         self._error_message.text = msg
    105         animations.FadeTo(self._error_message, self._error_message.opacity, 1.0, duration=0.1)
    106         animations.FadeTo(self._loading_sprite, self._loading_sprite.opacity, 0.0, duration=0.1)
    107         animations.FadeTo(self._contents_cont, self._contents_cont.opacity, 0.0, duration=0.1)
    108 
    109     def _on_cancel_button_click(self, _button):
    110         self.SetModalResult(uiconst.ID_CANCEL)
    111         self.CloseByUser()