Skip to content

Commit

Permalink
Refactor PowerBinder to make steps into separate modules / plugins.
Browse files Browse the repository at this point in the history
Apart from a couple of wee visual fixes, this should in principle act exactly the same way it did, but it's way more maintainable and extensible now.
  • Loading branch information
emersonrp committed Jan 25, 2025
2 parents 3880f8c + 6f3ef0a commit c67e536
Show file tree
Hide file tree
Showing 29 changed files with 1,625 additions and 1,519 deletions.
26 changes: 26 additions & 0 deletions UI/PowerBinderCommand/AFKCmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import wx
from UI.PowerBinderCommand import PowerBinderCommand

####### Away From Keyboard
class AFKCmd(PowerBinderCommand):
Name = "Away From Keyboard"
Menu = "Social"
def BuildUI(self, dialog):
sizer = wx.BoxSizer(wx.HORIZONTAL)
self.AFKName = wx.TextCtrl(dialog, -1)
self.AFKName.SetHint('Away From Keyboard Text')
sizer.Add(self.AFKName, 1, wx.ALIGN_CENTER_VERTICAL)


return sizer

def MakeBindString(self):
message = self.AFKName.GetValue()
return f"afk {message}" if message else "afk"

def Serialize(self):
return {'message': self.AFKName.GetValue()}

def Deserialize(self, init):
if init['message']:
self.AFKName.SetValue(init['message'])
148 changes: 148 additions & 0 deletions UI/PowerBinderCommand/AttributeMonitorCmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import wx
import wx.adv
from wx.adv import EditableListBox
from UI.PowerBinderCommand import PowerBinderCommand

####### Attribute Monitor
class AttributeMonitorCmd(PowerBinderCommand):
Name = "Attribute Monitor"
Menu = "Graphics / UI"

def BuildUI(self, dialog):
self.Page = dialog.Page
self.AttributeTable = {
'Base' : {
'Current Hit Points' : 'NT H',
'Max Hit Points' : 'X H',
'Current Endurance' : 'T E',
'Max Endurance' : 'X EN',
'Regeneration Rate' : 'N RAT',
'Recovery Rate' : 'Y RA',
'Endurance Consumption' : 'SU',
'ToHit Bonus' : 'T B',
'Accuracy Bonus' : 'CC',
'Last Hit Chance' : 'T C',
'Damage Bonus' : 'DA',
'Healing Bonus' : 'NG B',
'Recharge Time Bonus' : 'ME B',
'Endurance Discount' : 'CE DIS',
'Stealth Radius (PvP)' : 'PVP',
'Stealth Radius (PvE)' : 'PVE',
'Perception Radius' : 'RC',
'Range Bonus' : 'GE B',
'Threat Level' : 'AT L',
'Experience to Next Level' : 'XT',
'Experience Debt' : 'XP',
'Influence / Infamy' : 'INF',
'Inherent' : 'NH',
},
'Movement Speed' : {
'Flying Speed' : 'FL',
'Jumping Speed' : 'PI',
'Max Jump Height' : 'X J',
'Run Speed' : 'RU',
},
'Damage Resistance' : {
'Smashing Resistance' : 'G R',
'Lethal Resistance' : 'L R',
'Fire Resistance' : 'RE R',
'Cold Resistance' : 'COLD R',
'Energy Resistance' : 'DamageType[4]',
'Negative Energy Resistance' : 'GY R',
'Psyonic Resistance' : 'NIC R',
'Toxic Resistance' : 'XIC R',
},
'Defense' : {
'Base Defense' : 'BAS',
'Ranged Defense' : 'ED',
'Melee Defense' : 'MEL',
'AoE Defense' : '2',
'Smashing Defense' : '3',
'Lethal Defense' : '4',
'Fire Defense' : '5',
'Cold Defense' : '6',
'Energy Defense' : '7',
'Negative Energy Defense' : '8',
'Psionic Defense' : '9',
'Toxic Defense' : '1',
},
'Debuff Resistance' : {
'Regeneration Resistance' : 'ON R',
'Recovery Resistance' : 'RY R',
'To Hit Resistance' : 'IT R',
'Defense Resistance' : 'NSE RES',
},
'Status Effect Protection' : {
'Hold Protection' : 'D P',
'Immobilize Protection' : 'LIZE P',
'Stun Protection' : 'N P',
'Sleep Protection' : 'P P',
'Knockback Protection' : 'K P',
'Confuse Protection' : 'SE P',
'Terrorize Protection' : 'ZE P',
'Repel Protection' : 'EL P',
'Teleport Protection' : 'T P',
},
'Status Effect Resistance' : {
'Hold Resistance' : 'D R',
'Immobilize Resistance' : 'LIZE R',
'Stun Resistance' : 'N R',
'Sleep Resistance' : 'P R',
'Knockback Resistance' : 'K R',
'Confuse Resistance' : 'SE R',
'Terrorize Resistance' : 'ZE R',
'Placate Resistance' : 'TE R',
'Taunt Resistance' : 'NT R',
},
'Miscellaneous' : {
'Level Shift' : 'L S',
},
}
groupSizer = wx.BoxSizer(wx.HORIZONTAL)

self.AttributeMenu = wx.Menu()
for group, controls in self.AttributeTable.items():
submenu = wx.Menu()
self.AttributeMenu.AppendSubMenu(submenu, group)
for cb in controls:
submenu.Append(wx.ID_ANY, cb)

self.AttributeMenu.Bind(wx.EVT_MENU, self.OnMenuItem)

self.editbox = EditableListBox(dialog, label = "Attributes", style = wx.adv.EL_ALLOW_NEW|wx.adv.EL_ALLOW_DELETE)
groupSizer.Add(self.editbox)

newButton = self.editbox.GetNewButton()
newButton.Bind(wx.EVT_BUTTON, self.OnNewButton)

return groupSizer

def MakeBindString(self):
map = {}
bindstrings = []
for _, controls in self.AttributeTable.items():
for cb, data in controls.items():
map[cb] = data

for string in self.editbox.GetStrings():
if string:
bindstrings.append(f'monitorattribute {map[string]}')

return '$$'.join(bindstrings)

def Serialize(self):
return {
'attributes' : self.editbox.GetStrings()
}

def Deserialize(self, init):
self.editbox.SetStrings(init.get('attributes', []))

def OnNewButton(self, evt):
evt.GetEventObject().PopupMenu(self.AttributeMenu)

def OnMenuItem(self, evt):
menuitem = evt.EventObject.FindItemById(evt.GetId())
existingstrings = self.editbox.GetStrings()
existingstrings.append(menuitem.GetItemLabel())
self.editbox.SetStrings(existingstrings)
29 changes: 29 additions & 0 deletions UI/PowerBinderCommand/AutoPowerCmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import wx
from UI.PowerPicker import PowerPicker
from Icon import GetIcon
from UI.PowerBinderCommand import PowerBinderCommand

####### Auto Power
class AutoPowerCmd(PowerBinderCommand):
Name = "Auto Power"
Menu = "Powers"
def BuildUI(self, dialog):
autoPowerSizer = wx.BoxSizer(wx.HORIZONTAL)
autoPowerSizer.Add(wx.StaticText(dialog, -1, "Power:"), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, 4)
self.autoPowerName = PowerPicker(dialog)
autoPowerSizer.Add(self.autoPowerName, 1, wx.ALIGN_CENTER_VERTICAL)

return autoPowerSizer

def MakeBindString(self):
return f"powexecauto {self.autoPowerName.GetLabel()}"

def Serialize(self):
return {
'pname' : self.autoPowerName.GetLabel(),
'picon' : self.autoPowerName.IconFilename
}

def Deserialize(self, init):
if init.get('pname', ''): self.autoPowerName.SetLabel(init['pname'])
if init.get('picon', ''): self.autoPowerName.SetBitmap(GetIcon(init['picon']))
89 changes: 89 additions & 0 deletions UI/PowerBinderCommand/BuffDisplayCmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import wx
from UI.ControlGroup import ControlGroup
import wx.adv
from UI.PowerBinderCommand import PowerBinderCommand

####### Buff Display Command
class BuffDisplayCmd(PowerBinderCommand):
Name = "Buff Display Settings"
Menu = "Graphics / UI"
Groups = {}

def BuildUI(self, dialog):
self.Groups = {}
self.Page = dialog.Page
self.buffDisplayMap = {
'Status Window' : {
'Hide Auto' : 1,
'Hide Toggles' : 2,
'No Blinking' : 4,
'No Stacking' : 8,
'Numeric Stacking' : 16,
'Hide Buff Numbers' : 32,
'Stop Sending Buffs' : 64,
},
'Group Window' : {
'Hide Auto' : 256,
'Hide Toggles' : 512,
'No Blinking' : 1024,
'No Stacking' : 2048,
'Numeric Stacking' : 4096,
'Hide Buff Numbers' : 8192,
'Stop Sending Buffs' : 16384,
},
'Pet Window' : {
'Hide Auto' : 65536,
'Hide Toggles' : 131072,
'No Blinking' : 262144,
'No Stacking' : 524288,
'Numeric Stacking' : 1048576,
'Hide Buff Numbers' : 2097152,
'Stop Sending Buffs' : 4194304,
},
}
groupSizer = wx.BoxSizer(wx.HORIZONTAL)

for group, controls in self.buffDisplayMap.items():
self.Groups[group] = ControlGroup(dialog, self.Page, label = group)
groupid = self.Groups[group].GetStaticBox().GetId()
for cb, data in controls.items():
self.Groups[group].AddControl(
ctlType = 'checkbox',
ctlName = f"{groupid}_{group}_{cb}",
label = cb,
data = data,
)

groupSizer.Add(self.Groups[group])

return groupSizer

def CalculateValue(self):
page = wx.App.Get().Main.Profile.CustomBinds

total = 0

for group, controls in self.buffDisplayMap.items():
groupid = self.Groups[group].GetStaticBox().GetId()
for cb in controls:
checkbox = page.Ctrls[f"{groupid}_{group}_{cb}"]
if checkbox.IsChecked():
total = total + checkbox.Data
return total

def MakeBindString(self):
return f"optionset buffsettings {self.CalculateValue()}"

def Serialize(self):
return { 'value' : self.CalculateValue() }

def Deserialize(self, init):
value = init.get('value', 0)

value = value or 0 # in case we had for some reason 'None' stashed in the init values

for group, controls in self.buffDisplayMap.items():
groupid = self.Groups[group].GetStaticBox().GetId()
for cb in controls:
checkbox = self.Page.Ctrls[f"{groupid}_{group}_{cb}"]
checkbox.SetValue( checkbox.Data & value )
Loading

0 comments on commit c67e536

Please sign in to comment.