Added character name input to class selection window, removed "file save name" dialog from main menu navigation. Fixed scaling for button labels with different values than 1. Moved ScrollableWindowComponent's scrollbar to be lined up with the actual scrollbar arrows. Removed text entry mode from blocking controller / gamepad inputs.

pull/35/head
sigonasr2 1 year ago
parent 39a710727e
commit 15990152c7
  1. 4
      Adventures in Lestoria/Adventures in Lestoria.vcxproj
  2. 3
      Adventures in Lestoria/Adventures in Lestoria.vcxproj.filters
  3. 1
      Adventures in Lestoria/AdventuresInLestoria.cpp
  4. 25
      Adventures in Lestoria/ClassSelectionWindow.cpp
  5. 12
      Adventures in Lestoria/LoadFileButton.h
  6. 4
      Adventures in Lestoria/LoadGameWindow.cpp
  7. 17
      Adventures in Lestoria/MainMenuWindow.cpp
  8. 26
      Adventures in Lestoria/Menu.cpp
  9. 3
      Adventures in Lestoria/MenuComponent.cpp
  10. 2
      Adventures in Lestoria/SaveFile.cpp
  11. 53
      Adventures in Lestoria/SaveFileNameButton.h
  12. 18
      Adventures in Lestoria/SaveFileWindow.cpp
  13. 4
      Adventures in Lestoria/ScrollableWindowComponent.h
  14. 6
      Adventures in Lestoria/TextEntryLabel.h
  15. 2
      Adventures in Lestoria/Version.h
  16. 6
      Adventures in Lestoria/assets/config/Player.txt
  17. 7
      Adventures in Lestoria/olcPixelGameEngine.h

@ -526,6 +526,10 @@
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="SaveFileNameButton.h">
<SubType>
</SubType>
</ClInclude>
<ClInclude Include="ScrollableWindowComponent.h" />
<ClInclude Include="InventoryScrollableWindowComponent.h" />
<ClInclude Include="Slider.h" />

@ -441,6 +441,9 @@
<ClInclude Include="GameEvent.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SaveFileNameButton.h">
<Filter>Header Files\Interface</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Player.cpp">

@ -2413,7 +2413,6 @@ void AiL::InitializeDefaultKeybinds(){
KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::FACE_R)});
//KEY_CONFIRM.AddKeybind({CONTROLLER,static_cast<int>(GPButtons::START)});
KEY_CONFIRM.AddKeybind({KEY,Z});
KEY_CONFIRM.AddKeybind({KEY,SPACE});
KEY_CONFIRM.AddKeybind({KEY,ENTER});
KEY_BACK.AddKeybind({KEY,X});
KEY_BACK.AddKeybind({KEY,SHIFT});

@ -42,24 +42,37 @@ All rights reserved.
#include "MenuAnimatedIconToggleButton.h"
#include "GameState.h"
#include "ClassInfo.h"
#include "SaveFileNameButton.h"
#include "TextEntryLabel.h"
INCLUDE_game
using A=Attribute;
void Menu::InitializeClassSelectionWindow(){
Menu*classSelectionWindow=CreateMenu(CLASS_SELECTION,CENTERED,game->GetScreenSize()-vi2d{24,24});
vf2d windowSize=game->GetScreenSize()-vi2d{24,8};
Menu*classSelectionWindow=CreateMenu(CLASS_SELECTION,CENTERED,windowSize);
classSelectionWindow->S(A::CLASS_SELECTION)="Warrior"; //Default selected class.
vf2d outlineSize=classSelectionWindow->size-vf2d{13,13};
vf2d outlineSize=classSelectionWindow->size-vf2d{8,29};
classSelectionWindow->ADD("Class Selection Title Label",MenuLabel)(geom2d::rect<float>{{4,12},{outlineSize.x,32}},"Choose a Character Class",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
classSelectionWindow->ADD("Class Selection Title Label",MenuLabel)(geom2d::rect<float>{{4,20},{outlineSize.x,32}},"Choose a Character Class",2,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
auto outline=classSelectionWindow->ADD("Outline Border",MenuLabel)(geom2d::rect<float>{{4,4},outlineSize+vf2d{0,25}},"",1,ComponentAttr::OUTLINE)END;
auto outline=classSelectionWindow->ADD("Outline Border",MenuLabel)(geom2d::rect<float>{{4,4},outlineSize},"",1,ComponentAttr::OUTLINE)END;
classSelectionWindow->ADD("Character Name Label",MenuLabel)(geom2d::rect<float>{{windowSize.x/2-144.f,60.f},{96.f,24.f}},"Name:",2.0f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE|ComponentAttr::SHADOW)END;
classSelectionWindow->ADD("Character Name Box",SaveFileNameButton)(geom2d::rect<float>{{windowSize.x/2-48.f,60.f},{192.f,24}},[&](MenuFuncData data){
Component<TextEntryLabel>(SAVE_FILE_NAME,"Save File Name Text Entry")->SetInput(std::string(SaveFile::GetSaveFileName()));
game->TextEntryEnable(true);
Menu::OpenMenu(SAVE_FILE_NAME);
return true;
},vf2d{2.f,2.f})END;
vf2d navigationButtonSize={24*2.5f,16};
classSelectionWindow->ADD("Confirm",MenuComponent)(geom2d::rect<float>{{outlineSize.x+4-navigationButtonSize.x-2,outlineSize.y+4-navigationButtonSize.y-2},navigationButtonSize},"Confirm",[](MenuFuncData data){
classSelectionWindow->ADD("Confirm",MenuComponent)(geom2d::rect<float>{{outlineSize.x+4-navigationButtonSize.x-2,outlineSize.y+29-navigationButtonSize.y-2},navigationButtonSize},"Confirm",[](MenuFuncData data){
std::string selectedClass=data.component.lock()->S(A::CLASS_SELECTION);
data.game->ChangePlayerClass(classutils::StringToClass(selectedClass));
GameState::ChangeState(States::OVERWORLD_MAP);
@ -72,7 +85,7 @@ void Menu::InitializeClassSelectionWindow(){
float buttonTotalWidth=(buttonSize.x+buttonPadding.x)*3;
vf2d buttonStartPos=outline->GetPos()+vf2d{outlineSize.x/2,outlineSize.y/3}-vf2d{buttonTotalWidth/2,0};
vf2d buttonStartPos=outline->GetPos()+vf2d{outlineSize.x/2,outlineSize.y/3}-vf2d{buttonTotalWidth/2,0}+vf2d{0,24};
std::array<std::string,6>classNames={
Warrior::name,

@ -70,8 +70,6 @@ public:
if(playTime==-1){
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},"UNKNOWN");
}else{
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},saveFileName);
const std::map<std::string,std::string>classAnimations={
{Warrior::name,Warrior::walk_s},
{Ranger::name,Ranger::walk_s},
@ -85,6 +83,16 @@ public:
vf2d chapterTextSize=game->GetTextSize(chapterText);
window.DrawShadowStringDecal(rect.pos+vf2d{rect.size.x-chapterTextSize.x-2,2},chapterText);
vf2d saveFileNameSize=game->GetTextSizeProp(saveFileName);
float spaceAvailable=rect.size.x-chapterTextSize.x-8;
float scaleRatio=1.f;
if(saveFileNameSize.x>spaceAvailable){
scaleRatio=spaceAvailable/saveFileNameSize.x;
}
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},saveFileName,WHITE,BLACK,vf2d{scaleRatio,1.f});
const Animate2D::Frame&frame=ANIMATION_DATA[classAnimations.at(className)].GetFrame(animationTime);
geom2d::rect<int>sprRect=frame.GetSourceRect();
window.DrawPartialDecal(rect.pos+vf2d{rect.size.x-26,rect.size.y-36},sprRect.size,frame.GetSourceImage()->Decal(),sprRect.pos,sprRect.size);

@ -45,9 +45,9 @@ void Menu::InitializeLoadGameWindow(){
loadGameWindow->ADD("Game Files Label",MenuLabel)(geom2d::rect<float>{{-8,-12},{112,12}},"Load Game",1.0f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
loadGameWindow->ADD("Game Files List",ScrollableWindowComponent)(geom2d::rect<float>{{-8,4},{112,116}})END
->Enable(false);
loadGameWindow->ADD("Online Game Files List",ScrollableWindowComponent)(geom2d::rect<float>{{-8,4},{112,116}})END
->Enable(true);
loadGameWindow->ADD("Online Game Files List",ScrollableWindowComponent)(geom2d::rect<float>{{-8,4},{112,116}})END
->Enable(false);
loadGameWindow->ADD("Go Back Button",MenuComponent)(geom2d::rect<float>{{24,124},{48,12}},"Back",[](MenuFuncData menu){Menu::CloseMenu();return true;})END;

@ -40,25 +40,20 @@ All rights reserved.
#include "Menu.h"
#include "MenuComponent.h"
#include "SaveFile.h"
#include "util.h"
INCLUDE_game
INCLUDE_DATA
using A=Attribute;
void Menu::InitializeMainMenuWindow(){
Menu*mainMenuWindow=CreateMenu(MAIN_MENU,vi2d{132,120},vi2d{96,96});
auto newGameButton=mainMenuWindow->ADD("New Game Button",MenuComponent)(geom2d::rect<float>{{12,4},{72,24}},"New Game",[&](MenuFuncData data){
game->TextEntryEnable(true);
#ifdef __EMSCRIPTEN__
data.menu.S(A::NEXT_MENU)="New Game";
if(SaveFile::GetUserID().length()==0){
Menu::OpenMenu(USER_ID);
}else{
Menu::OpenMenu(SAVE_FILE_NAME);
}
#else
Menu::OpenMenu(SAVE_FILE_NAME);
#endif
std::string randomName=DATA["Player"]["Default Female Name"].GetString(util::random()%DATA["Player"]["Default Female Name"].GetValueCount());
SaveFile::SetSaveFileName(randomName); //Randomize a default name.
Menu::OpenMenu(CLASS_SELECTION);
return true;
})END;
auto loadGameButton=mainMenuWindow->ADD("Load Game Button",MenuComponent)(geom2d::rect<float>{{12,36},{72,24}},"Load Game",[](MenuFuncData data){

@ -171,11 +171,9 @@ void Menu::Update(AiL*game){
bool itemHovered=false;
if(!UsingMouseNavigation()){
if(!game->IsTextEntryEnabled()){
if(!selection.expired()){
selection.lock()->hovered=true;
itemHovered=true;
}
if(!selection.expired()){
selection.lock()->hovered=true;
itemHovered=true;
}
}else{
selection={};
@ -204,14 +202,12 @@ void Menu::Update(AiL*game){
};
if(!UsingMouseNavigation()){
if(!game->IsTextEntryEnabled()){
if(game->KEY_CONFIRM.Released()){
if(selection.expired()){//Dropping over an empty area.
ClearDraggingComponent();
}else
if(selection.lock()->DropDraggableItem(std::move(draggingComponent))){
ClearDraggingComponent();
}
if(game->KEY_CONFIRM.Released()){
if(selection.expired()){//Dropping over an empty area.
ClearDraggingComponent();
}else
if(selection.lock()->DropDraggableItem(std::move(draggingComponent))){
ClearDraggingComponent();
}
}
}else{
@ -226,9 +222,7 @@ void Menu::Update(AiL*game){
}
}
if(!game->IsTextEntryEnabled()){
KeyboardButtonNavigation(game,pos);
}
KeyboardButtonNavigation(game,pos);
for(auto&[key,component]:components){
if(component->renderInMain){

@ -109,9 +109,10 @@ void MenuComponent::DrawDecal(ViewPort&window,bool focused){
vi2d labelTextSize=vf2d(game->GetTextSizeProp(label))*adjustedScale;
if(fitToLabel){
float sizeRatio=((vf2d(labelTextSize)*adjustedScale).x)/(rect.size.x-2);
float sizeRatio=(vf2d(labelTextSize).x)/(rect.size.x-2);
if(sizeRatio>1){
adjustedScale.x/=sizeRatio;
labelTextSize.x/=sizeRatio;
}
}
window.DrawStringPropDecal(rect.pos+V(A::DRAW_OFFSET)+rect.size/2-vf2d(labelTextSize)/2.f,label,WHITE,adjustedScale);

@ -51,7 +51,7 @@ INCLUDE_game
size_t SaveFile::saveFileID=0;
std::string SaveFile::saveFileName="";
std::string SaveFile::username="";
bool SaveFile::onlineMode=true;
bool SaveFile::onlineMode=false;
const size_t SaveFile::GetSaveFileCount(){
std::filesystem::create_directories("save_file_path"_S);

@ -0,0 +1,53 @@
#pragma region License
/*
License (OLC-3)
~~~~~~~~~~~~~~~
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions or derivations of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice. This list of conditions and the following disclaimer must be
reproduced in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
Portions of this software are copyright © 2023 The FreeType
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
All rights reserved.
*/
#pragma endregion
#pragma once
#include "MenuComponent.h"
#include "SaveFile.h"
class SaveFileNameButton:public MenuComponent{
public:
inline SaveFileNameButton(geom2d::rect<float>rect,MenuFunc onClick,vf2d labelScaling,ButtonAttr attributes=ButtonAttr::FIT_TO_LABEL)
:MenuComponent(rect,"",MenuType::ENUM_END,onClick,labelScaling,attributes){}
inline void Update(AiL*game)override{
MenuComponent::Update(game);
label=SaveFile::GetSaveFileName();
}
};

@ -42,12 +42,12 @@ All rights reserved.
void Menu::InitializeSaveFileWindow(){
Menu*saveFileWindow=CreateMenu(SAVE_FILE_NAME,CENTERED,vi2d{96,96});
saveFileWindow->ADD("Save File Name Entry Label",MenuLabel)(geom2d::rect<float>{{-8,0},{112,36}},"Save File Name:",1.0f,ComponentAttr::SHADOW)END;
saveFileWindow->ADD("Save File Name Entry Label",MenuLabel)(geom2d::rect<float>{{-8,0},{112,36}},"Character Name:",1.0f,ComponentAttr::SHADOW)END;
saveFileWindow->ADD("Save File Name Text Entry",TextEntryLabel)(geom2d::rect<float>{{-8,36},{112,24}},[](std::string_view updatedLabel){
Component<MenuComponent>(SAVE_FILE_NAME,"Continue Button")->SetGrayedOut(updatedLabel.length()==0);
},false,16U,2.f,ComponentAttr::FIT_TO_LABEL|ComponentAttr::OUTLINE|ComponentAttr::SHADOW|ComponentAttr::BACKGROUND)END;
saveFileWindow->ADD("Back Button",MenuComponent)(geom2d::rect<float>{{-8,68},{48,12}},"Back",[](MenuFuncData data){Menu::CloseMenu();game->TextEntryEnable(false);return true;})END;
saveFileWindow->ADD("Continue Button",MenuComponent)(geom2d::rect<float>{{56,68},{48,12}},"Begin",MenuType::CLASS_SELECTION,[](MenuFuncData data){
saveFileWindow->ADD("Back Button",MenuComponent)(geom2d::rect<float>{{-8,68},{48,12}},"Cancel",[](MenuFuncData data){Menu::CloseMenu();game->TextEntryEnable(false);return true;})END;
saveFileWindow->ADD("Continue Button",MenuComponent)(geom2d::rect<float>{{56,68},{48,12}},"Submit",MenuType::CLASS_SELECTION,[](MenuFuncData data){
SaveFile::SetSaveFileName(game->TextEntryGetString());
if(SaveFile::IsOnline()){
SaveFile::SetSaveFileID(SaveFile::GetOnlineSaveFileCount());
@ -55,7 +55,6 @@ void Menu::InitializeSaveFileWindow(){
SaveFile::SetSaveFileID(SaveFile::GetSaveFileCount());
}
game->TextEntryEnable(false);
SaveFile::SaveGame();
return true;
})END
->SetGrayedOut(true);
@ -72,13 +71,6 @@ void Menu::InitializeSaveFileWindow(){
{game->KEY_SELECT,{"Return to Title Screen",[](MenuType type){
Component<MenuComponent>(type,"Back Button")->Click();
}}},
}
,{ //Button Navigation Rules
{"Continue Button",{
.left="Back Button",
.right="Back Button",}},
{"Back Button",{
.left="Continue Button",
.right="Continue Button",}},
});
},
{});
}

@ -229,8 +229,8 @@ protected:
float focusedWindowColorMult=(focused?1:"ThemeGlobal.MenuUnfocusedColorMult"_F);
window.FillRectDecal(rect.pos+parentPos+vf2d{rect.size.x-11.75f,scrollBarTop+12},{12,scrollBarHeight},PixelLerp(Menu::GetCurrentTheme().GetButtonCol(),Menu::GetCurrentTheme().GetHighlightCol(),scrollBarHoverTime/"ThemeGlobal.HighlightTime"_F)*focusedWindowColorMult);
window.DrawRectDecal(rect.pos+parentPos+vf2d{rect.size.x-11.75f,scrollBarTop+12},{12,scrollBarHeight},WHITE*focusedWindowColorMult);
window.FillRectDecal(rect.pos+parentPos+vf2d{rect.size.x-12.f,scrollBarTop+12},{12,scrollBarHeight},PixelLerp(Menu::GetCurrentTheme().GetButtonCol(),Menu::GetCurrentTheme().GetHighlightCol(),scrollBarHoverTime/"ThemeGlobal.HighlightTime"_F)*focusedWindowColorMult);
window.DrawRectDecal(rect.pos+parentPos+vf2d{rect.size.x-12.f,scrollBarTop+12},{12,scrollBarHeight},WHITE*focusedWindowColorMult);
}
inline float GetComponentIndex(std::weak_ptr<MenuComponent>comp){

@ -77,6 +77,12 @@ public:
}
}
inline virtual void SetInput(std::string text){
game->TextEntrySetString(text);
label=text;
if(runOnLabelChangeFunc)onLabelChangeFunc(text);
}
inline const std::string&GetLabel()const override{
if(censored){
return game->TextEntryGetString();

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 3
#define VERSION_PATCH 0
#define VERSION_BUILD 6402
#define VERSION_BUILD 6436
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -11,6 +11,12 @@ Player
Starting Money = 100
# A default starting name for the character. Specify multiple to randomize.
Default Female Name = Nia, Lea, Poppy, Ruby, Arc
# A default starting name for the character. Specify multiple to randomize.
Default Male Name = Cyrus, Odin, Usio, Lucio
# Amount of spd to increase/decrease vertically as you climb staircases
StaircaseClimbSpd = 45

@ -1208,6 +1208,7 @@ namespace olc
// Text Entry Routines
void TextEntryEnable(const bool bEnable, const std::string& sText = "");
const std::string&TextEntryGetString() const;
void TextEntrySetString(const std::string&str);
int32_t TextEntryGetCursor() const;
bool IsTextEntryEnabled() const;
void TextEntrySetCharLimit(const uint8_t charLimit);
@ -4299,6 +4300,12 @@ namespace olc
const std::string&PixelGameEngine::TextEntryGetString() const
{ return sTextEntryString; }
void PixelGameEngine::TextEntrySetString(const std::string&str){
sTextEntryString=str;
nTextEntryCursor=sTextEntryString.length();
};
int32_t PixelGameEngine::TextEntryGetCursor() const
{ return nTextEntryCursor; }

Loading…
Cancel
Save