99
1010; ======================================================================== MAIN CLASS ===============================================================
1111Class UCRMain {
12- Version := " 0.0.13 " ; The version of the main application
12+ Version := " 0.0.14 " ; The version of the main application
1313 SettingsVersion := " 0.0.5" ; The version of the settings file format
1414 _StateNames := {0 : " Normal" , 1 : " InputBind" , 2 : " GameBind" }
1515 _State := {Normal : 0 , InputBind: 1 , GameBind: 2 }
@@ -24,7 +24,7 @@ Class UCRMain {
2424 PluginDetails := {} ; A name-indexed list of plugin Details (Classname, Description etc). Name is ".Type" property of class
2525 PLUGIN_WIDTH := 680 ; The Width of a plugin
2626 PLUGIN_FRAME_WIDTH := 720 ; The width of the plugin area
27- SIDE_PANEL_WIDTH := 100 ; The default width of the side panel
27+ SIDE_PANEL_WIDTH := 150 ; The default width of the side panel
2828 TOP_PANEL_HEIGHT := 75 ; The amount of space reserved for the top panel (profile select etc)
2929 GUI_MIN_HEIGHT := 300 ; The minimum height of the app. Required because of the way AHK_H autosize/pos works
3030 CurrentSize := {w: this.PLUGIN_FRAME_WIDTH + this.SIDE_PANEL_WIDTH, h: this.GUI_MIN_HEIGHT} ; The current size of the app.
@@ -251,23 +251,25 @@ Class UCRMain {
251251 this.UpdateCurrentProfileReadout()
252252 this._ProfileToolbox.SelectProfileByID(id )
253253
254- ; Show which profiles are loaded
254+ ; Clear Profile Toolbox colours and start setting new ones
255255 this._ProfileToolbox.ResetProfileColors()
256256 this._ProfileToolbox.SetProfileColor(id , {fore: 0xffffff , back: 0xff9933 }) ; Fake default selection box
257257 this._ProfileToolbox.SetProfileColor(1 , {fore: 0x0 , back: 0x00ff00 })
258258 this._ProfileToolbox.SetProfileInherit(this.CurrentProfile.InheritsfromParent)
259259
260260 ; Start running new profile
261261 this._SetProfileInputThreadState(id ,1 )
262- this.CurrentProfile._Activate()
263-
264- ; Start running profiles which are inherited
265- this.ActivateProfilesInheritedBy(id )
262+ this.ActivateInputThread(this.CurrentProfile.id)
266263
267264 ; Make the new profile's Gui visible
268265 this.CurrentProfile._Show()
269266
267+ ; Make sure all linked or inherited profiles have active input threads
270268 this.StartThreadsLinkedToProfileId(this.CurrentProfile.id)
269+
270+ ; Activate profiles which are inherited
271+ this.ActivateProfilesInheritedBy(id )
272+
271273 WinSet ,Redraw ,,% " ahk_id " this._ProfileToolbox.hTreeview
272274
273275 ; Save settings
@@ -277,22 +279,34 @@ Class UCRMain {
277279 return 1
278280 }
279281
282+ ActivateInputThread (id ){
283+ profile := this.profiles[id ]
284+ ; OutputDebug % "UCR| Activating " id " (" profile.name ")"
285+ profile._Activate()
286+ this._ActiveInputThreads[id ] := profile
287+ }
288+
289+ DeActivateInputThread (id ){
290+ profile := this.profiles[id ]
291+ ; OutputDebug % "UCR| Deactivating " id " (" profile.name ")"
292+ profile._DeActivate()
293+ this._ActiveInputThreads.Delete (id )
294+ }
295+
280296 ActivateProfilesInheritedBy (id ){
281- if (this.profiles[id ].InheritsfromParent){
282- pp_id := this.profiles[id ].ParentProfile
283- pp := this.profiles[pp_id]
284- pp._Activate()
285- this._ActiveInputThreads[pp_id] := pp
286- this._ProfileToolbox.SetProfileColor(pp_id, {fore: 0x0 , back: 0x00ff00 })
297+ pp_id := this.profiles[id ].ParentProfile
298+ if (this.profiles[id ].InheritsfromParent && pp_id ! = id ){
299+ this._ProfileToolbox.SetProfileColor(pp_id, {fore: 0x0 , back: 0x00ffaa })
300+ this.ActivateInputThread(pp_id)
287301 }
288302 }
289303
290304 DeactivatePofilesNotInheritedBy (id ){
291305 for p_id, p in this._ActiveInputThreads {
292- if (p._IsGlobal || (p.InheritsfromParent && p.ParentProfle == id ))
306+ if (p_id == id || p._IsGlobal || (p.InheritsfromParent && p.ParentProfle == id )){
293307 continue
294- this.profiles[p_id]._Deactivate()
295- this._ActiveInputThreads. Delete (p_id)
308+ }
309+ this.DeActivateInputThread (p_id)
296310 }
297311 }
298312
@@ -321,8 +335,10 @@ Class UCRMain {
321335 StartThreadsLinkedToProfileId (id ){
322336 ; Start the InputThreads for any linked profiles
323337 profile := this.profiles[id ]
324- profile_list := [this.CurrentProfile._LinkedProfiles]
338+ profile_list := [profile._LinkedProfiles]
339+ ; If this profile Inherits from parent, then add the parent's _LinkedProfiles to the list
325340 if (profile.InheritsFromParent && profile.ParentProfile){
341+ this._SetProfileInputThreadState(profile.ParentProfile,1 ) ; Start the parent also
326342 profile_list.push(this.profiles[profile.ParentProfile]._LinkedProfiles)
327343 }
328344 Loop % profile_list.length() {
@@ -344,6 +360,8 @@ Class UCRMain {
344360 }
345361
346362 ProfileLinksChanged (){
363+ if (! this.CurrentProfile.id)
364+ return
347365 this.StopThreadsNotLinkedToProfileId(this.CurrentProfile.id)
348366 this.StartThreadsLinkedToProfileId(this.CurrentProfile.id)
349367 WinSet ,Redraw ,,% " ahk_id " this._ProfileToolbox.hTreeview
@@ -850,24 +868,25 @@ class _ProfileToolbox extends _ProfileSelect {
850868 ProfileColors := {}
851869 __New (){
852870 base.__New ()
853- Gui , Add , CheckBox , xm y110 aya hwndhInherits, Inherits from parent
871+ half_width := round (UCR.SIDE_PANEL_WIDTH / 2 ) - 5
872+ Gui , Add , CheckBox , xm y110 aya w150 hwndhInherits Center , Profile Inherits Plugins`nfrom parent
854873 this.hInheritsFromParent := hInherits
855874 fn := this.InheritToggled.Bind(this)
856875 GuiControl + g, % hInherits, % fn
857876
858- Gui , Add , Button , xm w30 hwndhAdd y130 aya aw1/ 2 , Add
877+ Gui , Add , Button , % " xm w " half_width " hwndhAdd y140 aya aw1/2" , Add
859878 fn := this.AddProfile.Bind(this,0 )
860879 GuiControl + g, % hAdd, % fn
861880
862- Gui , Add , Button , x+ 5 w60 hwndhAdd y130 aya axa aw1/ 2 , Add Child
881+ Gui , Add , Button , % " x+5 w " half_width " hwndhAdd y140 aya axa aw1/2" , Add Child
863882 fn := this.AddProfile.Bind(this,1 )
864883 GuiControl + g, % hAdd, % fn
865884
866- Gui , Add , Button , xm w50 hwndhRename y+ 5 aya axr aw1/ 2 , Rename
885+ Gui , Add , Button , % " xm w " half_width " hwndhRename y+5 aya axr aw1/2" , Rename
867886 fn := this.RenameProfile.Bind(this)
868887 GuiControl + g, % hRename, % fn
869888
870- Gui , Add , Button , x+ 5 w40 hwndhDelete yp aya axa aw1/ 2 , Delete
889+ Gui , Add , Button , % " x+5 w " half_width " hwndhDelete yp aya axa aw1/2" , Delete
871890 fn := this.DeleteProfile.Bind(this)
872891 GuiControl + g, % hDelete, % fn
873892
@@ -1182,7 +1201,7 @@ class _ProfileSelect {
11821201 Gui + ToolWindow
11831202 Gui + Resize
11841203 this.hwnd := hwnd
1185- Gui , Add , TreeView , w100 h100 aw ah hwndhTreeview AltSubmit
1204+ Gui , Add , TreeView , % " w " UCR.SIDE_PANEL_WIDTH " h100 aw ah hwndhTreeview AltSubmit"
11861205 this.hTreeview := hTreeview
11871206 ; Gui, Show
11881207 this.TV_EventFn := this.TV_Event.Bind(this)
@@ -1503,10 +1522,11 @@ Class _Profile {
15031522 Plugins := {} ; A ID-indexed array of Plugin instances
15041523 PluginOrder := [] ; The order that plugins are listed in
15051524 _IsGlobal := 0 ; 1 if this Profile is Global (Always active)
1506- _InputThread := 0 ; Holds the handle to the Input Thread, if active
1525+ _InputThread := 0 ; Holds the handle to the Input Thread, if loaded
15071526 _LinkedProfiles := {} ; Profiles with which this one is associated
15081527 __LinkedProfiles := {} ; Table of plugin to profile links, used to build _LinkedProfiles
15091528 InheritsFromParent := 0
1529+ _HotkeysActive := 0
15101530
15111531 __New (id, name, parent ){
15121532 static fn
@@ -1609,12 +1629,15 @@ Class _Profile {
16091629
16101630 ; The profile became active
16111631 _Activate (){
1632+ if (this._HotkeysActive)
1633+ return
16121634 if (this._InputThread == 0 ){
16131635 OutputDebug % " UCR| WARNING: Tried to Activate profile # " this.id " (" this.name " ) without an active Input Thread"
16141636 UCR._SetProfileInputThreadState(this.id,1 )
16151637 }
16161638 OutputDebug % " UCR| Activating input thread for profile # " this.id " (" this.name " )"
16171639 this._SetHotkeyState(1 )
1640+ this._HotkeysActive := 1
16181641 ; Fire Activate on each plugin
16191642 Loop % this.PluginOrder.length() {
16201643 plugin := this.Plugins[this.PluginOrder[A_Index ]]
@@ -1626,9 +1649,12 @@ Class _Profile {
16261649
16271650 ; The profile went inactive
16281651 _DeActivate (){
1652+ if (! this._HotkeysActive)
1653+ return
16291654 OutputDebug % " UCR| DeActivating input thread for profile # " this.id " (" this.name " )"
16301655 if (this._InputThread)
16311656 this._SetHotkeyState(0 )
1657+ this._HotkeysActive := 0
16321658 Loop % this.PluginOrder.length() {
16331659 plugin := this.Plugins[this.PluginOrder[A_Index ]]
16341660 plugin._OnInactive()
0 commit comments