Implement multi-level selection menu for mining crystals

This commit is contained in:
DarkPhoenix
2021-11-27 00:05:18 +03:00
parent 48818c9709
commit 9d8e338136
2 changed files with 83 additions and 3 deletions

View File

@@ -1,5 +1,6 @@
# noinspection PyPackageRequirements
from collections import OrderedDict
# noinspection PyPackageRequirements
import wx
import gui.fitCommands as cmd
@@ -25,8 +26,20 @@ class ChangeModuleAmmo(ContextMenuCombined):
'thermal': _t('Thermal'),
'explosive': _t('Explosive'),
'kinetic': _t('Kinetic'),
'mixed': _t('Mixed')
}
'mixed': _t('Mixed')}
self.oreChargeCatTrans = OrderedDict([
('a1', _t('Asteroid Common')),
('a2', _t('Asteroid Uncommon')),
('a3', _t('Asteroid Rare')),
('a4', _t('Asteroid Premium')),
('a5', _t('Asteroid Abyssal')),
('a6', _t('Asteroid Mercoxit')),
('r4', _t('Moon Ubiquitous')),
('r8', _t('Moon Common')),
('r16', _t('Moon Uncommon')),
('r32', _t('Moon Rare')),
('r64', _t('Moon Exceptional')),
('misc', _t('Misc'))])
def display(self, callingWindow, srcContext, mainItem, selection):
if srcContext not in ('fittingModule', 'projectedModule'):
@@ -115,6 +128,24 @@ class ChangeModuleAmmo(ContextMenuCombined):
self._addSeparator(subMenu, _t('More Damage'))
for menuItem in menuItems:
menu.Append(menuItem)
elif modType == 'miner':
menuItems = []
for catHandle, catLabel in self.oreChargeCatTrans.items():
charges = chargeDict.get(catHandle)
if not charges:
continue
if len(charges) == 1:
menuItems.append(self._addCharge(rootMenu if msw else menu, charges[0]))
else:
menuItem = wx.MenuItem(menu, wx.ID_ANY, catLabel)
menuItems.append(menuItem)
subMenu = wx.Menu()
subMenu.Bind(wx.EVT_MENU, self.handleAmmoSwitch)
menuItem.SetSubMenu(subMenu)
for charge in charges:
subMenu.Append(self._addCharge(rootMenu if msw else subMenu, charge))
for menuItem in menuItems:
menu.Append(menuItem)
elif modType == 'general':
for charge in chargeDict['general']:
menu.Append(self._addCharge(rootMenu if msw else menu, charge))

View File

@@ -21,12 +21,17 @@
import math
from collections import OrderedDict
import wx
from eos.const import FittingHardpoint
from eos.saveddata.module import Module
from eos.utils.stats import DmgTypes
from service.market import Market
_t = wx.GetTranslation
class Ammo:
instance = None
@@ -142,6 +147,50 @@ class Ammo:
all[prevType] = sub
return 'ddMissile', all
elif mod.item.group.name == 'Frequency Mining Laser':
def crystalSorter(charge):
if charge.name.endswith(' II'):
techLvl = 2
elif charge.name.endswith(' I'):
techLvl = 1
else:
techLvl = 0
if ' A ' in charge.name:
type_ = 'A'
elif ' B ' in charge.name:
type_ = 'B'
elif ' C ' in charge.name:
type_ = 'C'
else:
type_ = '0'
return type_, techLvl, charge.name
typeMap = {
253: 'a1',
254: 'a2',
255: 'a3',
256: 'a4',
257: 'a5',
258: 'a6',
259: 'r4',
260: 'r8',
261: 'r16',
262: 'r32',
263: 'r64'}
prelim = {}
for charge in chargesFlat:
oreTypeList = charge.getAttribute('specialisationAsteroidTypeList')
category = typeMap.get(oreTypeList, _t('Misc'))
prelim.setdefault(category, set()).add(charge)
final = OrderedDict()
for category, charges in prelim.items():
final[category] = sorted(charges, key=crystalSorter)
return 'miner', final
else:
def nameSorter(charge):