Handle use case of moving a module from market to fitting view
This commit is contained in:
@@ -361,6 +361,9 @@ class FittingView(d.Display):
|
||||
self.parent.SetPageTextIcon(pageIndex, text, bitmap)
|
||||
|
||||
def appendItem(self, event):
|
||||
'''
|
||||
Adds items that are double clicks from the market browser. We handle both modules and ammo
|
||||
'''
|
||||
if not self:
|
||||
event.Skip()
|
||||
return
|
||||
@@ -370,6 +373,7 @@ class FittingView(d.Display):
|
||||
if fitID is not None:
|
||||
sFit = Fit.getInstance()
|
||||
if sFit.isAmmo(itemID):
|
||||
# If we've selected ammo, then apply to the selected module(s)
|
||||
modules = []
|
||||
sel = self.GetFirstSelected()
|
||||
while sel != -1 and sel not in self.blanks:
|
||||
@@ -405,23 +409,17 @@ class FittingView(d.Display):
|
||||
|
||||
self.mainFrame.command.Submit(cmd.FitModuleRemoveCommand(self.activeFitID, modules))
|
||||
|
||||
def addModule(self, x, y, srcIdx):
|
||||
"""Add a module from the market browser"""
|
||||
def addModule(self, x, y, itemID):
|
||||
"""Add a module from the market browser (from dragging it)"""
|
||||
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
if dstRow != -1 and dstRow not in self.blanks:
|
||||
sFit = Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
mod = self.mods[dstRow]
|
||||
if not isinstance(mod, Module): # make sure we're not adding something to a T3D Mode
|
||||
return
|
||||
|
||||
moduleChanged = sFit.changeModule(fitID, self.mods[dstRow].modPosition, srcIdx)
|
||||
if moduleChanged is None:
|
||||
# the new module doesn't fit in specified slot, try to simply append it
|
||||
wx.PostEvent(self.mainFrame, ItemSelected(itemID=srcIdx))
|
||||
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.mainFrame.getActiveFit(), action="modadd", typeID=srcIdx))
|
||||
self.mainFrame.command.Submit(cmd.FitModuleAddCommand(fitID, itemID, self.mods[dstRow].modPosition))
|
||||
|
||||
def swapCargo(self, x, y, srcIdx):
|
||||
"""Swap a module from cargo to fitting window"""
|
||||
@@ -449,18 +447,13 @@ class FittingView(d.Display):
|
||||
sFit = Fit.getInstance()
|
||||
fit = sFit.getFit(self.activeFitID)
|
||||
|
||||
if mstate.CmdDown():
|
||||
clone = True
|
||||
else:
|
||||
clone = False
|
||||
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
|
||||
if dstRow != -1 and dstRow not in self.blanks:
|
||||
|
||||
mod1 = fit.modules[srcIdx]
|
||||
mod2 = self.mods[dstRow]
|
||||
|
||||
|
||||
if not isinstance(mod2, Module):
|
||||
return
|
||||
|
||||
@@ -468,9 +461,11 @@ class FittingView(d.Display):
|
||||
if mod1.slot != mod2.slot:
|
||||
return
|
||||
|
||||
clone = mstate.CmdDown() and mod2.isEmpty
|
||||
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
if getattr(mod2, "modPosition") is not None:
|
||||
self.mainFrame.command.Submit(cmd.FitModuleSwapOrCloneCommand(fitID, srcIdx, mod2.modPosition, clone and mod2.isEmpty))
|
||||
self.mainFrame.command.Submit(cmd.FitModuleSwapOrCloneCommand(fitID, srcIdx, mod2.modPosition, clone))
|
||||
else:
|
||||
pyfalog.error("Missing module position for: {0}", str(getattr(mod2, "ID", "Unknown")))
|
||||
|
||||
@@ -626,7 +621,6 @@ class FittingView(d.Display):
|
||||
else:
|
||||
mods = self.getSelectedMods()
|
||||
|
||||
sFit = Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
ctrl = event.cmdDown or event.middleIsDown
|
||||
click = "ctrl" if ctrl is True else "right" if event.GetButton() == 3 else "left"
|
||||
|
||||
3
gui/fitCommands/helpers.py
Normal file
3
gui/fitCommands/helpers.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from collections import namedtuple
|
||||
|
||||
ModuleInfoCache = namedtuple('ModuleInfoCache', ['modPosition', 'itemID', 'state', 'charge'])
|
||||
@@ -3,29 +3,56 @@ from service.fit import Fit
|
||||
|
||||
import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from .helpers import ModuleInfoCache
|
||||
|
||||
|
||||
class FitModuleAddCommand(wx.Command):
|
||||
def __init__(self, fitID, itemID):
|
||||
def __init__(self, fitID, itemID, position=None):
|
||||
wx.Command.__init__(self, True, "Module Add")
|
||||
# todo: evaluate mutaplasmid modules
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.sFit = Fit.getInstance()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
self.new_position = None
|
||||
self.new_position = position
|
||||
self.old_mod = None
|
||||
|
||||
def Do(self):
|
||||
# todo: figure how not to add this command to stack if module doesn't fit correctly.
|
||||
populate, self.new_position = self.sFit.appendModule(self.fitID, self.itemID)
|
||||
if populate is not None:
|
||||
change = None
|
||||
|
||||
# if we have a position set, try to apply the module to that position
|
||||
if self.new_position:
|
||||
fit = self.sFit.getFit(self.fitID)
|
||||
old_mod = fit.modules[self.new_position]
|
||||
cache = ModuleInfoCache(old_mod.modPosition, old_mod.itemID, old_mod.state, old_mod.charge)
|
||||
change = self.sFit.changeModule(self.fitID, self.new_position, self.itemID)
|
||||
if change is None:
|
||||
# the new module doesn't fit in specified slot, remove the position
|
||||
self.new_position = None
|
||||
elif not old_mod.isEmpty:
|
||||
self.old_mod = cache
|
||||
|
||||
# if we're not trying to set module to a position, simply append
|
||||
if not self.new_position:
|
||||
change, self.new_position = self.sFit.appendModule(self.fitID, self.itemID)
|
||||
|
||||
if change is not None:
|
||||
print('new position: ',self.new_position )
|
||||
# self.slotsChanged() # unsure how to handle this right now? Perhaps move this to the event itself?
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="modadd", typeID=self.itemID))
|
||||
return True
|
||||
return True
|
||||
return False
|
||||
|
||||
def Undo(self):
|
||||
if (self.new_position):
|
||||
# todo: self.slotsChanged()
|
||||
result = self.sFit.removeModule(self.fitID, [self.new_position])
|
||||
if self.new_position:
|
||||
if self.old_mod:
|
||||
# we added a module on top of another one
|
||||
m = self.sFit.changeModule(self.fitID, self.old_mod.modPosition, self.old_mod.itemID, False)
|
||||
m.state = self.old_mod.state
|
||||
m.charge = self.old_mod.charge
|
||||
else:
|
||||
# todo: self.slotsChanged()
|
||||
# we simply added a module, so simply remove
|
||||
result = self.sFit.removeModule(self.fitID, [self.new_position])
|
||||
wx.PostEvent(self.mainFrame, GE.FitChanged(fitID=self.fitID, action="moddel", typeID=self.itemID))
|
||||
return True
|
||||
|
||||
@@ -5,8 +5,7 @@ import gui.mainFrame
|
||||
from gui import globalEvents as GE
|
||||
from collections import namedtuple
|
||||
|
||||
ModuleInfoCache = namedtuple('ModuleInfoCache', ['modPosition', 'itemID', 'state', 'charge'])
|
||||
|
||||
from .helpers import ModuleInfoCache
|
||||
|
||||
class FitModuleRemoveCommand(wx.Command):
|
||||
def __init__(self, fitID, modules):
|
||||
|
||||
Reference in New Issue
Block a user