#pragma region License /* License (OLC-3) ~~~~~~~~~~~~~~~ Copyright 2024 Joshua Sigona 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 "RowInventoryScrollableWindowComponent.h" #include "InventoryCreator.h" #include "MenuItemItemButton.h" #include "RowItemDisplay.h" #include "MenuDecal.h" #include "SoundEffect.h" INCLUDE_game void Menu::InitializeArtificerDisassembleWindow(){ Menu*artificerDisassembleWindow=CreateMenu(ARTIFICER_DISASSEMBLE,CENTERED,game->GetScreenSize()-vi2d{52,52}); const auto ResetDisassemblyDisplay=[artificerDisassembleWindow](){ MenuType menuType{artificerDisassembleWindow->GetType()}; Component(menuType,"Down Arrow")->Disable(); Component(menuType,"Disassembly Result")->Disable(); Component(menuType,"Disassembly Result Title")->Disable(); Component(menuType,"Fragment Total Count")->Disable(); Component(menuType,"Disassemble Button")->Disable(); }; const auto EnableDisassemblyDisplay=[artificerDisassembleWindow](){ MenuType menuType{artificerDisassembleWindow->GetType()}; Component(menuType,"Down Arrow")->Enable(); Component(menuType,"Disassembly Result")->Enable(); Component(menuType,"Disassembly Result Title")->Enable(); Component(menuType,"Fragment Total Count")->Enable(); Component(menuType,"Disassemble Button")->Enable(); }; auto disassemblyTitleLabel{artificerDisassembleWindow->ADD("Disassembly Title Label",MenuLabel)(geom2d::rect{{},{artificerDisassembleWindow->size.x,24.f}},"Accessory Disassembly",2.f,ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::BACKGROUND)END}; auto inventoryLabel=artificerDisassembleWindow->ADD("Accessory List Label",MenuLabel)(geom2d::rect{{0.f,28.f},{180.f,12.f}},"Choose Accessory:",1.f,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END; auto itemIcon{artificerDisassembleWindow->ADD("Item Icon",MenuItemItemButton)(geom2d::rect({artificerDisassembleWindow->size.x/2+4.f,44.f},{48,48}),Item::BLANK,DO_NOTHING,"","Item Description",IconButtonAttr::NOT_SELECTABLE)END}; itemIcon->SetIconScale({2.f,2.f}); itemIcon->SetCompactDescriptions(true); auto accessoryDescription{artificerDisassembleWindow->ADD("Item Description",MenuLabel)(geom2d::rect{{artificerDisassembleWindow->size.x/2+56.f,44.f},{artificerDisassembleWindow->size.x/2-56.f,72.f}},"",0.5f,ComponentAttr::BACKGROUND|ComponentAttr::OUTLINE|ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN)END}; auto downArrow{artificerDisassembleWindow->ADD("Down Arrow",MenuDecal)(geom2d::rect{{artificerDisassembleWindow->size.x/2+4.f,92.f},{48,48}},GFX.at("downarrow.png"),DO_NOTHING,DO_NOTHING)END}; auto disassemblyResult{artificerDisassembleWindow->ADD("Disassembly Result",MenuIconButton)(geom2d::rect{{artificerDisassembleWindow->size.x/2+4.f,141.f},{48,48}},nullptr,DO_NOTHING,IconButtonAttr::NOT_SELECTABLE)END}; auto disassemblyResultTitle{artificerDisassembleWindow->ADD("Disassembly Result Title",MenuLabel)(geom2d::rect{{artificerDisassembleWindow->size.x/2+56.f,141.f},{artificerDisassembleWindow->size.x/2-56.f,24.f}},"",2.f,ComponentAttr::BACKGROUND|ComponentAttr::SHADOW|ComponentAttr::OUTLINE|ComponentAttr::FIT_TO_LABEL)END}; auto disassemblyTotalCount{artificerDisassembleWindow->ADD("Fragment Total Count",MenuLabel)(geom2d::rect{{artificerDisassembleWindow->size.x/2+56.f,127.f},{artificerDisassembleWindow->size.x/2-56.f,12.f}},"",0.85f,ComponentAttr::RIGHT_ALIGN|ComponentAttr::SHADOW|ComponentAttr::FIT_TO_LABEL)END}; auto disassembleButton{artificerDisassembleWindow->ADD("Disassemble Button",MenuComponent)(geom2d::rect{{artificerDisassembleWindow->size.x/2+72.f,171.f},{artificerDisassembleWindow->size.x/2-72.f,16.f}},"Disassemble",[ResetDisassemblyDisplay](MenuFuncData data){ auto it{Component(data.menu.type,"Item Icon")->GetItem()}; if(Inventory::Disassemble(it)==Inventory::DisassembleResult::SUCCESS){ SoundEffect::PlaySFX("Disassemble Item",SoundEffect::CENTERED); Component(data.menu.type,"Item Icon")->SetItem(Item::BLANK); Component(data.menu.type,"Disassembly Result")->SetIcon(nullptr); Component(data.menu.type,"Disassembly Result Title")->SetLabel(""); Component(data.menu.type,"Fragment Total Count")->SetLabel(""); ResetDisassemblyDisplay(); }else{ SoundEffect::PlaySFX("Locked Item",SoundEffect::CENTERED); game->AddNotification(AiL::Notification{"Cannot disassemble locked accessory!",5.f,RED}); } return true; })END}; auto inventoryDisplay=artificerDisassembleWindow->ADD("Accessory List",RowInventoryScrollableWindowComponent)(geom2d::rect{{0.f,44.f},{artificerDisassembleWindow->size.x/2-4.f,artificerDisassembleWindow->size.y-60}},"","",[](MenuFuncData data){ RowItemDisplay&item{*DYNAMIC_POINTER_CAST(data.component)}; DYNAMIC_POINTER_CAST(data.parentComponent.lock())->SelectChild(DYNAMIC_POINTER_CAST(data.component)); return true; },[EnableDisassemblyDisplay](MenuFuncData data){ EnableDisassemblyDisplay(); RowItemDisplay&item{*DYNAMIC_POINTER_CAST(data.component)}; Component(data.menu.type,"Item Icon")->SetItem(item.GetItem().lock()); Component(data.menu.type,"Disassembly Result")->SetIcon(item.GetItem().lock()->Icon().Decal()); Component(data.menu.type,"Disassembly Result Title")->SetLabel(item.GetItem().lock()->FragmentName()); Component(data.menu.type,"Fragment Total Count")->SetLabel(std::format("Currently Owned: {}",Inventory::GetItemCount(item.GetItem().lock()->FragmentName()))); return true; },[ResetDisassemblyDisplay,EnableDisassemblyDisplay](MenuFuncData data){ ResetDisassemblyDisplay(); auto childComponent{DYNAMIC_POINTER_CAST(data.parentComponent.lock())->GetSelectedChild()}; if(childComponent){ RowItemDisplay&item{childComponent.value().get()}; Component(data.menu.type,"Item Icon")->SetItem(item.GetItem().lock()); Component(data.menu.type,"Disassembly Result")->SetIcon(item.GetItem().lock()->Icon().Decal()); Component(data.menu.type,"Disassembly Result Title")->SetLabel(item.GetItem().lock()->FragmentName()); Component(data.menu.type,"Fragment Total Count")->SetLabel(std::format("Currently Owned: {}",Inventory::GetItemCount(item.GetItem().lock()->FragmentName()))); EnableDisassemblyDisplay(); } return true; }, InventoryCreator::RowPlayer_InventoryUpdate, InventoryWindowOptions{.padding=1,.size={artificerDisassembleWindow->size.x/2-5.f-12.f,28}})END; auto backButton=artificerDisassembleWindow->ADD("Back",MenuComponent)(geom2d::rect{{0.f,artificerDisassembleWindow->size.y-12.f},{96.f,16.f}},"Back",[](MenuFuncData data){ Menu::CloseMenu(); return true; })END; Menu::AddInventoryListener(inventoryDisplay,"Accessories"); ResetDisassemblyDisplay(); artificerDisassembleWindow->SetupKeyboardNavigation( [](MenuType type,Data&returnData){ //On Open auto&items{Component(type,"Accessory List")->GetComponents()}; if(items.size()>0){ returnData=items[0]; }else{ returnData="Back"; } }, { //Button Key {game->KEY_SCROLL,{"Navigate",[](MenuType type){}}}, {game->KEY_BACK,{"Stay",[](MenuType type){ Menu::CloseMenu(); }}}, {game->KEY_CONFIRM,{"Select",[](MenuType type){}}}, {{game->KEY_SHOULDER2,Pressed},{"Scroll Up/Down",[](MenuType type){}}}, {{game->KEY_SHOULDER,Pressed},{"Scroll Up/Down",[](MenuType type){}}}, {{game->KEY_FASTSCROLLUP,PressedDAS},{"Scroll",[](MenuType type){ Menu::menus[type]->GetSelection().lock()->parentComponent.lock()->DecreaseSelectionIndex(3.f); }}}, {{game->KEY_FASTSCROLLDOWN,PressedDAS},{"Scroll",[](MenuType type){ Menu::menus[type]->GetSelection().lock()->parentComponent.lock()->IncreaseSelectionIndex(3.f); }}}, } ,{ //Button Navigation Rules {"Accessory List",{ .up=[&](MenuType type,Data&returnData){ Menu::ScrollUp(type,"Accessory List",returnData,"Back"); }, .down=[&](MenuType type,Data&returnData){ Menu::ScrollDown(type,"Accessory List",returnData,"Back"); }, .left="Back", .right=[&](MenuType type,Data&returnData){ Menu::menus[type]->GetSelection().lock()->Click(); returnData="Disassemble Button"; },}}, {"Back",{ .up=[&](MenuType type,Data&returnData){ if(Component(type,"Accessory List")->GetSelectedChild())returnData=Component(type,"Accessory List")->GetSelectedChild().value().get().GetName(); else returnData=Component(type,"Accessory List")->GetComponents().back().lock()->GetName(); }, .down=[&](MenuType type,Data&returnData){ if(Component(type,"Accessory List")->GetSelectedChild())returnData=Component(type,"Accessory List")->GetSelectedChild().value().get().GetName(); else returnData=Component(type,"Accessory List")->GetComponents().front().lock()->GetName(); }, .left="Disassemble Button", .right="Disassemble Button",}}, {"Disassemble Button",{ .up=[&](MenuType type,Data&returnData){ returnData=Component(type,"Accessory List")->GetComponents().back().lock()->GetName(); }, .down=[&](MenuType type,Data&returnData){ returnData=Component(type,"Accessory List")->GetComponents().front().lock()->GetName(); }, .left=[&](MenuType type,Data&returnData){ if(Component(type,"Accessory List")->GetSelectedChild())returnData=Component(type,"Accessory List")->GetSelectedChild().value().get().GetName(); else returnData="Back"; }, .right="Back",}}, } ); }