The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
9.1 KiB
155 lines
9.1 KiB
#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 © 2024 The FreeType
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
All rights reserved.
|
|
*/
|
|
#pragma endregion
|
|
#include "Menu.h"
|
|
#include "AdventuresInLestoria.h"
|
|
#include "MenuLabel.h"
|
|
#include "MenuComponent.h"
|
|
#include "InventoryScrollableWindowComponent.h"
|
|
#include "PopupMenuLabel.h"
|
|
#include "Unlock.h"
|
|
#include "State_OverworldMap.h"
|
|
|
|
INCLUDE_game
|
|
|
|
void Menu::InitializeLevelCompleteWindow(){
|
|
geom2d::rect<int>windowSize={{28,28},game->GetScreenSize()-vf2d{56,56}};
|
|
|
|
Menu*levelCompleteWindow=Menu::CreateMenu(LEVEL_COMPLETE,windowSize.pos,windowSize.size);
|
|
|
|
levelCompleteWindow->ADD("Stage Complete Label",MenuLabel)(geom2d::rect<float>{{0,4},{windowSize.size.x-1.f,20}},"Stage Completed",2,ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND|ComponentAttr::SHADOW)END;
|
|
|
|
levelCompleteWindow->ADD("Monster Loot Outline",MenuComponent)(geom2d::rect<float>{{0,32},{windowSize.size.x-80.f,72}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END;
|
|
levelCompleteWindow->ADD("Monster Loot Label",MenuLabel)(geom2d::rect<float>{{0,32},{windowSize.size.x-80.f,12}},"Monster Loot",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE)END;
|
|
auto monsterLootWindow=levelCompleteWindow->ADD("Monster Loot Window",InventoryScrollableWindowComponent)(geom2d::rect<float>{{0,44},{windowSize.size.x-80.f,60}},"Monster Loot Popup Item Name","Monster Loot Popup Item Description",DO_NOTHING,InventoryCreator::Player_InventoryUpdate)END;
|
|
Menu::AddInventoryListener(monsterLootWindow,"Monster Loot");
|
|
|
|
levelCompleteWindow->ADD("Stage Loot Outline",MenuComponent)(geom2d::rect<float>{{0,108},{windowSize.size.x-80.f,72}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END;
|
|
levelCompleteWindow->ADD("Stage Loot Label",MenuLabel)(geom2d::rect<float>{{0,108},{windowSize.size.x-80.f,12}},"Stage Loot",1,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE)END;
|
|
auto stageLootWindow=levelCompleteWindow->ADD("Stage Loot Window",InventoryScrollableWindowComponent)(geom2d::rect<float>{{0,120},{windowSize.size.x-80.f,60}},"Stage Loot Popup Item Name","Stage Loot Popup Item Description",DO_NOTHING,InventoryCreator::Player_InventoryUpdate)END;
|
|
Menu::AddInventoryListener(stageLootWindow,"Stage Loot");
|
|
|
|
auto nextButtonAction=[](MenuFuncData data){
|
|
Unlock::UnlockArea(State_OverworldMap::GetCurrentConnectionPoint().map);
|
|
Merchant::RandomizeTravelingMerchant();
|
|
GameState::ChangeState(States::GAME_HUB,0.25f);
|
|
return true;
|
|
};
|
|
|
|
levelCompleteWindow->ADD("Level Details Outline",MenuComponent)(geom2d::rect<float>{{windowSize.size.x-72.f,32},{71,72}},"",DO_NOTHING,ButtonAttr::UNSELECTABLE)END;
|
|
levelCompleteWindow->ADD("Level EXP Gain Outline",MenuLabel)(geom2d::rect<float>{{windowSize.size.x-72.f,104},{71,36}},"+ Exp",1,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
|
|
levelCompleteWindow->ADD("Next Button",MenuComponent)(geom2d::rect<float>{{windowSize.size.x-72.f,144},{71,32}},"Next",nextButtonAction)END;
|
|
|
|
levelCompleteWindow->ADD("Monster Loot Popup Item Name",PopupMenuLabel)(geom2d::rect<float>{{0,108},{windowSize.size.x-80.f,12}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
|
|
levelCompleteWindow->ADD("Monster Loot Popup Item Description",PopupMenuLabel)(geom2d::rect<float>{{0,120},{windowSize.size.x-80.f,60}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
|
|
|
|
levelCompleteWindow->ADD("Stage Loot Popup Item Name",PopupMenuLabel)(geom2d::rect<float>{{0,32},{windowSize.size.x-80.f,12}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
|
|
levelCompleteWindow->ADD("Stage Loot Popup Item Description",PopupMenuLabel)(geom2d::rect<float>{{0,44},{windowSize.size.x-80.f,60}},"",1.0f,ComponentAttr::LEFT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END;
|
|
|
|
levelCompleteWindow->SetupKeyboardNavigation(
|
|
[](MenuType type,Data&returnData){ //On Open
|
|
auto monsterLoot=Component<InventoryScrollableWindowComponent>(type,"Monster Loot Window");
|
|
auto stageLoot=Component<InventoryScrollableWindowComponent>(type,"Stage Loot Window");
|
|
if(monsterLoot->GetComponents().size()>0){
|
|
returnData=monsterLoot->GetComponents().front();
|
|
}else
|
|
if(stageLoot->GetComponents().size()>0){
|
|
returnData=stageLoot->GetComponents().front();
|
|
}else{
|
|
returnData="Next Button";
|
|
}
|
|
},
|
|
{ //Button Key
|
|
{{game->KEY_SHOULDER,Pressed},{"Scroll",[](MenuType type){}}},
|
|
{{game->KEY_FASTSCROLLDOWN,PressedDAS,InputEngageGroup::NOT_VISIBLE},{"Scroll",[](MenuType type){
|
|
auto selection=Menu::menus[type]->GetSelection();
|
|
if(!selection.expired()){
|
|
auto parentComponent=DYNAMIC_POINTER_CAST<InventoryScrollableWindowComponent>(selection.lock()->parentComponent);
|
|
int invWidth=int((parentComponent->rect.size.x-12)/(float(parentComponent->options.size.x)+parentComponent->options.padding));
|
|
parentComponent->IncreaseSelectionIndex(invWidth*3.f);
|
|
}
|
|
}}},
|
|
{{game->KEY_FASTSCROLLUP,PressedDAS,InputEngageGroup::NOT_VISIBLE},{"Scroll",[](MenuType type){
|
|
auto selection=Menu::menus[type]->GetSelection();
|
|
if(!selection.expired()){
|
|
auto parentComponent=DYNAMIC_POINTER_CAST<InventoryScrollableWindowComponent>(selection.lock()->parentComponent);
|
|
int invWidth=int((parentComponent->rect.size.x-12)/(float(parentComponent->options.size.x)+parentComponent->options.padding));
|
|
parentComponent->IncreaseSelectionIndex(invWidth*-3.f);
|
|
}
|
|
}}},
|
|
{game->KEY_SCROLL,{"View Items",[](MenuType type){}}},
|
|
{game->KEY_START,{"Continue",[](MenuType type){}}},
|
|
}
|
|
,{ //Button Navigation Rules
|
|
{"Monster Loot Window",{
|
|
.up=[](MenuType type,Data&returnData){
|
|
auto&selection=Menu::menus[type]->GetSelection();
|
|
auto&itemsList=Component<InventoryScrollableWindowComponent>(type,"Monster Loot Window")->GetComponents();
|
|
auto itemsWindow=Component<InventoryScrollableWindowComponent>(type,"Monster Loot Window");
|
|
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return comp.lock()==selection.lock();});
|
|
if(itemsList.size()>0){
|
|
if(component==itemsList.end()){
|
|
//Set the selected button to the last element in the list.
|
|
returnData=itemsList.back();
|
|
}else{
|
|
int invWidth=int((itemsWindow->rect.size.x-12)/(float(itemsWindow->options.size.x)+itemsWindow->options.padding));
|
|
std::weak_ptr<MenuItemButton>selectedButton=DYNAMIC_POINTER_CAST<MenuItemButton>(*component);
|
|
int newRowIndex=selectedButton.lock()->inventoryIndex-invWidth; //Moving up moves the cursor up an entire row.
|
|
if(newRowIndex<0){
|
|
//This means we have to wrap around.
|
|
returnData="OK Button";
|
|
return;
|
|
}
|
|
if(newRowIndex<0||newRowIndex>=itemsList.size())ERR(std::format("New Row Index ended up out-of-bounds! newRowIndex={}. THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
|
//Select the component that matches this new number.
|
|
auto component=std::find_if(itemsList.begin(),itemsList.end(),[&](auto&comp){return DYNAMIC_POINTER_CAST<MenuItemButton>(comp)->inventoryIndex==newRowIndex;});
|
|
if(component==itemsList.end())ERR(std::format("WARNING! Could not find row index {} in items list while navigating! THIS SHOULD NOT BE HAPPENING!",newRowIndex));
|
|
returnData=*component;
|
|
}
|
|
}else{
|
|
returnData="OK Button";
|
|
}
|
|
},
|
|
.down="Load Game Button",}},
|
|
{"Load Game Button",{
|
|
.up="New Game Button",
|
|
.down="Quit Game Button",}},
|
|
{"Quit Game Button",{
|
|
.up="Load Game Button",
|
|
.down="New Game Button",}},
|
|
});
|
|
} |