itemtraderwindow_legacy.py (6807B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\itemTrader\itemtraderwindow_legacy.py 2 from carbon.common.script.util.format import FmtAmt 3 from carbonui import fontconst 4 from carbonui.primitives.sprite import Sprite 5 from carbonui.control.window import Window 6 import carbonui.const as uiconst 7 from carbonui.primitives.container import Container 8 from carbonui.control.scrollContainer import ScrollContainer 9 from carbonui.primitives.flowcontainer import FlowContainer 10 from carbonui.primitives.line import Line 11 from eve.client.script.ui.control.eveLabel import Label, EveLabelLarge 12 from carbonui.control.button import Button 13 from eve.common.script.util.eveFormat import FmtISK 14 from eveservices.menu import GetMenuService 15 from localization import GetByLabel 16 from eve.client.script.ui.control.eveIcon import Icon 17 import evetypes 18 import blue 19 20 class ItemTraderWindow(Window): 21 __guid__ = 'form.ItemTraderWindow' 22 default_minSize = (300, 489) 23 default_windowID = 'itemTrader_legacy' 24 25 def ApplyAttributes(self, attributes): 26 Window.ApplyAttributes(self, attributes) 27 self.itemTrader = attributes.itemTrader 28 self.shipID = attributes.shipID 29 self.cargoChecker = attributes.cargoChecker 30 self.default_caption = evetypes.GetName(self.itemTrader.typeID) 31 self.ConstructButtons() 32 self.mainContainer = Container(name='mainContainer', parent=self.sr.main) 33 self.ConstructInputSection() 34 self.outputSection = None 35 36 def ConstructButtons(self): 37 buttonParent = FlowContainer(name='buttonParent', parent=self.sr.main, align=uiconst.TOBOTTOM, padding=6, autoHeight=True, centerContent=True, contentSpacing=(6, 6)) 38 self.acceptButton = Button(parent=buttonParent, label=GetByLabel('UI/PVPTrade/Accept'), func=self.Accept, align=uiconst.NOALIGN) 39 Button(parent=buttonParent, label=GetByLabel('UI/Common/Buttons/Cancel'), func=self.Close, align=uiconst.NOALIGN) 40 self.CanPlayerAcceptTrade() 41 42 def ConstructInputSection(self): 43 self.inputSection = Container(name='inputSection', parent=self.mainContainer, align=uiconst.TOTOP_PROP, height=0.55, padding=(5, 0, 5, 0)) 44 self.inputHeader = Container(name='inputHeader', parent=self.inputSection, align=uiconst.TOTOP, height=50) 45 Label(parent=self.inputHeader, text=GetByLabel('UI/Inflight/SpaceComponents/ItemTrader/RequiredItems', itemCount=2), fontsize=25, align=uiconst.CENTER) 46 Line(parent=self.inputHeader, align=uiconst.TOBOTTOM) 47 self.inputListSection = ScrollContainer(name='inputListSection', parent=self.inputSection, align=uiconst.TOTOP, height=192) 48 inputIsk = self.itemTrader.GetInputIsk() 49 self.PopulateItemsToScroll(self.inputListSection, self.itemTrader.GetInputItems()) 50 self.AddIskToScroll(self.inputListSection, inputIsk) 51 52 def Accept(self, *args): 53 if not self.CanPlayerAcceptTrade(): 54 return 55 success = self.ProcessTrade() 56 if success: 57 self.ConstructOutputSection() 58 self.CanPlayerAcceptTrade() 59 60 def AddIskToScroll(self, scroll, amount): 61 if amount <= 0: 62 return 63 itemContainer = Container(parent=scroll, align=uiconst.TOTOP, height=64) 64 Line(parent=itemContainer, align=uiconst.TOBOTTOM) 65 Sprite(parent=itemContainer, align=uiconst.CENTERLEFT, width=64, height=64, texturePath='res:/ui/Texture/WindowIcons/wallet.png') 66 labelContainer = Container(parent=itemContainer, align=uiconst.TOALL, padding=(64, 0, 64, 0)) 67 EveLabelLarge(parent=labelContainer, text=FmtISK(amount, False), align=uiconst.CENTERLEFT, width=128) 68 69 def PopulateItemsToScroll(self, scroll, items): 70 for typeId, quantity in items.iteritems(): 71 itemContainer = Container(parent=scroll, align=uiconst.TOTOP, height=64) 72 Line(parent=itemContainer, align=uiconst.TOBOTTOM) 73 icon = Icon(parent=itemContainer, typeID=typeId, align=uiconst.CENTERLEFT, width=64, height=64) 74 icon.GetMenu = lambda t = typeId: GetMenuService().GetMenuFromItemIDTypeID(None, t) 75 icon.OnClick = lambda t = typeId: sm.GetService('info').ShowInfo(typeID=t) 76 labelContainer = Container(parent=itemContainer, name='labelContainer', align=uiconst.TOALL, padding=(64, 0, 64, 0)) 77 Label(parent=labelContainer, text=evetypes.GetName(typeId), fontsize=fontconst.EVE_SMALL_FONTSIZE, align=uiconst.CENTER, width=128) 78 quantityContainer = Container(parent=itemContainer, name='quantityContainer', align=uiconst.TORIGHT, width=64) 79 qtyText = FmtAmt(quantity) 80 qtyLabel = Label(parent=quantityContainer, text=GetByLabel('UI/Common/Quantity') + ' ' + qtyText, fontsize=fontconst.EVE_SMALL_FONTSIZE, align=uiconst.CENTER) 81 quantityContainer.width = max(quantityContainer.width, qtyLabel.width) 82 83 def ConstructOutputSection(self): 84 self.CloseOutputSection() 85 blue.pyos.synchro.Sleep(1000) 86 self.CloseOutputSection() 87 self.outputSection = Container(name='outputSection', parent=self.mainContainer, align=uiconst.TOTOP_PROP, height=0.45, padding=(5, 0, 5, 0)) 88 self.outputHeader = Container(name='outputHeader', parent=self.outputSection, align=uiconst.TOTOP, height=50) 89 Label(parent=self.outputHeader, text=GetByLabel('UI/Inflight/SpaceComponents/ItemTrader/DeliveredItems', itemCount=2), fontsize=25, align=uiconst.CENTER) 90 Line(parent=self.outputHeader, align=uiconst.TOBOTTOM) 91 self.outputListSection = ScrollContainer(name='outputListSection', parent=self.outputSection, align=uiconst.TOTOP, height=128) 92 self.PopulateItemsToScroll(self.outputListSection, self.itemTrader.GetOutputItems()) 93 94 def CanPlayerAcceptTrade(self): 95 if not self.cargoChecker.IsRequiredCargoSpaceAvailable(): 96 self.acceptButton.Disable() 97 self.acceptButton.hint = GetByLabel('UI/Inflight/SpaceComponents/ItemTrader/LackOfCargo') 98 return False 99 if not self.cargoChecker.AreRequiredItemsPresent(): 100 self.acceptButton.Disable() 101 self.acceptButton.hint = GetByLabel('UI/Inflight/SpaceComponents/ItemTrader/MissingItem') 102 return False 103 if sm.GetService('wallet').GetWealth() < self.itemTrader.GetInputIsk(): 104 self.acceptButton.Disable() 105 self.acceptButton.hint = GetByLabel('UI/Inflight/SpaceComponents/ItemTrader/MissingISK') 106 return False 107 self.acceptButton.Enable() 108 self.acceptButton.hint = '' 109 return True 110 111 def ProcessTrade(self): 112 return self.itemTrader.ProcessTrade() 113 114 def CloseOutputSection(self): 115 if self.outputSection: 116 self.outputSection.Close()