diff --git a/application/src/engine.py b/application/src/engine.py index ffa697c..75e62dd 100644 --- a/application/src/engine.py +++ b/application/src/engine.py @@ -60,7 +60,7 @@ class GameStats(): self.last_fight['damage'] = damage_stats.DamageStats() elif stat_type == StatType.Overall: self.zone['damage'] = damage_stats.DamageStats() - self.last_fight['damage'] = [] + self.last_fight['damage'] = damage_stats.DamageStats() def damage_stats(self, stat_type): if stat_type == StatType.Zone: @@ -124,7 +124,8 @@ def get_stats(stat_type: StatType, with_damage: bool): time = game_stats.time_stats(stat_type)['seconds_in_game'] fame = FameStat(Number(fame['fame']), Number( fame['fame'] / time if time > 0.0 else 0.0)) - players = game_stats.damage_stats(stat_type) + players = list(filter(lambda p: p.value != + 0.0 if with_damage else True, game_stats.damage_stats(stat_type))) return players, fame, time diff --git a/application/src/gui/modules/main.py b/application/src/gui/modules/main.py index f23a277..1cb2fe7 100644 --- a/application/src/gui/modules/main.py +++ b/application/src/gui/modules/main.py @@ -1,82 +1,25 @@ import sys import functools -import datetime -from PySide2.QtCore import QTimer +from PySide2 import QtGui from PySide2.QtCore import Qt - +from PySide2.QtCore import QTimer +from PySide2.QtWidgets import QComboBox from PySide2.QtWidgets import QHBoxLayout from PySide2.QtWidgets import QPushButton from PySide2.QtWidgets import QVBoxLayout from PySide2.QtWidgets import QWidget -from PySide2.QtWidgets import QLabel -from PySide2.QtWidgets import QComboBox -from PySide2 import QtGui -from PySide2 import QtCore - -from .list_view import List -from . import about from ... import engine + from ...utils import assets from ...utils.config import config -from ...stats.list_item import PlayerListItem -class Mode: - DMG_CURRENT_ZONE = 'Stats (dmg): Current zone' - DMG_OVERALL = 'Stats (dmg): Overall' - DMG_LAST_FIGHT = 'Stats (dmg): Last fight' - CURRENT_ZONE = 'Stats (all): Current zone' - OVERALL = 'Stats (all): Overall' - LAST_FIGHT = 'Stats (all): Last fight' +from .view_type import ViewType +from .views import ModeBasedListView +from .views import StatsType - -class CopyButton(QPushButton): - def __init__(self, clipboard, players : PlayerListItem, mode, fame): - QPushButton.__init__(self) - self.clipboard = clipboard - self.players : PlayerListItem = players - self.mode = mode - self.fame = fame - - self.clicked.connect(self.copy) - self.setIcon(QtGui.QIcon(assets.path('copy.png'))) - self.setToolTip("Copy to clipboard") - - def copy(self): - clip = "{}, FPH: {}\nDMG: \n".format( - self.mode(), self.fame()) - for index, i in enumerate(self.players()[:3]): - clip += '{}. {}-{}/{}-{}%'.format(index+1, - i.name, i.value, i.value_per_second, i.percentage) - clip += "\n" - clip += "(AOStats https://git.io/JeBD1)" - - self.clipboard.clear(mode=self.clipboard.Clipboard) - self.clipboard.setText(clip, mode=self.clipboard.Clipboard) - - -class ResetButton(QPushButton): - def __init__(self, mode): - QPushButton.__init__(self) - - self.mode = mode - - self.setIcon(QtGui.QIcon(assets.path('reset.png'))) - self.setToolTip("Reset") - self.clicked.connect(self.reset) - - def reset(self): - reset = { - Mode.DMG_CURRENT_ZONE: engine.reset_zone_stats, - Mode.DMG_LAST_FIGHT: engine.reset_last_fight_stats, - Mode.DMG_OVERALL: engine.reset_stats, - Mode.CURRENT_ZONE: engine.reset_zone_stats, - Mode.LAST_FIGHT: engine.reset_last_fight_stats, - Mode.OVERALL: engine.reset_stats, - } - - reset[self.mode()]() +from . import about class AboutButton(QPushButton): @@ -103,70 +46,48 @@ class CloseButton(QPushButton): sys.exit(0) -class InteractiveBar(QWidget): - def __init__(self, table, clipboard): +class ViewTypeWidget(QComboBox): + def __init__(self): + QComboBox.__init__(self) + self.addItem(ViewType.DMG) + self.addItem(ViewType.DMG_ALL) + + def get_view_type(self): + return self.currentText() + + +class TopBar(QWidget): + def __init__(self): QWidget.__init__(self) - self.mode = ModeWidget() - self.table = table + self.view_type = ViewTypeWidget() self.layout = QHBoxLayout() - self.fame_per_hour = 0.0 - - self.layout.addWidget(self.mode) - - self.copy_button = CopyButton( - clipboard, self.table.get_player_list_items, self.mode.get_mode, self.get_fame_per_hour) - self.layout.addWidget(self.copy_button) - - self.reset_button = ResetButton(self.mode.get_mode) - self.layout.addWidget(self.reset_button) + self.layout.setSpacing(0) + self.layout.setMargin(0) + self.layout.addWidget(self.view_type) self.about_button = AboutButton() self.layout.addWidget(self.about_button) self.close_button = CloseButton(config()['window']['frameless']) self.layout.addWidget(self.close_button) - + self.setLayout(self.layout) - def get_fame_per_hour(self): - return self.fame_per_hour - - def set_fame_per_hour(self, fpm): - self.fame_per_hour = fpm - - def close(self): - sys.exit(0) - - -class ModeWidget(QComboBox): - def __init__(self): - QComboBox.__init__(self) - self.addItem(Mode.DMG_CURRENT_ZONE) - self.addItem(Mode.DMG_OVERALL) - self.addItem(Mode.DMG_LAST_FIGHT) - self.addItem(Mode.CURRENT_ZONE) - self.addItem(Mode.OVERALL) - self.addItem(Mode.LAST_FIGHT) - - def get_mode(self): - return self.currentText() class MainWidget(QWidget): def __init__(self, clipboard): QWidget.__init__(self) self.mouse_pos = None - self.table = List() - self.fame_label = QLabel() - self.fame_label.setAlignment(QtCore.Qt.AlignmentFlag.AlignHCenter) - self.bar = InteractiveBar(self.table, clipboard) self.layout = QVBoxLayout() - self.layout.addWidget(self.bar) - self.layout.addWidget(self.fame_label) - self.layout.addWidget(self.table) - self.setLayout(self.layout) + self.top_bar = TopBar() + self.layout.addWidget(self.top_bar) + self.view = ModeBasedListView(clipboard) + self.layout.addWidget(self.view) + + self.setLayout(self.layout) self.refresh() timer = QTimer(self) @@ -174,20 +95,31 @@ class MainWidget(QWidget): timer.start(500) def refresh(self): - player_list_items, fame_stat, elapsed = self.session() - self.table.update(player_list_items) - self.bar.set_fame_per_hour(fame_stat.fame_per_hour) - self.fame_label.setText("{} | Fame {} | FPH {}".format( - datetime.timedelta(seconds=elapsed), fame_stat.fame, fame_stat.fame_per_hour)) + player_list_items, fame_stat, elapsed = self.damage_stats() + self.view.update( + self.top_bar.view_type.get_view_type(), + elapsed, + fame_stat.fame, + fame_stat.fame_per_hour, + player_list_items + ) def mousePressEvent(self, event): self.mouse_pos = event.pos() def mouseMoveEvent(self, event): - if self.bar.geometry().contains(event.pos()): + invalid_regions = ( + self.top_bar.geometry(), + self.view.geometry(), + ) + + if any(region.contains(event.pos()) for region in invalid_regions): return if not self.mouse_pos: return + if any(region.contains(self.mouse_pos) for region in invalid_regions): + return + if event.buttons() & Qt.LeftButton: diff = event.pos() - self.mouse_pos @@ -195,14 +127,18 @@ class MainWidget(QWidget): self.move(newpos) - def session(self): - sessions = { - Mode.DMG_CURRENT_ZONE: functools.partial(engine.zone_stats, with_damage=True), - Mode.DMG_LAST_FIGHT: functools.partial(engine.last_fight_stats, with_damage=True), - Mode.DMG_OVERALL: functools.partial(engine.overall_stats, with_damage=True), - Mode.CURRENT_ZONE: engine.zone_stats, - Mode.LAST_FIGHT: engine.last_fight_stats, - Mode.OVERALL: engine.overall_stats + def damage_stats(self): + stats = { + ViewType.DMG: { + StatsType.ZONE: functools.partial(engine.zone_stats, with_damage=True), + StatsType.LAST_FIGHT: functools.partial(engine.last_fight_stats, with_damage=True), + StatsType.OVERALL: functools.partial(engine.overall_stats, with_damage=True), + }, + ViewType.DMG_ALL: { + StatsType.ZONE: functools.partial(engine.zone_stats, with_damage=False), + StatsType.LAST_FIGHT: functools.partial(engine.last_fight_stats, with_damage=False), + StatsType.OVERALL: functools.partial(engine.overall_stats, with_damage=False), + } } - return sessions[self.bar.mode.currentText()]() + return stats[self.top_bar.view_type.get_view_type()][self.view.get_mode()]() diff --git a/application/src/gui/modules/view_type.py b/application/src/gui/modules/view_type.py new file mode 100644 index 0000000..dbc6ff6 --- /dev/null +++ b/application/src/gui/modules/view_type.py @@ -0,0 +1,3 @@ +class ViewType: + DMG = 'Stats (damage)' + DMG_ALL = 'Stats (damage all)' \ No newline at end of file diff --git a/application/src/gui/modules/views/__init__.py b/application/src/gui/modules/views/__init__.py new file mode 100644 index 0000000..9990877 --- /dev/null +++ b/application/src/gui/modules/views/__init__.py @@ -0,0 +1,2 @@ +from .mode_based_list_view import ModeBasedListView +from .stats_type import StatsType diff --git a/application/src/gui/modules/views/copy_button.py b/application/src/gui/modules/views/copy_button.py new file mode 100644 index 0000000..047d6a1 --- /dev/null +++ b/application/src/gui/modules/views/copy_button.py @@ -0,0 +1,40 @@ + +from PySide2.QtWidgets import QPushButton +from PySide2 import QtGui + +from ....utils import assets +from ....stats.list_item import PlayerListItem + +from .stats_type import StatsType + + +class CopyButton(QPushButton): + def __init__(self, clipboard): + QPushButton.__init__(self) + self.clipboard = clipboard + self.prefix = '<< INITIAL PREFIX >>' + self.players: PlayerListItem = [] + self.mode = StatsType.ZONE + self.fame = 0.0 + + self.clicked.connect(self.copy) + self.setIcon(QtGui.QIcon(assets.path('copy.png'))) + self.setToolTip("Copy to clipboard") + + def copy(self): + clip = "{}: {}, FPH: {}\n".format( + self.prefix, self.mode, self.fame) + for index, i in enumerate(self.players[:3]): + clip += '{}. {}-{}/{}-{}%'.format(index+1, + i.name, i.value, i.value_per_second, i.percentage) + clip += "\n" + clip += "(AOStats https://git.io/JeBD1)" + + self.clipboard.clear(mode=self.clipboard.Clipboard) + self.clipboard.setText(clip, mode=self.clipboard.Clipboard) + + def update(self, prefix: str, players: PlayerListItem, mode: str, fame: float): + self.prefix = prefix + self.players = players + self.mode = mode + self.fame = fame diff --git a/application/src/gui/modules/list_view/__init__.py b/application/src/gui/modules/views/list_view/__init__.py similarity index 100% rename from application/src/gui/modules/list_view/__init__.py rename to application/src/gui/modules/views/list_view/__init__.py diff --git a/application/src/gui/modules/list_view/list.py b/application/src/gui/modules/views/list_view/list.py similarity index 97% rename from application/src/gui/modules/list_view/list.py rename to application/src/gui/modules/views/list_view/list.py index c6806ef..97dbaa0 100644 --- a/application/src/gui/modules/list_view/list.py +++ b/application/src/gui/modules/views/list_view/list.py @@ -1,9 +1,10 @@ -from ....utils import assets -from ....utils import names -from ....utils import async_request -from ....utils import weapon - +from io import BytesIO +import collections +import functools +import re +from typing import List from PIL import Image, ImageQt + from PySide2 import QtCore from PySide2 import QtGui from PySide2.QtCore import Qt @@ -19,13 +20,11 @@ from PySide2.QtWidgets import QProgressBar from PySide2.QtWidgets import QPushButton from PySide2.QtWidgets import QVBoxLayout -from io import BytesIO -import collections -import functools -import re -from typing import List - -from ....stats.list_item import PlayerListItem +from .....stats.list_item import PlayerListItem +from .....utils import assets +from .....utils import async_request +from .....utils import names +from .....utils import weapon Style = collections.namedtuple('Style', 'bg') diff --git a/application/src/gui/modules/views/mode_based_list_view.py b/application/src/gui/modules/views/mode_based_list_view.py new file mode 100644 index 0000000..bd5b2c8 --- /dev/null +++ b/application/src/gui/modules/views/mode_based_list_view.py @@ -0,0 +1,83 @@ +# from PySide2.QtCore import QTimer +# from PySide2.QtCore import Qt + +from typing import Callable + +from PySide2.QtWidgets import QHBoxLayout +# from PySide2.QtWidgets import QPushButton +from PySide2.QtWidgets import QVBoxLayout + +# from PySide2.QtWidgets import QLabel + + +# from PySide2 import QtGui +# from PySide2 import QtCore + +from PySide2.QtWidgets import QComboBox +from PySide2.QtWidgets import QWidget + +from ....stats.list_item import PlayerListItem + +from .list_view import List +from .stats_type import StatsType +from .player_stats import PlayerStats +from .copy_button import CopyButton +from .reset_button import ResetButton + + +class ModeWidget(QComboBox): + def __init__(self): + QComboBox.__init__(self) + self.addItem(StatsType.OVERALL) + self.addItem(StatsType.ZONE) + self.addItem(StatsType.LAST_FIGHT) + + def get_mode(self): + return self.currentText() + + +class SessionBar(QWidget): + def __init__(self, clipboard): + QWidget.__init__(self) + self.layout = QHBoxLayout() + + self.reset_button = ResetButton() + self.layout.addWidget(self.reset_button) + + self.copy_button = CopyButton(clipboard) + self.layout.addWidget(self.copy_button) + + self.mode = ModeWidget() + self.layout.addWidget(self.mode) + + self.player_stats = PlayerStats() + self.layout.addWidget(self.player_stats) + + self.setLayout(self.layout) + + def update(self): + self.reset_button.update(self.mode.get_mode()) + + +class ModeBasedListView(QWidget): + def __init__(self, clipboard): + QWidget.__init__(self) + self.layout = QVBoxLayout() + self.layout.setSpacing(0) + self.layout.setMargin(0) + self.session_bar = SessionBar(clipboard) + self.layout.addWidget(self.session_bar) + + self.list_view = List() + self.layout.addWidget(self.list_view) + + self.setLayout(self.layout) + + def update(self, prefix, elapsed, fame, fame_per_hour, players: PlayerListItem): + self.session_bar.player_stats.update(elapsed, fame, fame_per_hour) + self.session_bar.copy_button.update(prefix, self.list_view.get_player_list_items(), self.session_bar.mode.get_mode(), fame) + self.list_view.update(players) + self.session_bar.update() + + def get_mode(self) -> str: + return self.session_bar.mode.get_mode() \ No newline at end of file diff --git a/application/src/gui/modules/views/player_stats.py b/application/src/gui/modules/views/player_stats.py new file mode 100644 index 0000000..443090a --- /dev/null +++ b/application/src/gui/modules/views/player_stats.py @@ -0,0 +1,20 @@ +import datetime + +from PySide2.QtWidgets import QLabel +from PySide2 import QtGui +from PySide2 import QtCore + +from ....utils import assets +from ....stats.list_item import PlayerListItem +from .... import engine + + +class PlayerStats(QLabel): + def __init__(self): + QLabel.__init__(self) + + self.update(0, 0.0, 0.0) + + def update(self, elapsed, fame, fame_per_hour): + self.setText("{} | Fame {} | FPH {}".format( + datetime.timedelta(seconds=elapsed), fame, fame_per_hour)) \ No newline at end of file diff --git a/application/src/gui/modules/views/reset_button.py b/application/src/gui/modules/views/reset_button.py new file mode 100644 index 0000000..86942ca --- /dev/null +++ b/application/src/gui/modules/views/reset_button.py @@ -0,0 +1,33 @@ + +from typing import Callable + +from PySide2.QtWidgets import QPushButton +from PySide2 import QtGui + +from ....utils import assets +from ....stats.list_item import PlayerListItem +from .... import engine + +from .stats_type import StatsType + +class ResetButton(QPushButton): + def __init__(self): + QPushButton.__init__(self) + + self.stat_type: str = StatsType.ZONE + + self.setIcon(QtGui.QIcon(assets.path('reset.png'))) + self.setToolTip("Reset") + self.clicked.connect(self.reset) + + def reset(self): + reset = { + StatsType.ZONE: engine.reset_zone_stats, + StatsType.LAST_FIGHT: engine.reset_last_fight_stats, + StatsType.OVERALL: engine.reset_stats, + } + + reset[self.stat_type]() + + def update(self, stat_type: str): + self.stat_type = stat_type diff --git a/application/src/gui/modules/views/stats_type.py b/application/src/gui/modules/views/stats_type.py new file mode 100644 index 0000000..96acaa7 --- /dev/null +++ b/application/src/gui/modules/views/stats_type.py @@ -0,0 +1,4 @@ +class StatsType: + ZONE = 'Zone' + OVERALL = 'Overall' + LAST_FIGHT = 'Fight'