diff --git a/Basic Round-Robin/BasicRoundRobin.Common.iss b/Basic Round-Robin/BasicRoundRobin.Common.iss index 705f96d..dcfdaab 100644 --- a/Basic Round-Robin/BasicRoundRobin.Common.iss +++ b/Basic Round-Robin/BasicRoundRobin.Common.iss @@ -1,42 +1,29 @@ -objectdef brrSettings +objectdef brrProfile { - variable filepath AgentFolder="${Script.CurrentDirectory}" + variable string Name + variable bool DefaultAllow=TRUE + variable bool SwitchAsHotkey=TRUE + variable bool IncludeMouse=FALSE + variable jsonvalue Overrides + variable jsonvalue Hotkey - variable jsonvalue hotkeyToggleRoundRobin="$$> + variable bool Enabled + + method Initialize(jsonvalue jo) { - "controls":"F12" + This:FromJSON[jo] } - <$$" - method Initialize() - { - Overrides:SetValue["$$> + method Shutdown() { - "F12":{"ignore":true}, - "${Input.Button[160]}":{"ignore":true}, - "${Input.Button[161]}":{"ignore":true}, - "${Input.Button[162]}":{"ignore":true}, - "${Input.Button[163]}":{"ignore":true}, - "${Input.Button[164]}":{"ignore":true}, - "${Input.Button[165]}":{"ignore":true} - }<$$"] - - This:Load + This:DisableHotkey } - method Load() + method FromJSON(jsonvalueref jo) { - variable jsonvalue jo - if !${AgentFolder.FileExists[brr.Settings.json]} + if !${jo.Type.Equal[object]} return - - if !${jo:ParseFile["${AgentFolder~}/brr.Settings.json"](exists)} || !${jo.Type.Equal[object]} - { - return - } - - if ${jo.Has[enable]} - Enable:Set["${jo.Get[enable]~}"] + if ${jo.Has[includeMouse]} IncludeMouse:Set["${jo.Get[includeMouse]~}"] if ${jo.Has[defaultAllow]} @@ -47,14 +34,141 @@ objectdef brrSettings if ${jo.Has[overrides]} Overrides:SetValue["${jo.Get[overrides].AsJSON~}"] + if ${jo.Has[hotkey]} + Hotkey:SetValue["${jo.Get[hotkey].AsJSON~}"] + } + + member AsJSON() + { + variable jsonvalue jo + jo:SetValue["$$> + { + "includeMouse":${IncludeMouse.AsJSON~}, + "overrides":${Overrides.AsJSON~}, + "defaultAllow":${DefaultAllow.AsJSON~}, + "switchAsHotkey":${SwitchAsHotkey.AsJSON~}, + "hotkey":${Hotkey.AsJSON~} + } + <$$"] + return "${jo.AsJSON~}" + } + + method EnableHotkey() + { + variable jsonvalue joBinding + variable string startCommand + if ${Hotkey.Type.Equal[object]} && ${Hotkey.Has[controls]} + { + joBinding:SetValue["${Hotkey.AsJSON~}"] + joBinding:Set[name,"\"brr.profile.${Name~}\""] + + startCommand:Set["BRRSession:ToggleProfile[${Name.AsJSON~}]"] + + joBinding:Set[eventHandler,"$$> + { + "type":"task", + "taskManager":"brrSession", + "task":{ + "type":"ls1.code", + "start":${startCommand.AsJSON~} + } + } + <$$"] + + LGUI2:AddBinding["${joBinding.AsJSON~}"] + + Enabled:Set[1] + } + } + + method DisableHotkey() + { + LGUI2:RemoveBinding["brr.profile.${Name~}"] + Enabled:Set[0] + } +} + +objectdef brrSettings +{ + variable filepath AgentFolder="${Script.CurrentDirectory}" + + + + method Initialize() + { + This:Load + + if !${Profiles.Used} + { + Profiles:Set[default,"$$> + { + "defaultAllow":true, + "includeMouse":false, + "switchAsHotkey":true, + "hotkey":{ + "controls":"F12" + }, + "overrides":{ + "F12":{"ignore":true}, + "${Input.Button[160]}":{"ignore":true}, + "${Input.Button[161]}":{"ignore":true}, + "${Input.Button[162]}":{"ignore":true}, + "${Input.Button[163]}":{"ignore":true}, + "${Input.Button[164]}":{"ignore":true}, + "${Input.Button[165]}":{"ignore":true} + } + } + <$$"] + } + + + } + + method Convert(jsonvalueref jo) + { + ; make sure it hasnt already been converted + if ${jo.Has[profiles]} + return + variable jsonvalue joHotkeys + variable jsonvalue joWrapper + joWrapper:SetValue["${jo.AsJSON~}"] joHotkeys:SetValue["${jo.Get[hotkeys].AsJSON~}"] if ${joHotkeys.Type.Equal[object]} { if ${joHotkeys.Has[toggleRoundRobin]} - hotkeyToggleRoundRobin:SetValue["${joHotkeys.Get[toggleRoundRobin].AsJSON~}"] + joWrapper:Set["hotkey","${joHotkeys.Get[toggleRoundRobin].AsJSON~}"] } + + joWrapper:Erase[hotkeys] + + jo:Clear + jo:Set["profiles","{\"original\":${joWrapper.AsJSON~}}"] + +; Profiles:Set["original","${joWrapper.AsJSON~}"] + + } + + method Load() + { + variable jsonvalue jo + if !${AgentFolder.FileExists[brr.Settings.json]} + return + + if !${jo:ParseFile["${AgentFolder~}/brr.Settings.json"](exists)} || !${jo.Type.Equal[object]} + { + return + } + + This:Convert[jo] + + if ${jo.Has[profiles]} + { + Profiles:FromJSON["${jo.Get[profiles].AsJSON~}"] + Profiles:ForEach["ForEach.Value.Name:Set[\"\${ForEach.Key~}\"]"] + } + } @@ -70,22 +184,32 @@ objectdef brrSettings variable jsonvalue jo jo:SetValue["$$> { - "enable":${Enable.AsJSON~}, - "includeMouse":${IncludeMouse.AsJSON~}, - "overrides":${Overrides.AsJSON~}, - "defaultAllow":${DefaultAllow.AsJSON~}, - "switchAsHotkey":${SwitchAsHotkey.AsJSON~}, - "hotkeys":{ - "toggleRoundRobin":${hotkeyToggleRoundRobin.AsJSON~} - } + "profiles":${Profiles.AsJSON~} } <$$"] return "${jo.AsJSON~}" } - variable bool Enable=FALSE - variable bool DefaultAllow=TRUE - variable bool SwitchAsHotkey=TRUE - variable bool IncludeMouse=FALSE - variable jsonvalue Overrides + method EnableHotkeys() + { + Profiles:ForEach["ForEach.Value:EnableHotkey"] + } + + method DisableHotkeys() + { + Profiles:ForEach["ForEach.Value:DisableHotkey"] + } + + method SetCurrentProfile(string newValue) + { + CurrentProfile:SetReference["Profiles.Get[${newValue.AsJSON~}]"] + } + + method ClearCurrentProfile() + { + CurrentProfile:SetReference[NULL] + } + + variable collection:brrProfile Profiles + variable weakref CurrentProfile } diff --git a/Basic Round-Robin/BasicRoundRobin.Session.iss b/Basic Round-Robin/BasicRoundRobin.Session.iss index 9b5dd9f..d221e5b 100644 --- a/Basic Round-Robin/BasicRoundRobin.Session.iss +++ b/Basic Round-Robin/BasicRoundRobin.Session.iss @@ -4,65 +4,57 @@ objectdef brrSession { variable taskmanager TaskManager=${LMAC.NewTaskManager["brrSession"]} variable brrSettings Settings - variable bool Enabled method Initialize() { LGUI2:LoadPackageFile[BasicRoundRobin.Session.lgui2Package.json] - if ${Settings.Enable} - This:Enable - This:EnableHotkeys + This.Settings:EnableHotkeys } method Shutdown() { This:Disable - This:DisableHotkeys + This.Settings:DisableHotkeys TaskManager:Destroy LGUI2:UnloadPackageFile[BasicRoundRobin.Session.lgui2Package.json] } - - - method EnableHotkeys() + + member:uint GetNextSlot() { - variable jsonvalue joBinding - if ${Settings.hotkeyToggleRoundRobin.Type.Equal[object]} && ${Settings.hotkeyToggleRoundRobin.Has[controls]} - { - joBinding:SetValue["${Settings.hotkeyToggleRoundRobin.AsJSON~}"] - joBinding:Set[name,"\"brr.toggleRoundRobin\""] - joBinding:Set[eventHandler,"$$> - { - "type":"task", - "taskManager":"brrSession", - "task":{ - "type":"ls1.code", - "start":"uplink BRRUplink:ToggleEnable" - } - } - <$$"] + variable uint Slot=${JMB.Slot} + if !${Slot} + return 0 - LGUI2:AddBinding["${joBinding.AsJSON~}"] - } - } + Slot:Inc + if ${Slot}>${JMB.Slots.Used} + return 1 - method DisableHotkeys() - { - LGUI2:RemoveBinding["brr.toggleRoundRobin"] + return ${Slot} } + method NextWindow() { - BWLSession:NextWindow[${Settings.SwitchAsHotkey}] - } + variable uint nextSlot=${This.GetNextSlot} + if !${nextSlot} + return + + if !${Display.Window.IsForeground} + return + + uplink focus "jmb${nextSlot}" + if ${Settings.CurrentProfile.SwitchAsHotkey} + relay "jmb${nextSlot}" "Event[OnHotkeyFocused]:Execute" + } method OnControlHook(string controlName) { - variable bool Advance=${Settings.DefaultAllow} + variable bool Advance=${Settings.CurrentProfile.DefaultAllow} ; check for overrides variable jsonvalueref Override - Override:SetReference["Settings.Overrides[${controlName.AsJSON~}]"] + Override:SetReference["Settings.CurrentProfile.Overrides[${controlName.AsJSON~}]"] if ${Override.Type.Equal[object]} { @@ -95,20 +87,27 @@ objectdef brrSession method OnMouseButtonHook() { - if ${This.IncludeMouse} + if ${Settings.CurrentProfile.IncludeMouse} This:OnControlHook["${Context.Args[controlName]~}"] } - method Enable() + method Enable(string profile) { + Settings:SetCurrentProfile["${profile~}"] + LGUI2.Element[basicRoundRobin.allButtons]:Destroy LGUI2:LoadJSON["${LGUI2.Template[brr.allButtons].AsJSON~}"] - Enabled:Set[1] } method Disable() { + Settings:ClearCurrentProfile LGUI2.Element[basicRoundRobin.allButtons]:Destroy - Enabled:Set[0] + } + + ; used by the GUI to indicate profile hotkey was pressed. pass to the uplink for processing + method ToggleProfile(string profile) + { + relay uplink "BRRUplink:ToggleProfile[${profile.AsJSON~}]" } } diff --git a/Basic Round-Robin/BasicRoundRobin.Session.lgui2package.json b/Basic Round-Robin/BasicRoundRobin.Session.lgui2package.json index 0c57a56..06ad4dc 100644 --- a/Basic Round-Robin/BasicRoundRobin.Session.lgui2package.json +++ b/Basic Round-Robin/BasicRoundRobin.Session.lgui2package.json @@ -63,6 +63,11 @@ } }, "elements": [ + { + "type":"panel", + "visibility":"hidden", + "name":"basicRoundRobin.events" + }, { "type": "window", "name": "basicRoundRobin.window", diff --git a/Basic Round-Robin/BasicRoundRobin.Uplink.iss b/Basic Round-Robin/BasicRoundRobin.Uplink.iss index 37f46b6..dc0cdd1 100644 --- a/Basic Round-Robin/BasicRoundRobin.Uplink.iss +++ b/Basic Round-Robin/BasicRoundRobin.Uplink.iss @@ -17,43 +17,34 @@ objectdef brrUplink LGUI2:UnloadPackageFile[BasicRoundRobin.Uplink.lgui2Package.json] } - method NextWindow() + method ToggleProfile(string newProfile) { - BWLSession:NextWindow - } - - - method ToggleEnable() - { - This:SetEnable[${Settings.Enable.Not}] - } + if !${newProfile.NotNULLOrEmpty} || ${Settings.CurrentProfile.Name.Equal["${newProfile~}"]} + { +; echo "[BRR] Disabling" + ; activating same profile is a toggle off + Settings:ClearCurrentProfile - method SetEnable(bool newValue) - { - if ${newValue}==${Settings.Enable} - return - Settings.Enable:Set[${newValue}] + ; push updated setting + relay all "BRRSession:Disable" - if ${newValue} - { - RestoreFocusFollowsMouse:Set[${BWLUplink.FocusFollowsMouse}] - BWLUplink:SetFocusFollowsMouse[FALSE] - } - else - { if ${RestoreFocusFollowsMouse} { BWLUplink:SetFocusFollowsMouse[TRUE] } } + else + { +; echo "[BRR] Enabling" + if !${Settings.CurrentProfile.Reference(exists)} + RestoreFocusFollowsMouse:Set[${BWLUplink.Settings.FocusFollowsMouse}] -; Settings:Store + BWLUplink:SetFocusFollowsMouse[FALSE] + Settings:SetCurrentProfile["${newProfile~}"] - ; push updated setting - if ${newValue} - relay all "BRRSession:Enable" - else - relay all "BRRSession:Disable" + ; push updated setting + relay all "BRRSession:Enable[${newProfile.AsJSON~}]" + } } } diff --git a/Basic Round-Robin/BasicRoundRobin.Uplink.lgui2package.json b/Basic Round-Robin/BasicRoundRobin.Uplink.lgui2package.json index ce05c36..46945a6 100644 --- a/Basic Round-Robin/BasicRoundRobin.Uplink.lgui2package.json +++ b/Basic Round-Robin/BasicRoundRobin.Uplink.lgui2package.json @@ -1,6 +1,11 @@ { "$schema": "http://www.lavishsoft.com/schema/lgui2Package.json", "elements": [ + { + "type":"panel", + "visibility":"hidden", + "name":"basicRoundRobin.events" + }, { "type": "window", "name": "basicRoundRobin.window", @@ -31,13 +36,35 @@ }, "children":[ { - "type":"checkbox", - "content":"Enable Round-Robin Mode", - "checkedBinding":{ - "pullFormat":"${BRRUplink.Settings.Enable}", - "pushFormat":["BRRUplink:SetEnable[\"","\"]"] - } - } + "_dock":"top", + "type":"textblock", + "text":"Work in progress. :)", + }, + { + "type":"stackpanel", + "_dock":"top", + "visibility":"collapsed", + "orientation":"horizontal", + "children":[ + "Toggle Hotkey:", + { + "name":"brr.hotkeyPicker", + "type":"inputpicker", + "minSize":[100,30], + "multipleControlMode":true, + "valueBinding":{ + "pullFormat":"${BRRUplink.Settings.hotkeyToggleRoundRobin}", + "pushFormat":["BRRUplink:SetHotkey[\"","\"]"], + "pullOnce":true, + "pullHook":{ + "elementName":"basicRoundRobin.events", + "flags":"global", + "event":"onHotkeyChanged" + } + } + } + ] + } ] }, {