fix: allow focus target of previous targeters
Fix #1. Keep track of hovers independently of ImGui in order to test if nothing is being hovered.
This commit is contained in:
parent
bccd0383b1
commit
63911a7b53
|
@ -270,6 +270,7 @@ namespace PeepingTom {
|
||||||
this.lastTargetAmount = targeting.Length;
|
this.lastTargetAmount = targeting.Length;
|
||||||
if (ImGui.Begin(this.plugin.Name, ref this.visible, ImGuiWindowFlags.AlwaysAutoResize)) {
|
if (ImGui.Begin(this.plugin.Name, ref this.visible, ImGuiWindowFlags.AlwaysAutoResize)) {
|
||||||
ImGui.Text("Targeting you");
|
ImGui.Text("Targeting you");
|
||||||
|
bool anyHovered = false;
|
||||||
if (ImGui.ListBoxHeader("##targeting", targeting.Length, 5)) {
|
if (ImGui.ListBoxHeader("##targeting", targeting.Length, 5)) {
|
||||||
// add the two first players for testing
|
// add the two first players for testing
|
||||||
//foreach (PlayerCharacter p in this.pi.ClientState.Actors
|
//foreach (PlayerCharacter p in this.pi.ClientState.Actors
|
||||||
|
@ -287,7 +288,7 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
this.previousTargeters.Insert(0, new Targeter(targeter));
|
this.previousTargeters.Insert(0, new Targeter(targeter));
|
||||||
}
|
}
|
||||||
this.AddEntry(new Targeter(targeter), targeter.Address);
|
this.AddEntry(new Targeter(targeter), targeter.Address, ref anyHovered);
|
||||||
}
|
}
|
||||||
if (this.config.KeepHistory) {
|
if (this.config.KeepHistory) {
|
||||||
// only keep the configured number of previous targeters (ignoring ones that are currently targeting)
|
// only keep the configured number of previous targeters (ignoring ones that are currently targeting)
|
||||||
|
@ -301,12 +302,12 @@ namespace PeepingTom {
|
||||||
.ToArray();
|
.ToArray();
|
||||||
// add previous targeters to the list
|
// add previous targeters to the list
|
||||||
foreach (Targeter oldTargeter in previous) {
|
foreach (Targeter oldTargeter in previous) {
|
||||||
this.AddEntry(oldTargeter, null, ImGuiSelectableFlags.Disabled);
|
this.AddEntry(oldTargeter, null, ref anyHovered, ImGuiSelectableFlags.Disabled);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ImGui.ListBoxFooter();
|
ImGui.ListBoxFooter();
|
||||||
}
|
}
|
||||||
if (this.config.FocusTargetOnHover && !ImGui.IsAnyItemHovered() && this.previousFocus != null) {
|
if (this.config.FocusTargetOnHover && !anyHovered && this.previousFocus != null) {
|
||||||
// old focus target still here
|
// old focus target still here
|
||||||
if (this.pi.ClientState.Actors.Any(actor => actor.Address == this.previousFocus)) {
|
if (this.pi.ClientState.Actors.Any(actor => actor.Address == this.previousFocus)) {
|
||||||
this.FocusTarget((IntPtr)this.previousFocus);
|
this.FocusTarget((IntPtr)this.previousFocus);
|
||||||
|
@ -337,11 +338,10 @@ namespace PeepingTom {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AddEntry(Targeter targeter, IntPtr? address, ref bool anyHovered, ImGuiSelectableFlags flags = ImGuiSelectableFlags.None) {
|
||||||
|
|
||||||
private void AddEntry(Targeter targeter, IntPtr? address, ImGuiSelectableFlags flags = ImGuiSelectableFlags.None) {
|
|
||||||
ImGui.Selectable(targeter.Name, false, flags);
|
ImGui.Selectable(targeter.Name, false, flags);
|
||||||
bool hover = ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled);
|
bool hover = ImGui.IsItemHovered(ImGuiHoveredFlags.AllowWhenDisabled);
|
||||||
|
anyHovered |= hover;
|
||||||
bool left = hover && ImGui.IsMouseClicked(0);
|
bool left = hover && ImGui.IsMouseClicked(0);
|
||||||
bool right = hover && ImGui.IsMouseClicked(1);
|
bool right = hover && ImGui.IsMouseClicked(1);
|
||||||
if (address == null) {
|
if (address == null) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user