Implemented User ID screen, added a text change callback function for text entry labels.
This commit is contained in:
parent
6dc88f0d1f
commit
57f0b84dff
@ -47,8 +47,9 @@ using A=Attribute;
|
||||
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){
|
||||
mainMenuWindow->ADD("New Game Button",MenuComponent)({{12,4},{72,24}},"New Game",[&](MenuFuncData data){
|
||||
#ifdef __EMSCRIPTEN__
|
||||
data.menu.S(A::NEXT_MENU)="New Game";
|
||||
if(SaveFile::GetUserID().length()==0){
|
||||
game->TextEntryEnable(true);
|
||||
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){
|
||||
SaveFile::UpdateSaveGameData();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
data.menu.S(A::NEXT_MENU)="Load Game";
|
||||
if(SaveFile::GetUserID().length()==0){
|
||||
game->TextEntryEnable(true);
|
||||
Menu::OpenMenu(USER_ID);
|
||||
|
@ -705,7 +705,7 @@ void Menu::RecalculateComponentCount(){
|
||||
componentCount=displayComponents.size()+buttons.size();
|
||||
}
|
||||
|
||||
MenuType Menu::GetType(){
|
||||
const MenuType Menu::GetType()const{
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -720,3 +720,7 @@ void Menu::AddChapterListener(MenuComponent*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 const vf2d CENTERED;
|
||||
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.
|
||||
std::vector<MenuComponent*>displayComponents; //Components that are only for displaying purposes.
|
||||
static std::map<MenuType,Menu*>menus;
|
||||
@ -260,9 +260,10 @@ T*Component(MenuType menu,std::string componentName){
|
||||
|
||||
struct MenuFuncData{
|
||||
Menu&menu;
|
||||
Crawler*game;
|
||||
MenuComponent*component;
|
||||
ScrollableWindowComponent*parentComponent;
|
||||
Crawler*const game;
|
||||
MenuComponent*const component;
|
||||
ScrollableWindowComponent*const parentComponent=nullptr;
|
||||
MenuFuncData(Menu&menu,Crawler*const game,MenuComponent*const component,ScrollableWindowComponent*const parentComponent=nullptr);
|
||||
};
|
||||
|
||||
using MenuFunc=std::function<bool(MenuFuncData)>;
|
@ -257,3 +257,7 @@ void MenuComponent::SetGrayedOut(bool grayedOut){
|
||||
void MenuComponent::OnPlayerMoneyUpdate(uint32_t newMoney){}
|
||||
|
||||
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);
|
||||
virtual void OnPlayerMoneyUpdate(uint32_t newMoney);
|
||||
virtual void OnChapterUpdate(uint8_t newChapter);
|
||||
virtual void Click();
|
||||
};
|
@ -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}},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("Continue Button",MenuComponent)({{56,68},{48,12}},"Begin",MenuType::CLASS_SELECTION,[](MenuFuncData data){
|
||||
SaveFile::SetSaveFileName(game->TextEntryGetString());
|
||||
|
@ -39,16 +39,18 @@ All rights reserved.
|
||||
|
||||
#include "MenuLabel.h"
|
||||
|
||||
#define TEXTCHANGE_DONOTHING [](std::string_view updatedLabel){}
|
||||
|
||||
class TextEntryLabel:public MenuLabel{
|
||||
protected:
|
||||
std::string enteredText;
|
||||
std::string lastTextEntryStr;
|
||||
float blinkTimer=0;
|
||||
uint8_t charLimit=16;
|
||||
bool censored=false;
|
||||
std::function<void(std::string_view updatedLabel)>onTextChangeCallbackFunc;
|
||||
public:
|
||||
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 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),onTextChangeCallbackFunc(onTextChangeCallbackFunc),censored(censored),charLimit(charLimit){}
|
||||
|
||||
inline virtual void Update(Crawler*game)override{
|
||||
MenuLabel::Update(game);
|
||||
@ -58,6 +60,10 @@ public:
|
||||
|
||||
std::string censoredTextEntry;
|
||||
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)+'*';});
|
||||
|
||||
std::string_view finalLabel=censored?censoredTextEntry:textEntry;
|
||||
|
@ -39,10 +39,32 @@ All rights reserved.
|
||||
#include "Menu.h"
|
||||
#include "MenuLabel.h"
|
||||
#include "TextEntryLabel.h"
|
||||
#include "SaveFile.h"
|
||||
|
||||
using A=Attribute;
|
||||
|
||||
void Menu::InitializeUserIDWindow(){
|
||||
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 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…
x
Reference in New Issue
Block a user