First draft of state switching in fitting view
This commit is contained in:
2
eos
2
eos
Submodule eos updated: 04fd4f2d85...326c46d681
@@ -25,6 +25,7 @@ import gui.display as d
|
||||
from gui.contextMenu import ContextMenu
|
||||
import sys
|
||||
from eos.types import Slot
|
||||
from gui.builtinViewColumns.moduleState import ModuleState
|
||||
|
||||
FitChanged, FIT_CHANGED = wx.lib.newevent.NewEvent()
|
||||
|
||||
@@ -50,6 +51,8 @@ class FittingView(d.Display):
|
||||
self.activeFitID = None
|
||||
|
||||
self.Bind(wx.EVT_KEY_UP, self.kbEvent)
|
||||
self.Bind(wx.EVT_LEFT_DOWN, self.click)
|
||||
self.Bind(wx.EVT_RIGHT_DOWN, self.click)
|
||||
|
||||
def getSelectedMods(self):
|
||||
sel = []
|
||||
@@ -106,12 +109,14 @@ class FittingView(d.Display):
|
||||
def removeItem(self, event):
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
cFit = service.Fit.getInstance()
|
||||
populate = cFit.removeModule(self.activeFitID, self.mods[self.GetItemData(row)].position)
|
||||
col = self.getColumn(event.Position)
|
||||
if col != self.getColIndex(ModuleState):
|
||||
cFit = service.Fit.getInstance()
|
||||
populate = cFit.removeModule(self.activeFitID, self.mods[self.GetItemData(row)].position)
|
||||
|
||||
if populate is not None:
|
||||
if populate: self.slotsChanged()
|
||||
wx.PostEvent(self.mainFrame, FitChanged(fitID=self.activeFitID))
|
||||
if populate is not None:
|
||||
if populate: self.slotsChanged()
|
||||
wx.PostEvent(self.mainFrame, FitChanged(fitID=self.activeFitID))
|
||||
|
||||
def generateMods(self):
|
||||
cFit = service.Fit.getInstance()
|
||||
@@ -143,7 +148,8 @@ class FittingView(d.Display):
|
||||
|
||||
def scheduleMenu(self, event):
|
||||
event.Skip()
|
||||
wx.CallAfter(self.spawnMenu)
|
||||
if self.getColumn(event.Position) != self.getColIndex(ModuleState):
|
||||
wx.CallAfter(self.spawnMenu)
|
||||
|
||||
def spawnMenu(self):
|
||||
cFit = service.Fit.getInstance()
|
||||
@@ -163,3 +169,13 @@ class FittingView(d.Display):
|
||||
|
||||
menu = ContextMenu.getMenu(selection, *contexts)
|
||||
self.PopupMenu(menu)
|
||||
|
||||
def click(self, event):
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
col = self.getColumn(event.Position)
|
||||
if col == self.getColIndex(ModuleState):
|
||||
sFit = service.Fit.getInstance()
|
||||
sFit.toggleModulesState(self.mods[self.GetItemData(row)], self.getSelectedMods(), "right" if event.Button == 3 else "left")
|
||||
wx.PostEvent(self.mainFrame, FitChanged(fitID=self.mainFrame.getActiveFit()))
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
import eos.db
|
||||
import eos.types
|
||||
from eos.types import State
|
||||
from eos.types import State, Slot
|
||||
import copy
|
||||
from service.damagePattern import DamagePattern
|
||||
|
||||
@@ -291,3 +291,41 @@ class Fit(object):
|
||||
def saveImportedFits(self, fits):
|
||||
for fit in fits:
|
||||
eos.db.save(fit)
|
||||
|
||||
def toggleModulesState(self, base, modules, click):
|
||||
proposedState = self.__getProposedState(base, click)
|
||||
if proposedState != base.state:
|
||||
base.state = proposedState
|
||||
for mod in modules:
|
||||
if mod != base:
|
||||
mod.state = self.__getProposedState(mod, click, proposedState)
|
||||
|
||||
eos.db.commit()
|
||||
|
||||
# Old state : New State
|
||||
transitionMap = {State.OVERHEATED: State.ACTIVE,
|
||||
State.ACTIVE: State.OFFLINE,
|
||||
State.OFFLINE: State.ONLINE,
|
||||
State.ONLINE: State.ACTIVE}
|
||||
|
||||
def __getProposedState(self, mod, click, proposedState=None):
|
||||
if mod.slot in (Slot.RIG, Slot.SUBSYSTEM) or mod.isEmpty:
|
||||
return State.ONLINE
|
||||
|
||||
currState = mod.state
|
||||
if proposedState is not None:
|
||||
state = proposedState
|
||||
elif click == "right":
|
||||
if currState == State.OVERHEATED:
|
||||
state = State.ACTIVE
|
||||
elif mod.isValidState(State.OVERHEATED):
|
||||
state = State.OVERHEATED
|
||||
else:
|
||||
state = self.transitionMap[currState]
|
||||
while not mod.isValidState(state):
|
||||
state =- 1
|
||||
|
||||
if mod.isValidState(state):
|
||||
return state
|
||||
else:
|
||||
return currState
|
||||
|
||||
Reference in New Issue
Block a user