Fix some module-related command calls
This commit is contained in:
@@ -33,8 +33,12 @@ class RemoveItem(ContextMenu):
|
||||
fit = sFit.getFit(fitID)
|
||||
|
||||
if srcContext == "fittingModule":
|
||||
positions = []
|
||||
for position, mod in enumerate(fit.modules):
|
||||
if mod in selection:
|
||||
positions.append(position)
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveLocalModuleCommand(
|
||||
fitID=fitID, modules=[module for module in selection if module is not None]))
|
||||
fitID=fitID, positions=positions))
|
||||
elif srcContext == "droneItem":
|
||||
drone = selection[0]
|
||||
if drone in fit.drones:
|
||||
|
||||
@@ -138,7 +138,10 @@ class ChangeItemToVariation(ContextMenu):
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
if context == 'fittingModule':
|
||||
positions = [mod.modPosition for mod in self.selection]
|
||||
positions = []
|
||||
for position, mod in enumerate(fit.modules):
|
||||
if mod in self.selection:
|
||||
positions.append(position)
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleMetasCommand(
|
||||
fitID=fitID, positions=positions, newItemID=item.ID))
|
||||
elif context == 'droneItem':
|
||||
|
||||
@@ -29,11 +29,11 @@ class FillWithModule(ContextMenu):
|
||||
|
||||
if srcContext == "fittingModule":
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithLocalModulesCommand(
|
||||
fitID=fitID,
|
||||
position=fit.modules.index(selection[0])))
|
||||
return # the command takes care of the PostEvent
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=fitID))
|
||||
mod = selection[0]
|
||||
if mod in fit.modules:
|
||||
position = fit.modules.index(mod)
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithLocalModulesCommand(
|
||||
fitID=fitID, position=position))
|
||||
|
||||
|
||||
FillWithModule.register()
|
||||
|
||||
@@ -5,6 +5,7 @@ import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenu
|
||||
from gui.fitCommands import GuiConvertMutatedLocalModuleCommand, GuiRevertMutatedLocalModuleCommand
|
||||
from service.settings import ContextMenuSettings
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class ChangeModuleMutation(ContextMenu):
|
||||
@@ -55,17 +56,21 @@ class ChangeModuleMutation(ContextMenu):
|
||||
|
||||
def handleMenu(self, event):
|
||||
mutaplasmid, mod = self.eventIDs[event.Id]
|
||||
|
||||
self.mainFrame.command.Submit(GuiConvertMutatedLocalModuleCommand(
|
||||
fitID=self.mainFrame.getActiveFit(),
|
||||
position=mod.modPosition,
|
||||
mutaplasmid=mutaplasmid))
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
if mod in fit.modules:
|
||||
position = fit.modules.index(mod)
|
||||
self.mainFrame.command.Submit(GuiConvertMutatedLocalModuleCommand(
|
||||
fitID=fitID, position=position, mutaplasmid=mutaplasmid))
|
||||
|
||||
def activate(self, fullContext, selection, i):
|
||||
mod = selection[0]
|
||||
self.mainFrame.command.Submit(GuiRevertMutatedLocalModuleCommand(
|
||||
fitID=self.mainFrame.getActiveFit(),
|
||||
position=mod.modPosition))
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
if mod in fit.modules:
|
||||
position = fit.modules.index(mod)
|
||||
self.mainFrame.command.Submit(GuiRevertMutatedLocalModuleCommand(
|
||||
fitID=fitID, position=position))
|
||||
|
||||
def getBitmap(self, context, selection):
|
||||
return None
|
||||
|
||||
@@ -374,7 +374,7 @@ class FittingView(d.Display):
|
||||
if len(modules) > 0:
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(fitID, modules, itemID))
|
||||
else:
|
||||
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID, itemID))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
|
||||
|
||||
event.Skip()
|
||||
|
||||
@@ -396,7 +396,14 @@ class FittingView(d.Display):
|
||||
if not isinstance(modules, list):
|
||||
modules = [modules]
|
||||
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveLocalModuleCommand(self.activeFitID, modules))
|
||||
fit = Fit.getInstance().getFit(self.activeFitID)
|
||||
positions = []
|
||||
for position, mod in enumerate(fit.modules):
|
||||
if mod in modules:
|
||||
positions.append(position)
|
||||
|
||||
self.mainFrame.command.Submit(cmd.GuiRemoveLocalModuleCommand(
|
||||
fitID=self.activeFitID, positions=positions))
|
||||
|
||||
def addModule(self, x, y, itemID):
|
||||
"""Add a module from the market browser (from dragging it)"""
|
||||
@@ -408,7 +415,8 @@ class FittingView(d.Display):
|
||||
if not isinstance(mod, Module): # make sure we're not adding something to a T3D Mode
|
||||
return
|
||||
|
||||
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID, itemID, self.mods[dstRow].modPosition))
|
||||
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(
|
||||
fitID=fitID, itemID=itemID, position=self.mods[dstRow].modPosition))
|
||||
|
||||
def swapCargo(self, x, y, cargoItemID):
|
||||
"""Swap a module from cargo to fitting window"""
|
||||
@@ -434,27 +442,27 @@ class FittingView(d.Display):
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
|
||||
if dstRow != -1 and dstRow not in self.blanks:
|
||||
mod1 = fit.modules[srcIdx]
|
||||
mod2 = self.mods[dstRow]
|
||||
|
||||
try:
|
||||
mod1 = fit.modules[srcIdx]
|
||||
mod2 = self.mods[dstRow]
|
||||
except IndexError:
|
||||
return
|
||||
if not isinstance(mod2, Module):
|
||||
return
|
||||
|
||||
# can't swap modules to different racks
|
||||
if mod1.slot != mod2.slot:
|
||||
return
|
||||
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
if getattr(mod2, "modPosition") is not None:
|
||||
mstate = wx.GetMouseState()
|
||||
if mstate.cmdDown and mod2.isEmpty:
|
||||
self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
|
||||
fitID=fitID, srcPosition=srcIdx, dstPosition=mod2.modPosition))
|
||||
elif not mstate.cmdDown:
|
||||
self.mainFrame.command.Submit(cmd.GuiSwapLocalModulesCommand(
|
||||
fitID=fitID, position1=srcIdx, position2=mod2.modPosition))
|
||||
else:
|
||||
if mod2 not in fit.modules:
|
||||
pyfalog.error("Missing module position for: {0}", str(getattr(mod2, "ID", "Unknown")))
|
||||
return
|
||||
mod2Position = fit.modules.index(mod2)
|
||||
mstate = wx.GetMouseState()
|
||||
if mstate.cmdDown and mod2.isEmpty:
|
||||
self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
|
||||
fitID=self.activeFitID, srcPosition=srcIdx, dstPosition=mod2Position))
|
||||
elif not mstate.cmdDown:
|
||||
self.mainFrame.command.Submit(cmd.GuiSwapLocalModulesCommand(
|
||||
fitID=self.activeFitID, position1=srcIdx, position2=mod2Position))
|
||||
|
||||
def generateMods(self):
|
||||
"""
|
||||
@@ -607,18 +615,35 @@ class FittingView(d.Display):
|
||||
curr = self.GetNextSelected(curr)
|
||||
|
||||
if row not in sel:
|
||||
mods = [self.mods[self.GetItemData(row)]]
|
||||
try:
|
||||
mods = [self.mods[self.GetItemData(row)]]
|
||||
except IndexError:
|
||||
return
|
||||
else:
|
||||
mods = self.getSelectedMods()
|
||||
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
ctrl = event.cmdDown or event.altDown or event.middleIsDown
|
||||
click = "ctrl" if ctrl is True else "right" if event.GetButton() == 3 else "left"
|
||||
|
||||
try:
|
||||
mainMod = self.mods[self.GetItemData(row)]
|
||||
except IndexError:
|
||||
return
|
||||
|
||||
mainPosition = None
|
||||
positions = []
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
for position, mod in enumerate(Fit.getInstance().getFit(fitID).modules):
|
||||
if mod in mods:
|
||||
positions.append(position)
|
||||
if mod is mainMod:
|
||||
mainPosition = position
|
||||
if mainPosition is None:
|
||||
return
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleStatesCommand(
|
||||
fitID=fitID,
|
||||
mainPosition=self.mods[self.GetItemData(row)].modPosition,
|
||||
positions=[mod.modPosition for mod in mods],
|
||||
mainPosition=mainPosition,
|
||||
positions=positions,
|
||||
click=click))
|
||||
|
||||
# update state tooltip
|
||||
|
||||
@@ -67,8 +67,8 @@ class CalcAddLocalModuleCommand(wx.Command):
|
||||
return self.subsystemCmd.Undo()
|
||||
if self.savedPosition is None:
|
||||
return False
|
||||
from .localRemove import CalcRemoveLocalModuleCommand
|
||||
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit)
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.savedPosition], commit=self.commit)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
|
||||
@@ -44,8 +44,8 @@ class CalcCloneLocalModuleCommand(wx.Command):
|
||||
|
||||
def Undo(self):
|
||||
pyfalog.debug('Undoing cloning of local module from position {} to position {} for fit ID {}'.format(self.srcPosition, self.dstPosition, self.fitID))
|
||||
from .localRemove import CalcRemoveLocalModuleCommand
|
||||
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.dstPosition])
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.dstPosition])
|
||||
if not cmd.Do():
|
||||
return False
|
||||
restoreCheckedStates(Fit.getInstance().getFit(self.fitID), self.savedStateCheckChanges)
|
||||
|
||||
@@ -9,7 +9,7 @@ from service.fit import Fit
|
||||
pyfalog = Logger(__name__)
|
||||
|
||||
|
||||
class CalcRemoveLocalModuleCommand(wx.Command):
|
||||
class CalcRemoveLocalModulesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, positions, commit=True):
|
||||
wx.Command.__init__(self, True, 'Remove Module')
|
||||
|
||||
@@ -68,8 +68,8 @@ class CalcReplaceLocalModuleCommand(wx.Command):
|
||||
fit = sFit.getFit(self.fitID)
|
||||
# Remove if there was no module
|
||||
if self.oldModInfo is None:
|
||||
from .localRemove import CalcRemoveLocalModuleCommand
|
||||
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[self.position], commit=self.commit)
|
||||
from .localRemove import CalcRemoveLocalModulesCommand
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=[self.position], commit=self.commit)
|
||||
if not cmd.Do():
|
||||
return False
|
||||
sFit.recalc(fit)
|
||||
|
||||
@@ -2,26 +2,32 @@ import wx
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModuleCommand
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModulesCommand
|
||||
from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiRemoveLocalModuleCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, modules):
|
||||
def __init__(self, fitID, positions):
|
||||
wx.Command.__init__(self, True, 'Remove Local Module')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.modCache = {mod.modPosition: ModuleInfo.fromModule(mod) for mod in modules if not mod.isEmpty}
|
||||
self.positions = positions
|
||||
self.savedTypeIDs = None
|
||||
|
||||
def Do(self):
|
||||
cmd = CalcRemoveLocalModuleCommand(fitID=self.fitID, positions=[pos for pos in self.modCache])
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.fitID)
|
||||
self.savedTypeIDs = {m.itemID for m in fit.modules if not m.isEmpty}
|
||||
cmd = CalcRemoveLocalModulesCommand(fitID=self.fitID, positions=self.positions)
|
||||
success = self.internalHistory.submit(cmd)
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
sFit.recalc(self.fitID)
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID={mod.itemID for mod in self.modCache.values()}) if success else GE.FitChanged(fitID=self.fitID))
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.savedTypeIDs)
|
||||
if success and self.savedTypeIDs else
|
||||
GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
@@ -29,5 +35,7 @@ class GuiRemoveLocalModuleCommand(wx.Command):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID={mod.itemID for mod in self.modCache.values()}) if success else GE.FitChanged(fitID=self.fitID))
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedTypeIDs)
|
||||
if success and self.savedTypeIDs else
|
||||
GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
@@ -5,7 +5,7 @@ import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from gui.fitCommands.calc.cargo.add import CalcAddCargoCommand
|
||||
from gui.fitCommands.calc.cargo.remove import CalcRemoveCargoCommand
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModuleCommand
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModulesCommand
|
||||
from gui.fitCommands.calc.module.localReplace import CalcReplaceLocalModuleCommand
|
||||
from gui.fitCommands.helpers import CargoInfo, InternalCommandHistory, ModuleInfo
|
||||
from service.fit import Fit
|
||||
@@ -110,7 +110,7 @@ class GuiLocalModuleToCargoCommand(wx.Command):
|
||||
cargoInfo=CargoInfo(itemID=srcMod.chargeID, amount=srcMod.numCharges),
|
||||
commit=False))
|
||||
if not self.copy:
|
||||
commands.append(CalcRemoveLocalModuleCommand(
|
||||
commands.append(CalcRemoveLocalModulesCommand(
|
||||
fitID=self.fitID,
|
||||
positions=[self.srcModPosition],
|
||||
commit=False))
|
||||
|
||||
@@ -17,7 +17,7 @@ from eos.db import gamedata_session, getCategory, getAttributeInfo, getGroup
|
||||
from eos.gamedata import Attribute, Effect, Group, Item, ItemEffect
|
||||
from eos.utils.spoolSupport import SpoolType, SpoolOptions
|
||||
from gui.fitCommands.calc.module.localAdd import CalcAddLocalModuleCommand
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModuleCommand
|
||||
from gui.fitCommands.calc.module.localRemove import CalcRemoveLocalModulesCommand
|
||||
from gui.fitCommands.helpers import ModuleInfo
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ class EfsPort:
|
||||
fit = eos.db.getFit(fitID)
|
||||
mwdPropSpeed = fit.maxSpeed
|
||||
mwdPosition = list(filter(lambda mod: mod.item and mod.item.ID == propID, fit.modules))[0].position
|
||||
CalcRemoveLocalModuleCommand(fitID, [mwdPosition]).Do()
|
||||
CalcRemoveLocalModulesCommand(fitID, [mwdPosition]).Do()
|
||||
sFit.recalc(fit)
|
||||
fit = eos.db.getFit(fitID)
|
||||
return mwdPropSpeed
|
||||
|
||||
Reference in New Issue
Block a user