From 6dc88f0d1f1df5a0114c1e210260ecb897562e48 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Tue, 2 Jan 2024 21:50:14 -0600 Subject: [PATCH] Add censoring to input box and add user ID request box when a user ID has not been established in the emscripten port. --- Crawler/MainMenuWindow.cpp | 31 ++++++++++++++++++++----------- Crawler/MonsterAttribute.h | 1 + Crawler/SaveFile.cpp | 7 +++++++ Crawler/SaveFile.h | 2 ++ Crawler/SaveFileWindow.cpp | 2 +- Crawler/TextEntryLabel.h | 15 +++++++++++---- Crawler/UserIDMenu.cpp | 6 ++++-- 7 files changed, 46 insertions(+), 18 deletions(-) diff --git a/Crawler/MainMenuWindow.cpp b/Crawler/MainMenuWindow.cpp index 49864327..a67e8aad 100644 --- a/Crawler/MainMenuWindow.cpp +++ b/Crawler/MainMenuWindow.cpp @@ -48,9 +48,13 @@ void Menu::InitializeMainMenuWindow(){ Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,vi2d{96,96}); mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[](MenuFuncData data){ - game->TextEntryEnable(true); #ifdef __EMSCRIPTEN__ - Menu::OpenMenu(USER_ID); + if(SaveFile::GetUserID().length()==0){ + game->TextEntryEnable(true); + Menu::OpenMenu(USER_ID); + }else{ + Menu::OpenMenu(SAVE_FILE_NAME); + } #else Menu::OpenMenu(SAVE_FILE_NAME); #endif @@ -59,15 +63,20 @@ void Menu::InitializeMainMenuWindow(){ mainMenuWindow->ADD("Load Game Button",MenuComponent)({{12,36},{72,24}},"Load Game",[](MenuFuncData data){ SaveFile::UpdateSaveGameData(); #ifdef __EMSCRIPTEN__ - SaveFile::Server_GetLoadInfo([](std::string_view response){ - if(response!="ERR"){ - std::ofstream file("save_file_path"_S+"metadata.dat"); - file<TextEntryEnable(true); + Menu::OpenMenu(USER_ID); + }else{ + SaveFile::Server_GetLoadInfo([](std::string_view response){ + if(response!="ERR"){ + std::ofstream file("save_file_path"_S+"metadata.dat"); + file<SendRequest(CreateServerRequest(SaveFileOperation::SAVE_METADATA_FILE,fileContents.str()),""); game->responseCallback=respCallbackFunc; +} + +const std::string_view SaveFile::GetUserID(){ + return SaveFile::username; +} +const void SaveFile::SetUserID(std::string_view userID){ + SaveFile::username=userID; } \ No newline at end of file diff --git a/Crawler/SaveFile.h b/Crawler/SaveFile.h index 47eb880a..df4dd9d5 100644 --- a/Crawler/SaveFile.h +++ b/Crawler/SaveFile.h @@ -56,6 +56,8 @@ public: static const std::string_view GetSaveFileName(); static const void SetSaveFileName(std::string_view saveFileName); static const size_t GetSaveFileCount(); + static const std::string_view GetUserID(); + static const void SetUserID(std::string_view userID); static const void SaveGame(); static const void LoadGame(); static const void SetSaveFileID(size_t saveFileID); diff --git a/Crawler/SaveFileWindow.cpp b/Crawler/SaveFileWindow.cpp index 823d1859..8721683a 100644 --- a/Crawler/SaveFileWindow.cpp +++ b/Crawler/SaveFileWindow.cpp @@ -43,7 +43,7 @@ All rights reserved. void Menu::InitializeSaveFileWindow(){ Menu*saveFileWindow=CreateMenu(SAVE_FILE_NAME,CENTERED,vi2d{96,96}); - saveFileWindow->ADD("Save File Name Text Entry",TextEntryLabel)({{-8,36},{112,24}},"",16U,2.f,ComponentAttr::FIT_TO_LABEL|ComponentAttr::OUTLINE|ComponentAttr::SHADOW|ComponentAttr::BACKGROUND)END; + saveFileWindow->ADD("Save File Name Text Entry",TextEntryLabel)({{-8,36},{112,24}},false,16U,2.f,ComponentAttr::FIT_TO_LABEL|ComponentAttr::OUTLINE|ComponentAttr::SHADOW|ComponentAttr::BACKGROUND)END; saveFileWindow->ADD("Back Button",MenuComponent)({{-8,68},{48,12}},"Back",[](MenuFuncData data){Menu::CloseMenu();game->TextEntryEnable(false);return true;})END; saveFileWindow->ADD("Continue Button",MenuComponent)({{56,68},{48,12}},"Begin",MenuType::CLASS_SELECTION,[](MenuFuncData data){ SaveFile::SetSaveFileName(game->TextEntryGetString()); diff --git a/Crawler/TextEntryLabel.h b/Crawler/TextEntryLabel.h index 43978ac7..b081dfc0 100644 --- a/Crawler/TextEntryLabel.h +++ b/Crawler/TextEntryLabel.h @@ -44,9 +44,10 @@ protected: std::string enteredText; float blinkTimer=0; uint8_t charLimit=16; + bool censored=false; public: - inline TextEntryLabel(geom2d::rectrect,std::string label,const uint8_t charLimit=16,float scale=1,ComponentAttr attributes=ComponentAttr::NONE) - :MenuLabel(rect,label,scale,attributes),charLimit(charLimit){} + inline TextEntryLabel(geom2d::rectrect,const bool censored=false,const uint8_t charLimit=16,float scale=1,ComponentAttr attributes=ComponentAttr::NONE) + :MenuLabel(rect,"",scale,attributes),censored(censored),charLimit(charLimit){} inline virtual void Update(Crawler*game)override{ @@ -55,11 +56,17 @@ public: game->TextEntrySetCharLimit(charLimit); + std::string censoredTextEntry; + std::string_view textEntry=game->TextEntryGetString(); + censoredTextEntry=std::accumulate(textEntry.begin(),textEntry.end(),""s,[](std::string currentStr,const char&c){return std::move(currentStr)+'*';}); + + std::string_view finalLabel=censored?censoredTextEntry:textEntry; + if(game->IsTextEntryEnabled()){ if(blinkTimer<0.5f){ - SetLabel(game->TextEntryGetString().substr(0,game->TextEntryGetCursor())+" "+game->TextEntryGetString().substr(game->TextEntryGetCursor())); + SetLabel(std::string(finalLabel.substr(0,game->TextEntryGetCursor()))+" "+std::string(finalLabel.substr(game->TextEntryGetCursor()))); }else{ - SetLabel(game->TextEntryGetString().substr(0,game->TextEntryGetCursor())+"|"+game->TextEntryGetString().substr(game->TextEntryGetCursor())); + SetLabel(std::string(finalLabel.substr(0,game->TextEntryGetCursor()))+"|"+std::string(finalLabel.substr(game->TextEntryGetCursor()))); } } } diff --git a/Crawler/UserIDMenu.cpp b/Crawler/UserIDMenu.cpp index a3248ab4..d91efc57 100644 --- a/Crawler/UserIDMenu.cpp +++ b/Crawler/UserIDMenu.cpp @@ -38,9 +38,11 @@ All rights reserved. #include "Menu.h" #include "MenuLabel.h" +#include "TextEntryLabel.h" void Menu::InitializeUserIDWindow(){ - Menu*userIDWindow=CreateMenu(USER_ID,CENTERED,vi2d{144,96}); + Menu*userIDWindow=CreateMenu(USER_ID,CENTERED,vi2d{168,120}); - userIDWindow->ADD("User ID Creation Explanation",MenuLabel)({{0,0},{144,96}},"user_id_message"_FS+"\n\n"+"user_id_message2"_FS,1.f,ComponentAttr::SHADOW|ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; + userIDWindow->ADD("User ID Creation Explanation",MenuLabel)({{0,-4},{168,92}},"user_id_message"_FS+"\n\n"+"user_id_message2"_FS,1.f,ComponentAttr::SHADOW|ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE)END; + userIDWindow->ADD("User ID Input",TextEntryLabel)({{36,94},{96,12}},true,24U,1.f,ComponentAttr::BACKGROUND|ComponentAttr::FIT_TO_LABEL|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END; } \ No newline at end of file