Add projected drone change command, and remove some prints

This commit is contained in:
blitzmann
2018-08-18 00:45:26 -04:00
parent fd83a4b709
commit b17314f3c6
6 changed files with 82 additions and 7 deletions

View File

@@ -21,7 +21,7 @@ class ChangeAmount(ContextMenu):
if not self.settings.get('amount'):
return False
return srcContext in ("droneItem", "cargoItem", "projectedFit", "fighterItem", "projectedFighter")
return srcContext in ("droneItem", "projectedDrone", "cargoItem", "projectedFit", "fighterItem", "projectedFighter")
def getText(self, itmContext, selection):
return u"Change {0} Quantity".format(itmContext)
@@ -30,7 +30,7 @@ class ChangeAmount(ContextMenu):
thing = selection[0]
mainFrame = gui.mainFrame.MainFrame.getInstance()
fitID = mainFrame.getActiveFit()
srcContext = fullContext[0]
if isinstance(thing, es_Fit):
value = thing.getProjectionInfo(fitID).amount
else:
@@ -50,7 +50,10 @@ class ChangeAmount(ContextMenu):
self.mainFrame.command.Submit(cmd.GuiChangeCargoQty(fitID, fit.cargo.index(thing), int(float(cleanInput))))
return # no need for post event here
elif isinstance(thing, Drone):
self.mainFrame.command.Submit(cmd.GuiChangeDroneQty(fitID, fit.drones.index(thing), int(float(cleanInput))))
if srcContext == "droneItem":
self.mainFrame.command.Submit(cmd.GuiChangeDroneQty(fitID, fit.drones.index(thing), int(float(cleanInput))))
else:
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, fit.projectedDrones.index(thing), int(float(cleanInput))))
elif isinstance(thing, es_Fit):
self.mainFrame.command.Submit(cmd.GuiChangeProjectedFitQty(fitID, thing.ID, int(float(cleanInput))))
return

View File

@@ -50,7 +50,7 @@ class BoosterSideEffect(ContextMenu):
if not effect.effect.isImplemented:
continue
menuItem = self.addEffect(rootMenu if msw else sub, effect)
sub.AppendItem(menuItem)
sub.Append(menuItem)
menuItem.Check(effect.active)
return sub

View File

@@ -91,7 +91,7 @@ class MetaSwap(ContextMenu):
# Sort items by metalevel, and group within that metalevel
items = list(self.variations)
print(context)
if "implantItem" in context:
# sort implants based on name
items.sort(key=lambda x: x.name)
@@ -122,7 +122,7 @@ class MetaSwap(ContextMenu):
id = ContextMenu.nextID()
mitem = wx.MenuItem(rootMenu, id, item.name)
bindmenu.Bind(wx.EVT_MENU, self.handleModule, mitem)
print(context)
self.moduleLookup[id] = item, context
m.Append(mitem)
return m

View File

@@ -28,4 +28,5 @@ from .guiRemoveDrone import GuiRemoveDroneCommand
from .guiChangeFighterQty import GuiChangeFighterQty
from .guiChangeCargoQty import GuiChangeCargoQty
from .guiChangeProjectedFitQty import GuiChangeProjectedFitQty
from .guiChangeDroneQty import GuiChangeDroneQty
from .guiChangeDroneQty import GuiChangeDroneQty
from.guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty

View File

@@ -0,0 +1,32 @@
import wx
from service.fit import Fit
import gui.mainFrame
from gui import globalEvents as GE
#from .helpers import ModuleInfoCache
from eos.saveddata.module import Module, State
import eos.db
from logbook import Logger
pyfalog = Logger(__name__)
class FitChangeProjectedDroneQty(wx.Command):
def __init__(self, fitID, position, amount=1):
wx.Command.__init__(self, True, "Drone add")
self.fitID = fitID
self.position = position
self.amount = amount # add x amount. If this goes over amount, removes stack
self.old_amount = None
def Do(self):
pyfalog.debug("Changing active fighters ({0}) for fit ({1}) to amount: {2}", self.position, self.fitID, self.amount)
fit = eos.db.getFit(self.fitID)
drone = fit.projectedDrones[self.position]
self.old_amount = drone.amount
drone.amount = self.amount
eos.db.commit()
return True
def Undo(self):
cmd = FitChangeProjectedDroneQty(self.fitID, self.position, self.old_amount)
return cmd.Do()

View File

@@ -0,0 +1,39 @@
import wx
import eos.db
import gui.mainFrame
from service.fit import Fit
from gui import globalEvents as GE
from .calc.fitAddModule import FitAddModuleCommand
from .calc.fitReplaceModule import FitReplaceModuleCommand
from .calc.fitChangeProjectedDroneQty import FitChangeProjectedDroneQty
from service.fit import Fit
from logbook import Logger
pyfalog = Logger(__name__)
class GuiChangeProjectedDroneQty(wx.Command):
def __init__(self, fitID, position, amount=1):
wx.Command.__init__(self, True, "")
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
self.sFit = Fit.getInstance()
self.fitID = fitID
self.position = position
self.amount = amount
self.internal_history = wx.CommandProcessor()
def Do(self):
cmd = FitChangeProjectedDroneQty(self.fitID, self.position, self.amount)
if self.internal_history.Submit(cmd):
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
pyfalog.debug("{} Undo()".format(self))
for _ in self.internal_history.Commands:
self.internal_history.Undo()
self.sFit.recalc(self.fitID)
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID))
return True