Skip to content

Commit

Permalink
Merge pull request ddnet#8828 from dobrykafe/pr-save-07-skins
Browse files Browse the repository at this point in the history
Implement 0.7 skin save button
  • Loading branch information
def- authored Aug 27, 2024
2 parents 7df1b24 + 31ee6ab commit 5a66dc0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
51 changes: 51 additions & 0 deletions src/game/client/components/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,11 @@ void CMenus::RenderPopupFullscreen(CUIRect Screen)
pButtonText = m_aMessageButton;
TopAlign = true;
}
else if(m_Popup == POPUP_SAVE_SKIN)
{
pTitle = Localize("Save skin");
pExtraText = Localize("Are you sure you want to save your skin? If a skin with this name already exists, it will be replaced.");
}

CUIRect Box, Part;
Box = Screen;
Expand Down Expand Up @@ -1756,6 +1761,52 @@ void CMenus::RenderPopupFullscreen(CUIRect Screen)
SetActive(false);
}
}
else if(m_Popup == POPUP_SAVE_SKIN)
{
CUIRect Label, TextBox, Yes, No;

Box.HSplitBottom(20.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);
Part.VMargin(80.0f, &Part);

Part.VSplitMid(&No, &Yes);

Yes.VMargin(20.0f, &Yes);
No.VMargin(20.0f, &No);

static CButtonContainer s_ButtonNo;
if(DoButton_Menu(&s_ButtonNo, Localize("No"), 0, &No) || Ui()->ConsumeHotkey(CUi::HOTKEY_ESCAPE))
m_Popup = POPUP_NONE;

static CButtonContainer s_ButtonYes;
if(DoButton_Menu(&s_ButtonYes, Localize("Yes"), m_SkinNameInput.IsEmpty() ? 1 : 0, &Yes) || Ui()->ConsumeHotkey(CUi::HOTKEY_ENTER))
{
if(m_SkinNameInput.GetLength())
{
if(m_SkinNameInput.GetString()[0] != 'x' && m_SkinNameInput.GetString()[1] != '_')
{
if(m_pClient->m_Skins7.SaveSkinfile(m_SkinNameInput.GetString(), m_Dummy))
{
m_Popup = POPUP_NONE;
m_SkinListNeedsUpdate = true;
}
else
PopupMessage(Localize("Error"), Localize("Unable to save the skin"), Localize("Ok"), POPUP_SAVE_SKIN);
}
else
PopupMessage(Localize("Error"), Localize("Unable to save the skin with a reserved name"), Localize("Ok"), POPUP_SAVE_SKIN);
}
}

Box.HSplitBottom(60.f, &Box, &Part);
Box.HSplitBottom(24.f, &Box, &Part);

Part.VMargin(60.0f, &Label);
Label.VSplitLeft(100.0f, &Label, &TextBox);
TextBox.VSplitLeft(20.0f, nullptr, &TextBox);
Ui()->DoLabel(&Label, Localize("Name"), 18.0f, TEXTALIGN_ML);
Ui()->DoClearableEditBox(&m_SkinNameInput, &TextBox, 12.0f);
}
else
{
Box.HSplitBottom(20.f, &Box, &Part);
Expand Down
1 change: 1 addition & 0 deletions src/game/client/components/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,7 @@ class CMenus : public CComponent
POPUP_QUIT,
POPUP_RESTART,
POPUP_WARNING,
POPUP_SAVE_SKIN,

// demo player states
DEMOPLAYER_NONE = 0,
Expand Down
8 changes: 8 additions & 0 deletions src/game/client/components/menus_settings7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,14 @@ void CMenus::RenderSettingsTee7(CUIRect MainView)
// bottom buttons
if(s_CustomSkinMenu)
{
static CButtonContainer s_CustomSkinSaveButton;
if(DoButton_Menu(&s_CustomSkinSaveButton, Localize("Save"), 0, &ButtonLeft))
{
m_Popup = POPUP_SAVE_SKIN;
m_SkinNameInput.SelectAll();
Ui()->SetActiveItem(&m_SkinNameInput);
}

static CButtonContainer s_RandomizeSkinButton;
if(DoButton_Menu(&s_RandomizeSkinButton, Localize("Randomize"), 0, &ButtonMiddle))
{
Expand Down
4 changes: 2 additions & 2 deletions src/game/client/components/skins7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ bool CSkins7::ValidateSkinParts(char *apPartNames[protocol7::NUM_SKINPARTS], int
bool CSkins7::SaveSkinfile(const char *pSaveSkinName, int Dummy)
{
char aBuf[IO_MAX_PATH_LENGTH];
str_format(aBuf, sizeof(aBuf), "skins/%s.json", pSaveSkinName);
str_format(aBuf, sizeof(aBuf), SKINS_DIR "/%s.json", pSaveSkinName);
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_WRITE, IStorage::TYPE_SAVE);
if(!File)
return false;
Expand All @@ -547,7 +547,7 @@ bool CSkins7::SaveSkinfile(const char *pSaveSkinName, int Dummy)
Writer.WriteAttribute("filename");
Writer.WriteStrValue(ms_apSkinVariables[Dummy][PartIndex]);

const bool CustomColors = *ms_apUCCVariables[PartIndex];
const bool CustomColors = *ms_apUCCVariables[Dummy][PartIndex];
Writer.WriteAttribute("custom_colors");
Writer.WriteBoolValue(CustomColors);

Expand Down

0 comments on commit 5a66dc0

Please sign in to comment.