Implemented User ID screen, added a text change callback function for text entry labels.

pull/28/head
sigonasr2 11 months ago
parent 6dc88f0d1f
commit 57f0b84dff
  1. 4
      Crawler/MainMenuWindow.cpp
  2. 8
      Crawler/Menu.cpp
  3. 9
      Crawler/Menu.h
  4. 6
      Crawler/MenuComponent.cpp
  5. 1
      Crawler/MenuComponent.h
  6. 2
      Crawler/SaveFileWindow.cpp
  7. 14
      Crawler/TextEntryLabel.h
  8. 24
      Crawler/UserIDMenu.cpp

@ -47,8 +47,9 @@ using A=Attribute;
void Menu::InitializeMainMenuWindow(){ void Menu::InitializeMainMenuWindow(){
Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,vi2d{96,96}); Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,vi2d{96,96});
mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[](MenuFuncData data){ mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[&](MenuFuncData data){
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
data.menu.S(A::NEXT_MENU)="New Game";
if(SaveFile::GetUserID().length()==0){ if(SaveFile::GetUserID().length()==0){
game->TextEntryEnable(true); game->TextEntryEnable(true);
Menu::OpenMenu(USER_ID); Menu::OpenMenu(USER_ID);
@ -63,6 +64,7 @@ void Menu::InitializeMainMenuWindow(){
mainMenuWindow->ADD("Load Game Button",MenuComponent)({{12,36},{72,24}},"Load Game",[](MenuFuncData data){ mainMenuWindow->ADD("Load Game Button",MenuComponent)({{12,36},{72,24}},"Load Game",[](MenuFuncData data){
SaveFile::UpdateSaveGameData(); SaveFile::UpdateSaveGameData();
#ifdef __EMSCRIPTEN__ #ifdef __EMSCRIPTEN__
data.menu.S(A::NEXT_MENU)="Load Game";
if(SaveFile::GetUserID().length()==0){ if(SaveFile::GetUserID().length()==0){
game->TextEntryEnable(true); game->TextEntryEnable(true);
Menu::OpenMenu(USER_ID); Menu::OpenMenu(USER_ID);

@ -705,7 +705,7 @@ void Menu::RecalculateComponentCount(){
componentCount=displayComponents.size()+buttons.size(); componentCount=displayComponents.size()+buttons.size();
} }
MenuType Menu::GetType(){ const MenuType Menu::GetType()const{
return type; return type;
} }
@ -719,4 +719,8 @@ void Menu::AddChapterListener(MenuComponent*component){
ERR("WARNING! Component "<<component->name<<" has already been added to the Chapter listener list! There should not be any duplicates!!") ERR("WARNING! Component "<<component->name<<" has already been added to the Chapter listener list! There should not be any duplicates!!")
} }
chapterListeners.push_back(component); chapterListeners.push_back(component);
} }
MenuFuncData::MenuFuncData(Menu&menu,Crawler*const game,MenuComponent*const component,ScrollableWindowComponent*const parentComponent)
:menu(menu),game(game),component(component),parentComponent(parentComponent){}

@ -198,7 +198,7 @@ public:
static std::vector<MenuComponent*>unhandledComponents; //This list contains MenuComponents that are created and haven't been assigned via _AddComponent. If we get to the end of menu initialization and there are any components in this vector, we have leaked memory and will report this. static std::vector<MenuComponent*>unhandledComponents; //This list contains MenuComponents that are created and haven't been assigned via _AddComponent. If we get to the end of menu initialization and there are any components in this vector, we have leaked memory and will report this.
static const vf2d CENTERED; static const vf2d CENTERED;
static bool IsMenuOpen(); static bool IsMenuOpen();
MenuType GetType(); const MenuType GetType()const;
safemap<std::string,MenuComponent*>components; //A friendly way to interrogate any component we are interested in. safemap<std::string,MenuComponent*>components; //A friendly way to interrogate any component we are interested in.
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes. std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
static std::map<MenuType,Menu*>menus; static std::map<MenuType,Menu*>menus;
@ -260,9 +260,10 @@ T*Component(MenuType menu,std::string componentName){
struct MenuFuncData{ struct MenuFuncData{
Menu&menu; Menu&menu;
Crawler*game; Crawler*const game;
MenuComponent*component; MenuComponent*const component;
ScrollableWindowComponent*parentComponent; ScrollableWindowComponent*const parentComponent=nullptr;
MenuFuncData(Menu&menu,Crawler*const game,MenuComponent*const component,ScrollableWindowComponent*const parentComponent=nullptr);
}; };
using MenuFunc=std::function<bool(MenuFuncData)>; using MenuFunc=std::function<bool(MenuFuncData)>;

@ -256,4 +256,8 @@ void MenuComponent::SetGrayedOut(bool grayedOut){
void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){} void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){}
void MenuComponent::OnChapterUpdate(uint8_t newChapter){} void MenuComponent::OnChapterUpdate(uint8_t newChapter){}
void MenuComponent::Click(){
onClick(MenuFuncData{*Menu::menus[parentMenu],game,this});
}

@ -153,4 +153,5 @@ public:
void SetGrayedOut(bool grayedOut); void SetGrayedOut(bool grayedOut);
virtual void OnPlayerMoneyUpdate(uint32_t newMoney); virtual void OnPlayerMoneyUpdate(uint32_t newMoney);
virtual void OnChapterUpdate(uint8_t newChapter); virtual void OnChapterUpdate(uint8_t newChapter);
virtual void Click();
}; };

@ -43,7 +43,7 @@ All rights reserved.
void Menu::InitializeSaveFileWindow(){ void Menu::InitializeSaveFileWindow(){
Menu*saveFileWindow=CreateMenu(SAVE_FILE_NAME,CENTERED,vi2d{96,96}); Menu*saveFileWindow=CreateMenu(SAVE_FILE_NAME,CENTERED,vi2d{96,96});
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("Save File Name Text Entry",TextEntryLabel)({{-8,36},{112,24}},TEXTCHANGE_DONOTHING,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("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){ saveFileWindow->ADD("Continue Button",MenuComponent)({{56,68},{48,12}},"Begin",MenuType::CLASS_SELECTION,[](MenuFuncData data){
SaveFile::SetSaveFileName(game->TextEntryGetString()); SaveFile::SetSaveFileName(game->TextEntryGetString());

@ -39,16 +39,18 @@ All rights reserved.
#include "MenuLabel.h" #include "MenuLabel.h"
#define TEXTCHANGE_DONOTHING [](std::string_view updatedLabel){}
class TextEntryLabel:public MenuLabel{ class TextEntryLabel:public MenuLabel{
protected: protected:
std::string enteredText; std::string lastTextEntryStr;
float blinkTimer=0; float blinkTimer=0;
uint8_t charLimit=16; uint8_t charLimit=16;
bool censored=false; bool censored=false;
std::function<void(std::string_view updatedLabel)>onTextChangeCallbackFunc;
public: public:
inline TextEntryLabel(geom2d::rect<float>rect,const bool censored=false,const uint8_t charLimit=16,float scale=1,ComponentAttr attributes=ComponentAttr::NONE) inline TextEntryLabel(geom2d::rect<float>rect,std::function<void(std::string_view updatedLabel)>onTextChangeCallbackFunc=TEXTCHANGE_DONOTHING,const bool censored=false,const uint8_t charLimit=16,float scale=1,ComponentAttr attributes=ComponentAttr::NONE)
:MenuLabel(rect,"",scale,attributes),censored(censored),charLimit(charLimit){} :MenuLabel(rect,"",scale,attributes),onTextChangeCallbackFunc(onTextChangeCallbackFunc),censored(censored),charLimit(charLimit){}
inline virtual void Update(Crawler*game)override{ inline virtual void Update(Crawler*game)override{
MenuLabel::Update(game); MenuLabel::Update(game);
@ -58,6 +60,10 @@ public:
std::string censoredTextEntry; std::string censoredTextEntry;
std::string_view textEntry=game->TextEntryGetString(); std::string_view textEntry=game->TextEntryGetString();
if(textEntry!=lastTextEntryStr){
lastTextEntryStr=textEntry;
onTextChangeCallbackFunc(lastTextEntryStr);
}
censoredTextEntry=std::accumulate(textEntry.begin(),textEntry.end(),""s,[](std::string currentStr,const char&c){return std::move(currentStr)+'*';}); 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; std::string_view finalLabel=censored?censoredTextEntry:textEntry;

@ -39,10 +39,32 @@ All rights reserved.
#include "Menu.h" #include "Menu.h"
#include "MenuLabel.h" #include "MenuLabel.h"
#include "TextEntryLabel.h" #include "TextEntryLabel.h"
#include "SaveFile.h"
using A=Attribute;
void Menu::InitializeUserIDWindow(){ void Menu::InitializeUserIDWindow(){
Menu*userIDWindow=CreateMenu(USER_ID,CENTERED,vi2d{168,120}); Menu*userIDWindow=CreateMenu(USER_ID,CENTERED,vi2d{168,120});
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 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; userIDWindow->ADD("User ID Input",TextEntryLabel)({{36,94},{96,12}},[](std::string_view newLabel){
Component<MenuComponent>(USER_ID,"Submit Button")->SetGrayedOut(newLabel.length()==0);
},true,24U,1.f,ComponentAttr::BACKGROUND|ComponentAttr::FIT_TO_LABEL|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
userIDWindow->ADD("Back Button",MenuComponent)({{18,110},{48,12}},"Back",[](MenuFuncData data){
Menu::CloseMenu();
return true;
})END;
userIDWindow->ADD("Submit Button",MenuComponent)({{102,110},{48,12}},"Submit",[](MenuFuncData data){
SaveFile::SetUserID(Component<TextEntryLabel>(USER_ID,"User ID Input")->GetLabel());
if(Menu::menus[MAIN_MENU]->S(A::NEXT_MENU)=="New Game"){
Component<MenuComponent>(MAIN_MENU,"New Game Button")->Click();
}else
if(Menu::menus[MAIN_MENU]->S(A::NEXT_MENU)=="Load Game"){
Component<MenuComponent>(MAIN_MENU,"Load Game Button")->Click();
}else{
ERR("WARNING! Unknown Next Menu set! Current Value:"<<std::quoted(Menu::menus[MAIN_MENU]->S(A::NEXT_MENU)));
}
return true;
})END
->SetGrayedOut(true);
} }
Loading…
Cancel
Save