Finish up ammo menus
This commit is contained in:
2
eos
2
eos
Submodule eos updated: 5479be126c...42cb0b6180
@@ -4,6 +4,7 @@ import service
|
||||
import gui.fittingView
|
||||
import wx
|
||||
from gui import bitmapLoader
|
||||
from eos.types import Hardpoint
|
||||
|
||||
class ModuleAmmoPicker(ContextMenu):
|
||||
def __init__(self):
|
||||
@@ -22,8 +23,9 @@ class ModuleAmmoPicker(ContextMenu):
|
||||
|
||||
validCharges = currCharges
|
||||
|
||||
self.charges = validCharges
|
||||
return True
|
||||
self.charges = list(validCharges)
|
||||
self.hardpoint = mod.hardpoint
|
||||
return len(self.charges) > 0
|
||||
|
||||
def getText(self, context, selection):
|
||||
return "Ammo"
|
||||
@@ -31,33 +33,123 @@ class ModuleAmmoPicker(ContextMenu):
|
||||
def activate(self, context, selection, i):
|
||||
pass
|
||||
|
||||
def turretSorter(self, charge):
|
||||
range = charge.getAttribute("weaponRangeMultiplier")
|
||||
damage = 0
|
||||
for type in ("em", "explosive", "kinetic", "thermal"):
|
||||
damage += charge.getAttribute("%sDamage" % type)
|
||||
|
||||
return (-range, damage)
|
||||
|
||||
MISSILE_ORDER = ["em", "explosive", "kinetic", "thermal"]
|
||||
def missileSorter(self, charge):
|
||||
for i, type in enumerate(self.MISSILE_ORDER):
|
||||
damage = charge.getAttribute("%sDamage" % type)
|
||||
if damage > 0:
|
||||
return (type, damage)
|
||||
|
||||
def nameSorter(self, charge):
|
||||
n = charge.name
|
||||
return (len(n), n)
|
||||
|
||||
def addCharge(self, menu, charge):
|
||||
id = wx.NewId()
|
||||
name = charge.name if charge is not None else "Empty"
|
||||
self.chargeIds[id] = charge
|
||||
item = wx.MenuItem(menu, id, name)
|
||||
item.charge = charge
|
||||
if charge is not None and charge.icon is not None:
|
||||
bitmap = bitmapLoader.getBitmap(charge.icon.iconFile, "pack")
|
||||
if bitmap is not None:
|
||||
item.SetBitmap(bitmap)
|
||||
|
||||
return item
|
||||
|
||||
def getSubMenu(self, context, selection, menu, i):
|
||||
menu.Bind(wx.EVT_MENU, self.handleAmmoSwitch)
|
||||
m = wx.Menu()
|
||||
self.chargeIds = {}
|
||||
for charge in self.charges:
|
||||
id = wx.NewId()
|
||||
self.chargeIds[id] = charge
|
||||
item = wx.MenuItem(m, id, charge.name)
|
||||
item.charge = charge
|
||||
if charge.icon is not None:
|
||||
bitmap = bitmapLoader.getBitmap(charge.icon.iconFile, "pack")
|
||||
if bitmap is not None:
|
||||
item.SetBitmap(bitmap)
|
||||
m.AppendItem(item)
|
||||
previousRangeMod = None
|
||||
if self.hardpoint == Hardpoint.TURRET:
|
||||
idRange = wx.NewId()
|
||||
m.Append(idRange, "--- Range ---")
|
||||
m.Enable(idRange, False)
|
||||
items = []
|
||||
self.charges.sort(key=self.turretSorter)
|
||||
for charge in self.charges:
|
||||
currRangeMod = charge.getAttribute("weaponRangeMultiplier")
|
||||
if previousRangeMod is None or previousRangeMod != currRangeMod:
|
||||
sub = None
|
||||
base = charge
|
||||
previousRangeMod = currRangeMod
|
||||
item = self.addCharge(m, charge)
|
||||
items.append(item)
|
||||
else:
|
||||
if sub is None:
|
||||
sub = wx.Menu()
|
||||
item.SetSubMenu(sub)
|
||||
sub.AppendItem(self.addCharge(sub, base))
|
||||
sub.AppendItem(self.addCharge(sub, charge))
|
||||
for item in items:
|
||||
m.AppendItem(item)
|
||||
|
||||
idDamage = wx.NewId()
|
||||
m.Append(idDamage, "--- Damage ---")
|
||||
m.Enable(idDamage, False)
|
||||
elif self.hardpoint == Hardpoint.MISSILE:
|
||||
self.charges.sort(key=self.missileSorter)
|
||||
type = None
|
||||
sub = None
|
||||
for charge in self.charges:
|
||||
currType = None
|
||||
for t in ("em", "explosive", "kinetic", "thermal"):
|
||||
if charge.getAttribute("%sDamage" % t) > 0:
|
||||
currType = t
|
||||
break
|
||||
|
||||
if currType != type or type is None:
|
||||
if sub is not None:
|
||||
id = wx.NewId()
|
||||
sub.Append(id, "--- More Damage ---")
|
||||
sub.Enable(id, False)
|
||||
type = currType
|
||||
item = wx.MenuItem(m, wx.ID_ANY, type.capitalize())
|
||||
bitmap = bitmapLoader.getBitmap("%s_small" % type, "icons")
|
||||
if bitmap is not None:
|
||||
item.SetBitmap(bitmap)
|
||||
|
||||
sub = wx.Menu()
|
||||
id = wx.NewId()
|
||||
sub.Append(id, "--- Less Damage ---")
|
||||
sub.Enable(id, False)
|
||||
item.SetSubMenu(sub)
|
||||
m.AppendItem(item)
|
||||
|
||||
if charge.name != "Defender I":
|
||||
sub.AppendItem(self.addCharge(sub, charge))
|
||||
else:
|
||||
defender = charge
|
||||
|
||||
if defender is not None:
|
||||
m.AppendItem(self.addCharge(sub, defender))
|
||||
else:
|
||||
self.charges.sort(key=self.nameSorter)
|
||||
for charge in self.charges:
|
||||
m.AppendItem(self.addCharge(m, charge))
|
||||
|
||||
m.AppendItem(self.addCharge(m, None))
|
||||
return m
|
||||
|
||||
def handleAmmoSwitch(self, event):
|
||||
charge = self.chargeIds.get(event.Id)
|
||||
if charge is None:
|
||||
charge = self.chargeIds.get(event.Id, False)
|
||||
if charge is False:
|
||||
event.Skip()
|
||||
return
|
||||
|
||||
sFit = service.Fit.getInstance()
|
||||
fitID = self.mainFrame.getActiveFit()
|
||||
modules = map(lambda mod: mod.position, self.mainFrame.getFittingView().getSelectedMods())
|
||||
sFit.setAmmo(fitID, charge.ID, modules)
|
||||
sFit.setAmmo(fitID, charge.ID if charge is not None else None, modules)
|
||||
wx.PostEvent(self.mainFrame, gui.fittingView.FitChanged(fitID=fitID))
|
||||
|
||||
ModuleAmmoPicker.register()
|
||||
|
||||
@@ -171,6 +171,7 @@ class FittingView(d.Display):
|
||||
self.PopupMenu(menu)
|
||||
|
||||
def click(self, event):
|
||||
event.Skip()
|
||||
row, _ = self.HitTest(event.Position)
|
||||
if row != -1:
|
||||
col = self.getColumn(event.Position)
|
||||
|
||||
@@ -314,10 +314,10 @@ class ItemParams (wx.Panel):
|
||||
return "%s (%d)" % (attribute.name.capitalize(), value)
|
||||
|
||||
trans = {"Inverse Absolute Percent": (lambda: (1-value)*100, unitName),
|
||||
"Absolute Percent": (lambda: (value * 100) , unitName),
|
||||
"Milliseconds": (lambda: value / 1000.0, unitName),
|
||||
"Volume": (lambda: value, u"m\u00B3"),
|
||||
"Sizeclass": (lambda: value, ""),
|
||||
"Absolute Percent": (lambda: (value * 100) , unitName),
|
||||
"Milliseconds": (lambda: value / 1000.0, unitName),
|
||||
"typeID": (itemIDCallback, ""),
|
||||
"groupID": (groupIDCallback,""),
|
||||
"attributeID": (attributeIDCallback, "")}
|
||||
|
||||
BIN
icons/em_small.png
Executable file
BIN
icons/em_small.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 775 B |
BIN
icons/explosive_small.png
Executable file
BIN
icons/explosive_small.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 814 B |
BIN
icons/kinetic_small.png
Executable file
BIN
icons/kinetic_small.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 593 B |
BIN
icons/thermal_small.png
Executable file
BIN
icons/thermal_small.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 766 B |
Reference in New Issue
Block a user