Add censoring to input box and add user ID request box when a user ID has not been established in the emscripten port.

pull/28/head
sigonasr2 11 months ago
parent 7bfa728ccb
commit 6dc88f0d1f
  1. 31
      Crawler/MainMenuWindow.cpp
  2. 1
      Crawler/MonsterAttribute.h
  3. 7
      Crawler/SaveFile.cpp
  4. 2
      Crawler/SaveFile.h
  5. 2
      Crawler/SaveFileWindow.cpp
  6. 15
      Crawler/TextEntryLabel.h
  7. 6
      Crawler/UserIDMenu.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<<response;
Menu::OpenMenu(LOAD_GAME);
}else{
std::cout<<"WARNING! Failed to retrieve load game information from the server!"<<std::endl;
}
});
if(SaveFile::GetUserID().length()==0){
game->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<<response;
Menu::OpenMenu(LOAD_GAME);
}else{
std::cout<<"WARNING! Failed to retrieve load game information from the server!"<<std::endl;
}
});
}
#else
Menu::OpenMenu(LOAD_GAME);
#endif

@ -75,4 +75,5 @@ enum class Attribute{
ITEM_NAME,
ITEM_QUANTITY,
LAST_INVENTORY_TYPE_OPENED,
NEXT_MENU, //Set to 0 for New Game, Set to 1 for Load Game Menu. This is used for the username checks
};

@ -260,3 +260,10 @@ const void SaveFile::Server_SaveMetadataFile(std::function<void(std::string_view
game->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;
}

@ -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);

@ -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());

@ -44,9 +44,10 @@ protected:
std::string enteredText;
float blinkTimer=0;
uint8_t charLimit=16;
bool censored=false;
public:
inline TextEntryLabel(geom2d::rect<float>rect,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::rect<float>rect,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())));
}
}
}

@ -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;
}
Loading…
Cancel
Save