Skip to content

Commit 0cea470

Browse files
InfernioSharlikran
authored andcommitted
WIP: Show ESP/M and ESL counts in the bottom right corner
Only on games with ESL support, obviously. Had to expand the bottom right part of the status bar for ESL games to do this, and took that opportunity to factor out some common code in the BashStatusBar methods. As the TODO mentions, I'm not really happy with this. It feels like we should already be storing this information somewhere instead of having to compute it on the fly. I've probably just overlooked the spot where it's stored though. Improve performance of ESP/M & ESL counter Use a reduce with lambda instead of iterating over the entire list. Should be much faster, since we didn't need the full lists to begin with.
1 parent d047be5 commit 0cea470

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

Mopy/bash/basher/__init__.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,8 +1760,17 @@ def __init__(self,parent):
17601760
super(ModPanel, self).__init__(parent)
17611761
BashFrame.modList = self.uiList
17621762

1763-
def _sbCount(self): return _(u'Mods:') + u' %d/%d' % (
1764-
len(load_order.cached_active_tuple()), len(bosh.modInfos))
1763+
def _sbCount(self):
1764+
all_mods = load_order.cached_active_tuple()
1765+
total_str = _(u'Mods:') + u' %u/%u' % (len(all_mods),
1766+
len(bosh.modInfos))
1767+
if not bush.game.has_esl:
1768+
return total_str
1769+
else:
1770+
regular_mods_count = reduce(lambda accum, mod_path: accum + 1 if
1771+
not bosh.modInfos[mod_path].is_esl() else accum, all_mods, 0)
1772+
return total_str + _(u' (ESP/M: %u, ESL: %u)') % (
1773+
regular_mods_count, len(all_mods) - regular_mods_count)
17651774

17661775
def ClosePanel(self, destroy=False):
17671776
load_order.persist_orders()
@@ -3581,11 +3590,7 @@ def UpdateIconSizes(self):
35813590
# Update settings
35823591
if orderChanged: settings.setChanged('bash.statusbar.order')
35833592
if hideChanged: settings.setChanged('bash.statusbar.hide')
3584-
# Refresh
3585-
self.SetStatusWidths([self.iconsSize * len(self.buttons), -1, 130])
3586-
self.SetSize((-1, self.iconsSize))
3587-
self.GetParent().SendSizeEvent()
3588-
self.OnSize()
3593+
self._do_refresh(refresh_icon_size=True)
35893594

35903595
def HideButton(self,button):
35913596
if button in self.buttons:
@@ -3596,11 +3601,7 @@ def HideButton(self,button):
35963601
self.buttons.remove(button)
35973602
settings['bash.statusbar.hide'].add(link.uid)
35983603
settings.setChanged('bash.statusbar.hide')
3599-
# Refresh
3600-
self.SetStatusWidths(
3601-
[self.iconsSize * len(self.buttons), -1, 130])
3602-
self.GetParent().SendSizeEvent()
3603-
self.OnSize()
3604+
self._do_refresh()
36043605

36053606
def UnhideButton(self,link):
36063607
uid = link.uid
@@ -3625,10 +3626,7 @@ def UnhideButton(self,link):
36253626
insertBefore = i
36263627
break
36273628
self.buttons.insert(insertBefore,button)
3628-
# Refresh
3629-
self.SetStatusWidths([self.iconsSize * len(self.buttons), -1, 130])
3630-
self.GetParent().SendSizeEvent()
3631-
self.OnSize()
3629+
self._do_refresh()
36323630

36333631
def GetLink(self,uid=None,index=None,button=None):
36343632
"""Get the Link object with a specific uid,
@@ -3645,6 +3643,17 @@ def GetLink(self,uid=None,index=None,button=None):
36453643
return link
36463644
return None
36473645

3646+
def _do_refresh(self, refresh_icon_size=False):
3647+
"""Updates status widths and the icon sizes, if refresh_icon_size is
3648+
True. Also propagates resizing events.
3649+
3650+
:param refresh_icon_size: Whether or not to update icon sizes too."""
3651+
txt_len = 280 if bush.game.has_esl else 130
3652+
self.SetStatusWidths([self.iconsSize * len(self.buttons), -1, txt_len])
3653+
if refresh_icon_size: self.SetSize((-1, self.iconsSize))
3654+
self.GetParent().SendSizeEvent()
3655+
self.OnSize()
3656+
36483657
#------------------------------------------------------------------------------
36493658
class BashFrame(BaltFrame):
36503659
"""Main application frame."""

0 commit comments

Comments
 (0)