/
planetModeContainer.py
219 lines (168 loc) · 10.2 KB
/
planetModeContainer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import uiconst
import planet
import uicls
import planetCommon
import util
import localization
EDITMODECONTAINER_HEIGHT = 110
class PlanetModeContainer(uicls.NeocomContainer):
__guid__ = 'planet.ui.PlanetModeContainer'
default_name = 'planetModeContainer'
__notifyevents__ = ['OnEditModeChanged', 'OnEditModeBuiltOrDestroyed', 'OnPlanetCommandCenterDeployedOrRemoved']
default_padLeft = 0
def ApplyAttributes(self, attributes):
self.mode = None
uicls.NeocomContainer.ApplyAttributes(self, attributes)
self.inEditMode = False
self.CreateLayout()
sm.RegisterNotify(self)
def CreateLayout(self):
self.headerContainer = uicls.Container(parent=self.content, name='headerContainer', align=uiconst.TOTOP, pos=(0, 0, 0, 40))
self.editModeContainer = uicls.Container(parent=self.content, name='buttonContainer', align=uiconst.TOTOP, state=uiconst.UI_HIDDEN, padding=(0, 0, 0, 5))
self.editModeContent = uicls.Container(parent=self.editModeContainer, name='editModeContent', align=uiconst.TOALL, padding=(10, 6, 10, 6))
uicls.Fill(parent=self.editModeContainer, color=util.Color.GetGrayRGBA(0.0, 0.3))
uicls.Frame(parent=self.editModeContainer, color=util.Color.GetGrayRGBA(0.0, 0.2))
self.tabButtonContainer = uicls.Container(parent=self.content, name='tabButtonContainer', align=uiconst.TOTOP, pos=(0, 0, 0, 28))
self.tabPanelContainer = uicls.Container(parent=self.content, name='tabPanelContainer', align=uiconst.TOALL, padTop=4)
self.heading = uicls.EveLabelMedium(text=localization.GetByLabel('UI/PI/Common/ViewingPlanet'), name='heading', parent=self.headerContainer, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED)
self.planetName = uicls.EveHeaderLarge(parent=self.headerContainer, top=self.heading.textheight, state=uiconst.UI_NORMAL)
self.resourceControllerTab = planet.ui.ResourceController(parent=self.tabPanelContainer)
self.editModeTab = planet.ui.PlanetEditModeContainer(parent=self.tabPanelContainer)
tabs = [[localization.GetByLabel('UI/Common/Build'),
self.editModeTab,
self,
None,
'editModeTab'], [localization.GetByLabel('UI/PI/Common/Scan'),
self.resourceControllerTab,
self,
None,
'resourceControllerTab']]
self.modeButtonGroup = uicls.FlatButtonGroup(parent=self.tabButtonContainer, align=uiconst.TOTOP, height=28, toggleEnabled=False)
self.modeButtonGroup.Startup(tabs, selectedArgs=['editModeTab'])
BTNSIZE = 24
exitBtn = uicls.Button(parent=self.content, align=uiconst.TOPRIGHT, pos=(0,
0,
BTNSIZE,
BTNSIZE), icon='ui_73_16_45', iconSize=16, func=self.ExitPlanetMode, alwaysLite=True, color=util.Color.RED, hint=localization.GetByLabel('UI/PI/Common/ExitPlanetMode'))
homeBtn = uicls.Button(parent=self.content, align=uiconst.TOPRIGHT, pos=(exitBtn.left + exitBtn.width + 2,
0,
BTNSIZE,
BTNSIZE), icon='ui_73_16_46', iconSize=16, func=self.ViewCommandCenter, alwaysLite=True, hint=localization.GetByLabel('UI/PI/Common/ViewPlanetaryCommandCenter'))
if sm.GetService('machoNet').GetClientConfigVals().get('enableDustLink'):
dustViewBtn = uicls.Button(parent=self.content, align=uiconst.TOPRIGHT, pos=(homeBtn.left + homeBtn.width + 2,
0,
BTNSIZE,
BTNSIZE), icon='ui_73_16_44', iconSize=16, func=self.ChangeToDustView, alwaysLite=True)
dustViewBtn.hint = localization.GetByLabel('UI/PI/Common/DustView')
self.sr.homeBtn = homeBtn
self.UpdatePlanetText()
self.UpdateHomeButton()
self.CreateEditModeContainer()
def UpdatePlanetText(self):
planetUI = sm.GetService('planetUI')
planetID = planetUI.planetID
planetData = sm.GetService('map').GetPlanetInfo(planetID)
self.planetName.text = '<url=showinfo:%s//%s>%s</url>' % (planetData.typeID, planetID, cfg.evelocations.Get(planetID).locationName)
def OnButtonSelected(self, mode):
sm.GetService('audio').SendUIEvent('wise:/msg_pi_general_switch_play')
if mode == 'resourceControllerTab':
sm.GetService('planetUI').planetAccessRequired = True
def ExitPlanetMode(self, *args):
sm.GetService('viewState').CloseSecondaryView('planet')
def ViewCommandCenter(self, *args):
sm.GetService('planetUI').FocusCameraOnCommandCenter()
def OnPlanetCommandCenterDeployedOrRemoved(self, *args):
self.UpdateHomeButton()
def UpdateHomeButton(self):
if session.charid in sm.GetService('planetUI').planet.colonies:
self.sr.homeBtn.state = uiconst.UI_NORMAL
else:
self.sr.homeBtn.state = uiconst.UI_HIDDEN
def CreateEditModeContainer(self):
uicls.EveHeaderLarge(parent=self.editModeContent, text=localization.GetByLabel('UI/PI/Common/EditsPending'), align=uiconst.RELATIVE)
self.powerGauge = uicls.Gauge(parent=self.editModeContent, pos=(0, 22, 125, 34), color=planetCommon.PLANET_COLOR_POWER, label=localization.GetByLabel('UI/PI/Common/PowerUsage'))
self.cpuGauge = uicls.Gauge(parent=self.editModeContent, pos=(140, 22, 125, 34), color=planetCommon.PLANET_COLOR_CPU, label=localization.GetByLabel('UI/PI/Common/CpuUsage'))
self.UpdatePowerAndCPUGauges()
btns = [[localization.GetByLabel('UI/Common/Submit'), self.Submit, ()], [localization.GetByLabel('UI/Common/Cancel'), self.Cancel, ()]]
bottom = uicls.Container(parent=self.editModeContent, align=uiconst.TOBOTTOM, pos=(0, 0, 0, 40))
btns = uicls.ButtonGroup(btns=btns, subalign=uiconst.CENTERRIGHT, parent=bottom, line=False, alwaysLite=True)
self.costText = planet.ui.CaptionAndSubtext(parent=bottom, align=uiconst.TOPLEFT, top=13, caption=localization.GetByLabel('UI/Common/Cost'), subtext='')
def UpdatePowerAndCPUGauges(self):
colony = sm.GetService('planetUI').GetCurrentPlanet().GetColony(session.charid)
if not colony or colony.colonyData is None:
return
originalData = sm.GetService('planetUI').GetCurrentPlanet().GetEditModeData()
if originalData is None:
origCpu = 0
origPower = 0
else:
origCpu = originalData.GetColonyCpuUsage()
origPower = originalData.GetColonyPowerUsage()
cpuOutput = float(colony.colonyData.GetColonyCpuSupply())
powerOutput = float(colony.colonyData.GetColonyPowerSupply())
cpu = colony.colonyData.GetColonyCpuUsage()
power = colony.colonyData.GetColonyPowerUsage()
cpuDiff = cpu - origCpu
powerDiff = power - origPower
self.cpuGauge.SetValue(cpu / cpuOutput if cpuOutput > 0 else 0)
self.cpuGauge.HideAllMarkers()
self.cpuGauge.ShowMarker(origCpu / cpuOutput if cpuOutput > 0 else 0)
self.powerGauge.SetValue(power / powerOutput if powerOutput > 0 else 0)
self.powerGauge.HideAllMarkers()
self.powerGauge.ShowMarker(origPower / powerOutput if powerOutput > 0 else 0)
if cpuDiff >= 0:
localization.GetByLabel('UI/PI/Common/TeraFlopsAmountIncrease', amount=cpuDiff)
else:
localization.GetByLabel('UI/PI/Common/TeraFlopsAmount', amount=cpuDiff)
if powerDiff >= 0:
localization.GetByLabel('UI/PI/Common/MegaWattsAmountIncrease', amount=powerDiff)
else:
localization.GetByLabel('UI/PI/Common/MegaWattsAmount', amount=powerDiff)
self.cpuGauge.hint = localization.GetByLabel('UI/PI/Common/TeraFlopsDiff', current=origCpu, after=cpu, maximum=cpuOutput)
self.powerGauge.hint = localization.GetByLabel('UI/PI/Common/MegaWattsDiff', current=origPower, after=power, maximum=powerOutput)
def UpdateCostOfCurrentChanges(self):
cost = sm.GetService('planetUI').GetCurrentPlanet().GetCostOfCurrentEdits()
import util
self.costText.SetSubtext(util.FmtISK(cost, showFractionsAlways=0))
def Submit(self):
sm.GetService('planetUI').planet.SubmitChanges()
sm.GetService('audio').SendUIEvent('wise:/msg_pi_build_submit_play')
def Cancel(self):
sm.GetService('planetUI').planet.RevertChanges()
sm.GetService('audio').SendUIEvent('wise:/msg_pi_build_cancel_play')
def OnEditModeChanged(self, isEdit):
if not self or self.destroyed:
return
if not isEdit:
uicore.effect.MorphUI(self.editModeContainer, 'opacity', 0.0, time=250.0, newthread=False, float=True)
if not self or self.destroyed:
return
uicore.effect.MorphUI(self.editModeContainer, 'height', 0, time=250.0, newthread=False)
if not self or self.destroyed:
return
self.editModeContainer.state = uiconst.UI_HIDDEN
self.inEditMode = False
else:
self.UpdatePowerAndCPUGauges()
self.UpdateCostOfCurrentChanges()
self.editModeContainer.height = 0
self.editModeContainer.opacity = 0.0
self.editModeContainer.state = uiconst.UI_NORMAL
EDITMODECONTAINER_HEIGHT = 105
uicore.effect.MorphUI(self.editModeContainer, 'height', EDITMODECONTAINER_HEIGHT, time=250.0, newthread=False)
uicore.effect.MorphUI(self.editModeContainer, 'opacity', 1.0, time=250.0, newthread=False, float=True)
self.inEditMode = True
def OnEditModeBuiltOrDestroyed(self):
if not self.inEditMode:
self.editModeContainer.height = 0
self.editModeContainer.opacity = 0.0
self.editModeContainer.state = uiconst.UI_NORMAL
EDITMODECONTAINER_HEIGHT = 105
uicore.effect.MorphUI(self.editModeContainer, 'height', EDITMODECONTAINER_HEIGHT, time=250.0, newthread=False)
uicore.effect.MorphUI(self.editModeContainer, 'opacity', 1.0, time=250.0, newthread=False, float=True)
self.inEditMode = True
self.UpdatePowerAndCPUGauges()
self.UpdateCostOfCurrentChanges()
def ChangeToDustView(self, *args, **kwargs):
if sm.GetService('machoNet').GetClientConfigVals().get('enableDustLink'):
sm.GetService('planetUI').ChangeToDustView()