Avoid crashing when clicking Choose with no item selected

Also "Disabled" (darkened) the choose button if no item is selected.
This commit is contained in:
Cara 2020-05-03 23:39:37 +09:30
parent 8072f91f51
commit eafe992f4a

View file

@ -186,15 +186,23 @@ namespace Dalamud.Interface
ImGui.EndChild(); ImGui.EndChild();
if (ImGui.Button(Loc.Localize("Choose", "Choose"))) { // Darken choose button if it shouldn't be clickable
OnItemChosen?.Invoke(this, this.searchTask.Result[this.selectedItemIndex]); ImGui.PushStyleVar(ImGuiStyleVar.Alpha, this.selectedItemIndex < 0 ? 0.25f : 1);
if (this.closeOnChoose) { if (ImGui.Button(Loc.Localize("Choose", "Choose"))) {
this.selectedItemTex?.Dispose(); try {
isOpen = false; 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) { if (!this.closeOnChoose) {
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button(Loc.Localize("Close", "Close"))) if (ImGui.Button(Loc.Localize("Close", "Close")))