Skip to content

Commit

Permalink
Clear out default power tray keys if new ones are defined
Browse files Browse the repository at this point in the history
Previously, if the user selected new keybinds for the power tray buttons,
it was possible to get multiple keys bound to them, which could be both
visually and behaviorally confusing.

With this release, by default, if a key is bound to a power tray button,
the default key for that button (if different) will be unbound.  A
checkbox has been added to turn off this behavior, if for some reason
someone was relying on the doubled-up keybind definitions.

Also added was a "Keybind Profile" picker that needs to be set to match
the in-game one to make this functionality work correctly.
  • Loading branch information
emersonrp committed Jan 9, 2025
2 parents 2dcd600 + 703cf81 commit fd6eead
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 6 deletions.
12 changes: 12 additions & 0 deletions Help/KeepExistingTrayBinds.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head><title>Keep Existing / Default Tray Binds</title></head>
<body>
<h1>Keep Existing / Default Tray Binds</h1>
<p>Normally, BindControl's binds are added to the game's default set of binds. In the case of the power tray buttons, this can cause some display confusion as well as unexpected results, and so BindControl treats these differently by default.</p>
<p>For instance, suppose you were using the "Modern" Keybind Profile in-game, and then in BindControl you activated the checkbox for the Tertiary power tray, and assigned the Tertiary Tray keys to be <code>Ctrl-1</code> - <code>Ctrl-0</code>.</p>
<p>Once the BindControl binds were loaded, assuming the default set of <code>Shift-1</code> - <code>Shift-0</code> had not been reassigned somewhere else, <b>both</b> sets of binds would be active for the power tray buttons, and only the "primary" one would be displayed on the buttons in-game. This is probably not the desired result in this case.</p>
<p>Therefore, by default, <b>for the power tray keys only</b>, BindControl will remove what it expects are the existing binds for any key that you define a keybind for. <b>NOTE</b>: in order for this to work correctly, you must set the "Keybind Profile" picker in BindControl to match the one in the Options Menu &gt; Keybinds in-game.</p>
<p>If you check the box for "Keep Existing / Default Tray Binds" then BindControl will not do this, and will "double up" any existing keybinds as described above.</p>
<p>It is most likely that leaving the box unchecked will give the behavior you expect.</p>
</body>
</html>
71 changes: 65 additions & 6 deletions Page/Gameplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from BLF import BLF
from Help import HelpButton

from UI.ControlGroup import ControlGroup
from BindFile import KeyBind

from UI.ControlGroup import ControlGroup, cgChoice
from UI.KeySelectDialog import bcKeyButton
from Page import Page

Expand Down Expand Up @@ -57,21 +59,44 @@ def __init__(self, parent):
self.Init[ctlname] = f"{mod}{button}"
UI.Labels[ctlname] = f"{name} Tray, Button {button}"

self.KeybindProfiles = {
'Modern': {
'Secondary' : 'ALT',
'Tertiary' : 'SHIFT',
'Server' : 'CTRL',
},
'Classic': {
'Secondary' : 'ALT',
'Tertiary' : 'CTRL',
},
'Joystick': {
'Secondary' : 'ALT',
},
'Launch (Issue 0)': {
'Secondary' : 'ALT',
},
}

def BuildPage(self):

##### Power Tray Buttons
traySizer = wx.StaticBoxSizer(wx.HORIZONTAL, self, label = 'Power Tray Buttons')
traySizer = wx.StaticBoxSizer(wx.VERTICAL, self, label = 'Power Tray Buttons')
staticbox = traySizer.GetStaticBox()


# Horizontal sizer for "help" button
GridHelpSizer = wx.BoxSizer(wx.HORIZONTAL)

# Tray Grid
trayGridSizer = wx.FlexGridSizer(14,4,0)

self.FillTrayButtons = {}
for b in (1,2,3,4):
self.FillTrayButtons[b] = wx.Button(staticbox, wx.ID_ANY, "Fill")
setattr(self.FillTrayButtons[b], 'Tray', b)
self.FillTrayButtons[b].Bind(wx.EVT_BUTTON, self.OnFillTray)
self.FillTrayButtons[b].SetToolTip("Fill the buttons with the numbers 1 - 0. Hold a modifier key while clicking to use that modifier key in the binds.")

trayGridSizer = wx.FlexGridSizer(14,4,0)

for tray in (4,3,2,1):
label = ['', 'Main', 'Secondary', 'Tertiary', 'Server'][tray]
checkbox = wx.CheckBox(staticbox, wx.ID_ANY, label = f"{label} Tray")
Expand Down Expand Up @@ -102,10 +127,33 @@ def BuildPage(self):
trayGridSizer.Add(prevbutton, 1, wx.ALIGN_CENTER)
trayGridSizer.Add(nextbutton, 1, wx.ALIGN_CENTER)

traySizer.Add(trayGridSizer, 0, wx.ALL, 10)
GridHelpSizer.Add(trayGridSizer, 0, wx.ALL, 10)
traygridbutton = HelpButton(staticbox, 'PowerTrayButtons.html')
traySizer.Add(traygridbutton, 0, wx.ALL, 10)
GridHelpSizer.Add(traygridbutton, 0, wx.ALL, 10)

traySizer.Add(GridHelpSizer, 0, wx.ALL, 10)

# Keybind Profile picker
KBProfileSizer = wx.BoxSizer(wx.HORIZONTAL)

KBProfileSizer.Add(wx.StaticText(staticbox, wx.ID_ANY, "Keybind Profile:"), 0, wx.ALIGN_CENTER_VERTICAL, 10)
KBProfilePicker = cgChoice(staticbox, wx.ID_ANY, choices = ['Modern', 'Joystick', 'Classic', 'Launch (Issue 0)'])
KBProfilePicker.SetSelection(0)
UI.Labels['KBProfile'] = "Keybind Profile"
self.Ctrls['KBProfile'] = KBProfilePicker
KBProfilePicker.SetToolTip("This should be set to match the Keybind Profile you have set in the in-game options.")
KBProfileSizer.Add(KBProfilePicker, 0, wx.ALIGN_CENTER_VERTICAL, 10)

KeepExistingCB = wx.CheckBox(staticbox, wx.ID_ANY, "Keep Existing / Default Tray Binds")
KeepExistingCB.SetValue(False)
UI.Labels['KeepExisting'] = "Keep Existing / Default Tray Binds"
self.Ctrls['KeepExisting'] = KeepExistingCB
KBProfileSizer.Add(KeepExistingCB, 0, wx.ALIGN_CENTER_VERTICAL, 10)

KBProfileSizer.Add(HelpButton(staticbox, 'KeepExistingTrayBinds.html'), 0, wx.ALIGN_CENTER_VERTICAL, 5)


traySizer.Add(KBProfileSizer, 0, wx.ALL, 10)
# Bottom Sizer for narrower boxes
bottomSizer = wx.BoxSizer(wx.HORIZONTAL)

Expand Down Expand Up @@ -248,10 +296,13 @@ def PopulateBindFiles(self):
if self.GetState('Tray1Enabled'):
ResetFile.SetBind(self.Ctrls[f"Tray1Button{button}"].MakeFileKeyBind(f"powexec_slot {slotbutton}"))
if self.GetState('Tray2Enabled'):
self.CheckForDefaultKeyToClear('Secondary', 2, button)
ResetFile.SetBind(self.Ctrls[f"Tray2Button{button}"].MakeFileKeyBind(f"powexec_altslot {slotbutton}"))
if self.GetState('Tray3Enabled'):
self.CheckForDefaultKeyToClear('Tertiary', 3, button)
ResetFile.SetBind(self.Ctrls[f"Tray3Button{button}"].MakeFileKeyBind(f"powexec_alt2slot {slotbutton}"))
if self.GetState('Tray4Enabled'):
self.CheckForDefaultKeyToClear('Server', 4, button)
ResetFile.SetBind(self.Ctrls[f"Tray4Button{button}"].MakeFileKeyBind(f"powexec_serverslot {slotbutton}"))

if self.GetState('Tray1Enabled'):
Expand Down Expand Up @@ -319,6 +370,14 @@ def PopulateBindFiles(self):

return True

def CheckForDefaultKeyToClear(self, trayname, traynum, button):
if self.GetState("KeepExisting") == False:
if KBProfile := self.KeybindProfiles.get(self.GetState('KBProfile'), None):
if DefModKey := KBProfile.get(trayname, None):
DefKey = f"{DefModKey}+{button}"
if self.GetState(f"Tray{traynum}Button{button}") != DefKey and not self.Profile.CheckConflict(DefKey, ''):
self.Profile.ResetFile().SetBind(KeyBind(DefKey, "", self, "nop"))

def AllBindFiles(self):
files = [self.Profile.GetBindFile("teamsel", "reset.txt")]
dirs = ["teamsel", "teamsel2"]
Expand Down

0 comments on commit fd6eead

Please sign in to comment.