feat(housing): allow dragging to reorder bookmarks
This commit is contained in:
parent
43fc2223b7
commit
6364c4fc5e
|
@ -21,5 +21,13 @@ namespace RoleplayersToolbox.Tools.Housing {
|
||||||
Plot = this.Plot,
|
Plot = this.Plot,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal bool AnyZero() {
|
||||||
|
return this.Name == string.Empty
|
||||||
|
|| this.WorldId == 0
|
||||||
|
|| this.Area == 0
|
||||||
|
|| this.Ward == 0
|
||||||
|
|| this.Plot == 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace RoleplayersToolbox.Tools.Housing {
|
||||||
private HousingTool Tool { get; }
|
private HousingTool Tool { get; }
|
||||||
private HousingConfig Config { get; }
|
private HousingConfig Config { get; }
|
||||||
internal (Bookmark editing, int index)? Editing;
|
internal (Bookmark editing, int index)? Editing;
|
||||||
|
private int _dragging = -1;
|
||||||
|
|
||||||
internal bool ShouldDraw;
|
internal bool ShouldDraw;
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ namespace RoleplayersToolbox.Tools.Housing {
|
||||||
|
|
||||||
var toDelete = -1;
|
var toDelete = -1;
|
||||||
|
|
||||||
|
(int src, int dst)? drag = null;
|
||||||
if (ImGui.BeginChild("bookmark-list", new Vector2(-1, -1))) {
|
if (ImGui.BeginChild("bookmark-list", new Vector2(-1, -1))) {
|
||||||
for (var i = 0; i < this.Config.Bookmarks.Count; i++) {
|
for (var i = 0; i < this.Config.Bookmarks.Count; i++) {
|
||||||
var bookmark = this.Config.Bookmarks[i];
|
var bookmark = this.Config.Bookmarks[i];
|
||||||
|
@ -85,12 +87,40 @@ namespace RoleplayersToolbox.Tools.Housing {
|
||||||
ImGui.TreePop();
|
ImGui.TreePop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui.IsItemActive() || this._dragging == i) {
|
||||||
|
this._dragging = i;
|
||||||
|
var step = 0;
|
||||||
|
if (ImGui.GetIO().MouseDelta.Y < 0 && ImGui.GetMousePos().Y < ImGui.GetItemRectMin().Y) {
|
||||||
|
step = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui.GetIO().MouseDelta.Y > 0 && ImGui.GetMousePos().Y > ImGui.GetItemRectMax().Y) {
|
||||||
|
step = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (step != 0) {
|
||||||
|
drag = (i, i + step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.EndChild();
|
ImGui.EndChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ImGui.IsMouseDown(ImGuiMouseButton.Left) && this._dragging != -1) {
|
||||||
|
this._dragging = -1;
|
||||||
|
this.Plugin.SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drag != null && drag.Value.dst < this.Config.Bookmarks.Count && drag.Value.dst >= 0) {
|
||||||
|
this._dragging = drag.Value.dst;
|
||||||
|
var temp = this.Config.Bookmarks[drag.Value.src];
|
||||||
|
this.Config.Bookmarks[drag.Value.src] = this.Config.Bookmarks[drag.Value.dst];
|
||||||
|
this.Config.Bookmarks[drag.Value.dst] = temp;
|
||||||
|
}
|
||||||
|
|
||||||
if (toDelete > -1) {
|
if (toDelete > -1) {
|
||||||
this.Config.Bookmarks.RemoveAt(toDelete);
|
this.Config.Bookmarks.RemoveAt(toDelete);
|
||||||
this.Plugin.SaveConfig();
|
this.Plugin.SaveConfig();
|
||||||
|
@ -157,7 +187,7 @@ namespace RoleplayersToolbox.Tools.Housing {
|
||||||
bookmark.Plot = (uint) Math.Max(1, Math.Min(60, plot));
|
bookmark.Plot = (uint) Math.Max(1, Math.Min(60, plot));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui.Button("Save")) {
|
if (ImGui.Button("Save") && !bookmark.AnyZero()) {
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
this.Config.Bookmarks.Add(bookmark);
|
this.Config.Bookmarks.Add(bookmark);
|
||||||
} else if (index < this.Config.Bookmarks.Count) {
|
} else if (index < this.Config.Bookmarks.Count) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user