Mass-replace modules when dragging something from market and dropping over another module while holding alt

This commit is contained in:
DarkPhoenix
2019-04-21 15:33:00 +03:00
parent 6694caafa0
commit 4821bd1c72
6 changed files with 86 additions and 38 deletions

View File

@@ -432,12 +432,13 @@ class FittingView(d.Display):
def addModule(self, x, y, itemID):
"""Add a module from the market browser (from dragging it)"""
fitID = self.mainFrame.getActiveFit()
item = Market.getInstance().getItem(itemID)
fit = Fit.getInstance().getFit(fitID)
dstRow, _ = self.HitTest((x, y))
if dstRow != -1 and dstRow not in self.blanks:
if dstRow == -1 or dstRow in self.blanks:
dstMod = None
else:
try:
dstMod = self.mods[dstRow]
except IndexError:
@@ -446,23 +447,32 @@ class FittingView(d.Display):
dstMod = None
if dstMod not in fit.modules:
dstMod = None
mstate = wx.GetMouseState()
if item.isModule and mstate.altDown:
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
elif item.isModule and dstMod is not None:
position = fit.modules.index(dstMod)
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(
fitID=fitID, itemID=itemID, position=position))
elif item.isSubsystem:
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
elif item.isCharge and dstMod is not None and not dstMod.isEmpty:
dstPos = fit.modules.index(dstMod) if dstMod is not None else None
mstate = wx.GetMouseState()
# If we dropping on a module, try to replace, or add if replacement fails
if item.isModule and dstMod is not None:
positions = getSimilarModPositions(fit.modules, dstMod) if mstate.altDown else [dstPos]
command = cmd.GuiReplaceLocalModuleCommand(fitID=fitID, itemID=itemID, positions=positions)
if not self.mainFrame.command.Submit(command):
if mstate.altDown:
positions = getSimilarModPositions(fit.modules, dstMod)
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
else:
positions = [fit.modules.index(dstMod)]
if len(positions) > 0:
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(
fitID=fitID, positions=positions, chargeItemID=itemID))
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
elif item.isModule:
if mstate.altDown:
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
else:
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
elif item.isSubsystem:
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
elif item.isCharge and dstMod is not None and not dstMod.isEmpty:
if mstate.altDown:
positions = getSimilarModPositions(fit.modules, dstMod)
else:
positions = [fit.modules.index(dstMod)]
if len(positions) > 0:
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(
fitID=fitID, positions=positions, chargeItemID=itemID))
def swapCargo(self, x, y, cargoItemID):
"""Swap a module from cargo to fitting window"""

View File

@@ -43,6 +43,7 @@ from .gui.localModule.mutatedConvert import GuiConvertMutatedLocalModuleCommand
from .gui.localModule.mutatedImport import GuiImportLocalMutatedModuleCommand
from .gui.localModule.mutatedRevert import GuiRevertMutatedLocalModuleCommand
from .gui.localModule.remove import GuiRemoveLocalModuleCommand
from .gui.localModule.replace import GuiReplaceLocalModuleCommand
from .gui.localModule.swap import GuiSwapLocalModulesCommand
from .gui.localModuleCargo.cargoToLocalModule import GuiCargoToLocalModuleCommand
from .gui.localModuleCargo.localModuleToCargo import GuiLocalModuleToCargoCommand

View File

@@ -36,6 +36,8 @@ class CalcReplaceLocalModuleCommand(wx.Command):
newMod = self.newModInfo.toModule(fallbackState=stateLimit(self.newModInfo.itemID))
if newMod is None:
return False
if newMod.slot != oldMod.slot:
return False
# Dummy it out in case the next bit fails
fit.modules.free(self.position)
if not newMod.fits(fit):

View File

@@ -2,42 +2,28 @@ import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.changeCharges import CalcChangeModuleChargesCommand
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
from service.market import Market
class GuiAddLocalModuleCommand(wx.Command):
def __init__(self, fitID, itemID, position=None):
def __init__(self, fitID, itemID):
wx.Command.__init__(self, True, 'Add Local Module')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.position = position
def Do(self):
position = self.position
success = False
item = Market.getInstance().getItem(self.itemID)
# Module to position
if position is not None:
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID))
success = self.internalHistory.submit(cmd)
# Something went wrong with trying to fit the module into specific location, keep going to append it instead
if not success:
position = None
# Module without position
if position is None:
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))
success = self.internalHistory.submit(cmd)
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=ModuleInfo(itemID=self.itemID))
success = self.internalHistory.submit(cmd)
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID) if success else GE.FitChanged(fitID=self.fitID))
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)
if success else
GE.FitChanged(fitID=self.fitID))
return success
def Undo(self):
@@ -45,5 +31,7 @@ class GuiAddLocalModuleCommand(wx.Command):
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.itemID) if success else GE.FitChanged(fitID=self.fitID))
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.itemID)
if success else
GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -0,0 +1,45 @@
import wx
import eos.db
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
from service.fit import Fit
class GuiReplaceLocalModuleCommand(wx.Command):
def __init__(self, fitID, itemID, positions):
wx.Command.__init__(self, True, 'Replace Local Module')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.itemID = itemID
self.positions = positions
def Do(self):
results = []
for position in self.positions:
cmd = CalcReplaceLocalModuleCommand(fitID=self.fitID, position=position, newModInfo=ModuleInfo(itemID=self.itemID), commit=False)
results.append(self.internalHistory.submit(cmd))
success = any(results)
eos.db.commit()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(
gui.mainFrame.MainFrame.getInstance(),
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.itemID)
if success else
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, action='moddel', typeID=self.itemID)
if success else
GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -353,6 +353,8 @@ def getSimilarModPositions(mods, mainMod):
mainEffects = set(getattr(mainMod.item, 'effects', ()))
positions = []
for position, mod in enumerate(mods):
if mod.isEmpty:
continue
# Always include selected module itself
if mod is mainMod:
positions.append(position)