mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Refactor CEditorMap::CMapInfo
Reduce duplicate code. Make code more similar to upstream.
This commit is contained in:
parent
cdd19beee4
commit
001d11d9ed
|
@ -6662,6 +6662,7 @@ void CEditorMap::Clean()
|
|||
DeleteAll(m_vpSounds);
|
||||
|
||||
m_MapInfo.Reset();
|
||||
m_MapInfoTmp.Reset();
|
||||
|
||||
m_vSettings.clear();
|
||||
|
||||
|
|
|
@ -370,30 +370,29 @@ public:
|
|||
class CMapInfo
|
||||
{
|
||||
public:
|
||||
char m_aAuthorTmp[32];
|
||||
char m_aVersionTmp[16];
|
||||
char m_aCreditsTmp[128];
|
||||
char m_aLicenseTmp[32];
|
||||
|
||||
char m_aAuthor[sizeof(m_aAuthorTmp)];
|
||||
char m_aVersion[sizeof(m_aVersionTmp)];
|
||||
char m_aCredits[sizeof(m_aCreditsTmp)];
|
||||
char m_aLicense[sizeof(m_aLicenseTmp)];
|
||||
char m_aAuthor[32];
|
||||
char m_aVersion[16];
|
||||
char m_aCredits[128];
|
||||
char m_aLicense[32];
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_aAuthorTmp[0] = 0;
|
||||
m_aVersionTmp[0] = 0;
|
||||
m_aCreditsTmp[0] = 0;
|
||||
m_aLicenseTmp[0] = 0;
|
||||
m_aAuthor[0] = '\0';
|
||||
m_aVersion[0] = '\0';
|
||||
m_aCredits[0] = '\0';
|
||||
m_aLicense[0] = '\0';
|
||||
}
|
||||
|
||||
m_aAuthor[0] = 0;
|
||||
m_aVersion[0] = 0;
|
||||
m_aCredits[0] = 0;
|
||||
m_aLicense[0] = 0;
|
||||
void Copy(const CMapInfo &Source)
|
||||
{
|
||||
str_copy(m_aAuthor, Source.m_aAuthor);
|
||||
str_copy(m_aVersion, Source.m_aVersion);
|
||||
str_copy(m_aCredits, Source.m_aCredits);
|
||||
str_copy(m_aLicense, Source.m_aLicense);
|
||||
}
|
||||
};
|
||||
CMapInfo m_MapInfo;
|
||||
CMapInfo m_MapInfoTmp;
|
||||
|
||||
struct CSetting
|
||||
{
|
||||
|
|
|
@ -120,10 +120,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMenuFile(void *pContext, CUIRect Vie
|
|||
if(pEditor->DoButton_MenuItem(&s_MapInfoButton, "Map details", 0, &Slot, 0, "Adjust the map details of the current map"))
|
||||
{
|
||||
const CUIRect *pScreen = pEditor->UI()->Screen();
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aAuthorTmp, pEditor->m_Map.m_MapInfo.m_aAuthor);
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aVersionTmp, pEditor->m_Map.m_MapInfo.m_aVersion);
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aCreditsTmp, pEditor->m_Map.m_MapInfo.m_aCredits);
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aLicenseTmp, pEditor->m_Map.m_MapInfo.m_aLicense);
|
||||
pEditor->m_Map.m_MapInfoTmp.Copy(pEditor->m_Map.m_MapInfo);
|
||||
static SPopupMenuId s_PopupMapInfoId;
|
||||
constexpr float PopupWidth = 400.0f;
|
||||
constexpr float PopupHeight = 170.0f;
|
||||
|
@ -1372,7 +1369,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMapInfo(void *pContext, CUIRect View
|
|||
Label.VSplitLeft(60.0f, nullptr, &Button);
|
||||
Button.HMargin(3.0f, &Button);
|
||||
static float s_AuthorBox = 0;
|
||||
pEditor->DoEditBox(&s_AuthorBox, &Button, pEditor->m_Map.m_MapInfo.m_aAuthorTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aAuthorTmp), 10.0f, &s_AuthorBox);
|
||||
pEditor->DoEditBox(&s_AuthorBox, &Button, pEditor->m_Map.m_MapInfoTmp.m_aAuthor, sizeof(pEditor->m_Map.m_MapInfoTmp.m_aAuthor), 10.0f, &s_AuthorBox);
|
||||
|
||||
// version box
|
||||
View.HSplitTop(20.0f, &Label, &View);
|
||||
|
@ -1380,7 +1377,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMapInfo(void *pContext, CUIRect View
|
|||
Label.VSplitLeft(60.0f, nullptr, &Button);
|
||||
Button.HMargin(3.0f, &Button);
|
||||
static float s_VersionBox = 0;
|
||||
pEditor->DoEditBox(&s_VersionBox, &Button, pEditor->m_Map.m_MapInfo.m_aVersionTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aVersionTmp), 10.0f, &s_VersionBox);
|
||||
pEditor->DoEditBox(&s_VersionBox, &Button, pEditor->m_Map.m_MapInfoTmp.m_aVersion, sizeof(pEditor->m_Map.m_MapInfoTmp.m_aVersion), 10.0f, &s_VersionBox);
|
||||
|
||||
// credits box
|
||||
View.HSplitTop(20.0f, &Label, &View);
|
||||
|
@ -1388,7 +1385,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMapInfo(void *pContext, CUIRect View
|
|||
Label.VSplitLeft(60.0f, nullptr, &Button);
|
||||
Button.HMargin(3.0f, &Button);
|
||||
static float s_CreditsBox = 0;
|
||||
pEditor->DoEditBox(&s_CreditsBox, &Button, pEditor->m_Map.m_MapInfo.m_aCreditsTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aCreditsTmp), 10.0f, &s_CreditsBox);
|
||||
pEditor->DoEditBox(&s_CreditsBox, &Button, pEditor->m_Map.m_MapInfoTmp.m_aCredits, sizeof(pEditor->m_Map.m_MapInfoTmp.m_aCredits), 10.0f, &s_CreditsBox);
|
||||
|
||||
// license box
|
||||
View.HSplitTop(20.0f, &Label, &View);
|
||||
|
@ -1396,7 +1393,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMapInfo(void *pContext, CUIRect View
|
|||
Label.VSplitLeft(60.0f, nullptr, &Button);
|
||||
Button.HMargin(3.0f, &Button);
|
||||
static float s_LicenseBox = 0;
|
||||
pEditor->DoEditBox(&s_LicenseBox, &Button, pEditor->m_Map.m_MapInfo.m_aLicenseTmp, sizeof(pEditor->m_Map.m_MapInfo.m_aLicenseTmp), 10.0f, &s_LicenseBox);
|
||||
pEditor->DoEditBox(&s_LicenseBox, &Button, pEditor->m_Map.m_MapInfoTmp.m_aLicense, sizeof(pEditor->m_Map.m_MapInfoTmp.m_aLicense), 10.0f, &s_LicenseBox);
|
||||
|
||||
// button bar
|
||||
ButtonBar.VSplitLeft(110.0f, &Label, &ButtonBar);
|
||||
|
@ -1408,10 +1405,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupMapInfo(void *pContext, CUIRect View
|
|||
static int s_ConfirmButton = 0;
|
||||
if(pEditor->DoButton_Editor(&s_ConfirmButton, "Confirm", 0, &Label, 0, nullptr) || (Active && pEditor->UI()->ConsumeHotkey(CUI::HOTKEY_ENTER)))
|
||||
{
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aAuthor, pEditor->m_Map.m_MapInfo.m_aAuthorTmp);
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aVersion, pEditor->m_Map.m_MapInfo.m_aVersionTmp);
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aCredits, pEditor->m_Map.m_MapInfo.m_aCreditsTmp);
|
||||
str_copy(pEditor->m_Map.m_MapInfo.m_aLicense, pEditor->m_Map.m_MapInfo.m_aLicenseTmp);
|
||||
pEditor->m_Map.m_MapInfo.Copy(pEditor->m_Map.m_MapInfoTmp);
|
||||
return CUI::POPUP_CLOSE_CURRENT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue