Skip to content

Commit

Permalink
Merge pull request ddnet#9003 from Robyt3/Editor-Prompt-Fix
Browse files Browse the repository at this point in the history
Fix some editor quick actions not being clickable, small refactoring
  • Loading branch information
def- authored Sep 20, 2024
2 parents b6f80e5 + 7b64152 commit 034e497
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/game/editor/prompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ void CPrompt::OnRender(CUIRect _)

if(m_PromptInput.IsEmpty() || FuzzyMatch(pQuickAction->Label(), m_PromptInput.GetString()))
{
bool Skip = false;
if(m_ResetFilterResults)
if(pQuickAction == m_pLastAction)
Skip = true;
if(!Skip)
if(!m_ResetFilterResults || pQuickAction != m_pLastAction)
m_vpFilteredPromptList.push_back(pQuickAction);
}
}
Expand All @@ -130,25 +126,23 @@ void CPrompt::OnRender(CUIRect _)

for(size_t i = 0; i < m_vpFilteredPromptList.size(); i++)
{
const CListboxItem Item = s_ListBox.DoNextItem(m_vpFilteredPromptList[i], m_PromptSelectedIndex >= 0 && (size_t)m_PromptSelectedIndex == i);
const CListboxItem Item = s_ListBox.DoNextItem(m_vpFilteredPromptList[i]->ActionButtonId(), m_PromptSelectedIndex >= 0 && (size_t)m_PromptSelectedIndex == i);
if(!Item.m_Visible)
continue;

CUIRect LabelColumn, DescColumn;
float Margin = 5.0f;
Item.m_Rect.VSplitLeft(Margin, nullptr, &LabelColumn);
Item.m_Rect.VMargin(Margin, &LabelColumn);
LabelColumn.VSplitLeft(LabelWidth, &LabelColumn, &DescColumn);
DescColumn.VSplitRight(Margin, &DescColumn, nullptr);
DescColumn.VSplitLeft(Margin, nullptr, &DescColumn);

SLabelProperties Props;
Props.m_MaxWidth = LabelColumn.w;
Props.m_EllipsisAtEnd = true;
Ui()->DoLabel(&LabelColumn, m_vpFilteredPromptList[i]->Label(), 10.0f, TEXTALIGN_ML, Props);

Props.m_MaxWidth = DescColumn.w;
ColorRGBA DescColor = TextRender()->DefaultTextColor();
DescColor.a = Item.m_Selected ? 1.0f : 0.8f;
TextRender()->TextColor(DescColor);
TextRender()->TextColor(TextRender()->DefaultTextColor().WithAlpha(Item.m_Selected ? 1.0f : 0.8f));
Ui()->DoLabel(&DescColumn, m_vpFilteredPromptList[i]->Description(), 10.0f, TEXTALIGN_MR, Props);
TextRender()->TextColor(TextRender()->DefaultTextColor());
}
Expand Down
4 changes: 4 additions & 0 deletions src/game/editor/quick_action.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CQuickAction
FButtonActiveCallback m_pfnActiveCallback;
FButtonColorCallback m_pfnColorCallback;

const char m_ActionButtonId = 0;

public:
CQuickAction(
const char *pLabel,
Expand Down Expand Up @@ -64,6 +66,8 @@ class CQuickAction
}

const char *Description() const { return m_pDescription; }

const void *ActionButtonId() const { return &m_ActionButtonId; }
};

#endif

0 comments on commit 034e497

Please sign in to comment.