Implement basic ammo switching context menu. (still needs much
polishing)
This commit is contained in:
2
eos
2
eos
Submodule eos updated: 7c9a59ca2a...04fd4f2d85
@@ -1 +1 @@
|
|||||||
__all__ = ["itemStats", "damagePattern"]
|
__all__ = ["itemStats", "damagePattern", "moduleAmmoPicker"]
|
||||||
|
|||||||
63
gui/builtinContextMenus/moduleAmmoPicker.py
Executable file
63
gui/builtinContextMenus/moduleAmmoPicker.py
Executable file
@@ -0,0 +1,63 @@
|
|||||||
|
from gui.contextMenu import ContextMenu
|
||||||
|
import gui.mainFrame
|
||||||
|
import service
|
||||||
|
import gui.fittingView
|
||||||
|
import wx
|
||||||
|
from gui import bitmapLoader
|
||||||
|
|
||||||
|
class ModuleAmmoPicker(ContextMenu):
|
||||||
|
def __init__(self):
|
||||||
|
self.mainFrame = gui.mainFrame.MainFrame.getInstance()
|
||||||
|
|
||||||
|
def display(self, context, selection):
|
||||||
|
if self.mainFrame.getActiveFit() is None or context != "module":
|
||||||
|
return False
|
||||||
|
|
||||||
|
modules = self.mainFrame.getFittingView().getSelectedMods()
|
||||||
|
validCharges = None
|
||||||
|
for mod in modules:
|
||||||
|
currCharges = mod.getValidCharges()
|
||||||
|
if validCharges is not None and validCharges != currCharges:
|
||||||
|
return False
|
||||||
|
|
||||||
|
validCharges = currCharges
|
||||||
|
|
||||||
|
self.charges = validCharges
|
||||||
|
return True
|
||||||
|
|
||||||
|
def getText(self, context, selection):
|
||||||
|
return "Ammo"
|
||||||
|
|
||||||
|
def activate(self, context, selection, i):
|
||||||
|
pass
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
return m
|
||||||
|
|
||||||
|
def handleAmmoSwitch(self, event):
|
||||||
|
charge = self.chargeIds.get(event.Id)
|
||||||
|
if charge is None:
|
||||||
|
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)
|
||||||
|
wx.PostEvent(self.mainFrame, gui.fittingView.FitChanged(fitID=fitID))
|
||||||
|
|
||||||
|
ModuleAmmoPicker.register()
|
||||||
@@ -49,6 +49,10 @@ class ContextMenu(object):
|
|||||||
item = wx.MenuItem(menu, id, text)
|
item = wx.MenuItem(menu, id, text)
|
||||||
menu.info[id] = (m, context, it)
|
menu.info[id] = (m, context, it)
|
||||||
|
|
||||||
|
sub = m.getSubMenu(context, selection, menu, it)
|
||||||
|
if sub is not None:
|
||||||
|
item.SetSubMenu(sub)
|
||||||
|
|
||||||
if bitmap is not None:
|
if bitmap is not None:
|
||||||
if multiple:
|
if multiple:
|
||||||
bp = bitmap[it]
|
bp = bitmap[it]
|
||||||
@@ -77,12 +81,17 @@ class ContextMenu(object):
|
|||||||
selection = (selection,)
|
selection = (selection,)
|
||||||
|
|
||||||
m.activate(context, selection, i)
|
m.activate(context, selection, i)
|
||||||
|
else:
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
def display(self, context, selection):
|
def display(self, context, selection):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def activate(self, context, selection, i):
|
def activate(self, context, selection, i):
|
||||||
raise NotImplementedError()
|
return None
|
||||||
|
|
||||||
|
def getSubMenu(self, context, selection, menu, i):
|
||||||
|
return None
|
||||||
|
|
||||||
def getText(self, context, selection):
|
def getText(self, context, selection):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
@@ -90,4 +99,5 @@ class ContextMenu(object):
|
|||||||
def getBitmap(self, context, selection):
|
def getBitmap(self, context, selection):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
from gui.builtinContextMenus import *
|
from gui.builtinContextMenus import *
|
||||||
|
|||||||
@@ -141,9 +141,12 @@ class Display(wx.ListCtrl):
|
|||||||
|
|
||||||
for i, col in enumerate(self.activeColumns):
|
for i, col in enumerate(self.activeColumns):
|
||||||
if not col.resized:
|
if not col.resized:
|
||||||
|
self.SetColumnWidth(i, wx.LIST_AUTOSIZE_USEHEADER)
|
||||||
|
headerWidth = self.GetColumnWidth(i)
|
||||||
self.SetColumnWidth(i, col.size)
|
self.SetColumnWidth(i, col.size)
|
||||||
if self.GetColumnWidth(i) < 40 and col.size == wx.LIST_AUTOSIZE:
|
baseWidth = self.GetColumnWidth(i)
|
||||||
self.SetColumnWidth(i, 40)
|
if baseWidth < headerWidth:
|
||||||
|
self.SetColumnWidth(i, headerWidth)
|
||||||
|
|
||||||
for sel in selection:
|
for sel in selection:
|
||||||
self.Select(sel)
|
self.Select(sel)
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ class FittingView(d.Display):
|
|||||||
|
|
||||||
self.Bind(wx.EVT_KEY_UP, self.kbEvent)
|
self.Bind(wx.EVT_KEY_UP, self.kbEvent)
|
||||||
|
|
||||||
|
def getSelectedMods(self):
|
||||||
|
sel = []
|
||||||
|
row = self.GetFirstSelected()
|
||||||
|
while row != -1:
|
||||||
|
sel.append(self.mods[self.GetItemData(row)])
|
||||||
|
row = self.GetNextSelected(row)
|
||||||
|
|
||||||
|
return sel
|
||||||
|
|
||||||
def kbEvent(self,event):
|
def kbEvent(self,event):
|
||||||
keycode = event.GetKeyCode()
|
keycode = event.GetKeyCode()
|
||||||
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
|
if keycode == wx.WXK_DELETE or keycode == wx.WXK_NUMPAD_DELETE:
|
||||||
|
|||||||
@@ -107,6 +107,10 @@ class MainFrame(wx.Frame):
|
|||||||
view = self.fitMultiSwitch.GetPage(sel).view
|
view = self.fitMultiSwitch.GetPage(sel).view
|
||||||
return view.activeFitID
|
return view.activeFitID
|
||||||
|
|
||||||
|
def getFittingView(self):
|
||||||
|
sel = self.fitMultiSwitch.GetSelection()
|
||||||
|
return self.fitMultiSwitch.GetPage(sel).view
|
||||||
|
|
||||||
def mouseHit(self, event):
|
def mouseHit(self, event):
|
||||||
tab, _ = self.notebookBrowsers.HitTest(event.Position)
|
tab, _ = self.notebookBrowsers.HitTest(event.Position)
|
||||||
if tab != -1:
|
if tab != -1:
|
||||||
|
|||||||
Reference in New Issue
Block a user