Add ability to fill fit with item, and fix some charge-related stuff
This commit is contained in:
@@ -25,6 +25,7 @@ from gui.builtinContextMenus import ( # noqa: E402,F401
|
||||
moduleFill,
|
||||
skillAffectors,
|
||||
# Market stuff
|
||||
itemFill,
|
||||
droneAddStack,
|
||||
cargoAdd,
|
||||
cargoAddAmmo,
|
||||
|
||||
35
gui/builtinContextMenus/itemFill.py
Normal file
35
gui/builtinContextMenus/itemFill.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import gui.fitCommands as cmd
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenu
|
||||
from service.settings import ContextMenuSettings
|
||||
|
||||
|
||||
class FillWithItem(ContextMenu):
|
||||
|
||||
def __init__(self):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
self.settings = ContextMenuSettings.getInstance()
|
||||
|
||||
def display(self, srcContext, selection):
|
||||
if not self.settings.get('moduleFill'):
|
||||
return False
|
||||
if srcContext not in ('marketItemGroup', 'marketItemMisc'):
|
||||
return False
|
||||
if self.mainFrame.getActiveFit() is None:
|
||||
return False
|
||||
item = selection[0]
|
||||
if item.category.name != 'Module':
|
||||
return False
|
||||
return True
|
||||
|
||||
def getText(self, itmContext, selection):
|
||||
return "Fill With Module"
|
||||
|
||||
def activate(self, fullContext, selection, i):
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(
|
||||
fitID=self.mainFrame.getActiveFit(),
|
||||
itemID=int(selection[0].ID)))
|
||||
self.mainFrame.additionsPane.select('Drones')
|
||||
|
||||
|
||||
FillWithItem.register()
|
||||
@@ -1,8 +1,4 @@
|
||||
# noinspection PyPackageRequirements
|
||||
import wx
|
||||
|
||||
import gui.fitCommands as cmd
|
||||
import gui.globalEvents as GE
|
||||
import gui.mainFrame
|
||||
from gui.contextMenu import ContextMenu
|
||||
from service.fit import Fit
|
||||
@@ -32,7 +28,7 @@ class FillWithModule(ContextMenu):
|
||||
mod = selection[0]
|
||||
if mod in fit.modules:
|
||||
position = fit.modules.index(mod)
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithLocalModulesCommand(
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithClonedLocalModulesCommand(
|
||||
fitID=fitID, position=position))
|
||||
|
||||
|
||||
|
||||
@@ -358,23 +358,37 @@ class FittingView(d.Display):
|
||||
fitID = self.activeFitID
|
||||
if fitID is not None:
|
||||
item = Market.getInstance().getItem(itemID, eager='group.category')
|
||||
if item is None or not (item.isModule or item.isSubsystem):
|
||||
if item is None:
|
||||
event.Skip()
|
||||
return
|
||||
mstate = wx.GetMouseState()
|
||||
# If we've selected ammo, then apply to the selected module(s)
|
||||
if item.isCharge:
|
||||
# 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:
|
||||
mod = self.mods[self.GetItemData(sel)]
|
||||
if isinstance(mod, Module) and not mod.isEmpty:
|
||||
modules.append(self.mods[self.GetItemData(sel)])
|
||||
sel = self.GetNextSelected(sel)
|
||||
positions = []
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
if mstate.altDown:
|
||||
for position, mod in enumerate(fit.modules):
|
||||
if isinstance(mod, Module) and not mod.isEmpty:
|
||||
positions.append(position)
|
||||
else:
|
||||
sel = self.GetFirstSelected()
|
||||
while sel != -1 and sel not in self.blanks:
|
||||
try:
|
||||
mod = self.mods[self.GetItemData(sel)]
|
||||
except IndexError:
|
||||
sel = self.GetNextSelected(sel)
|
||||
continue
|
||||
if isinstance(mod, Module) and not mod.isEmpty and mod in fit.modules:
|
||||
positions.append(fit.modules.index(mod))
|
||||
sel = self.GetNextSelected(sel)
|
||||
|
||||
if len(modules) > 0:
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(fitID, modules, itemID))
|
||||
else:
|
||||
if len(positions) > 0:
|
||||
self.mainFrame.command.Submit(cmd.GuiChangeLocalModuleChargesCommand(
|
||||
fitID=fitID, positions=positions, chargeItemID=itemID))
|
||||
elif (item.isModule and not mstate.altDown) or item.isSubsystem:
|
||||
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(fitID=fitID, itemID=itemID))
|
||||
elif item.isModule and mstate.altDown:
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
|
||||
|
||||
event.Skip()
|
||||
|
||||
@@ -408,15 +422,46 @@ class FittingView(d.Display):
|
||||
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:
|
||||
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
|
||||
|
||||
self.mainFrame.command.Submit(cmd.GuiAddLocalModuleCommand(
|
||||
fitID=fitID, itemID=itemID, position=self.mods[dstRow].modPosition))
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
item = Market.getInstance().getItem(itemID)
|
||||
fit = Fit.getInstance().getFit(fitID)
|
||||
mstate = wx.GetMouseState()
|
||||
if item.isModule and mstate.altDown:
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithNewLocalModulesCommand(fitID=fitID, itemID=itemID))
|
||||
elif item.isModule:
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
if dstRow != -1 and dstRow not in self.blanks:
|
||||
try:
|
||||
mod = self.mods[dstRow]
|
||||
except IndexError:
|
||||
return
|
||||
if not isinstance(mod, Module):
|
||||
return
|
||||
if mod in fit.modules:
|
||||
position = fit.modules.index(mod)
|
||||
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:
|
||||
dstRow, _ = self.HitTest((x, y))
|
||||
if dstRow != -1 and dstRow not in self.blanks:
|
||||
try:
|
||||
mod = self.mods[dstRow]
|
||||
except IndexError:
|
||||
return
|
||||
if not isinstance(mod, Module):
|
||||
return
|
||||
if mod.isEmpty:
|
||||
return
|
||||
if mod in fit.modules:
|
||||
if mstate.altDown:
|
||||
positions = filterModsByGroups(fit.modules, mod)
|
||||
else:
|
||||
positions = [fit.modules.index(mod)]
|
||||
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"""
|
||||
@@ -459,7 +504,7 @@ class FittingView(d.Display):
|
||||
mod2Position = fit.modules.index(mod2)
|
||||
mstate = wx.GetMouseState()
|
||||
if mstate.cmdDown and mstate.altDown:
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithLocalModulesCommand(
|
||||
self.mainFrame.command.Submit(cmd.GuiFillWithClonedLocalModulesCommand(
|
||||
fitID=self.activeFitID, position=srcIdx))
|
||||
elif mstate.cmdDown and mod2.isEmpty:
|
||||
self.mainFrame.command.Submit(cmd.GuiCloneLocalModuleCommand(
|
||||
|
||||
@@ -37,7 +37,8 @@ from .gui.localModule.changeMetas import GuiChangeLocalModuleMetasCommand
|
||||
from .gui.localModule.changeSpool import GuiChangeLocalModuleSpoolCommand
|
||||
from .gui.localModule.changeStates import GuiChangeLocalModuleStatesCommand
|
||||
from .gui.localModule.clone import GuiCloneLocalModuleCommand
|
||||
from .gui.localModule.fill import GuiFillWithLocalModulesCommand
|
||||
from .gui.localModule.fillAdd import GuiFillWithNewLocalModulesCommand
|
||||
from .gui.localModule.fillClone import GuiFillWithClonedLocalModulesCommand
|
||||
from .gui.localModule.mutatedConvert import GuiConvertMutatedLocalModuleCommand
|
||||
from .gui.localModule.mutatedImport import GuiImportLocalMutatedModuleCommand
|
||||
from .gui.localModule.mutatedRevert import GuiRevertMutatedLocalModuleCommand
|
||||
|
||||
46
gui/fitCommands/gui/localModule/fillAdd.py
Normal file
46
gui/fitCommands/gui/localModule/fillAdd.py
Normal file
@@ -0,0 +1,46 @@
|
||||
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.helpers import InternalCommandHistory, ModuleInfo
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiFillWithNewLocalModulesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, itemID):
|
||||
wx.Command.__init__(self, True, 'Fill with New Local Modules')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.itemID = itemID
|
||||
|
||||
def Do(self):
|
||||
info = ModuleInfo(itemID=self.itemID)
|
||||
added_modules = 0
|
||||
while True:
|
||||
cmd = CalcAddLocalModuleCommand(fitID=self.fitID, newModInfo=info, commit=False)
|
||||
if not self.internalHistory.submit(cmd):
|
||||
break
|
||||
added_modules += 1
|
||||
eos.db.commit()
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
success = added_modules > 0
|
||||
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
|
||||
@@ -8,10 +8,10 @@ from gui.fitCommands.helpers import InternalCommandHistory, ModuleInfo
|
||||
from service.fit import Fit
|
||||
|
||||
|
||||
class GuiFillWithLocalModulesCommand(wx.Command):
|
||||
class GuiFillWithClonedLocalModulesCommand(wx.Command):
|
||||
|
||||
def __init__(self, fitID, position):
|
||||
wx.Command.__init__(self, True, 'Fill with Local Modules')
|
||||
wx.Command.__init__(self, True, 'Fill with Cloned Local Modules')
|
||||
self.internalHistory = InternalCommandHistory()
|
||||
self.fitID = fitID
|
||||
self.position = position
|
||||
@@ -34,7 +34,9 @@ class GuiFillWithLocalModulesCommand(wx.Command):
|
||||
success = added_modules > 0
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID) if success else GE.FitChanged(fitID=self.fitID))
|
||||
GE.FitChanged(fitID=self.fitID, action='modadd', typeID=self.savedItemID)
|
||||
if success else
|
||||
GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
|
||||
def Undo(self):
|
||||
@@ -43,5 +45,7 @@ class GuiFillWithLocalModulesCommand(wx.Command):
|
||||
Fit.getInstance().recalc(self.fitID)
|
||||
wx.PostEvent(
|
||||
gui.mainFrame.MainFrame.getInstance(),
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.savedItemID) if success else GE.FitChanged(fitID=self.fitID))
|
||||
GE.FitChanged(fitID=self.fitID, action='moddel', typeID=self.savedItemID)
|
||||
if success else
|
||||
GE.FitChanged(fitID=self.fitID))
|
||||
return success
|
||||
Reference in New Issue
Block a user