Rework local drone GUI commands
This commit is contained in:
@@ -17,6 +17,9 @@
|
||||
# along with pyfa. If not, see <http://www.gnu.org/licenses/>.
|
||||
# =============================================================================
|
||||
|
||||
|
||||
import math
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
@@ -117,7 +120,7 @@ class DroneView(Display):
|
||||
row = self.GetFirstSelected()
|
||||
if row != -1:
|
||||
drone = self.drones[self.GetItemData(row)]
|
||||
self.removeDrone(drone)
|
||||
self.removeDroneStack(drone)
|
||||
|
||||
event.Skip()
|
||||
|
||||
@@ -227,7 +230,11 @@ class DroneView(Display):
|
||||
|
||||
def removeDrone(self, drone):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, self.original.index(drone)))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, self.original.index(drone), 1))
|
||||
|
||||
def removeDroneStack(self, drone):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, self.original.index(drone), math.inf))
|
||||
|
||||
def click(self, event):
|
||||
event.Skip()
|
||||
@@ -237,7 +244,7 @@ class DroneView(Display):
|
||||
if col == self.getColIndex(State):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
drone = self.drones[row]
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleDroneCommand(fitID, self.original.index(drone)))
|
||||
self.mainFrame.command.Submit(cmd.GuiToggleDroneStateCommand(fitID, self.original.index(drone)))
|
||||
|
||||
def spawnMenu(self, event):
|
||||
sel = self.GetFirstSelected()
|
||||
|
||||
@@ -55,7 +55,7 @@ class ChangeAmount(ContextMenu):
|
||||
if srcContext == "projectedDrone":
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneQty(fitID, thing.itemID, cleanInput))
|
||||
else:
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeDroneQty(fitID, fit.drones.index(thing), cleanInput))
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeDroneAmount(fitID, fit.drones.index(thing), cleanInput))
|
||||
elif isinstance(thing, es_Fit):
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedFitQty(fitID, thing.ID, cleanInput))
|
||||
elif isinstance(thing, es_Fighter):
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import math
|
||||
|
||||
import gui.fitCommands as cmd
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenu
|
||||
@@ -25,8 +27,8 @@ class ItemRemove(ContextMenu):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
fit = sFit.getFit(fitID)
|
||||
|
||||
idx = fit.drones.index(selection[0])
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, idx, fit.drones[idx].amount))
|
||||
position = fit.drones.index(selection[0])
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, position, math.inf))
|
||||
|
||||
|
||||
ItemRemove.register()
|
||||
|
||||
@@ -43,7 +43,7 @@ class ItemRemove(ContextMenu):
|
||||
self.mainFrame.command.Submit(cmd.GuiModuleAddChargeCommand(fitID, None, selection))
|
||||
return
|
||||
elif srcContext == "droneItem":
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, fit.drones.index(selection[0])))
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveDroneCommand(fitID, fit.drones.index(selection[0]), 1))
|
||||
return
|
||||
elif srcContext == "fighterItem":
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveFighterCommand(fitID, fit.fighters.index(selection[0])))
|
||||
|
||||
@@ -9,12 +9,12 @@ from .commandFit.add import GuiAddCommandFitCommand
|
||||
from .commandFit.remove import GuiRemoveCommandFitCommand
|
||||
from .commandFit.toggleState import GuiToggleCommandFitStateCommand
|
||||
from .guiAddCharge import GuiModuleAddChargeCommand
|
||||
from .guiAddDrone import GuiAddDroneCommand
|
||||
from .drone.add import GuiAddDroneCommand
|
||||
from .guiAddFighter import GuiAddFighterCommand
|
||||
from .guiAddModule import GuiModuleAddCommand
|
||||
from .guiAddProjected import GuiAddProjectedCommand
|
||||
from .guiCargoToModule import GuiCargoToModuleCommand
|
||||
from .guiChangeDroneQty import GuiChangeDroneQty
|
||||
from .drone.changeAmount import GuiChangeDroneAmount
|
||||
from .guiChangeFighterQty import GuiChangeFighterQty
|
||||
from .guiChangeProjectedDroneQty import GuiChangeProjectedDroneQty
|
||||
from .guiChangeProjectedFighterAmount import GuiChangeProjectedFighterAmount
|
||||
@@ -27,14 +27,14 @@ from .guiModuleToCargo import GuiModuleToCargoCommand
|
||||
from .guiMutaConvert import GuiMutaConvertCommand
|
||||
from .guiMutaRevert import GuiMutaRevertCommand
|
||||
from .guiRebaseItems import GuiRebaseItemsCommand
|
||||
from .guiRemoveDrone import GuiRemoveDroneCommand
|
||||
from .drone.remove import GuiRemoveDroneCommand
|
||||
from .guiRemoveFighter import GuiRemoveFighterCommand
|
||||
from .guiRemoveModule import GuiModuleRemoveCommand
|
||||
from .guiRemoveProjected import GuiRemoveProjectedCommand
|
||||
from .guiSetMode import GuiSetModeCommand
|
||||
from .guiSetSpoolup import GuiSetSpoolup
|
||||
from .guiSwapCloneModule import GuiModuleSwapOrCloneCommand
|
||||
from .guiToggleDrone import GuiToggleDroneCommand
|
||||
from .drone.toggleState import GuiToggleDroneStateCommand
|
||||
from .guiToggleFighter import GuiToggleFighterCommand
|
||||
from .guiToggleFighterAbility import GuiToggleFighterAbilityCommand
|
||||
from .guiToggleModuleState import GuiModuleStateChangeCommand
|
||||
|
||||
0
gui/fitCommands/drone/__init__.py
Normal file
0
gui/fitCommands/drone/__init__.py
Normal file
@@ -1,29 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.helpers import DroneInfo
|
||||
from .calcCommands.drone.localAdd import CalcAddLocalDroneCommand
|
||||
from gui.fitCommands.calcCommands.drone.localAdd import CalcAddLocalDroneCommand
|
||||
from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiAddDroneCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, "Drone Add")
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
wx.Command.__init__(self, True, 'Add Drone')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=1, amountActive=0))
|
||||
if self.internalHistory.Submit(cmd):
|
||||
if self.internalHistory.submit(CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=DroneInfo(itemID=self.itemID, amount=1, amountActive=0))):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
success = self.internalHistory.undoAll()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return success
|
||||
39
gui/fitCommands/drone/changeAmount.py
Normal file
39
gui/fitCommands/drone/changeAmount.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import math
|
||||
|
||||
import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calcCommands.drone.localChangeAmount import CalcChangeLocalDroneAmountCommand
|
||||
from gui.fitCommands.calcCommands.drone.localRemove import CalcRemoveLocalDroneCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiChangeDroneAmount(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position, amount):
|
||||
wx.Command.__init__(self, True, 'Change Drone Amount')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
if self.amount > 0:
|
||||
if self.internalHistory.submit(CalcChangeLocalDroneAmountCommand(fitID=self.fitID, position=self.position, amount=self.amount)):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
else:
|
||||
if self.internalHistory.submit(CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=math.inf)):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
@@ -1,30 +1,30 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calcCommands.drone.localRemove import CalcRemoveLocalDroneCommand
|
||||
from gui.fitCommands.calcCommands.drone.localRemove import CalcRemoveLocalDroneCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiRemoveDroneCommand(wx.Command):
|
||||
def __init__(self, fitID, position, amount=1):
|
||||
wx.Command.__init__(self, True, "Drone Remove")
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
|
||||
def __init__(self, fitID, position, amount):
|
||||
wx.Command.__init__(self, True, 'Remove Drone')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amount = amount
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcRemoveLocalDroneCommand(self.fitID, self.position, self.amount)
|
||||
if self.internalHistory.Submit(cmd):
|
||||
if self.internalHistory.submit(CalcRemoveLocalDroneCommand(fitID=self.fitID, position=self.position, amount=self.amount)):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
success = self.internalHistory.undoAll()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return success
|
||||
@@ -1,28 +1,29 @@
|
||||
import wx
|
||||
from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calcCommands.drone.localToggleState import CalcToggleLocalDroneStateCommand
|
||||
from gui.fitCommands.calcCommands.drone.localToggleState import CalcToggleLocalDroneStateCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiToggleDroneCommand(wx.Command):
|
||||
class GuiToggleDroneStateCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
wx.Command.__init__(self, True, 'Toggle Drone State')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
|
||||
def Do(self):
|
||||
if self.internalHistory.Submit(CalcToggleLocalDroneStateCommand(self.fitID, self.position)):
|
||||
if self.internalHistory.submit(CalcToggleLocalDroneStateCommand(fitID=self.fitID, position=self.position)):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
success = self.internalHistory.undoAll()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return success
|
||||
@@ -1,31 +0,0 @@
|
||||
import wx
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .calcCommands.drone.localChangeAmount import CalcChangeLocalDroneAmountCommand
|
||||
from service.fit import Fit
|
||||
from logbook import Logger
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class GuiChangeDroneQty(wx.Command):
|
||||
def __init__(self, fitID, position, amount=1):
|
||||
wx.Command.__init__(self, True, "")
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
self.amount = amount
|
||||
self.internalHistory = wx.CommandProcessor()
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcChangeLocalDroneAmountCommand(self.fitID, self.position, self.amount)
|
||||
if self.internalHistory.Submit(cmd):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
for _ in self.internalHistory.Commands:
|
||||
self.internalHistory.Undo()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
|
||||
return True
|
||||
Reference in New Issue
Block a user