Skip to content

Commit

Permalink
Major rework of Help system as mostly popups; support <a> links
Browse files Browse the repository at this point in the history
  • Loading branch information
emersonrp committed May 27, 2024
1 parent 30296cb commit 9c4998b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
8 changes: 8 additions & 0 deletions Help/ControllerModifiers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head><title>Controller Modifiers</title></head>
<body>
<p>Extra controller modifiers were added in Homecoming Issue 27, Page 1. They can be used to make extra "chord"-style binds using a controller. The details of this scheme are too complicated to summarize here. Please check the <a href="https://wiki.homecomingservers.com/wiki/Issue_27_Page_1#Enhanced_Gamepad_Support">Patch Notes</a> for details.</p>

<p>Note that BindControl does <b>NOT</b> set up these modifiers for you. This configuration is intended to match whatever configuration you have manually added to the game with the <code>/controller_modifiers</code> and <code>/extra_modifiers</code> commands.</p>
</body>
</html>
76 changes: 63 additions & 13 deletions Help/__init__.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,94 @@
import sys
import os
from typing import Dict
import webbrowser
import wx
import wx.html
from Icon import GetIcon

class HelpWindow(wx.MiniFrame):
def __init__(self, parent, filename):
wx.MiniFrame.__init__(self, parent, size = (800, 600),
style = wx.CAPTION|wx.CLOSE_BOX|wx.STAY_ON_TOP|wx.RESIZE_BORDER)
class HelpHTMLWindow(wx.html.HtmlWindow):
def __init__(self, parent, filename, size = (800, 600)):
wx.html.HtmlWindow.__init__(self, parent, size = size)

self.manualsizer = wx.BoxSizer(wx.VERTICAL)
self.manualpane = wx.html.HtmlWindow(self, size = (800, 600))
self.manualpane.SetRelatedFrame(self, '%s')
self.manualsizer.Add(self.manualpane, 1, wx.EXPAND)
self.SetSizer(self.manualsizer)
base_path = getattr(sys, '_MEIPASS', '')
if base_path:
base_path = base_path + "/Help/"
else:
base_path = os.path.dirname(os.path.abspath(__file__))
self.manualpane.LoadFile(f"{base_path}/{filename}")
self.LoadFile(f"{base_path}/{filename}")

self.Bind(wx.html.EVT_HTML_LINK_CLICKED, self.HandleLinkClicked)

def HandleLinkClicked(self, evt):
linkinfo = evt.GetLinkInfo()
page = linkinfo.GetHref()
webbrowser.open(page)


class HelpWindow(wx.MiniFrame):
def __init__(self, parent, filename):
wx.MiniFrame.__init__(self, parent, title = filename, size = (800, 600),
style = wx.TINY_CAPTION|wx.DEFAULT_FRAME_STYLE)

manualhtml = HelpHTMLWindow(self, filename)

self.manualsizer = wx.BoxSizer(wx.VERTICAL)

self.manualsizer.Add(manualhtml, 1, wx.EXPAND)
self.SetSizer(self.manualsizer)

self.Layout()

HelpWindows[filename] = self

class HelpButton(wx.BitmapButton):
class HelpPopup(wx.PopupTransientWindow):
def __init__(self, parent, filename):
wx.PopupTransientWindow.__init__(self, parent)

self.panel = wx.Panel(self)
self.panel.SetBackgroundColour([127,127,127])
manualhtml = HelpHTMLWindow(self.panel, filename, size = (600, 300))

manualsizer = wx.BoxSizer(wx.VERTICAL)
manualsizer.Add(manualhtml, 1, wx.EXPAND|wx.ALL, 3)

self.panel.SetSizer(manualsizer)
manualsizer.Fit(self.panel)
manualsizer.Fit(self)
self.Layout()

HelpPopups[filename] = self

class HelpButton(wx.BitmapButton):
def __init__(self, parent, filename, type = "popup"):
wx.BitmapButton.__init__(self, parent, -1, GetIcon('Help'))
self.Filename = filename
self.WinType = type

self.Bind(wx.EVT_BUTTON, self.GetHelpHandler())

def GetHelpHandler(self):
def OnClick(_): ShowHelpWindow(self.Parent, self.Filename)
if self.WinType == "popup":
def OnClick(event): ShowHelpPopup(self, self.Filename, event)
else:
def OnClick(event): ShowHelpWindow(self, self.Filename, event)
return OnClick


HelpWindows: Dict[str, HelpWindow] = {}
def ShowHelpWindow(parent, filename):
def ShowHelpWindow(parent, filename, _ = None):
if not HelpWindows.get(filename, None):
HelpWindows[filename] = HelpWindow(parent, filename)
HelpWindows[filename].Show()

HelpPopups: Dict[str, HelpPopup] = {}
def ShowHelpPopup(self, filename, event):
if not HelpPopups.get(filename, None):
HelpPopups[filename] = HelpPopup(self, filename)

btn = event.GetEventObject()
pos = btn.ClientToScreen( (0,0) )
sz = btn.GetSize()
HelpPopups[filename].Position(pos, (0, sz[1]))
HelpPopups[filename].Popup()

4 changes: 3 additions & 1 deletion UI/PrefsDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import wx
import wx.lib.stattext as ST
import UI
from Help import HelpButton
from UI.KeySelectDialog import bcKeyButton
from bcController import bcController

Expand Down Expand Up @@ -104,7 +105,8 @@ def __init__(self, parent):
if controller.GetNumberJoysticks() > 0:
controllerName.SetLabel(controller.GetProductName())
controllerSizer.Add( controllerName, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 6)
controllerSizer.Add( wx.StaticText(controllerPanel, label = ''))
controllerhelpbutton = HelpButton(controllerPanel, 'ControllerModifiers.html')
controllerSizer.Add( controllerhelpbutton)

# Pickers for controller_modifiers
possible_mods = controller.ListOfPossibleMods()
Expand Down

0 comments on commit 9c4998b

Please sign in to comment.