Added method to check/get modes, and start GUI integration (simple context menu)
This commit is contained in:
@@ -100,7 +100,10 @@ class Fit(object):
|
||||
self.extraAttributes = ModifiedAttributeDict(self)
|
||||
self.extraAttributes.original = self.EXTRA_ATTRIBUTES
|
||||
self.ship = Ship(db.getItem(self.shipID)) if self.shipID is not None else None
|
||||
self.mode = Mode(db.getItem(self.mode)) if self.mode is not None else None
|
||||
if self.ship is not None and self.mode is not None:
|
||||
self.mode = self.ship.checkMode(Mode(self.mode))
|
||||
else:
|
||||
self.mode = None
|
||||
|
||||
@property
|
||||
def targetResists(self):
|
||||
|
||||
@@ -24,8 +24,6 @@ class Mode(ItemAttrShortcut, HandledItem):
|
||||
|
||||
def __init__(self, item):
|
||||
self.__item = item
|
||||
self.itemID = item.ID if item is not None else None
|
||||
|
||||
self.__itemModifiedAttributes = ModifiedAttributeDict()
|
||||
|
||||
if not isinstance(item, int):
|
||||
@@ -57,10 +55,6 @@ class Mode(ItemAttrShortcut, HandledItem):
|
||||
def fits(self, fit):
|
||||
raise NotImplementedError()
|
||||
|
||||
# @ todo: rework to get valid modes (probably put in fit object, not mode)
|
||||
def getValidModes(self):
|
||||
raise NotImplementedError()
|
||||
|
||||
def clear(self):
|
||||
self.itemModifiedAttributes.clear()
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
from eos.modifiedAttributeDict import ModifiedAttributeDict, ItemAttrShortcut
|
||||
from eos.effectHandlerHelpers import HandledItem
|
||||
from eos.saveddata.mode import Mode
|
||||
|
||||
class Ship(ItemAttrShortcut, HandledItem):
|
||||
def __init__(self, item):
|
||||
@@ -65,6 +66,41 @@ class Ship(ItemAttrShortcut, HandledItem):
|
||||
if effect.runTime == runTime and effect.isType("passive"):
|
||||
effect.handler(fit, self, ("ship",))
|
||||
|
||||
def checkMode(self, mode):
|
||||
"""
|
||||
Checks if provided mode is valid.
|
||||
|
||||
If ship has modes, and current mode is not valid, return forced mode
|
||||
else if mode is valid, return Mode
|
||||
else if ship does not have modes, return None
|
||||
"""
|
||||
modes = self.getValidModes()
|
||||
if modes != None:
|
||||
if mode == None or mode not in modes:
|
||||
# We have a tact dessy, but mode is None or not valid. Force new mode
|
||||
return modes[0]
|
||||
elif mode in modes:
|
||||
# We have a valid mode
|
||||
return mode
|
||||
return None
|
||||
|
||||
def getValidModes(self):
|
||||
"""Gets valid modes for ship, returns None if not a t3 dessy"""
|
||||
# @todo: is there a better way to determine this that isn't hardcoded groupIDs?
|
||||
if self.item.groupID != 1305:
|
||||
return None
|
||||
|
||||
modeGroupID = 1306
|
||||
import eos.db
|
||||
|
||||
modes = []
|
||||
g = eos.db.getGroup(modeGroupID, eager=("items.icon", "items.attributes"))
|
||||
for item in g.items:
|
||||
if item.raceID == self.item.raceID:
|
||||
modes.append(Mode(item))
|
||||
|
||||
return modes
|
||||
|
||||
def __deepcopy__(self, memo):
|
||||
copy = Ship(self.item)
|
||||
return copy
|
||||
|
||||
@@ -14,6 +14,7 @@ __all__ = [
|
||||
"whProjector",
|
||||
"cargo",
|
||||
"shipJump",
|
||||
"tacticalMode",
|
||||
"targetResists",
|
||||
"priceClear"
|
||||
]
|
||||
|
||||
47
gui/builtinContextMenus/tacticalMode.py
Normal file
47
gui/builtinContextMenus/tacticalMode.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import wx
|
||||
from gui.contextMenu import ContextMenu
|
||||
import gui.mainFrame
|
||||
import service
|
||||
from gui.shipBrowser import Stage3Selected
|
||||
|
||||
class TacticalMode(ContextMenu):
|
||||
def __init__(self):
|
||||
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||
|
||||
def display(self, srcContext, selection):
|
||||
sFit = service.Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
self.ship = sFit.getFit(fitID).ship
|
||||
self.modes = self.ship.getValidModes()
|
||||
|
||||
if not srcContext in ("fittingShip") or self.modes is None:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def getText(self, itmContext, selection):
|
||||
return "Modes"
|
||||
|
||||
def handleModeChange(self, event):
|
||||
mode = self.modeIds[event.Id]
|
||||
print mode
|
||||
# @todo fit service change mode
|
||||
|
||||
def addMode(self, menu, mode):
|
||||
label = mode.item.name.rsplit()[-2]
|
||||
id = wx.NewId()
|
||||
self.modeIds[id] = mode
|
||||
menuItem = wx.MenuItem(menu, id, label, kind=wx.ITEM_CHECK)
|
||||
menu.Bind(wx.EVT_MENU, self.handleModeChange, menuItem)
|
||||
return menuItem
|
||||
|
||||
def getSubMenu(self, context, selection, menu, i, pitem):
|
||||
sub = wx.Menu()
|
||||
self.modeIds = {}
|
||||
# Items that have a parent
|
||||
for mode in self.modes:
|
||||
sub.AppendItem(self.addMode(sub, mode))
|
||||
|
||||
return sub
|
||||
|
||||
TacticalMode.register()
|
||||
@@ -22,9 +22,9 @@ import re
|
||||
import gui.mainFrame
|
||||
import bitmapLoader
|
||||
import sys
|
||||
import wx.lib.mixins.listctrl as listmix
|
||||
import wx.lib.mixins.listctrl as listmix
|
||||
import wx.html
|
||||
from eos.types import Ship, Module, Skill, Booster, Implant, Drone
|
||||
from eos.types import Ship, Module, Skill, Booster, Implant, Drone, Mode
|
||||
from gui.utils.numberFormatter import formatAmount
|
||||
import service
|
||||
import config
|
||||
@@ -535,7 +535,7 @@ class ItemEffects (wx.Panel):
|
||||
|
||||
|
||||
class ItemAffectedBy (wx.Panel):
|
||||
ORDER = [Ship, Module, Drone, Implant, Booster, Skill]
|
||||
ORDER = [Ship, Mode, Module, Drone, Implant, Booster, Skill]
|
||||
def __init__(self, parent, stuff, item):
|
||||
wx.Panel.__init__ (self, parent)
|
||||
self.stuff = stuff
|
||||
|
||||
Reference in New Issue
Block a user