Skip to content

Commit

Permalink
Add more Overlunky launch options
Browse files Browse the repository at this point in the history
  • Loading branch information
Dregu committed Dec 11, 2022
1 parent c8a8a2a commit a776244
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/modlunky2/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class Config:
)
playlunky_version: Optional[str] = field(default=None, skip_if_default=True)
playlunky_console: bool = field(default=False, skip_if_default=True)
playlunky_overlunky: bool = field(default=False, skip_if_default=True)
playlunky_shortcut: bool = field(default=False, skip_if_default=True)
geometry: str = field(default=f"{MIN_WIDTH}x{MIN_HEIGHT}", skip_if_default=True)
spelunky_fyi_root: str = field(
Expand Down
70 changes: 61 additions & 9 deletions src/modlunky2/ui/overlunky.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import zipfile
from io import BytesIO
from tkinter import ttk

from functools import partial
import webbrowser
import requests

from modlunky2.config import Config
Expand Down Expand Up @@ -45,14 +46,16 @@ def download_overlunky_release(call, install_dir, launch):


class DownloadFrame(ttk.Frame):
def __init__(self, parent, modlunky_config: Config, task_manager):
def __init__(self, parent, modlunky_config: Config, task_manager, tab):
super().__init__(parent)

self.parent = parent
self.modlunky_config = modlunky_config
self.task_manager = task_manager
self.columnconfigure(0, weight=1)
self.rowconfigure(0, minsize=60)
self.rowconfigure(1, minsize=60)
self.rowconfigure(2, minsize=60)

self.task_manager.register_task(
"overlunky:start_download",
Expand All @@ -69,8 +72,22 @@ def __init__(self, parent, modlunky_config: Config, task_manager):
"overlunky:download_failed", self.on_download_failed
)

self.button = ttk.Button(self, text="Download Latest", command=self.download)
self.button.grid(row=0, column=0, sticky="nswe")
self.button = ttk.Button(
self,
text="Download latest WHIP build and script bundle",
command=self.download,
)
self.button.grid(row=0, column=0, pady=5, padx=5, sticky="nswe")

self.button_update = ttk.Button(
self,
text="Reconfigure automatic updates",
command=partial(tab.launch, ["--update"]),
)
self.button_update.grid(row=1, column=0, pady=5, padx=5, sticky="nswe")

self.button_guide = ttk.Button(self, text="Documentation", command=tab.guide)
self.button_guide.grid(row=2, column=0, pady=5, padx=5, sticky="nswe")

def download(self, launch=False):
self.button["state"] = tk.DISABLED
Expand All @@ -97,12 +114,19 @@ def on_download_finished(self, launch=False):
self.button["state"] = tk.NORMAL


def launch_overlunky(_call, exe_path, command_prefix: Optional[List[str]]):
def launch_overlunky(
_call,
exe_path,
command_prefix: Optional[List[str]],
command_args: Optional[List[str]],
):
logger.info("Executing Overlunky Launcher with %s", exe_path)
working_dir = exe_path.parent
cmd = [f"{exe_path}"]
if command_prefix:
cmd = command_prefix + cmd
if command_args:
cmd = cmd + command_args
proc = subprocess.Popen(
cmd, cwd=working_dir, creationflags=subprocess.CREATE_NEW_CONSOLE
)
Expand Down Expand Up @@ -134,17 +158,41 @@ def __init__(self, tab_control, modlunky_config, task_manager, *args, **kwargs):
self.overlunky_frame.rowconfigure(0, weight=0)
self.overlunky_frame.rowconfigure(1, weight=1)
self.overlunky_frame.rowconfigure(2, minsize=60)
self.overlunky_frame.rowconfigure(3, minsize=60)
self.overlunky_frame.rowconfigure(4, minsize=60)
self.overlunky_frame.columnconfigure(0, weight=1)

self.download_frame = DownloadFrame(
self.overlunky_frame, self.modlunky_config, self.task_manager
self.overlunky_frame, self.modlunky_config, self.task_manager, self
)
self.download_frame.grid(row=1, column=0, pady=5, padx=5, sticky="nswe")

self.button_launch = ttk.Button(
self.overlunky_frame, text="Launch!", command=self.launch
self.overlunky_frame,
text="Inject to running game process",
command=partial(
self.launch,
["--console"],
),
)
self.button_launch.grid(row=2, column=0, pady=5, padx=5, sticky="nswe")
self.button_launch.grid(row=3, column=0, pady=5, padx=5, sticky="nswe")

self.button_launch_game = ttk.Button(
self.overlunky_frame,
text="Launch vanilla game with Overlunky",
command=partial(
self.launch,
["--console", "--launch_game", self.modlunky_config.install_dir],
),
)
self.button_launch_game.grid(row=4, column=0, pady=5, padx=5, sticky="nswe")

ttk.Label(
self.overlunky_frame,
text="To use Overlunky with Playlunky/mods, use 'Inject' or enable 'Load Overlunky' option in the Playlunky tab.",
font="sans 9 bold",
).grid(row=5, column=0, padx=5, pady=5, sticky="s")

self.on_load()

def enable_button(self):
Expand All @@ -171,7 +219,7 @@ def should_install(self):

return answer

def launch(self):
def launch(self, args=None):
exe_path = self.modlunky_config.install_dir / OVERLUNKY_EXE

self.disable_button()
Expand All @@ -189,8 +237,12 @@ def launch(self):
"overlunky:launch_overlunky",
exe_path=exe_path,
command_prefix=self.modlunky_config.command_prefix,
command_args=args,
)

def overlunky_closed(self):
self.enable_button()
self.on_load()

def guide(self):
webbrowser.open_new_tab("https://github.com/spelunky-fyi/overlunky#readme")
18 changes: 18 additions & 0 deletions src/modlunky2/ui/play/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def __init__(self, parent, play_tab, modlunky_config: Config):
command=self.handle_console_checkbutton,
)

self.enable_overlunky_var = tk.BooleanVar()
self.enable_overlunky_var.set(self.modlunky_config.playlunky_overlunky)
self.enable_overlunky_checkbox = ttk.Checkbutton(
self,
text="Load Overlunky",
variable=self.enable_overlunky_var,
compound="left",
command=self.handle_overlunky_checkbutton,
)

self.desktop_shortcut_var = tk.BooleanVar()
self.desktop_shortcut_var.set(self.modlunky_config.playlunky_shortcut)
self.desktop_shortcut_checkbox = ttk.Checkbutton(
Expand Down Expand Up @@ -102,6 +112,10 @@ def __init__(self, parent, play_tab, modlunky_config: Config):
row=row_num, column=0, padx=3, sticky="w"
)
row_num += 1
self.enable_overlunky_checkbox.grid(
row=row_num, column=0, padx=3, sticky="w"
)
row_num += 1

@staticmethod
def format_text(text):
Expand All @@ -111,6 +125,10 @@ def handle_console_checkbutton(self):
self.modlunky_config.playlunky_console = self.enable_console_var.get()
self.modlunky_config.save()

def handle_overlunky_checkbutton(self):
self.modlunky_config.playlunky_overlunky = self.enable_overlunky_var.get()
self.modlunky_config.save()

@property
def shortcut_path(self):
return Path(winshell.desktop(), "Playlunky.lnk")
Expand Down
11 changes: 10 additions & 1 deletion src/modlunky2/ui/play/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@


def launch_playlunky(
_call, install_dir, exe_path, use_console, command_prefix: Optional[List[str]]
_call,
install_dir,
exe_path,
use_console,
use_overlunky,
command_prefix: Optional[List[str]],
):
logger.info(
"Executing Playlunky Launcher with %s", exe_path.relative_to(PLAYLUNKY_DATA_DIR)
Expand All @@ -42,6 +47,9 @@ def launch_playlunky(
if use_console:
cmd.append("--console")

if use_overlunky:
cmd.append("--overlunky")

proc = subprocess.Popen(cmd, cwd=working_dir)
proc.communicate()

Expand Down Expand Up @@ -327,6 +335,7 @@ def play(self):
install_dir=self.modlunky_config.install_dir,
exe_path=exe_path,
use_console=self.modlunky_config.playlunky_console,
use_overlunky=self.modlunky_config.playlunky_overlunky,
command_prefix=self.modlunky_config.command_prefix,
)

Expand Down

0 comments on commit a776244

Please sign in to comment.