Skip to content

Commit

Permalink
Improved Conditionals and table appearance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Friendly0Fire committed Aug 20, 2022
1 parent ddf69cf commit 5d72da9
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 53 deletions.
2 changes: 1 addition & 1 deletion GW2Radial/common
25 changes: 17 additions & 8 deletions GW2Radial/src/Wheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,16 +377,24 @@ void Wheel::DrawMenu(Keybind** currentEditedKeybind)

ImGui::Text("Ordering top to bottom is clockwise starting at noon.");

ImGuiHelpTooltip("Show/Use Conditions control the behavior of each menu item depending on current circumstances. The player's state (in combat, on or under water, and in WvW) "
"can be taken into account to modify displayed and usable items. A 'displayed' item is shown in the menu. A 'usable' item is considered to be possible to "
"activate in the current context, but is not necessarily displayed on the radial menu; this can be useful for 'fast mode' utility, e.g. having the Skimmer "
"be the only usable mount underwater and not displaying it, making it hidden in normal play but instantly triggering it when underwater. "
"A 'displayed' but not 'usable' item will be queued (if queuing is enabled) until such a time it is marked as usable.");

if (ImGui::BeginTable("##OrderingTable", 3, ImGuiTableFlags_SizingStretchProp))
ImGuiHelpTooltip({
{ImGuiHelpTooltipElementType::DEFAULT,
"Show/Use Conditions control the behavior of each menu item depending on current circumstances. The character's state (in combat, on or under water, and in WvW) "
"can be taken into account to modify displayed and usable items." },
{ ImGuiHelpTooltipElementType::BULLET, "A \"displayed\" item is shown in the menu." },
{ ImGuiHelpTooltipElementType::BULLET,
"A \"usable\" item is considered to be possible to activate in the current context, but is not necessarily displayed on the radial menu. "
"This can be useful for \"fast mode\", e.g. having the Skimmer be the only usable mount underwater and not displaying it, "
"making it hidden in normal play but instantly triggering it when underwater." },
{ ImGuiHelpTooltipElementType::BULLET, "A \"displayed\" but not \"usable\" item will be queued (if queuing is enabled) until such a time it is marked as usable."}
});

ImGui::PushStyleColor(ImGuiCol_TableRowBg, 0);
ImGui::PushStyleColor(ImGuiCol_TableRowBgAlt, (ImGui::GetColorU32(ImGuiCol_FrameBg) & 0xFFFFFF) | 0x33000000);
if (ImGui::BeginTable("##OrderingTable", 3, ImGuiTableFlags_SizingStretchProp | ImGuiTableFlags_RowBg))
{
ImGui::TableSetupColumn("Show/Use Conditions", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("Name");
ImGui::TableSetupColumn("Show/Use Conditions", ImGuiTableColumnFlags_WidthFixed);
ImGui::TableSetupColumn("##UpDown", ImGuiTableColumnFlags_WidthFixed);

ImGui::TableHeadersRow();
Expand All @@ -410,6 +418,7 @@ void Wheel::DrawMenu(Keybind** currentEditedKeybind)

ImGui::EndTable();
}
ImGui::PopStyleColor(2);

MenuSectionMisc();

Expand Down
95 changes: 51 additions & 44 deletions GW2Radial/src/WheelElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Wheel.h>
#include <WheelElement.h>
#include <common/IconFontCppHeaders/IconsFontAwesome5.h>
#include <imgui_internal.h>

namespace GW2Radial
{
Expand Down Expand Up @@ -42,17 +43,47 @@ int WheelElement::DrawPriority(int extremumIndicator)
ImVec4 col = ToImGui(color_);
ImGui::PushStyleColor(ImGuiCol_Text, col);

auto props = props_.value();
const float realItemSpacing = ImGui::GetStyle().ItemSpacing.x;
constexpr float fontOffset = 5.f;
constexpr float fontMultiplier = 0.6f;
const float realItemSpacing = ImGui::GetStyle().ItemSpacing.x;
auto props = props_.value();

auto previewFmt = [props, realItemSpacing](ConditionalProperties v, ConditionalProperties u, char c) mutable
ImGui::TableNextColumn();
if (!isBound() || props == ConditionalProperties::NONE)
ImGui::PushFont(Core::i().fontItalic());
auto displayName = displayName_;
if (!keybind_.isSet())
displayName += " [No keybind]";
ImGui::TextUnformatted(displayName.c_str());
if (!isBound() || props == ConditionalProperties::NONE)
ImGui::PopFont();

ImGui::TableNextColumn();

static const auto previewMaxDims = []()
{
auto character = ImGui::CalcTextSize("X");
ImGui::PushFont(Core::i().fontIcon());
ImGui::SetWindowFontScale(fontMultiplier);
float iconA = ImGui::CalcTextSize(ICON_FA_CHECK_DOUBLE).x;
float iconB = ImGui::CalcTextSize(ICON_FA_EYE).x;
float iconC = ImGui::CalcTextSize(ICON_FA_HAND_POINTER).x;
ImGui::SetWindowFontScale(1.f);
ImGui::PopFont();

return ImVec2((character.x + std::max({ iconA, iconB, iconC })) * 5 + ImGui::GetStyle().ItemSpacing.x * (2 + 5 - 1), character.y);
}();

auto previewFmt = [props, realItemSpacing](ConditionalProperties v, ConditionalProperties u, char c) mutable
{
if (notNone(props & (v | u)))
{
const float cursorY = ImGui::GetCursorPosY();
ImGui::TextUnformatted(&c, &c + 1);
ImGui::SameLine();
ImGui::PushFont(Core::i().fontIcon());
ImGui::SetWindowFontScale(0.9f);
ImGui::SetCursorPosY(cursorY + fontOffset);
ImGui::SetWindowFontScale(fontMultiplier);
if (notNone(props & v) && notNone(props & u)) // Visible and usable
ImGui::TextUnformatted(ICON_FA_CHECK_DOUBLE);
else if (notNone(props & v) && isNone(props & u)) // Visible but not usable
Expand All @@ -62,39 +93,12 @@ int WheelElement::DrawPriority(int extremumIndicator)
ImGui::SetWindowFontScale(1.f);
ImGui::PopFont();
ImGui::SameLine(0.f, realItemSpacing);
ImGui::SetCursorPosY(cursorY);
}
};

ImGui::TableNextColumn();
float cursorX = ImGui::GetCursorPosX();

ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetStyle().ItemSpacing.x);

ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.f, 0.f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0.f, 0.f));
previewFmt(ConditionalProperties::VISIBLE_DEFAULT, ConditionalProperties::USABLE_DEFAULT, 'D');
previewFmt(ConditionalProperties::VISIBLE_IN_COMBAT, ConditionalProperties::USABLE_IN_COMBAT, 'C');
previewFmt(ConditionalProperties::VISIBLE_UNDERWATER, ConditionalProperties::USABLE_UNDERWATER, 'U');
previewFmt(ConditionalProperties::VISIBLE_ON_WATER, ConditionalProperties::USABLE_ON_WATER, 'O');
previewFmt(ConditionalProperties::VISIBLE_WVW, ConditionalProperties::USABLE_WVW, 'W');
ImGui::PopStyleVar(2);

static const float previewMaxWidth = []()
{
float character = ImGui::CalcTextSize("X").x;
ImGui::PushFont(Core::i().fontIcon());
ImGui::SetWindowFontScale(0.9f);
float iconA = ImGui::CalcTextSize(ICON_FA_CHECK_DOUBLE).x;
float iconB = ImGui::CalcTextSize(ICON_FA_EYE).x;
float iconC = ImGui::CalcTextSize(ICON_FA_HAND_POINTER).x;
ImGui::SetWindowFontScale(1.f);
ImGui::PopFont();

return (character + std::max({ iconA, iconB, iconC })) * 5 + ImGui::GetStyle().ItemSpacing.x * (2 + 4 - 1);
}();
ImGui::SetCursorPosX(cursorX + previewMaxWidth);

if (ImGui::BeginCombo(("##ConditionalProps" + nickname_).c_str(), nullptr, ImGuiComboFlags_NoPreview))
ImGui::SetNextItemWidth(ImGui::GetFrameHeight() + previewMaxDims.x);
if (ImGui::BeginCombo(("##ConditionalProps" + nickname_).c_str(), nullptr, ImGuiComboFlags_CustomPreview))
{
auto chk = [&props, suffix = "##" + nickname_](ConditionalProperties p, const char* display)
{
Expand All @@ -120,20 +124,23 @@ int WheelElement::DrawPriority(int extremumIndicator)

ImGui::EndCombo();
}
if (ImGui::BeginComboPreview())
{
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.f, 0.f));
ImGui::PushStyleVar(ImGuiStyleVar_ItemInnerSpacing, ImVec2(0.f, 0.f));
previewFmt(ConditionalProperties::VISIBLE_DEFAULT, ConditionalProperties::USABLE_DEFAULT, 'D');
previewFmt(ConditionalProperties::VISIBLE_IN_COMBAT, ConditionalProperties::USABLE_IN_COMBAT, 'C');
previewFmt(ConditionalProperties::VISIBLE_UNDERWATER, ConditionalProperties::USABLE_UNDERWATER, 'U');
previewFmt(ConditionalProperties::VISIBLE_ON_WATER, ConditionalProperties::USABLE_ON_WATER, 'O');
previewFmt(ConditionalProperties::VISIBLE_WVW, ConditionalProperties::USABLE_WVW, 'W');
ImGui::PopStyleVar(2);

ImGui::EndComboPreview();
}

if (props != props_.value())
props_.value(props);

ImGui::TableNextColumn();
if (!isBound() || props == ConditionalProperties::NONE)
ImGui::PushFont(Core::i().fontItalic());
auto displayName = displayName_;
if (!keybind_.isSet())
displayName += " [No keybind]";
ImGui::TextUnformatted(displayName.c_str());
if (!isBound() || props == ConditionalProperties::NONE)
ImGui::PopFont();

ImGui::PushFont(Core::i().fontIcon());

int rv = 0;
Expand Down

0 comments on commit 5d72da9

Please sign in to comment.