Refactor CEditor::PopupEvent and improve layout

Swap buttons so confirm button is on the right and cancel button is on the left consistently.

Decrease empty space and popup size.

Add missing title for `POPEVENT_LOADCURRENT` (caught by the added assertion).

Improve messages by adding additional empty line for existing line breaks.
This commit is contained in:
Robert Müller 2023-04-01 13:43:37 +02:00
parent 91ce99b65b
commit b20cf7865c
2 changed files with 75 additions and 55 deletions

View file

@ -6352,8 +6352,10 @@ void CEditor::Render()
if(m_PopupEventActivated) if(m_PopupEventActivated)
{ {
static int s_PopupID = 0; static int s_PopupEventId;
UiInvokePopupMenu(&s_PopupID, 0, Width / 2.0f - 200.0f, Height / 2.0f - 100.0f, 400.0f, 200.0f, PopupEvent); constexpr float PopupWidth = 400.0f;
constexpr float PopupHeight = 150.0f;
UiInvokePopupMenu(&s_PopupEventId, 0, Width / 2.0f - PopupWidth / 2.0f, Height / 2.0f - PopupHeight / 2.0f, PopupWidth, PopupHeight, PopupEvent);
m_PopupEventActivated = false; m_PopupEventActivated = false;
m_PopupEventWasActivated = true; m_PopupEventWasActivated = true;
} }

View file

@ -1487,63 +1487,90 @@ int CEditor::PopupMapInfo(CEditor *pEditor, CUIRect View, void *pContext)
int CEditor::PopupEvent(CEditor *pEditor, CUIRect View, void *pContext) int CEditor::PopupEvent(CEditor *pEditor, CUIRect View, void *pContext)
{ {
CUIRect Label, ButtonBar; const char *pTitle;
const char *pMessage;
// title
View.HSplitTop(10.0f, nullptr, &View);
View.HSplitTop(30.0f, &Label, &View);
if(pEditor->m_PopupEventType == POPEVENT_EXIT) if(pEditor->m_PopupEventType == POPEVENT_EXIT)
pEditor->UI()->DoLabel(&Label, "Exit the editor", 20.0f, TEXTALIGN_CENTER); {
else if(pEditor->m_PopupEventType == POPEVENT_LOAD) pTitle = "Exit the editor";
pEditor->UI()->DoLabel(&Label, "Load map", 20.0f, TEXTALIGN_CENTER); pMessage = "The map contains unsaved data, you might want to save it before you exit the editor.\n\nContinue anyway?";
}
else if(pEditor->m_PopupEventType == POPEVENT_LOAD || pEditor->m_PopupEventType == POPEVENT_LOADCURRENT)
{
pTitle = "Load map";
pMessage = "The map contains unsaved data, you might want to save it before you load a new map.\n\nContinue anyway?";
}
else if(pEditor->m_PopupEventType == POPEVENT_NEW) else if(pEditor->m_PopupEventType == POPEVENT_NEW)
pEditor->UI()->DoLabel(&Label, "New map", 20.0f, TEXTALIGN_CENTER); {
pTitle = "New map";
pMessage = "The map contains unsaved data, you might want to save it before you create a new map.\n\nContinue anyway?";
}
else if(pEditor->m_PopupEventType == POPEVENT_SAVE) else if(pEditor->m_PopupEventType == POPEVENT_SAVE)
pEditor->UI()->DoLabel(&Label, "Save map", 20.0f, TEXTALIGN_CENTER); {
pTitle = "Save map";
pMessage = "The file already exists.\n\nDo you want to overwrite the map?";
}
else if(pEditor->m_PopupEventType == POPEVENT_LARGELAYER) else if(pEditor->m_PopupEventType == POPEVENT_LARGELAYER)
pEditor->UI()->DoLabel(&Label, "Large layer", 20.0f, TEXTALIGN_CENTER); {
pTitle = "Large layer";
pMessage = "You are trying to set the height or width of a layer to more than 1000 tiles. This is actually possible, but only rarely necessary. It may cause the editor to work slower and will result in a larger file size as well as higher memory usage for client and server.";
}
else if(pEditor->m_PopupEventType == POPEVENT_PREVENTUNUSEDTILES) else if(pEditor->m_PopupEventType == POPEVENT_PREVENTUNUSEDTILES)
pEditor->UI()->DoLabel(&Label, "Unused tiles disabled", 20.0f, TEXTALIGN_CENTER); {
pTitle = "Unused tiles disabled";
pMessage = "Unused tiles can't be placed by default because they could get a use later and then destroy your map.\n\nActivate the 'Unused' switch to be able to place every tile.";
}
else if(pEditor->m_PopupEventType == POPEVENT_IMAGEDIV16) else if(pEditor->m_PopupEventType == POPEVENT_IMAGEDIV16)
pEditor->UI()->DoLabel(&Label, "Image width/height", 20.0f, TEXTALIGN_CENTER); {
pTitle = "Image width/height";
pMessage = "The width or height of this image is not divisible by 16. This is required for images used in tile layers.";
}
else if(pEditor->m_PopupEventType == POPEVENT_IMAGE_MAX) else if(pEditor->m_PopupEventType == POPEVENT_IMAGE_MAX)
pEditor->UI()->DoLabel(&Label, "Max images", 20.0f, TEXTALIGN_CENTER); {
pTitle = "Max images";
pMessage = "The client only allows a maximum of 64 images.";
}
else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES) else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES)
pEditor->UI()->DoLabel(&Label, "Place border tiles", 20.0f, TEXTALIGN_CENTER); {
pTitle = "Place border tiles";
pMessage = "This is going to overwrite any existing tiles around the edges of the layer.\n\nContinue?";
}
else
{
dbg_assert(false, "m_PopupEventType invalid");
return 1;
}
View.HSplitBottom(10.0f, &View, nullptr); CUIRect Label, ButtonBar, Button;
View.Margin(10.0f, &View);
View.HSplitBottom(20.0f, &View, &ButtonBar); View.HSplitBottom(20.0f, &View, &ButtonBar);
// notification text // title
View.HSplitTop(30.0f, nullptr, &View); View.HSplitTop(20.0f, &Label, &View);
View.VMargin(40.0f, &View); pEditor->UI()->DoLabel(&Label, pTitle, 20.0f, TEXTALIGN_CENTER);
View.HSplitTop(10.0f, nullptr, &View);
// message
View.HSplitTop(20.0f, &Label, &View); View.HSplitTop(20.0f, &Label, &View);
SLabelProperties Props; SLabelProperties Props;
Props.m_MaxWidth = Label.w - 10.0f; Props.m_MaxWidth = Label.w;
if(pEditor->m_PopupEventType == POPEVENT_EXIT) pEditor->UI()->DoLabel(&Label, pMessage, 10.0f, TEXTALIGN_LEFT, Props);
pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you exit the editor.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Props);
else if((pEditor->m_PopupEventType == POPEVENT_LOAD) || (pEditor->m_PopupEventType == POPEVENT_LOADCURRENT))
pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you load a new map.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Props);
else if(pEditor->m_PopupEventType == POPEVENT_NEW)
pEditor->UI()->DoLabel(&Label, "The map contains unsaved data, you might want to save it before you create a new map.\nContinue anyway?", 10.0f, TEXTALIGN_LEFT, Props);
else if(pEditor->m_PopupEventType == POPEVENT_SAVE)
pEditor->UI()->DoLabel(&Label, "The file already exists.\nDo you want to overwrite the map?", 10.0f, TEXTALIGN_LEFT);
else if(pEditor->m_PopupEventType == POPEVENT_LARGELAYER)
pEditor->UI()->DoLabel(&Label, "You are trying to set the height or width of a layer to more than 1000 tiles. This is actually possible, but only rarely necessary. It may cause the editor to work slower, larger file size as well as higher memory usage for client and server.", 10.0f, TEXTALIGN_LEFT, Props);
else if(pEditor->m_PopupEventType == POPEVENT_PREVENTUNUSEDTILES)
pEditor->UI()->DoLabel(&Label, "Unused tiles can't be placed by default because they could get a use later and then destroy your map.\nActivate the 'Unused' switch to be able to place every tile.", 10.0f, TEXTALIGN_LEFT, Props);
else if(pEditor->m_PopupEventType == POPEVENT_IMAGEDIV16)
pEditor->UI()->DoLabel(&Label, "The width or height of this image is not divisible by 16. This is required for images used in tile layers.", 10.0f, TEXTALIGN_LEFT, Props);
else if(pEditor->m_PopupEventType == POPEVENT_IMAGE_MAX)
pEditor->UI()->DoLabel(&Label, "The client only allows a maximum of 64 images.", 10.0f, TEXTALIGN_LEFT, Props);
else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES)
pEditor->UI()->DoLabel(&Label, "This is going to overwrite any existing tiles around the edges of the layer.\nContinue?", 10.0f, TEXTALIGN_LEFT, Props);
// button bar // button bar
ButtonBar.VSplitLeft(30.0f, nullptr, &ButtonBar); ButtonBar.VSplitLeft(110.0f, &Button, &ButtonBar);
ButtonBar.VSplitLeft(110.0f, &Label, &ButtonBar); if(pEditor->m_PopupEventType != POPEVENT_LARGELAYER && pEditor->m_PopupEventType != POPEVENT_PREVENTUNUSEDTILES && pEditor->m_PopupEventType != POPEVENT_IMAGEDIV16 && pEditor->m_PopupEventType != POPEVENT_IMAGE_MAX)
static int s_OkButton = 0; {
if(pEditor->DoButton_Editor(&s_OkButton, "Ok", 0, &Label, 0, nullptr) || pEditor->Input()->KeyPress(KEY_RETURN) || pEditor->Input()->KeyPress(KEY_KP_ENTER)) static int s_CancelButton = 0;
if(pEditor->DoButton_Editor(&s_CancelButton, "Cancel", 0, &Button, 0, nullptr))
{
pEditor->m_PopupEventWasActivated = false;
return 1;
}
}
ButtonBar.VSplitRight(110.0f, &ButtonBar, &Button);
static int s_ConfirmButton = 0;
if(pEditor->DoButton_Editor(&s_ConfirmButton, "Confirm", 0, &Button, 0, nullptr) || pEditor->UI()->ConsumeHotkey(CUI::HOTKEY_ENTER))
{ {
if(pEditor->m_PopupEventType == POPEVENT_EXIT) if(pEditor->m_PopupEventType == POPEVENT_EXIT)
{ {
@ -1568,21 +1595,12 @@ int CEditor::PopupEvent(CEditor *pEditor, CUIRect View, void *pContext)
return 0; // don't close this popup on error, because it would close the error popup instead return 0; // don't close this popup on error, because it would close the error popup instead
} }
else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES) else if(pEditor->m_PopupEventType == POPEVENT_PLACE_BORDER_TILES)
{
pEditor->PlaceBorderTiles(); pEditor->PlaceBorderTiles();
}
pEditor->m_PopupEventWasActivated = false; pEditor->m_PopupEventWasActivated = false;
return 1; return 1;
} }
ButtonBar.VSplitRight(30.0f, &ButtonBar, nullptr);
ButtonBar.VSplitRight(110.0f, &ButtonBar, &Label);
if(pEditor->m_PopupEventType != POPEVENT_LARGELAYER && pEditor->m_PopupEventType != POPEVENT_PREVENTUNUSEDTILES && pEditor->m_PopupEventType != POPEVENT_IMAGEDIV16 && pEditor->m_PopupEventType != POPEVENT_IMAGE_MAX)
{
static int s_AbortButton = 0;
if(pEditor->DoButton_Editor(&s_AbortButton, "Abort", 0, &Label, 0, nullptr))
{
pEditor->m_PopupEventWasActivated = false;
return 1;
}
}
return 0; return 0;
} }