When removing and adding characters to groups try to add them to the indices they previously were at

This commit is contained in:
2026-01-03 18:45:32 +01:00
parent 29f3146920
commit fab35f1cd5

View File

@@ -56,6 +56,7 @@
CharacterNameOverlayDragging := false ; Flag for drag state
CharacterNameOverlayOffsetX := 0 ; Drag offset X
CharacterNameOverlayOffsetY := 0 ; Drag offset Y
CharacterGroupPositions := Map() ; Track last known positions: groupName -> characterName -> index
__New() {
@@ -132,6 +133,9 @@
This.BorderActive := 0
This.ClientsInCharScreen := Map()
; Initialize character group positions from loaded groups
This.InitializeCharacterGroupPositions()
; Create character name overlay
This.CreateCharacterNameOverlay()
@@ -1259,6 +1263,9 @@
if (!IsObject(This.Hotkey_Groups[targetGroupName]["Characters"]))
This.Hotkey_Groups[targetGroupName]["Characters"] := []
if (!This.CharacterGroupPositions.Has(targetGroupName))
This.CharacterGroupPositions[targetGroupName] := Map()
alreadyInGroup := false
removeIndex := 0
for index, charName in This.Hotkey_Groups[targetGroupName]["Characters"] {
@@ -1270,13 +1277,24 @@
}
if (!alreadyInGroup) {
This.Hotkey_Groups[targetGroupName]["Characters"].Push(currentTitle)
previousIndex := This.CharacterGroupPositions[targetGroupName].Has(currentTitle) ? This.CharacterGroupPositions[targetGroupName][currentTitle] : -1
currentLength := This.Hotkey_Groups[targetGroupName]["Characters"].Length
if (previousIndex >= 1 && previousIndex <= currentLength) {
This.Hotkey_Groups[targetGroupName]["Characters"].InsertAt(previousIndex, currentTitle)
} else {
This.Hotkey_Groups[targetGroupName]["Characters"].Push(currentTitle)
previousIndex := This.Hotkey_Groups[targetGroupName]["Characters"].Length
}
This.CharacterGroupPositions[targetGroupName][currentTitle] := previousIndex
SetTimer(This.Save_Settings_Delay_Timer, -200)
This.NeedRestart := 1
ToolTip("Added " currentTitle " to group")
SetTimer(() => ToolTip(), -1500)
This.UpdateCharacterNameOverlay()
} else {
This.CharacterGroupPositions[targetGroupName][currentTitle] := removeIndex
This.Hotkey_Groups[targetGroupName]["Characters"].RemoveAt(removeIndex)
SetTimer(This.Save_Settings_Delay_Timer, -200)
This.NeedRestart := 1
@@ -1286,6 +1304,23 @@
}
}
InitializeCharacterGroupPositions() {
if (!IsObject(This.Hotkey_Groups) || This.Hotkey_Groups.Count = 0)
return
for groupName, groupData in This.Hotkey_Groups {
if (!IsObject(groupData["Characters"]))
continue
if (!This.CharacterGroupPositions.Has(groupName))
This.CharacterGroupPositions[groupName] := Map()
for index, charName in groupData["Characters"] {
This.CharacterGroupPositions[groupName][charName] := index
}
}
}
IsCharacterInGroup(charName) {
if (!IsObject(This.Hotkey_Groups) || This.Hotkey_Groups.Count = 0)
return false