Initial work on caching command fits unless needing to update. FitChanged event can now carry an action and typeID, only used in the CommandFit context menu (for now, can use this elsewhere). If the module being added or removed, we update the cached list.

This commit is contained in:
blitzman
2017-03-22 23:00:20 -04:00
parent 6c1d949cef
commit 4065022866
5 changed files with 59 additions and 15 deletions

View File

@@ -0,0 +1,46 @@
# noinspection PyPackageRequirements
import wx
from service.fit import Fit
from service.market import Market
import gui.mainFrame
from gui.contextMenu import ContextMenu
from service.settings import ContextMenuSettings
class CommandFits(ContextMenu):
# Get list of items that define a command fit
sMkt = Market.getInstance()
grp = sMkt.getGroup(1770) # Command burst group
commandTypeIDs = [item.ID for item in grp.items]
commandFits = []
menu = None
@classmethod
def populateFits(cls, evt):
if evt is None or (getattr(evt, 'action', None) in ("modadd", "moddel") and getattr(evt, 'typeID', None) in cls.commandTypeIDs):
# we are adding or removing an item that defines a command fit. Need to refresh fit list
sFit = Fit.getInstance()
cls.commandFits = sFit.getFitsWithModules(cls.commandTypeIDs)
print (cls.commandFits)
#todo: create menu here.
pass
def __init__(self):
print (self.__class__.commandTypeIDs)
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.settings = ContextMenuSettings.getInstance()
def display(self, srcContext, selection):
# todo: the whole thing
return False
def getText(self, itmContext, selection):
return "Command Fits"
def getSubMenu(self, context, selection, rootMenu, i, pitem):
if self.__class__.menu is None:
self.__class__.populateFits()
return self.__class__.menu
CommandFits.register()

View File

@@ -334,7 +334,7 @@ class FittingView(d.Display):
populate = sFit.appendModule(fitID, itemID)
if populate is not None:
self.slotsChanged()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID, action="modadd", typeID=itemID))
event.Skip()
@@ -355,7 +355,7 @@ class FittingView(d.Display):
if populate is not None:
self.slotsChanged()
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.activeFitID, action="moddel", typeID=module.item.ID))
def addModule(self, x, y, srcIdx):
"""Add a module from the market browser"""
@@ -368,7 +368,8 @@ class FittingView(d.Display):
if moduleChanged is None:
# the new module doesn't fit in specified slot, try to simply append it
wx.PostEvent(self.mainFrame, gui.marketBrowser.ItemSelected(itemID=srcIdx))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=srcIdx))
def swapCargo(self, x, y, srcIdx):
"""Swap a module from cargo to fitting window"""
@@ -379,10 +380,13 @@ class FittingView(d.Display):
module = self.mods[dstRow]
sFit = Fit.getInstance()
fit = sFit.getFit(self.activeFitID)
typeID = fit.cargo[srcIdx].item.ID
sFit.moveCargoToModule(self.mainFrame.getActiveFit(), module.modPosition, srcIdx,
mstate.CmdDown() and module.isEmpty)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=typeID))
def swapItems(self, x, y, srcIdx):
"""Swap two modules in fitting window"""

View File

@@ -125,7 +125,7 @@ class CargoView(d.Display):
if not mstate.CmdDown(): # if not copying, remove module
sFit.removeModule(self.mainFrame.getActiveFit(), module.position)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit()))
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="moddel", typeID=module.item.ID))
def fitChanged(self, event):
sFit = Fit.getInstance()

View File

@@ -23,10 +23,11 @@ import gui.display as d
import gui.globalEvents as GE
import gui.droneView
import gui.marketBrowser as marketBrowser
from gui.builtinViewColumns.state import State
from gui.contextMenu import ContextMenu
from gui.builtinContextMenus.commandFits import CommandFits
from service.fit import Fit
from service.market import Market
from eos.saveddata.drone import Drone as es_Drone
@@ -64,15 +65,7 @@ class CommandView(d.Display):
self.lastFitId = None
# Get list of items that define a command fit
sMkt = Market.getInstance()
grp = sMkt.getGroup(1770) # Command burst group
self.commandTypeIDs = [item.ID for item in grp.items]
sFit = Fit.getInstance()
commandFits = sFit.getFitsWithModules(self.commandTypeIDs)
print (commandFits)
self.mainFrame.Bind(GE.FIT_CHANGED, CommandFits.populateFits)
self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged)
self.Bind(wx.EVT_LEFT_DOWN, self.click)
self.Bind(wx.EVT_RIGHT_DOWN, self.click)

View File

@@ -205,4 +205,5 @@ from gui.builtinContextMenus import ( # noqa: E402,F401
metaSwap,
implantSets,
fighterAbilities,
commandFits,
)