Allow batch meta level change on fighters

This commit is contained in:
DarkPhoenix
2019-04-24 16:28:40 +03:00
parent 2d1613d8bc
commit 81da217a09
4 changed files with 54 additions and 22 deletions

View File

@@ -4,7 +4,7 @@ import wx
import gui.fitCommands as cmd
import gui.mainFrame
from gui.contextMenu import ContextMenuCombined
from gui.fitCommands.helpers import getSimilarModPositions
from gui.fitCommands.helpers import getSimilarModPositions, getSimilarFighters
from service.fit import Fit
from service.market import Market
from service.settings import ContextMenuSettings
@@ -186,11 +186,23 @@ class ChangeItemToVariation(ContextMenuCombined):
def __handleFighter(self, varItem):
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
fighter = self.mainItem
if fighter in fit.fighters:
position = fit.fighters.index(fighter)
self.mainFrame.command.Submit(cmd.GuiChangeLocalFighterMetaCommand(
fitID=fitID, position=position, newItemID=varItem.ID))
if wx.GetMouseState().altDown:
fighters = getSimilarFighters(fit.fighters, self.mainItem)
else:
fighters = self.selection
sMkt = Market.getInstance()
positions = []
for fighter in fighters:
if fighter not in fit.fighters:
continue
if fighter is self.mainItem:
positions.append(fit.fighters.index(fighter))
continue
fighterVariations = sMkt.getVariationsByItems((fighter.item,))
if fighterVariations == self.mainVariations:
positions.append(fit.fighters.index(fighter))
self.mainFrame.command.Submit(cmd.GuiChangeLocalFighterMetasCommand(
fitID=fitID, positions=positions, newItemID=varItem.ID))
def __handleImplant(self, varItem):
fitID = self.mainFrame.getActiveFit()

View File

@@ -28,7 +28,7 @@ from .gui.localDrone.toggleStates import GuiToggleLocalDroneStatesCommand
from .gui.localFighter.abilityToggleState import GuiToggleLocalFighterAbilityStateCommand
from .gui.localFighter.add import GuiAddLocalFighterCommand
from .gui.localFighter.changeAmount import GuiChangeLocalFighterAmountCommand
from .gui.localFighter.changeMeta import GuiChangeLocalFighterMetaCommand
from .gui.localFighter.changeMetas import GuiChangeLocalFighterMetasCommand
from .gui.localFighter.remove import GuiRemoveLocalFightersCommand
from .gui.localFighter.toggleState import GuiToggleLocalFighterStateCommand
from .gui.localModule.add import GuiAddLocalModuleCommand

View File

@@ -27,11 +27,19 @@ class GuiChangeLocalDroneMetasCommand(wx.Command):
for position in sorted(self.positions, reverse=True):
drone = fit.drones[position]
if drone.itemID == self.newItemID:
return False
continue
info = DroneInfo.fromDrone(drone)
info.itemID = self.newItemID
cmdRemove = CalcRemoveLocalDroneCommand(fitID=self.fitID, position=position, amount=math.inf, commit=False)
cmdAdd = CalcAddLocalDroneCommand(fitID=self.fitID, droneInfo=info, forceNewStack=True, commit=False)
cmdRemove = CalcRemoveLocalDroneCommand(
fitID=self.fitID,
position=position,
amount=math.inf,
commit=False)
cmdAdd = CalcAddLocalDroneCommand(
fitID=self.fitID,
droneInfo=info,
forceNewStack=True,
commit=False)
result.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
success = any(result)
eos.db.commit()

View File

@@ -1,5 +1,6 @@
import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.fighter.localAdd import CalcAddLocalFighterCommand
@@ -8,32 +9,43 @@ from gui.fitCommands.helpers import FighterInfo, InternalCommandHistory
from service.fit import Fit
class GuiChangeLocalFighterMetaCommand(wx.Command):
class GuiChangeLocalFighterMetasCommand(wx.Command):
def __init__(self, fitID, position, newItemID):
wx.Command.__init__(self, True, 'Change Local Fighter Meta')
def __init__(self, fitID, positions, newItemID):
wx.Command.__init__(self, True, 'Change Local Fighter Metas')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.positions = positions
self.newItemID = newItemID
def Do(self):
sFit = Fit.getInstance()
fit = sFit.getFit(self.fitID)
fighter = fit.fighters[self.position]
if fighter.itemID == self.newItemID:
return False
info = FighterInfo.fromFighter(fighter)
info.itemID = self.newItemID
cmdRemove = CalcRemoveLocalFighterCommand(fitID=self.fitID, position=self.position)
cmdAdd = CalcAddLocalFighterCommand(fitID=self.fitID, fighterInfo=info)
success = self.internalHistory.submitBatch(cmdRemove, cmdAdd)
result = []
for position in sorted(self.positions, reverse=True):
fighter = fit.fighters[position]
if fighter.itemID == self.newItemID:
continue
info = FighterInfo.fromFighter(fighter)
info.itemID = self.newItemID
cmdRemove = CalcRemoveLocalFighterCommand(
fitID=self.fitID,
position=position,
commit=False)
cmdAdd = CalcAddLocalFighterCommand(
fitID=self.fitID,
fighterInfo=info,
commit=False)
result.append(self.internalHistory.submitBatch(cmdRemove, cmdAdd))
success = any(result)
eos.db.commit()
sFit.recalc(fit)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
success = self.internalHistory.undoAll()
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success