Move booster and implant meta swap out of meta swap command

This commit is contained in:
DarkPhoenix
2019-04-15 13:28:15 +03:00
parent 82777d0b02
commit 960bef2b96
9 changed files with 97 additions and 20 deletions

View File

@@ -135,7 +135,7 @@ class BoosterView(d.Display):
event.Skip()
return
if self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID, event.itemID)):
if self.mainFrame.command.Submit(cmd.GuiAddBoosterCommand(fitID=fitID, itemID=event.itemID)):
self.mainFrame.additionsPane.select("Boosters")
event.Skip()
@@ -149,7 +149,7 @@ class BoosterView(d.Display):
def removeBooster(self, booster):
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID, self.original.index(booster)))
self.mainFrame.command.Submit(cmd.GuiRemoveBoosterCommand(fitID=fitID, position=self.original.index(booster)))
def click(self, event):
event.Skip()
@@ -158,7 +158,8 @@ class BoosterView(d.Display):
col = self.getColumn(event.Position)
if col == self.getColIndex(State):
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiToggleBoosterStateCommand(fitID, row))
booster = self.boosters[self.GetItemData(row)]
self.mainFrame.command.Submit(cmd.GuiToggleBoosterStateCommand(fitID=fitID, position=self.original.index(booster)))
def spawnMenu(self, event):
sel = self.GetFirstSelected()

View File

@@ -218,7 +218,8 @@ class ImplantDisplay(d.Display):
col = self.getColumn(event.Position)
if col == self.getColIndex(State):
fitID = self.mainFrame.getActiveFit()
self.mainFrame.command.Submit(cmd.GuiToggleImplantStateCommand(fitID, row))
implant = self.implants[self.GetItemData(row)]
self.mainFrame.command.Submit(cmd.GuiToggleImplantStateCommand(fitID=fitID, position=self.original.index(implant)))
def spawnMenu(self, event):
sel = self.GetFirstSelected()

View File

@@ -130,23 +130,19 @@ class MetaSwap(ContextMenu):
return
fitID = self.mainFrame.getActiveFit()
fit = Fit.getInstance().getFit(fitID)
self.mainFrame.command.Submit(cmd.GuiMetaSwapCommand(fitID, context, item.ID, self.selection))
if context == 'implantItem':
position = fit.implants.index(self.selection[0])
self.mainFrame.command.Submit(cmd.GuiSwapImplantMetaCommand(
fitID=fitID, position=position, itemID=item.ID))
if context == 'boosterItem':
position = fit.boosters.index(self.selection[0])
self.mainFrame.command.Submit(cmd.GuiSwapBoosterMetaCommand(
fitID=fitID, position=position, itemID=item.ID))
else:
self.mainFrame.command.Submit(cmd.GuiMetaSwapCommand(fitID, context, item.ID, self.selection))
# for selected_item in self.selection:
#
# elif isinstance(selected_item, Drone):
# drone_count = None
#
# for idx, drone_stack in enumerate(fit.drones):
# if drone_stack is selected_item:
# drone_count = drone_stack.amount
# sFit.removeDrone(fitID, idx, drone_count, False)
# break
#
# if drone_count:
# sFit.addDrone(fitID, item.ID, drone_count, True)
MetaSwap.register()

View File

@@ -121,7 +121,7 @@ class BaseImplantEditorView(wx.Panel):
def update(self):
"""Updates implant list based off the current context"""
self.implants = self.getImplantsFromContext()
self.implants = self.getImplantsFromContext()[:]
self.implants.sort(key=lambda i: int(i.getModifiedItemAttr("implantness")))
self.pluggedImplantsTree.update(self.implants)

View File

@@ -1,4 +1,5 @@
from .gui.booster.add import GuiAddBoosterCommand
from .gui.booster.metaSwap import GuiSwapBoosterMetaCommand
from .gui.booster.remove import GuiRemoveBoosterCommand
from .gui.booster.sideEffectToggleState import GuiToggleBoosterSideEffectStateCommand
from .gui.booster.toggleState import GuiToggleBoosterStateCommand
@@ -15,6 +16,7 @@ from .gui.guiModuleToCargo import GuiModuleToCargoCommand
from .gui.guiSwapCloneModule import GuiModuleSwapOrCloneCommand
from .gui.implant.add import GuiAddImplantCommand
from .gui.implant.changeLocation import GuiChangeImplantLocationCommand
from .gui.implant.metaSwap import GuiSwapImplantMetaCommand
from .gui.implant.remove import GuiRemoveImplantCommand
from .gui.implant.toggleState import GuiToggleImplantStateCommand
from .gui.itemsRebase import GuiRebaseItemsCommand

View File

@@ -0,0 +1,40 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.booster.add import CalcAddBoosterCommand
from gui.fitCommands.helpers import BoosterInfo, InternalCommandHistory
from service.fit import Fit
class GuiSwapBoosterMetaCommand(wx.Command):
def __init__(self, fitID, position, itemID):
wx.Command.__init__(self, True, 'Swap Booster Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.itemID = itemID
def Do(self):
sFit = Fit.getInstance()
booster = sFit.getFit(self.fitID).boosters[self.position]
if booster.itemID == self.itemID:
return False
cmd = CalcAddBoosterCommand(
fitID=self.fitID,
boosterInfo=BoosterInfo(
itemID=self.itemID,
state=booster.active,
sideEffects={se.effectID: se.active for se in booster.sideEffects}))
if self.internalHistory.submit(cmd):
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -0,0 +1,35 @@
import wx
import gui.mainFrame
from gui import globalEvents as GE
from gui.fitCommands.calc.implant.add import CalcAddImplantCommand
from gui.fitCommands.helpers import ImplantInfo, InternalCommandHistory
from service.fit import Fit
class GuiSwapImplantMetaCommand(wx.Command):
def __init__(self, fitID, position, itemID):
wx.Command.__init__(self, True, 'Swap Implant Meta')
self.internalHistory = InternalCommandHistory()
self.fitID = fitID
self.position = position
self.itemID = itemID
def Do(self):
sFit = Fit.getInstance()
implant = sFit.getFit(self.fitID).implants[self.position]
if implant.itemID == self.itemID:
return False
cmd = CalcAddImplantCommand(fitID=self.fitID, implantInfo=ImplantInfo(itemID=self.itemID, state=implant.active))
if self.internalHistory.submit(cmd):
sFit.recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return True
return False
def Undo(self):
success = self.internalHistory.undoAll()
Fit.getInstance().recalc(self.fitID)
wx.PostEvent(gui.mainFrame.MainFrame.getInstance(), GE.FitChanged(fitID=self.fitID))
return success

View File

@@ -411,6 +411,7 @@ class Character(object):
return
implant = es_Implant(eos.db.getItem(itemID))
char.implants.makeRoom(implant)
char.implants.append(implant)
eos.db.commit()

View File

@@ -55,6 +55,7 @@ class ImplantSets(object):
def addImplant(setID, itemID):
implant_set = eos.db.getImplantSet(setID)
implant = es_Implant(eos.db.getItem(itemID))
implant_set.implants.makeRoom(implant)
implant_set.implants.append(implant)
eos.db.commit()