mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 15:08:19 +00:00
Merge #3018
3018: Editor: Improve usability of server settings r=Jupeyy a=def- - Add Mod button - Show Del button only when it makes sense - Update command input text when clicking on an existing command - Make command clearable As requested by Cøke Co-authored-by: def <dennis@felsin9.de>
This commit is contained in:
commit
ce9ba5ec09
|
@ -302,6 +302,28 @@ void CEditor::EnvelopeEval(int TimeOffsetMillis, int Env, float *pChannels, void
|
|||
OTHER
|
||||
*********************************************************/
|
||||
|
||||
int CEditor::DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners)
|
||||
{
|
||||
bool ReturnValue = false;
|
||||
CUIRect EditBox;
|
||||
CUIRect ClearButton;
|
||||
pRect->VSplitRight(15.0f, &EditBox, &ClearButton);
|
||||
if(DoEditBox(pID, &EditBox, pStr, StrSize, FontSize, Offset, Hidden, Corners & ~CUI::CORNER_R))
|
||||
{
|
||||
ReturnValue = true;
|
||||
}
|
||||
|
||||
RenderTools()->DrawUIRect(&ClearButton, ColorRGBA(1, 1, 1, 0.33f * ButtonColorMul(pClearID)), Corners & ~CUI::CORNER_L, 3.0f);
|
||||
UI()->DoLabel(&ClearButton, "×", ClearButton.h * 0.8f, 0);
|
||||
if(UI()->DoButtonLogic(pClearID, "×", 0, &ClearButton))
|
||||
{
|
||||
pStr[0] = 0;
|
||||
UI()->SetActiveItem(pID);
|
||||
ReturnValue = true;
|
||||
}
|
||||
return ReturnValue;
|
||||
}
|
||||
|
||||
// copied from gc_menu.cpp, should be more generalized
|
||||
//extern int ui_do_edit_box(void *id, const CUIRect *rect, char *str, int str_size, float font_size, bool hidden=false);
|
||||
int CEditor::DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners)
|
||||
|
@ -5492,7 +5514,7 @@ void CEditor::RenderEnvelopeEditor(CUIRect View)
|
|||
}
|
||||
}
|
||||
|
||||
void CEditor::RenderServerSettingsEditor(CUIRect View)
|
||||
void CEditor::RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEditorLast)
|
||||
{
|
||||
static int s_CommandSelectedIndex = -1;
|
||||
|
||||
|
@ -5510,7 +5532,11 @@ void CEditor::RenderServerSettingsEditor(CUIRect View)
|
|||
|
||||
Button.VSplitLeft(70.0f, 0, &Button);
|
||||
Button.VSplitLeft(180.0f, &Button, 0);
|
||||
DoEditBox(&m_CommandBox, &Button, m_aSettingsCommand, sizeof(m_aSettingsCommand), 12.0f, &m_CommandBox);
|
||||
static int s_ClearButton = 0;
|
||||
DoClearableEditBox(&m_CommandBox, &s_ClearButton, &Button, m_aSettingsCommand, sizeof(m_aSettingsCommand), 12.0f, &m_CommandBox, false, CUI::CORNER_ALL);
|
||||
|
||||
if(!ShowServerSettingsEditorLast) // Just activated
|
||||
UI()->SetActiveItem(&m_CommandBox);
|
||||
|
||||
// buttons
|
||||
ToolBar.VSplitRight(50.0f, &ToolBar, &Button);
|
||||
|
@ -5532,18 +5558,54 @@ void CEditor::RenderServerSettingsEditor(CUIRect View)
|
|||
CEditorMap::CSetting Setting;
|
||||
str_copy(Setting.m_aCommand, m_aSettingsCommand, sizeof(Setting.m_aCommand));
|
||||
m_Map.m_lSettings.add(Setting);
|
||||
s_CommandSelectedIndex = m_Map.m_lSettings.size() - 1;
|
||||
}
|
||||
}
|
||||
UI()->SetActiveItem(&m_CommandBox);
|
||||
}
|
||||
|
||||
if(m_Map.m_lSettings.size())
|
||||
if(m_Map.m_lSettings.size() && s_CommandSelectedIndex > -1 && s_CommandSelectedIndex < m_Map.m_lSettings.size())
|
||||
{
|
||||
ToolBar.VSplitRight(50.0f, &ToolBar, &Button);
|
||||
Button.VSplitRight(5.0f, &Button, 0);
|
||||
static int s_ModButton = 0;
|
||||
if(DoButton_Editor(&s_ModButton, "Mod", 0, &Button, 0, "Modify a command from the command list.") || (Input()->KeyPress(KEY_M) && UI()->LastActiveItem() != &m_CommandBox))
|
||||
{
|
||||
if(str_comp(m_Map.m_lSettings[s_CommandSelectedIndex].m_aCommand, m_aSettingsCommand) != 0 && m_aSettingsCommand[0] != 0 && str_find(m_aSettingsCommand, " "))
|
||||
{
|
||||
bool Found = false;
|
||||
int i;
|
||||
for(i = 0; i < m_Map.m_lSettings.size(); i++)
|
||||
if(i != s_CommandSelectedIndex && !str_comp(m_Map.m_lSettings[i].m_aCommand, m_aSettingsCommand))
|
||||
{
|
||||
Found = true;
|
||||
break;
|
||||
}
|
||||
if(Found)
|
||||
{
|
||||
m_Map.m_lSettings.remove_index(s_CommandSelectedIndex);
|
||||
s_CommandSelectedIndex = i > s_CommandSelectedIndex ? i - 1 : i;
|
||||
}
|
||||
else
|
||||
{
|
||||
str_copy(m_Map.m_lSettings[s_CommandSelectedIndex].m_aCommand, m_aSettingsCommand, sizeof(m_Map.m_lSettings[s_CommandSelectedIndex].m_aCommand));
|
||||
}
|
||||
}
|
||||
UI()->SetActiveItem(&m_CommandBox);
|
||||
}
|
||||
|
||||
ToolBar.VSplitRight(50.0f, &ToolBar, &Button);
|
||||
Button.VSplitRight(5.0f, &Button, 0);
|
||||
static int s_DelButton = 0;
|
||||
if(DoButton_Editor(&s_DelButton, "Del", 0, &Button, 0, "Delete a command from the command list.") || (Input()->KeyPress(KEY_DELETE) && UI()->LastActiveItem() != &m_CommandBox))
|
||||
if(s_CommandSelectedIndex > -1 && s_CommandSelectedIndex < m_Map.m_lSettings.size())
|
||||
{
|
||||
m_Map.m_lSettings.remove_index(s_CommandSelectedIndex);
|
||||
if(s_CommandSelectedIndex >= m_Map.m_lSettings.size())
|
||||
s_CommandSelectedIndex = m_Map.m_lSettings.size() - 1;
|
||||
if(s_CommandSelectedIndex >= 0)
|
||||
str_copy(m_aSettingsCommand, m_Map.m_lSettings[s_CommandSelectedIndex].m_aCommand, sizeof(m_aSettingsCommand));
|
||||
UI()->SetActiveItem(&m_CommandBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5603,7 +5665,11 @@ void CEditor::RenderServerSettingsEditor(CUIRect View)
|
|||
Button.VSplitLeft(5.0f, 0, &Button);
|
||||
|
||||
if(DoButton_MenuItem(&m_Map.m_lSettings[i], m_Map.m_lSettings[i].m_aCommand, s_CommandSelectedIndex == i, &Button, 0, 0))
|
||||
{
|
||||
s_CommandSelectedIndex = i;
|
||||
str_copy(m_aSettingsCommand, m_Map.m_lSettings[i].m_aCommand, sizeof(m_aSettingsCommand));
|
||||
UI()->SetActiveItem(&m_CommandBox);
|
||||
}
|
||||
}
|
||||
ListCur += 17.0f;
|
||||
}
|
||||
|
@ -6044,8 +6110,12 @@ void CEditor::Render()
|
|||
RenderEnvelopeEditor(ExtraEditor);
|
||||
if(m_ShowUndo)
|
||||
RenderUndoList(UndoList);
|
||||
static bool s_ShowServerSettingsEditorLast = false;
|
||||
if(m_ShowServerSettingsEditor)
|
||||
RenderServerSettingsEditor(ExtraEditor);
|
||||
{
|
||||
RenderServerSettingsEditor(ExtraEditor, s_ShowServerSettingsEditorLast);
|
||||
}
|
||||
s_ShowServerSettingsEditorLast = m_ShowServerSettingsEditor;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -967,6 +967,7 @@ public:
|
|||
|
||||
int DoButton_ColorPicker(const void *pID, const CUIRect *pRect, ColorRGBA *pColor, const char *pToolTip = 0);
|
||||
|
||||
int DoClearableEditBox(void *pID, void *pClearID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden, int Corners);
|
||||
int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *Offset, bool Hidden = false, int Corners = CUI::CORNER_ALL);
|
||||
|
||||
void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness);
|
||||
|
@ -1049,7 +1050,7 @@ public:
|
|||
void RenderStatusbar(CUIRect View);
|
||||
void RenderEnvelopeEditor(CUIRect View);
|
||||
void RenderUndoList(CUIRect View);
|
||||
void RenderServerSettingsEditor(CUIRect View);
|
||||
void RenderServerSettingsEditor(CUIRect View, bool ShowServerSettingsEditorLast);
|
||||
|
||||
void RenderMenubar(CUIRect Menubar);
|
||||
void RenderFileDialog();
|
||||
|
|
Loading…
Reference in a new issue