Skip to content

Commit

Permalink
Clean unified look for all trackers
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Oct 10, 2023
1 parent 0c97b97 commit 75294ad
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 58 deletions.
Binary file added src/modlunky2/static/images/pacifist.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/modlunky2/static/images/timer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions src/modlunky2/ui/trackers/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class CategoryButtons(ttk.Frame):
def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.modlunky_config = modlunky_config
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
self.columnconfigure(0, weight=1, minsize=200)
self.columnconfigure(1, weight=10000)
self.rowconfigure(0, minsize=60)
self.window = None

Expand All @@ -116,6 +116,7 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
text="Category",
compound="left",
command=self.launch,
width=1,
)
self.category_button.grid(row=0, column=0, pady=5, padx=5, sticky="nswe")

Expand Down
68 changes: 50 additions & 18 deletions src/modlunky2/ui/trackers/pacifist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import tkinter as tk
from tkinter import ttk

from PIL import Image, ImageTk

from modlunky2.config import Config, PacifistTrackerConfig
from modlunky2.constants import BASE_DIR
from modlunky2.mem import Spel2Process
from modlunky2.mem.state import RunRecapFlags

Expand All @@ -15,23 +18,20 @@
logger = logging.getLogger(__name__)


class PacifistButtons(ttk.Frame):
def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
ICON_PATH = BASE_DIR / "static/images"


class PacifistModifiers(ttk.LabelFrame):
def __init__(
self, parent, pacifist_tracker_config: PacifistTrackerConfig, *args, **kwargs
):
super().__init__(parent, *args, **kwargs)
self.modlunky_config = modlunky_config
self.columnconfigure(0, weight=1)
self.rowconfigure(0, minsize=60)
self.window = None
self.parent = parent

self.pacifist_button = ttk.Button(
self,
text="Pacifist",
command=self.launch,
)
self.pacifist_button.grid(row=0, column=0, pady=5, padx=5, sticky="nswe")
self.pacifist_tracker_config = pacifist_tracker_config

self.show_kill_count = tk.BooleanVar()
self.show_kill_count.set(self.modlunky_config.trackers.pacifist.show_kill_count)
self.show_kill_count.set(self.pacifist_tracker_config.show_kill_count)
self.show_kill_count_checkbox = ttk.Checkbutton(
self,
text="Show Kill Count",
Expand All @@ -43,12 +43,39 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
self.show_kill_count_checkbox.grid(row=0, column=1, pady=5, padx=5, sticky="w")

def toggle_show_kill_count(self):
self.modlunky_config.trackers.pacifist.show_kill_count = (
self.show_kill_count.get()
self.pacifist_tracker_config.show_kill_count = self.show_kill_count.get()
self.parent.config_update_callback()


class PacifistButtons(ttk.Frame):
def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.modlunky_config = modlunky_config
self.columnconfigure(0, weight=1, minsize=200)
self.columnconfigure(1, weight=10000)
self.rowconfigure(0, minsize=60)
self.window = None

self.pacifist_icon = ImageTk.PhotoImage(
Image.open(ICON_PATH / "pacifist.png").resize(
(24, 24), Image.Resampling.LANCZOS
)
)
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.pacifist)

self.pacifist_button = ttk.Button(
self,
text="Pacifist",
image=self.pacifist_icon,
compound="left",
command=self.launch,
width=1,
)
self.pacifist_button.grid(row=0, column=0, pady=5, padx=5, sticky="nswe")

self.modifiers = PacifistModifiers(
self, self.modlunky_config.trackers.pacifist, text="Modifiers"
)
self.modifiers.grid(row=0, column=1, pady=5, padx=5, sticky="nswe")

def launch(self):
color_key = self.modlunky_config.tracker_color_key
Expand All @@ -62,6 +89,11 @@ def launch(self):
config=self.modlunky_config.trackers.pacifist,
)

def config_update_callback(self):
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.pacifist)

def window_closed(self):
self.window = None
# If we're in the midst of destroy() the button might not exist
Expand Down
100 changes: 62 additions & 38 deletions src/modlunky2/ui/trackers/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from tkinter import ttk
import datetime

from PIL import Image, ImageTk

from modlunky2.config import Config, TimerTrackerConfig
from modlunky2.constants import BASE_DIR
from modlunky2.mem import Spel2Process

from modlunky2.ui.trackers.common import (
Expand All @@ -14,25 +17,20 @@

logger = logging.getLogger(__name__)

ICON_PATH = BASE_DIR / "static/images"

class TimerButtons(ttk.Frame):
def __init__(self, parent, modlunky_config: Config, *args, **kwargs):

class TimerModifiers(ttk.LabelFrame):
def __init__(
self, parent, timer_tracker_config: TimerTrackerConfig, *args, **kwargs
):
super().__init__(parent, *args, **kwargs)
self.modlunky_config = modlunky_config
self.columnconfigure(0, weight=1)
self.rowconfigure(0, minsize=60)
self.window = None
self.modlunky_config.trackers.timer.anchor = "w"
self.parent = parent

self.timer_button = ttk.Button(
self,
text="Timer",
command=self.launch,
)
self.timer_button.grid(row=0, column=0, pady=5, padx=5, sticky="nswe")
self.timer_tracker_config = timer_tracker_config

self.show_total = tk.BooleanVar()
self.show_total.set(self.modlunky_config.trackers.timer.show_total)
self.show_total.set(self.timer_tracker_config.show_total)
self.show_total_checkbox = ttk.Checkbutton(
self,
text="Total",
Expand All @@ -44,7 +42,7 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
self.show_total_checkbox.grid(row=0, column=1, pady=5, padx=5, sticky="w")

self.show_level = tk.BooleanVar()
self.show_level.set(self.modlunky_config.trackers.timer.show_level)
self.show_level.set(self.timer_tracker_config.show_level)
self.show_level_checkbox = ttk.Checkbutton(
self,
text="Level",
Expand All @@ -56,7 +54,7 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
self.show_level_checkbox.grid(row=0, column=2, pady=5, padx=5, sticky="w")

self.show_last_level = tk.BooleanVar()
self.show_last_level.set(self.modlunky_config.trackers.timer.show_last_level)
self.show_last_level.set(self.timer_tracker_config.show_last_level)
self.show_last_level_checkbox = ttk.Checkbutton(
self,
text="Last Level",
Expand All @@ -68,7 +66,7 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
self.show_last_level_checkbox.grid(row=0, column=3, pady=5, padx=5, sticky="w")

self.show_tutorial = tk.BooleanVar()
self.show_tutorial.set(self.modlunky_config.trackers.timer.show_tutorial)
self.show_tutorial.set(self.timer_tracker_config.show_tutorial)
self.show_tutorial_checkbox = ttk.Checkbutton(
self,
text="Tutorial",
Expand All @@ -80,7 +78,7 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
self.show_tutorial_checkbox.grid(row=0, column=4, pady=5, padx=5, sticky="w")

self.show_startup = tk.BooleanVar()
self.show_startup.set(self.modlunky_config.trackers.timer.show_startup)
self.show_startup.set(self.timer_tracker_config.show_startup)
self.show_startup_checkbox = ttk.Checkbutton(
self,
text="Session",
Expand All @@ -92,34 +90,55 @@ def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
self.show_startup_checkbox.grid(row=0, column=5, pady=5, padx=5, sticky="w")

def toggle_show_total(self):
self.modlunky_config.trackers.timer.show_total = self.show_total.get()
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.timer)
self.timer_tracker_config.show_total = self.show_total.get()
self.parent.config_update_callback()

def toggle_show_level(self):
self.modlunky_config.trackers.timer.show_level = self.show_level.get()
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.timer)
self.timer_tracker_config.show_level = self.show_level.get()
self.parent.config_update_callback()

def toggle_show_last_level(self):
self.modlunky_config.trackers.timer.show_last_level = self.show_last_level.get()
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.timer)
self.timer_tracker_config.show_last_level = self.show_last_level.get()
self.parent.config_update_callback()

def toggle_show_tutorial(self):
self.modlunky_config.trackers.timer.show_tutorial = self.show_tutorial.get()
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.timer)
self.timer_tracker_config.show_tutorial = self.show_tutorial.get()
self.parent.config_update_callback()

def toggle_show_startup(self):
self.modlunky_config.trackers.timer.show_startup = self.show_startup.get()
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.timer)
self.timer_tracker_config.show_startup = self.show_startup.get()
self.parent.config_update_callback()


class TimerButtons(ttk.Frame):
def __init__(self, parent, modlunky_config: Config, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.modlunky_config = modlunky_config
self.columnconfigure(0, weight=1, minsize=200)
self.columnconfigure(1, weight=10000)
self.rowconfigure(0, minsize=60)
self.window = None

self.timer_icon = ImageTk.PhotoImage(
Image.open(ICON_PATH / "timer.png").resize(
(24, 24), Image.Resampling.LANCZOS
)
)

self.timer_button = ttk.Button(
self,
image=self.timer_icon,
text="Timer",
compound="left",
command=self.launch,
width=1,
)
self.timer_button.grid(row=0, column=0, pady=5, padx=5, sticky="nswe")

self.modifiers = TimerModifiers(
self, self.modlunky_config.trackers.timer, text="Modifiers"
)
self.modifiers.grid(row=0, column=1, pady=5, padx=5, sticky="nswe")

def launch(self):
color_key = self.modlunky_config.tracker_color_key
Expand All @@ -133,6 +152,11 @@ def launch(self):
config=self.modlunky_config.trackers.timer,
)

def config_update_callback(self):
self.modlunky_config.save()
if self.window:
self.window.update_config(self.modlunky_config.trackers.timer)

def window_closed(self):
self.window = None
# If we're in the midst of destroy() the button might not exist
Expand Down

0 comments on commit 75294ad

Please sign in to comment.