Skip to content

Commit

Permalink
Merge pull request #2624 from lunedis/feature/charges-for-fit
Browse files Browse the repository at this point in the history
Add "Charges For Active Fit" market tree shortcut
  • Loading branch information
DarkFenX authored Jul 9, 2024
2 parents d204e70 + ce9ce17 commit 451b5d4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
2 changes: 2 additions & 0 deletions gui/builtinMarketBrowser/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
ItemSelected, ITEM_SELECTED = wx.lib.newevent.NewEvent()

RECENTLY_USED_MODULES = -2

CHARGES_FOR_FIT = -3
58 changes: 51 additions & 7 deletions gui/builtinMarketBrowser/itemView.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
from logbook import Logger

import gui.builtinMarketBrowser.pfSearchBox as SBox
import gui.globalEvents as GE
from config import slotColourMap, slotColourMapDark
from eos.saveddata.module import Module
from gui.builtinMarketBrowser.events import ItemSelected, RECENTLY_USED_MODULES
from gui.builtinMarketBrowser.events import ItemSelected, RECENTLY_USED_MODULES, CHARGES_FOR_FIT
from gui.contextMenu import ContextMenu
from gui.display import Display
from gui.utils.staticHelpers import DragDropHelper
from gui.utils.dark import isDark
from service.fit import Fit
from service.market import Market
from service.ammo import Ammo


pyfalog = Logger(__name__)
Expand All @@ -32,6 +34,7 @@ def __init__(self, parent, marketBrowser):
self.filteredStore = set()
self.sMkt = marketBrowser.sMkt
self.sFit = Fit.getInstance()
self.sAmmo = Ammo.getInstance()

self.marketBrowser = marketBrowser
self.marketView = marketBrowser.marketView
Expand All @@ -51,6 +54,9 @@ def __init__(self, parent, marketBrowser):
self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.itemActivated)
self.Bind(wx.EVT_LIST_BEGIN_DRAG, self.startDrag)

# the "charges for active fitting" needs to listen to fitting changes
self.mainFrame.Bind(GE.FIT_CHANGED, self.fitChanged)

self.active = []

def delaySearch(self, evt):
Expand Down Expand Up @@ -91,7 +97,11 @@ def selectionMade(self, context):
if sel.IsOk():
# Get data field of the selected item (which is a marketGroup ID if anything was selected)
seldata = self.marketView.GetItemData(sel)
if seldata is not None and seldata != RECENTLY_USED_MODULES:
if seldata == RECENTLY_USED_MODULES:
items = self.sMkt.getRecentlyUsed()
elif seldata == CHARGES_FOR_FIT:
items = self.getChargesForActiveFit()
elif seldata is not None:
# If market group treeview item doesn't have children (other market groups or dummies),
# then it should have items in it and we want to request them
if self.marketView.ItemHasChildren(sel) is False:
Expand All @@ -103,18 +113,17 @@ def selectionMade(self, context):
else:
items = set()
else:
# If method was called but selection wasn't actually made or we have a hit on recently used modules
if seldata == RECENTLY_USED_MODULES:
items = self.sMkt.getRecentlyUsed()
else:
items = set()
items = set()

# Fill store
self.updateItemStore(items)

# Set toggle buttons / use search mode flag if recently used modules category is selected (in order to have all modules listed and not filtered)
if seldata == RECENTLY_USED_MODULES:
self.marketBrowser.mode = 'recent'

if seldata == CHARGES_FOR_FIT:
self.marketBrowser.mode = 'charges'

self.setToggles()
if context == 'tree' and self.marketBrowser.settings.get('marketMGMarketSelectMode') == 1:
Expand All @@ -123,6 +132,41 @@ def selectionMade(self, context):
btn.setUserSelection(True)
self.filterItemStore()

def getChargesForActiveFit(self):
fitId = self.mainFrame.getActiveFit()

# no active fit => no charges
if fitId is None:
return set()

fit = self.sFit.getFit(fitId)

# use a set so we only add one entry for each charge
items = set()
for mod in fit.modules:
charges = self.sAmmo.getModuleFlatAmmo(mod)
for charge in charges:
items.add(charge)
return items

def fitChanged(self, event):
# skip the event so the other handlers also get called
event.Skip()

if self.marketBrowser.mode != 'charges':
return

activeFitID = self.mainFrame.getActiveFit()
# if it was not the active fitting that was changed, do not do anything
if activeFitID is not None and activeFitID not in event.fitIDs:
return

items = self.getChargesForActiveFit()

# update the UI
self.updateItemStore(items)
self.filterItemStore()

def updateItemStore(self, items):
self.unfilteredStore = items

Expand Down
5 changes: 4 additions & 1 deletion gui/builtinMarketBrowser/marketTree.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import wx

from gui.cachingImageList import CachingImageList
from gui.builtinMarketBrowser.events import RECENTLY_USED_MODULES
from gui.builtinMarketBrowser.events import RECENTLY_USED_MODULES, CHARGES_FOR_FIT

from logbook import Logger

Expand Down Expand Up @@ -35,6 +35,9 @@ def __init__(self, parent, marketBrowser):
# Add recently used modules node
rumIconId = self.addImage("market_small", "gui")
self.AppendItem(self.root, _t("Recently Used Items"), rumIconId, data=RECENTLY_USED_MODULES)
# Add charges for active fitting node
cffIconId = self.addImage("damagePattern_small", "gui")
self.AppendItem(self.root, _t("Charges For Active Fit"), cffIconId, data=CHARGES_FOR_FIT)

# Bind our lookup method to when the tree gets expanded
self.Bind(wx.EVT_TREE_ITEM_EXPANDING, self.expandLookup)
Expand Down
2 changes: 1 addition & 1 deletion gui/marketBrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def mode(self, newMode):
setting = self.settings.get('marketMGSearchMode')
# We turn on all meta buttons for the duration of search/recents
if setting == 1:
if newMode in ('search', 'recent'):
if newMode in ('search', 'recent', 'charges'):
for btn in self.metaButtons:
btn.setUserSelection(True)
if newMode == 'normal':
Expand Down

0 comments on commit 451b5d4

Please sign in to comment.