diff --git a/src/gui/app.py b/src/gui/app.py index d08dadb..1220bba 100644 --- a/src/gui/app.py +++ b/src/gui/app.py @@ -72,13 +72,10 @@ def run(): app.setStyleSheet(style) - geometry = app.screens()[0].size() clipboard = app.clipboard() widget = MainWidget(clipboard) widget.setWindowOpacity(window_config['opacity']) - widget.resize(WIDTH, HEIGHT) - widget.move(0, geometry.height() - HEIGHT - 280) widget.setWindowTitle('Albion Online Stats') widget.setWindowIcon(QtGui.QIcon(path('albion-stats-icon.png'))) @@ -88,7 +85,11 @@ def run(): if window_config['frameless']: widget.setWindowFlag(Qt.FramelessWindowHint) - widget.show() + if window_config.get('fullscreen', True): + widget.showFullScreen() + else: + widget.resize(WIDTH, HEIGHT) + widget.show() current_version, latest_version = ( get_current_version(), get_latest_version()) diff --git a/src/gui/modules/main.py b/src/gui/modules/main.py index 756db95..3cf4f47 100644 --- a/src/gui/modules/main.py +++ b/src/gui/modules/main.py @@ -1,153 +1,413 @@ -import sys import functools +import sys from PySide6 import QtGui # type: ignore from PySide6.QtCore import Qt # type: ignore from PySide6.QtCore import QTimer # type: ignore -from PySide6.QtWidgets import QComboBox # type: ignore +from PySide6.QtWidgets import QButtonGroup # type: ignore +from PySide6.QtWidgets import QFrame # type: ignore +from PySide6.QtWidgets import QGridLayout # type: ignore from PySide6.QtWidgets import QHBoxLayout # type: ignore +from PySide6.QtWidgets import QLabel # type: ignore from PySide6.QtWidgets import QPushButton # type: ignore +from PySide6.QtWidgets import QScrollArea # type: ignore from PySide6.QtWidgets import QVBoxLayout # type: ignore from PySide6.QtWidgets import QWidget # type: ignore from ... import engine - from ...utils import assets from ...utils.config import config - -from .view_type import ViewType -from .views import ModeBasedListView -from .views import StatsType - +from ...utils.number import Number from . import about +from .view_type import ViewType +from .views import StatsType +from .views.list_view import ListItemView -class AboutButton(QPushButton): - def __init__(self): - QPushButton.__init__(self) - - self.about = about.About() - self.setIcon(QtGui.QIcon(assets.path('about.png'))) - self.setToolTip("About") - self.clicked.connect(self.about.show) +class Page: + Overview = 'overview' + Damage = 'damage' + Healing = 'healing' + Economy = 'economy' + Items = 'items' + Settings = 'settings' -class CloseButton(QPushButton): - def __init__(self, is_visible): - QPushButton.__init__(self) - - self.setIcon(QtGui.QIcon(assets.path('close.png'))) - self.setToolTip("Close") - self.clicked.connect(self.close) - if not is_visible: - self.hide() - - def close(self): - sys.exit(0) +PAGE_LABELS = { + Page.Overview: ('O', 'Overview'), + Page.Damage: ('D', 'Damage Done'), + Page.Healing: ('H', 'Healing Done'), + Page.Economy: ('$', 'Economy'), + Page.Items: ('I', 'Items Collected'), + Page.Settings: ('S', 'Settings'), +} -class ViewTypeWidget(QComboBox): - def __init__(self): - QComboBox.__init__(self) - self.addItem(ViewType.DMG) - self.addItem(ViewType.HEALING_DONE) - - def get_view_type(self): - return self.currentText() +SCOPE_LABELS = { + StatsType.ZONE: 'Current Zone', + StatsType.LAST_FIGHT: 'Last Fight', + StatsType.OVERALL: 'Overall Session', +} -class TopBar(QWidget): +class Sidebar(QWidget): + def __init__(self, on_page_changed, on_scope_changed): + QWidget.__init__(self) + self.setObjectName('Sidebar') + self.expanded = True + self.on_page_changed = on_page_changed + self.on_scope_changed = on_scope_changed + self.page_buttons = {} + self.scope_buttons = {} + + self.layout = QVBoxLayout() + self.layout.setContentsMargins(14, 14, 14, 14) + self.layout.setSpacing(8) + + self.toggle_button = QPushButton('Collapse') + self.toggle_button.setObjectName('SidebarToggle') + self.toggle_button.clicked.connect(self.toggle) + self.layout.addWidget(self.toggle_button) + + self.title = QLabel('AO Stats') + self.title.setObjectName('SidebarTitle') + self.layout.addWidget(self.title) + + self.page_group = QButtonGroup(self) + self.page_group.setExclusive(True) + for page, (_short, label) in PAGE_LABELS.items(): + button = QPushButton(label) + button.setCheckable(True) + button.clicked.connect(functools.partial(self._select_page, page)) + self.page_group.addButton(button) + self.page_buttons[page] = button + self.layout.addWidget(button) + + self.scope_label = QLabel('Scope') + self.scope_label.setObjectName('SidebarSection') + self.layout.addWidget(self.scope_label) + + self.scope_group = QButtonGroup(self) + self.scope_group.setExclusive(True) + for scope, label in SCOPE_LABELS.items(): + button = QPushButton(label) + button.setCheckable(True) + button.clicked.connect(functools.partial(self._select_scope, scope)) + self.scope_group.addButton(button) + self.scope_buttons[scope] = button + self.layout.addWidget(button) + + self.layout.addStretch(1) + self.setLayout(self.layout) + + def set_initial(self, page, scope): + self.page_buttons[page].setChecked(True) + self.scope_buttons[scope].setChecked(True) + + def _select_page(self, page): + self.on_page_changed(page) + + def _select_scope(self, scope): + self.on_scope_changed(scope) + + def toggle(self): + self.expanded = not self.expanded + self.setFixedWidth(220 if self.expanded else 72) + self.toggle_button.setText('Collapse' if self.expanded else '>>') + self.title.setVisible(self.expanded) + self.scope_label.setVisible(self.expanded) + for page, button in self.page_buttons.items(): + short, label = PAGE_LABELS[page] + button.setText(label if self.expanded else short) + for scope, button in self.scope_buttons.items(): + button.setText(SCOPE_LABELS[scope] if self.expanded else scope[:1]) + + +class StatCard(QFrame): + def __init__(self, title): + QFrame.__init__(self) + self.setObjectName('StatCard') + self.layout = QVBoxLayout() + self.layout.setContentsMargins(16, 12, 16, 12) + self.title = QLabel(title) + self.title.setObjectName('CardTitle') + self.value = QLabel('0') + self.value.setObjectName('CardValue') + self.layout.addWidget(self.title) + self.layout.addWidget(self.value) + self.setLayout(self.layout) + + def update_value(self, value): + self.value.setText(str(value)) + + +class HeaderBar(QWidget): def __init__(self): QWidget.__init__(self) - self.view_type = ViewTypeWidget() self.layout = QHBoxLayout() - self.layout.setSpacing(0) self.layout.setContentsMargins(0, 0, 0, 0) - self.layout.addWidget(self.view_type) + self.title = QLabel('Albion Online Stats') + self.title.setObjectName('HeaderTitle') + self.status = QLabel('Waiting for zone change') + self.status.setObjectName('HeaderStatus') + self.layout.addWidget(self.title) + self.layout.addStretch(1) + self.layout.addWidget(self.status) + self.setLayout(self.layout) - self.about_button = AboutButton() - self.layout.addWidget(self.about_button) + def update_status(self): + if engine.is_ready(): + self.status.setText('Tracking live Albion Online traffic') + else: + self.status.setText('Waiting for zone change to identify your character') - self.close_button = CloseButton(config()['window']['frameless']) - self.layout.addWidget(self.close_button) +class ItemsPanel(QFrame): + def __init__(self): + QFrame.__init__(self) + self.setObjectName('ItemsPanel') + self.layout = QVBoxLayout() + self.layout.setContentsMargins(16, 16, 16, 16) + title = QLabel('Items Collected') + title.setObjectName('PanelTitle') + body = QLabel( + 'Looted item tracking will appear here once item pickup packets are mapped.\n\n' + 'This panel stays visible while you review damage, healing, and economy stats.') + body.setObjectName('MutedText') + body.setWordWrap(True) + self.layout.addWidget(title) + self.layout.addWidget(body) + self.layout.addStretch(1) + self.setLayout(self.layout) + + +class SettingsPanel(QWidget): + def __init__(self, clipboard): + QWidget.__init__(self) + self.clipboard = clipboard + self.about = about.About() + self.layout = QVBoxLayout() + self.layout.setSpacing(12) + + description = QLabel( + 'Use this page for session actions. Fullscreen dashboard mode is the default; ' + 'set window.fullscreen = false in the config file to use a normal window.') + description.setWordWrap(True) + description.setObjectName('PageDescription') + self.layout.addWidget(description) + + reset_zone = QPushButton('Reset Current Zone') + reset_zone.clicked.connect(engine.reset_zone_stats) + self.layout.addWidget(reset_zone) + + reset_fight = QPushButton('Reset Last Fight') + reset_fight.clicked.connect(engine.reset_last_fight_stats) + self.layout.addWidget(reset_fight) + + reset_all = QPushButton('Reset Overall Session') + reset_all.clicked.connect(engine.reset_stats) + self.layout.addWidget(reset_all) + + about_button = QPushButton('About Albion Online Stats') + about_button.clicked.connect(self.about.show) + self.layout.addWidget(about_button) + + if not config()['window']['fullscreen']: + close_button = QPushButton('Close') + close_button.setIcon(QtGui.QIcon(assets.path('close.png'))) + close_button.clicked.connect(lambda: sys.exit(0)) + self.layout.addWidget(close_button) + + self.layout.addStretch(1) self.setLayout(self.layout) class MainWidget(QWidget): def __init__(self, clipboard): QWidget.__init__(self) + self.clipboard = clipboard + self.current_page = Page.Overview + self.current_scope = StatsType.ZONE - self.mouse_pos = None + self.root_layout = QHBoxLayout() + self.root_layout.setContentsMargins(0, 0, 0, 0) + self.root_layout.setSpacing(0) - self.layout = QVBoxLayout() - self.top_bar = TopBar() - self.layout.addWidget(self.top_bar) + self.sidebar = Sidebar(self.set_page, self.set_scope) + self.sidebar.set_initial(self.current_page, self.current_scope) + self.root_layout.addWidget(self.sidebar) - self.view = ModeBasedListView(clipboard) - self.layout.addWidget(self.view) + self.main_area = QWidget() + self.main_layout = QVBoxLayout() + self.main_layout.setContentsMargins(22, 18, 22, 18) + self.main_layout.setSpacing(14) + self.main_area.setLayout(self.main_layout) + + self.header = HeaderBar() + self.main_layout.addWidget(self.header) + + self.cards_layout = QGridLayout() + self.cards_layout.setSpacing(12) + self.elapsed_card = StatCard('Time in selected scope') + self.fame_card = StatCard('Fame gained') + self.fph_card = StatCard('Fame per hour') + self.ready_card = StatCard('Tracking status') + self.cards_layout.addWidget(self.elapsed_card, 0, 0) + self.cards_layout.addWidget(self.fame_card, 0, 1) + self.cards_layout.addWidget(self.fph_card, 0, 2) + self.cards_layout.addWidget(self.ready_card, 0, 3) + self.main_layout.addLayout(self.cards_layout) + + self.page_title = QLabel('Overview') + self.page_title.setObjectName('PageTitle') + self.page_description = QLabel('') + self.page_description.setObjectName('PageDescription') + self.page_description.setWordWrap(True) + self.main_layout.addWidget(self.page_title) + self.main_layout.addWidget(self.page_description) + + self.primary_label = QLabel('') + self.primary_label.setObjectName('PanelTitle') + self.main_layout.addWidget(self.primary_label) + + self.primary_list = ListItemView() + self.main_layout.addWidget(self.primary_list, 1) + + self.total_healing_label = QLabel('Total Healing') + self.total_healing_label.setObjectName('PanelTitle') + self.total_healing_list = ListItemView() + self.main_layout.addWidget(self.total_healing_label) + self.main_layout.addWidget(self.total_healing_list, 1) + + self.placeholder = QLabel('') + self.placeholder.setObjectName('MutedText') + self.placeholder.setWordWrap(True) + self.main_layout.addWidget(self.placeholder, 1) + + self.settings_panel = SettingsPanel(clipboard) + self.main_layout.addWidget(self.settings_panel, 1) + + self.root_layout.addWidget(self.main_area, 1) + self.root_layout.addWidget(ItemsPanel()) + self.setLayout(self.root_layout) - self.setLayout(self.layout) self.refresh() - timer = QTimer(self) timer.timeout.connect(self.refresh) timer.start(500) + def set_page(self, page): + self.current_page = page + self.refresh() + + def set_scope(self, scope): + self.current_scope = scope + self.refresh() + def refresh(self): - 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, - self.total_healing_stats() - ) + players, fame_stat, elapsed = self.primary_stats() + total_healing = self.total_healing_stats() - def mousePressEvent(self, event): - self.mouse_pos = event.pos() + self.header.update_status() + self.elapsed_card.update_value(self._format_time(elapsed)) + self.fame_card.update_value(fame_stat.fame) + self.fph_card.update_value(fame_stat.fame_per_hour) + self.ready_card.update_value('Ready' if engine.is_ready() else 'Not ready') - def mouseMoveEvent(self, event): - invalid_regions = ( - self.top_bar.geometry(), - self.view.geometry(), - ) + self._set_page_copy(players, total_healing) - 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 - newpos = self.pos() + diff - - self.move(newpos) - - def damage_stats(self): - stats = { - ViewType.DMG: { - StatsType.ZONE: functools.partial(engine.zone_stats, engine.CombatStatType.Damage), - StatsType.LAST_FIGHT: functools.partial(engine.last_fight_stats, engine.CombatStatType.Damage), - StatsType.OVERALL: functools.partial(engine.overall_stats, engine.CombatStatType.Damage), - }, - ViewType.HEALING_DONE: { - StatsType.ZONE: functools.partial(engine.zone_stats, engine.CombatStatType.Healing), - StatsType.LAST_FIGHT: functools.partial(engine.last_fight_stats, engine.CombatStatType.Healing), - StatsType.OVERALL: functools.partial(engine.overall_stats, engine.CombatStatType.Healing), - } + def primary_stats(self): + stat_kind = { + Page.Overview: engine.CombatStatType.Damage, + Page.Damage: engine.CombatStatType.Damage, + Page.Healing: engine.CombatStatType.Healing, + Page.Economy: engine.CombatStatType.Damage, + Page.Items: engine.CombatStatType.Damage, + Page.Settings: engine.CombatStatType.Damage, + }[self.current_page] + getters = { + StatsType.ZONE: functools.partial(engine.zone_stats, stat_kind), + StatsType.LAST_FIGHT: functools.partial(engine.last_fight_stats, stat_kind), + StatsType.OVERALL: functools.partial(engine.overall_stats, stat_kind), } - - return stats[self.top_bar.view_type.get_view_type()][self.view.get_mode()]() + return getters[self.current_scope]() def total_healing_stats(self): - stats = { + getters = { StatsType.ZONE: engine.zone_total_healing_stats, StatsType.LAST_FIGHT: engine.last_fight_total_healing_stats, StatsType.OVERALL: engine.overall_total_healing_stats, } + return getters[self.current_scope]() - return stats[self.view.get_mode()]() + def _set_page_copy(self, players, total_healing): + self.primary_list.hide() + self.primary_label.hide() + self.total_healing_label.hide() + self.total_healing_list.hide() + self.placeholder.hide() + self.settings_panel.hide() + + if self.current_page == Page.Overview: + self.page_title.setText('Overview') + self.page_description.setText( + 'A quick session summary for the selected scope. Use the left menu to inspect damage, healing, economy, and loot in more detail.') + self.primary_label.setText('Top Damage Dealers') + self.primary_label.show() + self.primary_list.show() + self.primary_list.update(players) + return + + if self.current_page == Page.Damage: + self.page_title.setText('Damage Done') + self.page_description.setText( + 'Damage attributed to each visible tracked player during the selected scope. DPS is based on combat time.') + self.primary_label.setText('Damage by Player') + self.primary_label.show() + self.primary_list.show() + self.primary_list.update(players) + return + + if self.current_page == Page.Healing: + self.page_title.setText('Healing Done') + self.page_description.setText( + 'Combat healing counts healing during fights. Total healing includes self-healing and post-fight recovery.') + self.primary_label.setText('Combat Healing') + self.primary_label.show() + self.primary_list.show() + self.primary_list.update(players) + self.total_healing_label.show() + self.total_healing_list.show() + self.total_healing_list.update(total_healing) + return + + if self.current_page == Page.Economy: + self.page_title.setText('Economy') + self.page_description.setText( + 'Fame is tracked now. Looted silver and other silver categories will appear here after their packet fields are mapped.') + self.placeholder.setText( + 'Silver tracking is not active yet. Planned categories: Looted Silver, Looted Silver per Hour, Other Silver, and Other Silver per Hour.') + self.placeholder.show() + return + + if self.current_page == Page.Items: + self.page_title.setText('Items Collected') + self.page_description.setText( + 'Collected item quantities will be shown here after item pickup packets are mapped. The right panel remains visible on every page.') + self.placeholder.setText( + 'No item pickup data is available yet. Once enabled, this page will show item name, quantity, and session scope totals.') + self.placeholder.show() + return + + self.page_title.setText('Settings') + self.page_description.setText('Reset scopes, view app information, and configure dashboard behavior.') + self.settings_panel.show() + + def _format_time(self, seconds): + seconds = int(seconds or 0) + hours = seconds // 3600 + minutes = (seconds % 3600) // 60 + remainder = seconds % 60 + if hours: + return f'{hours}h {minutes}m {remainder}s' + return f'{minutes}m {remainder}s' diff --git a/src/gui/styling.py b/src/gui/styling.py index e4567b0..a74c988 100644 --- a/src/gui/styling.py +++ b/src/gui/styling.py @@ -6,31 +6,128 @@ font_size = cfg['window']['font-size'] style = """ QWidget { font-size: %s; - background-color: black; - color: white; + background-color: #0f172a; + color: #e5edf8; } - #Motd, #Motd > * { - background-color: none; - color: none; - font-size: auto; + QPushButton { + background-color: #182235; + border: 1px solid #2a3a54; + border-radius: 8px; + padding: 10px 12px; + text-align: left; + color: #e5edf8; } - QListView { - min-height: 100px; + QPushButton:hover { + background-color: #24324a; } - QListView::item:selected:active { - background-color: black; - } - - QListView::item:selected { - background-color: black; + QPushButton:checked { + background-color: #f5b942; + border-color: #f5b942; + color: #111827; + font-weight: 700; } + #Sidebar { + background-color: #111827; + border-right: 1px solid #263449; + min-width: 220px; + max-width: 220px; + } + + #SidebarToggle { + text-align: center; + } + + #SidebarTitle { + color: #f5b942; + font-size: 22px; + font-weight: 800; + padding: 10px 4px 16px 4px; + } + + #SidebarSection { + color: #93a4bd; + font-weight: 700; + padding: 18px 4px 4px 4px; + text-transform: uppercase; + } + + #HeaderTitle { + font-size: 28px; + font-weight: 800; + color: #ffffff; + } + + #HeaderStatus { + color: #9fb0c8; + font-weight: 600; + } + + #StatCard, #ItemsPanel { + background-color: #182235; + border: 1px solid #293951; + border-radius: 14px; + } + + #ItemsPanel { + min-width: 300px; + max-width: 360px; + } + + #CardTitle { + color: #9fb0c8; + font-size: 13px; + font-weight: 700; + text-transform: uppercase; + } + + #CardValue { + color: #ffffff; + font-size: 24px; + font-weight: 800; + } + + #PageTitle { + font-size: 24px; + font-weight: 800; + color: #ffffff; + padding-top: 8px; + } + + #PageDescription, #MutedText { + color: #a9b7ca; + line-height: 1.35; + } + + #PanelTitle { + color: #f5b942; + font-size: 18px; + font-weight: 800; + padding-top: 8px; + } + + QListView { + background-color: #121c2e; + border: 1px solid #293951; + border-radius: 12px; + padding: 8px; + min-height: 160px; + } + + QListView::item { + min-height: 36px; + border-radius: 6px; + margin: 3px; + padding: 4px; + } + + QListView::item:selected:active, + QListView::item:selected, QListView::item:selected:!active { - background-color: black; - color: white; + background-color: #24324a; + color: #ffffff; } - """ % (font_size) diff --git a/src/utils/config.py b/src/utils/config.py index b99a10e..16fc15f 100644 --- a/src/utils/config.py +++ b/src/utils/config.py @@ -4,13 +4,14 @@ import toml from . import platform_utils -CFG_VERSION = '0.7' +CFG_VERSION = '0.8' default = """ [window] -width = 300 -height = 220 -font-size = '10px' +width = 1280 +height = 720 +font-size = '14px' +fullscreen = true # Note: do not change! # options bellow are here only for testing purposes diff --git a/tests/test_config.py b/tests/test_config.py index 1ad0a71..19de0f5 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -51,6 +51,8 @@ def test_config_creates_missing_directory(monkeypatch, tmp_path): cfg = config.config() assert os.path.isfile(expected) - assert cfg['window']['width'] == 300 + assert cfg['window']['width'] == 1280 + assert cfg['window']['height'] == 720 + assert cfg['window']['fullscreen'] is True config._config = None