infoPanelPlanetaryInteraction.py (12397B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\infoPanelPlanetaryInteraction.py 2 import carbonui.const as uiconst 3 import eveicon 4 import uthread 5 import eve.client.script.ui.shared.planet.planetCommon as planetCommon 6 from carbonui.control.buttonIcon import ButtonIcon 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.containerAutoSize import ContainerAutoSize 9 from carbonui.primitives.fill import Fill 10 from carbonui.primitives.frame import Frame 11 from carbonui.util.color import Color 12 from eve.client.script.ui.control import eveLabel 13 from carbonui.button.group import ButtonGroup 14 from carbonui import AxisAlignment, ButtonVariant, Density 15 from carbonui.control.button import Button 16 from eve.client.script.ui.control.toggleButtonGroup import ToggleButtonGroup 17 from eve.client.script.ui.control.gauge import Gauge 18 from eve.client.script.ui.shared.cloneGrade.omegaRestrictedEntryInfoPanel import OmegaRestrictedEntryInfoPanel 19 from eve.client.script.ui.shared.infoPanels.InfoPanelBase import InfoPanelBase 20 from eve.client.script.ui.shared.infoPanels.const.infoPanelConst import PANEL_PLANETARY_INTERACTION 21 from eve.client.script.ui.shared.planet.resourceController import ResourceController 22 from eve.client.script.ui.shared.planet.planetEditModeContainer import PlanetEditModeContainer 23 from eve.client.script.ui.shared.planet.pinContainers.BasePinContainer import CaptionAndSubtext 24 from eve.client.script.ui.shared.shipTree.infoBubble import SkillEntry 25 from eve.common.lib import appConst 26 from eve.common.script.util.eveFormat import FmtISK 27 from localization import GetByLabel 28 from carbonui.uicore import uicore 29 from omega.client.clone_grade_svc import get_clone_grade_svc 30 EDITMODECONTAINER_HEIGHT = 105 31 32 class InfoPanelPlanetaryInteraction(InfoPanelBase): 33 default_name = 'InfoPanelPlanetaryInteraction' 34 panelTypeID = PANEL_PLANETARY_INTERACTION 35 label = 'UI/Chat/ChannelNames/PlanetaryInteraction' 36 hasSettings = False 37 isCollapsable = False 38 default_iconTexturePath = 'res:/UI/Texture/Classes/InfoPanels/PlanetaryInteraction.png' 39 __notifyevents__ = ['OnEditModeChanged', 40 'OnEditModeBuiltOrDestroyed', 41 'OnPlanetCommandCenterDeployedOrRemoved', 42 'OnSubscriptionChanged'] 43 44 def ApplyAttributes(self, attributes): 45 InfoPanelBase.ApplyAttributes(self, attributes) 46 sm.RegisterNotify(self) 47 self.inEditMode = False 48 self.omegaWarning = OmegaRestrictedEntryInfoPanel(parent=self.mainCont, align=uiconst.TOTOP, height=45, text=GetByLabel('UI/CloneState/PlanetExportingDisabled'), hint=GetByLabel('UI/CloneState/PlanetExportingDisabledHint'), padding=(0, 4, 0, 2)) 49 self.editModeContainer = Container(parent=self.mainCont, name='buttonContainer', align=uiconst.TOTOP, state=uiconst.UI_HIDDEN, padding=(0, 0, 0, 5)) 50 self.editModeContent = Container(parent=self.editModeContainer, name='editModeContent', align=uiconst.TOALL, padding=(10, 6, 10, 6)) 51 Fill(parent=self.editModeContainer, color=Color.GetGrayRGBA(0.0, 0.3)) 52 Frame(parent=self.editModeContainer, color=Color.GetGrayRGBA(0.0, 0.2)) 53 self.modeButtonGroup = ToggleButtonGroup(parent=self.mainCont, align=uiconst.TOTOP, callback=self.OnButtonSelected, padding=(0, 4, 0, 4)) 54 self.tabPanelContainer = ContainerAutoSize(parent=self.mainCont, name='tabPanelContainer', align=uiconst.TOTOP) 55 self.planetName = self.headerCls(parent=self.headerCont, state=uiconst.UI_NORMAL, align=uiconst.CENTERLEFT) 56 self.resourceControllerTab = ResourceController(parent=self.tabPanelContainer) 57 self.editModeTab = PlanetEditModeContainer(parent=self.tabPanelContainer) 58 self.modeButtonGroup.AddButton('editModeTab', GetByLabel('UI/Common/Build'), self.editModeTab) 59 scanBtn = self.modeButtonGroup.AddButton('resourceControllerTab', GetByLabel('UI/PI/Common/Scan'), self.resourceControllerTab) 60 scanBtn.LoadTooltipPanel = self.LoadScanBtnTooltipPanel 61 scanBtn.tooltipPointer = uiconst.POINT_LEFT_2 62 btnID = settings.char.ui.Get('planetInfoPanelModeButtons', 'editModeTab') 63 self.modeButtonGroup.SelectByID(btnID) 64 BTNSIZE = 24 65 exitBtn = ButtonIcon(parent=self.headerCont, align=uiconst.CENTERRIGHT, pos=(0, 66 0, 67 BTNSIZE, 68 BTNSIZE), texturePath=eveicon.close, iconSize=16, func=self.ExitPlanetMode, hint=GetByLabel('UI/PI/Common/ExitPlanetMode')) 69 homeBtn = ButtonIcon(parent=self.headerCont, align=uiconst.CENTERRIGHT, pos=(exitBtn.left + exitBtn.width + 2, 70 0, 71 BTNSIZE, 72 BTNSIZE), texturePath=eveicon.house, iconSize=16, func=self.ViewCommandCenter, hint=GetByLabel('UI/PI/Common/ViewPlanetaryCommandCenter')) 73 self.sr.homeBtn = homeBtn 74 self.UpdatePlanetText() 75 self.UpdateHomeButton() 76 self.UpdateOmegaWarning() 77 self.CreateEditModeContainer() 78 planetUISvc = sm.GetService('planetUI') 79 planetUISvc.SetModeController(self) 80 uthread.new(self.OnEditModeChanged, planetUISvc.inEditMode) 81 82 def LoadScanBtnTooltipPanel(self, tooltipPanel, *args): 83 tooltipPanel.LoadGeneric2ColumnTemplate() 84 tooltipPanel.state = uiconst.UI_NORMAL 85 tooltipPanel.AddLabelMedium(text=GetByLabel('UI/PI/Common/ScanRange'), colSpan=2, bold=True) 86 tooltipPanel.AddRow(rowClass=SkillEntry, typeID=appConst.typeRemoteSensing, showLevel=False) 87 tooltipPanel.AddLabelMedium(text=GetByLabel('UI/PI/Common/ScanQuality'), colSpan=2, cellPadding=(0, 10, 0, 0), bold=True) 88 tooltipPanel.AddRow(rowClass=SkillEntry, typeID=appConst.typePlanetology, showLevel=False) 89 tooltipPanel.AddRow(rowClass=SkillEntry, typeID=appConst.typeAdvancedPlanetology, showLevel=False) 90 91 def UpdateOmegaWarning(self): 92 if not get_clone_grade_svc().is_omega_with_grace_period(): 93 self.omegaWarning.Show() 94 else: 95 self.omegaWarning.Hide() 96 97 @staticmethod 98 def IsAvailable(): 99 viewState = sm.GetService('viewState').GetCurrentView() 100 if viewState and viewState.name == 'planet': 101 return True 102 return False 103 104 def UpdatePlanetText(self): 105 planetUI = sm.GetService('planetUI') 106 planetID = planetUI.planetID 107 planetData = sm.GetService('map').GetPlanetInfo(planetID) 108 self.planetName.text = '<color=white url=showinfo:%s//%s>%s</url>' % (planetData.typeID, planetID, cfg.evelocations.Get(planetID).locationName) 109 110 def OnButtonSelected(self, mode, *args): 111 sm.GetService('audio').SendUIEvent('msg_pi_general_switch_play') 112 if mode == 'resourceControllerTab': 113 sm.GetService('planetUI').planetAccessRequired = True 114 settings.char.ui.Set('planetInfoPanelModeButtons', mode) 115 116 def ExitPlanetMode(self, *args): 117 self.Disable() 118 if not sm.GetService('viewState').CloseSecondaryView('planet'): 119 self.Enable() 120 121 def ViewCommandCenter(self, *args): 122 sm.GetService('planetUI').FocusCameraOnCommandCenter() 123 124 def OnPlanetCommandCenterDeployedOrRemoved(self, *args): 125 self.UpdateHomeButton() 126 127 def OnSubscriptionChanged(self): 128 self.UpdateOmegaWarning() 129 130 def UpdateHomeButton(self): 131 if sm.GetService('planetUI').IsColonyPresent(): 132 self.sr.homeBtn.state = uiconst.UI_NORMAL 133 else: 134 self.sr.homeBtn.state = uiconst.UI_HIDDEN 135 136 def CreateEditModeContainer(self): 137 eveLabel.EveHeaderLarge(parent=self.editModeContent, text=GetByLabel('UI/PI/Common/EditsPending'), align=uiconst.RELATIVE) 138 self.powerGauge = Gauge(parent=self.editModeContent, pos=(0, 22, 115, 34), color=planetCommon.PLANET_COLOR_POWER, label=GetByLabel('UI/PI/Common/PowerUsage')) 139 self.cpuGauge = Gauge(parent=self.editModeContent, pos=(130, 22, 115, 34), color=planetCommon.PLANET_COLOR_CPU, label=GetByLabel('UI/PI/Common/CpuUsage')) 140 self.UpdatePowerAndCPUGauges() 141 self.costText = CaptionAndSubtext(parent=ContainerAutoSize(parent=self.editModeContent, align=uiconst.TOBOTTOM_NOPUSH), align=uiconst.TOPLEFT, width=120, padBottom=0, caption=GetByLabel('UI/Common/Cost'), subtext='') 142 ButtonGroup(parent=self.editModeContent, align=uiconst.TOBOTTOM, button_alignment=AxisAlignment.END, density=Density.COMPACT, buttons=[Button(label=GetByLabel('UI/Common/Submit'), func=self.Submit, args=(), variant=ButtonVariant.PRIMARY), Button(label=GetByLabel('UI/Common/Cancel'), func=self.Cancel, args=())]) 143 144 def UpdatePowerAndCPUGauges(self): 145 colony = sm.GetService('planetUI').GetCurrentPlanet().GetColony(session.charid) 146 if not colony or colony.colonyData is None: 147 return 148 originalData = sm.GetService('planetUI').GetCurrentPlanet().GetEditModeData() 149 if originalData is None: 150 origCpu = 0 151 origPower = 0 152 else: 153 origCpu = originalData.GetColonyCpuUsage() 154 origPower = originalData.GetColonyPowerUsage() 155 cpuOutput = float(colony.colonyData.GetColonyCpuSupply()) 156 powerOutput = float(colony.colonyData.GetColonyPowerSupply()) 157 cpu = colony.colonyData.GetColonyCpuUsage() 158 power = colony.colonyData.GetColonyPowerUsage() 159 cpuDiff = cpu - origCpu 160 powerDiff = power - origPower 161 self.cpuGauge.SetValue(cpu / cpuOutput if cpuOutput > 0 else 0) 162 self.cpuGauge.HideAllMarkers() 163 self.cpuGauge.ShowMarker(origCpu / cpuOutput if cpuOutput > 0 else 0) 164 self.powerGauge.SetValue(power / powerOutput if powerOutput > 0 else 0) 165 self.powerGauge.HideAllMarkers() 166 self.powerGauge.ShowMarker(origPower / powerOutput if powerOutput > 0 else 0) 167 if cpuDiff >= 0: 168 GetByLabel('UI/PI/Common/TeraFlopsAmountIncrease', amount=cpuDiff) 169 else: 170 GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=cpuDiff) 171 if powerDiff >= 0: 172 GetByLabel('UI/PI/Common/MegaWattsAmountIncrease', amount=powerDiff) 173 else: 174 GetByLabel('UI/PI/Common/MegaWattsAmount', amount=powerDiff) 175 self.cpuGauge.hint = GetByLabel('UI/PI/Common/TeraFlopsDiff', current=origCpu, after=cpu, maximum=cpuOutput) 176 self.powerGauge.hint = GetByLabel('UI/PI/Common/MegaWattsDiff', current=origPower, after=power, maximum=powerOutput) 177 178 def UpdateCostOfCurrentChanges(self): 179 cost = sm.GetService('planetUI').GetCurrentPlanet().GetCostOfCurrentEdits() 180 self.costText.SetSubtext(FmtISK(cost, showFractionsAlways=0)) 181 182 def Submit(self): 183 sm.GetService('planetUI').planet.SubmitChanges() 184 sm.GetService('audio').SendUIEvent('msg_pi_build_submit_play') 185 186 def Cancel(self): 187 sm.GetService('planetUI').RevertChanges() 188 sm.GetService('audio').SendUIEvent('msg_pi_build_cancel_play') 189 190 def OnEditModeChanged(self, isEdit): 191 if not isEdit: 192 uicore.animations.FadeOut(self.editModeContainer, duration=0.3, sleep=True) 193 uicore.animations.MorphScalar(self.editModeContainer, 'height', self.editModeContainer.height, 0, duration=0.3, sleep=True) 194 self.editModeContainer.state = uiconst.UI_HIDDEN 195 self.inEditMode = False 196 else: 197 self.UpdatePowerAndCPUGauges() 198 self.UpdateCostOfCurrentChanges() 199 self.editModeContainer.state = uiconst.UI_NORMAL 200 uicore.animations.MorphScalar(self.editModeContainer, 'height', 0, EDITMODECONTAINER_HEIGHT, duration=0.3, sleep=True) 201 uicore.animations.FadeTo(self.editModeContainer, 0.0, 1.0, duration=0.3, sleep=True) 202 self.inEditMode = True 203 self.editModeTab.UpdateButtons(self.inEditMode) 204 205 def OnEditModeBuiltOrDestroyed(self, planetID): 206 planetUI = sm.GetService('planetUI') 207 if planetUI.planetID != planetID: 208 return 209 if not self.inEditMode: 210 self.editModeContainer.state = uiconst.UI_NORMAL 211 uicore.animations.MorphScalar(self.editModeContainer, 'height', 0, EDITMODECONTAINER_HEIGHT, duration=0.3, sleep=True) 212 uicore.animations.FadeTo(self.editModeContainer, 0.0, 1.0, duration=0.3, sleep=True) 213 self.inEditMode = True 214 self.UpdatePowerAndCPUGauges() 215 self.UpdateCostOfCurrentChanges() 216 self.editModeTab.UpdateButtons(self.inEditMode)