Add projection range commands for projected drones
This commit is contained in:
@@ -63,7 +63,8 @@ class ChangeItemProjectionRange(ContextMenuSingle):
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedModuleProjectionRangeCommand(
|
||||
fitID=fitID, position=position, projectionRange=newRange))
|
||||
elif isinstance(mainItem, Drone):
|
||||
pass
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeProjectedDroneProjectionRangeCommand(
|
||||
fitID=fitID, itemID=mainItem.itemID, projectionRange=newRange))
|
||||
elif isinstance(mainItem, Fighter):
|
||||
if mainItem in fit.projectedFighters:
|
||||
position = fit.projectedFighters.index(mainItem)
|
||||
|
||||
@@ -60,6 +60,7 @@ from .gui.projectedChangeStates import GuiChangeProjectedItemStatesCommand
|
||||
from .gui.projectedDrone.add import GuiAddProjectedDroneCommand
|
||||
from .gui.projectedDrone.changeAmount import GuiChangeProjectedDroneAmountCommand
|
||||
from .gui.projectedDrone.changeMetas import GuiChangeProjectedDroneMetasCommand
|
||||
from .gui.projectedDrone.changeProjectionRange import GuiChangeProjectedDroneProjectionRangeCommand
|
||||
from .gui.projectedFighter.abilityToggleState import GuiToggleProjectedFighterAbilityStateCommand
|
||||
from .gui.projectedFighter.add import GuiAddProjectedFighterCommand
|
||||
from .gui.projectedFighter.changeAmount import GuiChangeProjectedFighterAmountCommand
|
||||
|
||||
40
gui/fitCommands/calc/drone/projectedChangeProjectionRange.py
Normal file
40
gui/fitCommands/calc/drone/projectedChangeProjectionRange.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import wx
|
||||
from logbook import Logger
|
||||
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcChangeProjectedDroneProjectionRangeCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID, projectionRange):
|
||||
wx.Command.__init__(self, True, 'Change Projected Drone Projection Range')
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.projectionRange = projectionRange
|
||||
self.savedProjectionRange = None
|
||||
|
||||
def Do(self):
|
||||
pyfalog.debug('Doing change of projected drone {} projection range to {} on fit {}'.format(
|
||||
self.itemID, self.projectionRange, self.fitID))
|
||||
fit = Fit.getInstance().getFit(self.fitID)
|
||||
drone = next((pd for pd in fit.projectedDrones if pd.itemID == self.itemID), None)
|
||||
if drone is None:
|
||||
pyfalog.warning('Cannot find projected drone')
|
||||
return False
|
||||
if drone.projectionRange == self.projectionRange:
|
||||
return False
|
||||
self.savedProjectionRange = drone.projectionRange
|
||||
drone.projectionRange = self.projectionRange
|
||||
return True
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing change of projected drone {} projection range to {} on fit {}'.format(
|
||||
self.itemID, self.projectionRange, self.fitID))
|
||||
cmd = CalcChangeProjectedDroneProjectionRangeCommand(
|
||||
fitID=self.fitID,
|
||||
itemID=self.itemID,
|
||||
projectionRange=self.savedProjectionRange)
|
||||
return cmd.Do()
|
||||
@@ -7,7 +7,7 @@ import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.drone.projectedChangeAmount import CalcChangeProjectedDroneAmountCommand
|
||||
from gui.fitCommands.calc.drone.projectedRemove import CalcRemoveProjectedDroneCommand
|
||||
from gui.fitCommands.helpers import DroneInfo, InternalCommandHistory
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
|
||||
42
gui/fitCommands/gui/projectedDrone/changeProjectionRange.py
Normal file
42
gui/fitCommands/gui/projectedDrone/changeProjectionRange.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import wx
|
||||
|
||||
import eos.db
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.drone.projectedChangeProjectionRange import CalcChangeProjectedDroneProjectionRangeCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiChangeProjectedDroneProjectionRangeCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID, projectionRange):
|
||||
wx.Command.__init__(self, True, 'Change Projected Drone Projection Range')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.projectionRange = projectionRange
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcChangeProjectedDroneProjectionRangeCommand(
|
||||
fitID=self.fitID,
|
||||
itemID=self.itemID,
|
||||
projectionRange=self.projectionRange)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
eos.db.flush()
|
||||
sFit = Fit.getInstance()
|
||||
sFit.recalc(self.fitID)
|
||||
sFit.fill(self.fitID)
|
||||
eos.db.commit()
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
success = self.internalHistory.undoAll()
|
||||
eos.db.flush()
|
||||
sFit = Fit.getInstance()
|
||||
sFit.recalc(self.fitID)
|
||||
sFit.fill(self.fitID)
|
||||
eos.db.commit()
|
||||
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitIDs=(self.fitID,)))
|
||||
return success
|
||||
Reference in New Issue
Block a user