diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 01df1055e..c0f3792f3 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -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; @@ -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); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 2bc2437cc..23eb73480 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -811,6 +811,7 @@ public: POPUP_QUIT, POPUP_RESTART, POPUP_WARNING, + POPUP_SAVE_SKIN, // demo player states DEMOPLAYER_NONE = 0, diff --git a/src/game/client/components/menus_settings7.cpp b/src/game/client/components/menus_settings7.cpp index 71025cc9f..f8b54a639 100644 --- a/src/game/client/components/menus_settings7.cpp +++ b/src/game/client/components/menus_settings7.cpp @@ -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)) { diff --git a/src/game/client/components/skins7.cpp b/src/game/client/components/skins7.cpp index fb0f0bdf9..30d30f6ba 100644 --- a/src/game/client/components/skins7.cpp +++ b/src/game/client/components/skins7.cpp @@ -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; @@ -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);