Add main menu window interface outlines. Fixed menu labels not being centered properly.

pull/28/head
sigonasr2 1 year ago
parent e9952ca1be
commit b702fa2fe5
  1. 8
      Crawler/CharacterInfoWindow.cpp
  2. 12
      Crawler/ClassSelectionWindow.cpp
  3. 2
      Crawler/Crawler.vcxproj
  4. 6
      Crawler/Crawler.vcxproj.filters
  5. 2
      Crawler/GameState.cpp
  6. 4
      Crawler/InventoryWindow.cpp
  7. 12
      Crawler/MainMenuWindow.cpp
  8. 11
      Crawler/Menu.cpp
  9. 9
      Crawler/Menu.h
  10. 2
      Crawler/MenuItemButton.h
  11. 13
      Crawler/MenuLabel.h
  12. 18
      Crawler/State_GameRun.cpp
  13. 7
      Crawler/State_MainMenu.cpp
  14. 2
      Crawler/Version.h

@ -2,11 +2,15 @@
#include "Crawler.h" #include "Crawler.h"
#include "DEFINES.h" #include "DEFINES.h"
#include "Menu.h" #include "Menu.h"
#include "MenuLabel.h"
INCLUDE_game INCLUDE_game
typedef Attribute A; typedef Attribute A;
void Menu::InitializeCharacterInfoWindow(){ void Menu::InitializeClassInfoWindow(){
Menu*characterInfoWindow=CreateMenu(INVENTORY,CENTERED,game->GetScreenSize()-vi2d{4,4}); Menu*classInfoWindow=CreateMenu(CLASS_INFO,CENTERED,game->GetScreenSize()-vi2d{64,64});
MenuLabel*label=new MenuLabel(CLASS_INFO,{{classInfoWindow->pos.x,classInfoWindow->pos.y+8},{classInfoWindow->size.x,16}},"Warrior",2,true,true);
classInfoWindow->AddComponent("Class Name",label);
} }

@ -0,0 +1,12 @@
#pragma once
#include "Crawler.h"
#include "DEFINES.h"
#include "Menu.h"
#include "MenuLabel.h"
INCLUDE_game
typedef Attribute A;
void Menu::InitializeClassSelectionWindow(){
Menu*classSelectionWindow=CreateMenu(CLASS_SELECTION,CENTERED,game->GetScreenSize()-vi2d{4,4});
}

@ -311,6 +311,7 @@
<ClCompile Include="Bullet.cpp" /> <ClCompile Include="Bullet.cpp" />
<ClCompile Include="CharacterInfoWindow.cpp" /> <ClCompile Include="CharacterInfoWindow.cpp" />
<ClCompile Include="ChargedArrow.cpp" /> <ClCompile Include="ChargedArrow.cpp" />
<ClCompile Include="ClassSelectionWindow.cpp" />
<ClCompile Include="Crawler.cpp" /> <ClCompile Include="Crawler.cpp" />
<ClCompile Include="DamageNumber.cpp" /> <ClCompile Include="DamageNumber.cpp" />
<ClCompile Include="Effect.cpp" /> <ClCompile Include="Effect.cpp" />
@ -324,6 +325,7 @@
<ClCompile Include="Key.cpp" /> <ClCompile Include="Key.cpp" />
<ClCompile Include="LightningBolt.cpp" /> <ClCompile Include="LightningBolt.cpp" />
<ClCompile Include="LightningBoltEmitter.cpp" /> <ClCompile Include="LightningBoltEmitter.cpp" />
<ClCompile Include="MainMenuWindow.cpp" />
<ClCompile Include="Map.cpp" /> <ClCompile Include="Map.cpp" />
<ClCompile Include="Menu.cpp" /> <ClCompile Include="Menu.cpp" />
<ClCompile Include="MenuComponent.cpp" /> <ClCompile Include="MenuComponent.cpp" />

@ -335,6 +335,12 @@
<ClCompile Include="CharacterInfoWindow.cpp"> <ClCompile Include="CharacterInfoWindow.cpp">
<Filter>Source Files\Interface</Filter> <Filter>Source Files\Interface</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ClassSelectionWindow.cpp">
<Filter>Source Files\Interface</Filter>
</ClCompile>
<ClCompile Include="MainMenuWindow.cpp">
<Filter>Source Files\Interface</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="cpp.hint" /> <None Include="cpp.hint" />

@ -6,5 +6,5 @@ void GameState::Initialize(){
NEW_STATE(States::GAME_RUN,State_GameRun); NEW_STATE(States::GAME_RUN,State_GameRun);
NEW_STATE(States::MAIN_MENU,State_MainMenu); NEW_STATE(States::MAIN_MENU,State_MainMenu);
GameState::ChangeState(States::GAME_RUN); GameState::ChangeState(States::MAIN_MENU);
} }

@ -30,8 +30,8 @@ void Menu::InitializeInventoryWindow(){
//We don't have to actually populate the inventory list because now when an item gets added, it will automatically add the correct component in for us. //We don't have to actually populate the inventory list because now when an item gets added, it will automatically add the correct component in for us.
MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing-4)},windowSize),"",false,true}; MenuLabel*itemNameLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing-4)},windowSize),"",1,false,true};
inventoryWindow->AddComponent("itemName",itemNameLabel); inventoryWindow->AddComponent("itemName",itemNameLabel);
MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing)},{windowSize.x-4,windowSize.y-108}),"",true,true}; MenuLabel*itemDescriptionLabel=new MenuLabel{INVENTORY,geom2d::rect<float>(vf2d{2,float(initialInvHeight*totalSpacing+itemSpacing)},{windowSize.x-4,windowSize.y-108}),"",1,true,true};
inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel); inventoryWindow->AddComponent("itemDescription",itemDescriptionLabel);
} }

@ -0,0 +1,12 @@
#pragma once
#include "Crawler.h"
#include "DEFINES.h"
#include "Menu.h"
#include "MenuLabel.h"
INCLUDE_game
typedef Attribute A;
void Menu::InitializeMainMenuWindow(){
Menu*mainMenuWindow=CreateMenu(MAIN_MENU,CENTERED,game->GetScreenSize()-vi2d{4,4});
}

@ -30,6 +30,9 @@ void Menu::InitializeMenus(){
InitializeTestMenu(); InitializeTestMenu();
InitializeTestSubMenu(); InitializeTestSubMenu();
InitializeInventoryWindow(); InitializeInventoryWindow();
InitializeClassInfoWindow();
InitializeClassSelectionWindow();
InitializeMainMenuWindow();
for(MenuType type=TEST;type<MenuType::ENUM_END;type=MenuType(int(type+1))){ for(MenuType type=TEST;type<MenuType::ENUM_END;type=MenuType(int(type+1))){
if(menus.count(type)==0){ if(menus.count(type)==0){
@ -236,13 +239,13 @@ void Menu::Draw(Crawler*game){
game->Clear(BLANK); game->Clear(BLANK);
for(auto&component:displayComponents){ for(auto&component:displayComponents){
if(component->renderInMain){ if(component->renderInMain){
component->_Draw(game,{0,0},this==Menu::stack.back()); component->_Draw(game,pos,this==Menu::stack.back());
} }
} }
for(auto&key:buttons){ for(auto&key:buttons){
for(auto&button:key.second){ for(auto&button:key.second){
if(button->renderInMain){ if(button->renderInMain){
button->_Draw(game,{0,0},this==Menu::stack.back()); button->_Draw(game,pos,this==Menu::stack.back());
} }
} }
} }
@ -583,3 +586,7 @@ void Menu::AddInventoryListener(MenuComponent*component,ITCategory category){
throw; throw;
} }
} }
vf2d Menu::center(){
return pos+size/2;
}

@ -13,7 +13,9 @@ enum MenuType{
TEST, TEST,
TEST_2, TEST_2,
INVENTORY, INVENTORY,
CLASS_INFO,
CLASS_SELECTION,
MAIN_MENU,
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
/*DO NOT REMOVE!!*/ENUM_END//////////////////////////////// /*DO NOT REMOVE!!*/ENUM_END////////////////////////////////
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -57,6 +59,7 @@ public:
void SetMouseNavigation(bool mouseNavigation); void SetMouseNavigation(bool mouseNavigation);
static void InventorySlotsUpdated(ITCategory cat); //Called whenever an inventory item gets added to the player's inventory, thus increasing the total number of slots in our bag. static void InventorySlotsUpdated(ITCategory cat); //Called whenever an inventory item gets added to the player's inventory, thus increasing the total number of slots in our bag.
static void AddInventoryListener(MenuComponent*component,ITCategory category); //Adds a component to be in a given listener category. static void AddInventoryListener(MenuComponent*component,ITCategory category); //Adds a component to be in a given listener category.
vf2d center();
private: private:
Menu(vf2d pos,vf2d size); Menu(vf2d pos,vf2d size);
void HoverMenuSelect(Crawler*game); void HoverMenuSelect(Crawler*game);
@ -67,7 +70,9 @@ private:
static void InitializeTestMenu(); static void InitializeTestMenu();
static void InitializeTestSubMenu(); static void InitializeTestSubMenu();
static void InitializeInventoryWindow(); static void InitializeInventoryWindow();
static void InitializeCharacterInfoWindow(); static void InitializeClassInfoWindow();
static void InitializeClassSelectionWindow();
static void InitializeMainMenuWindow();
//X (0-3), Y (0-2) for specific 9-patch tile (tiled version). //X (0-3), Y (0-2) for specific 9-patch tile (tiled version).
static Renderable&GetPatchPart(int x,int y); static Renderable&GetPatchPart(int x,int y);

@ -30,6 +30,7 @@ protected:
virtual inline void Update(Crawler*game)override{ virtual inline void Update(Crawler*game)override{
MenuIconButton::Update(game); MenuIconButton::Update(game);
valid=invRef.size()>inventoryIndex&&ITEM_DATA.count(invRef[inventoryIndex]); valid=invRef.size()>inventoryIndex&&ITEM_DATA.count(invRef[inventoryIndex]);
if(Menu::stack.size()>0){
Menu*menu=Menu::stack.back(); Menu*menu=Menu::stack.back();
if(valid){ if(valid){
icon=ITEM_DATA.at(invRef[inventoryIndex]).Decal(); icon=ITEM_DATA.at(invRef[inventoryIndex]).Decal();
@ -57,6 +58,7 @@ protected:
} }
} }
} }
}
virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{ virtual inline void DrawDecal(Crawler*game,vf2d parentPos,bool focused)override{
MenuIconButton::DrawDecal(game,parentPos,focused); MenuIconButton::DrawDecal(game,parentPos,focused);
if(valid){ if(valid){

@ -9,9 +9,10 @@ INCLUDE_game
class MenuLabel:public MenuComponent{ class MenuLabel:public MenuComponent{
bool shadow=false; bool shadow=false;
bool centered=true; bool centered=true;
int scale=1;
public: public:
inline MenuLabel(MenuType parent,geom2d::rect<float>rect,std::string label,bool centered=true,bool shadow=false) inline MenuLabel(MenuType parent,geom2d::rect<float>rect,std::string label,int scale=1,bool centered=true,bool shadow=false)
:MenuComponent(parent,rect,label,MenuFunc{},false),centered(centered),shadow(shadow){ :MenuComponent(parent,rect,label,MenuFunc{},false),scale(scale),centered(centered),shadow(shadow){
border=false; border=false;
} }
inline void SetLabel(std::string text){ inline void SetLabel(std::string text){
@ -22,15 +23,15 @@ protected:
MenuComponent::Update(game); MenuComponent::Update(game);
} }
virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{ virtual void inline Draw(Crawler*game,vf2d parentPos,bool focused)override{
std::string wrappedText=util::WrapText(game,label,rect.size.x,true,{1,1}); std::string wrappedText=util::WrapText(game,label,rect.size.x,true,{float(scale),float(scale)});
vf2d drawPos=parentPos+rect.middle()-game->GetTextSizeProp(wrappedText)/2; //Assume centered. vf2d drawPos=-parentPos+rect.middle()-game->GetTextSizeProp(wrappedText)*float(scale)/2; //Assume centered.
if(!centered){ if(!centered){
drawPos=rect.pos+parentPos; drawPos=rect.pos+parentPos;
} }
if(shadow){ if(shadow){
game->DrawShadowStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); game->DrawShadowStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F,BLACK,{float(scale),float(scale)});
}else{ }else{
game->DrawStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F); game->DrawStringProp(drawPos,wrappedText,focused?WHITE:WHITE*"ThemeGlobal.MenuUnfocusedColorMult"_F,scale);
} }
} }
}; };

@ -15,26 +15,8 @@ void State_GameRun::OnUserUpdate(Crawler*game){
game->encounterDuration+=game->GetElapsedTime(); game->encounterDuration+=game->GetElapsedTime();
} }
if(game->GetKey(O).bPressed){
Inventory::AddItem("Dummy Item 14",192);
Inventory::AddItem("Dummy Item 15",35);
Inventory::AddItem("Dummy Item 16",6);
Inventory::AddItem("Dummy Item 17",3);
Inventory::AddItem("Dummy Item 18",1);
Inventory::AddItem("Dummy Item 19",8);
Inventory::AddItem("Dummy Item 20",4);
}
if(game->GetKey(P).bPressed){
Inventory::AddItem("Medium Mana Potion",1);
}
game->HandleUserInput(game->GetElapsedTime()); game->HandleUserInput(game->GetElapsedTime());
if(game->GetKey(T).bPressed){
GameState::ChangeState(States::MAIN_MENU);
}
game->UpdateEffects(game->GetElapsedTime()); game->UpdateEffects(game->GetElapsedTime());
game->GetPlayer()->Update(game->GetElapsedTime()); game->GetPlayer()->Update(game->GetElapsedTime());
for(Monster&m:MONSTER_LIST){ for(Monster&m:MONSTER_LIST){

@ -3,14 +3,11 @@
#include "Menu.h" #include "Menu.h"
void State_MainMenu::OnStateChange(GameState*prevState){ void State_MainMenu::OnStateChange(GameState*prevState){
Menu::OpenMenu(MenuType::TEST); Menu::OpenMenu(MenuType::CLASS_INFO);
}; };
void State_MainMenu::OnUserUpdate(Crawler*game){ void State_MainMenu::OnUserUpdate(Crawler*game){
if(game->GetKey(T).bPressed){
GameState::ChangeState(States::GAME_RUN);
}
}; };
void State_MainMenu::Draw(Crawler*game){ void State_MainMenu::Draw(Crawler*game){
game->DrawShadowStringDecal({0,0},"This will eventually be\nMain Menu stuff",BLACK,WHITE,{1,1},1);
}; };

@ -2,7 +2,7 @@
#define VERSION_MAJOR 0 #define VERSION_MAJOR 0
#define VERSION_MINOR 2 #define VERSION_MINOR 2
#define VERSION_PATCH 0 #define VERSION_PATCH 0
#define VERSION_BUILD 2167 #define VERSION_BUILD 2184
#define stringify(a) stringify_(a) #define stringify(a) stringify_(a)
#define stringify_(a) #a #define stringify_(a) #a

Loading…
Cancel
Save