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