Merge pull request #129 from Caraxi/remove-xlitem

Remove /xlitem
This commit is contained in:
goaaats 2020-06-15 11:17:39 +02:00 committed by GitHub
commit 9872a9fe0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 273 deletions

View file

@ -4,7 +4,6 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@ -16,17 +15,12 @@ using Dalamud.Game;
using Dalamud.Game.Chat;
using Dalamud.Game.Chat.SeStringHandling;
using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
using Dalamud.Game.Command;
using Dalamud.Game.Internal;
using Dalamud.Game.Internal.Gui;
using Dalamud.Game.Network;
using Dalamud.Interface;
using Dalamud.Plugin;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
using Serilog;
using Serilog.Core;
using Serilog.Events;
@ -380,17 +374,6 @@ namespace Dalamud {
this.isImguiDrawPluginWindow = this.pluginWindow != null && this.pluginWindow.Draw();
}
if (this.isImguiDrawItemSearchWindow)
{
this.isImguiDrawItemSearchWindow = this.itemSearchCommandWindow != null && this.itemSearchCommandWindow.Draw();
if (this.isImguiDrawItemSearchWindow == false)
{
this.itemSearchCommandWindow?.Dispose();
this.itemSearchCommandWindow = null;
}
}
if (this.isImguiDrawCreditsWindow)
{
this.isImguiDrawCreditsWindow = this.creditsWindow != null && this.creditsWindow.Draw();
@ -475,11 +458,6 @@ namespace Dalamud {
HelpMessage = Loc.Localize("DalamudBgmSetHelp", "Set the Game background music. Usage: /xlbgmset <BGM ID>")
});
CommandManager.AddHandler("/xlitem", new CommandInfo(OnItemLinkCommand)
{
HelpMessage = Loc.Localize("DalamudItemLinkHelp", "Open a window you can use to link any specific item to chat.")
});
#if DEBUG
CommandManager.AddHandler("/xldzpi", new CommandInfo(OnDebugZoneDownInjectCommand)
{
@ -640,22 +618,6 @@ namespace Dalamud {
Framework.Gui.SetBgm(ushort.Parse(arguments));
}
private ItemSearchWindow itemSearchCommandWindow;
private bool isImguiDrawItemSearchWindow;
private void OnItemLinkCommand(string command, string arguments)
{
this.itemSearchCommandWindow = new ItemSearchWindow(this.Data, new UiBuilder(this.InterfaceManager, "ItemSearcher"), false, arguments);
this.itemSearchCommandWindow.OnItemChosen += (sender, item) =>
{
this.Framework.Gui.Chat.PrintChat(new XivChatEntry
{
MessageBytes = SeStringUtils.CreateItemLink(item, false).Encode()
});
};
this.isImguiDrawItemSearchWindow = true;
}
#if DEBUG
private void OnDebugZoneDownInjectCommand(string command, string arguments) {
var data = File.ReadAllBytes(arguments);

View file

@ -1,235 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Net.Mime;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CheapLoc;
using Dalamud.Data;
using Dalamud.Data.LuminaExtensions;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
using ImGuiNET;
using ImGuiScene;
using Lumina.Excel.GeneratedSheets;
using Serilog;
using Item = Dalamud.Data.TransientSheet.Item;
namespace Dalamud.Interface
{
class ItemSearchWindow : IDisposable
{
private readonly DataManager data;
private readonly UiBuilder builder;
private readonly bool closeOnChoose;
private string lastSearchText = string.Empty;
private string searchText = string.Empty;
private int lastKind = 0;
private int currentKind = 0;
private int selectedItemIndex = -1;
private TextureWrap selectedItemTex;
private CancellationTokenSource searchCancelTokenSource;
private ValueTask<List<Item>> searchTask;
private List<Item> luminaItems;
public event EventHandler<Item> OnItemChosen;
public ItemSearchWindow(DataManager data, UiBuilder builder, bool closeOnChoose = true, string searchText = "") {
this.data = data;
this.builder = builder;
this.closeOnChoose = closeOnChoose;
this.searchText = searchText;
while (!data.IsDataReady)
Thread.Sleep(1);
Task.Run(() => this.data.GetExcelSheet<Item>().GetRows()).ContinueWith(t => this.luminaItems = t.Result);
}
public bool Draw() {
ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.FirstUseEver);
var isOpen = true;
if (!ImGui.Begin(Loc.Localize("DalamudItemSelectHeader", "Select an item"), ref isOpen, ImGuiWindowFlags.NoCollapse))
{
ImGui.End();
return false;
}
// Main window
ImGui.AlignTextToFramePadding();
ImGui.Text(Loc.Localize("DalamudItemSelect", "Please select an item."));
if (this.selectedItemTex != null) {
ImGui.Text(" ");
ImGui.SetCursorPosY(200f);
ImGui.SameLine();
ImGui.Image(this.selectedItemTex.ImGuiHandle, new Vector2(40, 40));
} else {
ImGui.Text(" ");
}
ImGui.Separator();
ImGui.Text(Loc.Localize("DalamudItemSearchVerb", "Search: "));
ImGui.SameLine();
ImGui.InputText("##searchbox", ref this.searchText, 32);
var kinds = new List<string> {Loc.Localize("DalamudItemSelectAll", "All")};
kinds.AddRange(this.data.GetExcelSheet<ItemUICategory>().GetRows().Where(x => !string.IsNullOrEmpty(x.Name)).Select(x => x.Name.Replace("\u0002\u001F\u0001\u0003", "-")));
ImGui.Text(Loc.Localize("DalamudItemSelectCategory", "Category: "));
ImGui.SameLine();
ImGui.Combo("##kindbox", ref this.currentKind, kinds.ToArray(),
kinds.Count);
var windowSize = ImGui.GetWindowSize();
ImGui.BeginChild("scrolling", new Vector2(0, windowSize.Y - ImGui.GetCursorPosY() - 40), true, ImGuiWindowFlags.HorizontalScrollbar);
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
if (this.luminaItems != null) {
if (!string.IsNullOrEmpty(this.searchText) || this.currentKind != 0)
{
if (this.lastSearchText != this.searchText || this.lastKind != this.currentKind)
{
this.lastSearchText = this.searchText;
this.lastKind = this.currentKind;
this.searchCancelTokenSource?.Cancel();
this.searchCancelTokenSource = new CancellationTokenSource();
var asyncEnum = this.luminaItems.ToAsyncEnumerable();
if (!string.IsNullOrEmpty(this.searchText))
{
Log.Debug("Searching for " + this.searchText);
asyncEnum = asyncEnum.Where(
x => (x.Name.ToLower().Contains(this.searchText.ToLower()) ||
int.TryParse(this.searchText, out var parsedId) &&
parsedId == x.RowId) && x.Icon < 65000);
}
if (this.currentKind != 0)
{
Log.Debug("Searching for C" + this.currentKind);
asyncEnum = asyncEnum.Where(x => x.ItemUICategory == this.currentKind);
}
this.selectedItemIndex = -1;
this.selectedItemTex?.Dispose();
this.selectedItemTex = null;
this.searchTask = asyncEnum.ToListAsync(this.searchCancelTokenSource.Token);
}
if (this.searchTask.IsCompletedSuccessfully)
{
for (var i = 0; i < this.searchTask.Result.Count; i++)
{
if (ImGui.Selectable(this.searchTask.Result[i].Name, this.selectedItemIndex == i, ImGuiSelectableFlags.AllowDoubleClick))
{
this.selectedItemIndex = i;
try
{
var iconTex = this.data.GetIcon(this.searchTask.Result[i].Icon);
this.selectedItemTex?.Dispose();
this.selectedItemTex =
this.builder.LoadImageRaw(iconTex.GetRgbaImageData(), iconTex.Header.Width,
iconTex.Header.Height, 4);
} catch (Exception ex)
{
Log.Error(ex, "Failed loading item texture");
this.selectedItemTex?.Dispose();
this.selectedItemTex = null;
}
if (ImGui.IsMouseDoubleClicked(0))
{
if (this.selectedItemTex != null){
OnItemChosen?.Invoke(this, this.searchTask.Result[i]);
if (this.closeOnChoose)
{
this.selectedItemTex?.Dispose();
isOpen = false;
}
}
}
}
}
}
}
else
{
ImGui.TextColored(new Vector4(0.86f, 0.86f, 0.86f, 1.00f), Loc.Localize("DalamudItemSelectHint", "Type to start searching..."));
this.selectedItemIndex = -1;
this.selectedItemTex?.Dispose();
this.selectedItemTex = null;
}
} else {
ImGui.TextColored(new Vector4(0.86f, 0.86f, 0.86f, 1.00f), Loc.Localize("DalamudItemSelectLoading", "Loading item list..."));
}
ImGui.PopStyleVar();
ImGui.EndChild();
// Darken choose button if it shouldn't be clickable
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, this.selectedItemIndex < 0 || this.selectedItemTex == null ? 0.25f : 1);
if (ImGui.Button(Loc.Localize("Choose", "Choose"))) {
try {
if (this.selectedItemTex != null) {
OnItemChosen?.Invoke(this, this.searchTask.Result[this.selectedItemIndex]);
if (this.closeOnChoose) {
this.selectedItemTex?.Dispose();
isOpen = false;
}
}
} catch (Exception ex) {
Log.Error($"Exception in Choose: {ex.Message}");
}
}
ImGui.PopStyleVar();
if (!this.closeOnChoose) {
ImGui.SameLine();
if (ImGui.Button(Loc.Localize("Close", "Close")))
{
this.selectedItemTex?.Dispose();
isOpen = false;
}
}
if (this.selectedItemIndex >= 0 && this.selectedItemTex == null) {
ImGui.SameLine();
ImGui.Text(Loc.Localize("DalamudItemNotLinkable", "This item is not linkable."));
}
ImGui.End();
return isOpen;
}
public void Dispose() {
this.selectedItemTex?.Dispose();
}
}
}