2023-11-20 23:25:36 -06:00
# pragma region License
2023-11-14 18:11:32 -06:00
/*
License ( OLC - 3 )
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
2024-01-02 00:46:32 -06:00
Copyright 2024 Joshua Sigona < sigonasr2 @ gmail . com >
2023-11-14 18:11:32 -06:00
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 .
2023-11-29 00:50:00 -06:00
2024-01-30 14:48:49 +00:00
Portions of this software are copyright © 2024 The FreeType
2023-11-29 00:50:00 -06:00
Project ( www . freetype . org ) . Please see LICENSE_FT . txt for more information .
All rights reserved .
2023-11-14 18:11:32 -06:00
*/
2023-11-20 23:25:36 -06:00
# pragma endregion
2024-01-04 05:21:56 -06:00
# include "AdventuresInLestoria.h"
2023-10-07 13:33:27 -05:00
# include "safemap.h"
# include "Item.h"
2023-10-07 15:47:26 -05:00
# include "MenuItemButton.h"
2023-10-07 19:06:56 -05:00
# include "MenuLabel.h"
2023-10-18 18:07:10 +00:00
# include "InventoryScrollableWindowComponent.h"
2023-10-07 13:33:27 -05:00
2023-12-05 23:07:49 -06:00
using A = Attribute ;
2023-10-07 13:33:27 -05:00
2023-11-14 23:20:13 -06:00
void Menu : : InitializeConsumableInventoryWindow ( ) {
2023-12-10 23:02:16 -06:00
int itemSpacing = 24 ;
int totalSpacing = 32 ;
2023-10-07 13:33:27 -05:00
2023-12-14 05:53:46 -06:00
vf2d windowSize = { float ( 160 + 16 ) , float ( 96 + 78 ) } ; //Need space for the button.
2023-10-11 19:50:12 -05:00
2023-12-10 19:14:37 -06:00
Menu * inventoryWindow = CreateMenu ( INVENTORY_CONSUMABLES , CENTERED , windowSize ) ;
2023-10-07 15:47:26 -05:00
2023-11-13 21:26:34 -06:00
inventoryWindow - > I ( A : : LOADOUT_SLOT ) = 0 ;
2024-01-16 00:20:30 -06:00
auto consumableWindow = inventoryWindow - > ADD ( " inventory " , InventoryScrollableWindowComponent ) ( geom2d : : rect < float > { { 0 , 15 } , { windowSize . x , 96.f } } , " itemName " , " itemDescription " ,
2023-11-21 21:23:48 -06:00
[ & ] ( MenuFuncData data ) {
2024-01-16 21:03:46 +00:00
std : : weak_ptr < MenuItemButton > button = DYNAMIC_POINTER_CAST < MenuItemButton > ( data . component . lock ( ) ) ;
2023-11-21 21:23:48 -06:00
data . game - > ClearLoadoutItem ( data . menu . I ( A : : LOADOUT_SLOT ) ) ;
2024-01-16 00:20:30 -06:00
for ( std : : weak_ptr < MenuComponent > component : data . parentComponent . lock ( ) - > GetComponents ( ) ) { //HACK ALERT! If we are accessing a parent component, it's because we are dealing with a scrolling window component, which has sub-components. So this should be a safe cast to make.
if ( component . lock ( ) - > GetName ( ) . starts_with ( " item " ) ) {
2024-01-16 21:03:46 +00:00
std : : weak_ptr < MenuItemButton > button2 = DYNAMIC_POINTER_CAST < MenuItemButton > ( component . lock ( ) ) ; //HACK ALERT! This is probably an item since we populated item lists using this name for the components. So we assume these are MenuItemButton classes.
2024-01-16 00:20:30 -06:00
if ( button2 . expired ( ) ) ERR ( " Could not cast item to a MenuItemButton*! " ) ;
if ( & * button2 . lock ( ) = = & * button . lock ( ) ) {
if ( button2 . lock ( ) - > selected ! = - 1 ) {
data . game - > ClearLoadoutItem ( button2 . lock ( ) - > selected ) ;
2023-11-21 21:23:48 -06:00
}
2024-01-16 00:20:30 -06:00
button2 . lock ( ) - > selected = - 1 ;
2023-11-21 21:23:48 -06:00
}
2024-01-16 00:20:30 -06:00
if ( button2 . lock ( ) - > selected = = data . menu . I ( A : : LOADOUT_SLOT ) ) {
button2 . lock ( ) - > selected = - 1 ;
2023-11-21 21:23:48 -06:00
}
}
}
2024-01-16 00:20:30 -06:00
button . lock ( ) - > selected = data . menu . I ( A : : LOADOUT_SLOT ) ;
data . game - > SetLoadoutItem ( button . lock ( ) - > selected , button . lock ( ) - > GetItem ( ) . lock ( ) - > ActualName ( ) ) ;
2023-11-21 21:23:48 -06:00
return true ;
2023-12-27 20:40:01 -06:00
} , InventoryCreator : : Player_InventoryUpdate ) END ;
2023-12-19 17:10:04 -06:00
Menu : : AddInventoryListener ( consumableWindow , " Consumables " ) ;
2023-10-12 18:35:45 -05:00
2023-10-17 05:35:19 -05:00
//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.
2024-01-16 00:20:30 -06:00
inventoryWindow - > ADD ( " Inventory Type Label " , MenuLabel ) ( geom2d : : rect < float > { { 0 , - 5 } , { windowSize . x - 1 , 18 } } , " Consumables " , 2 , ComponentAttr : : SHADOW | ComponentAttr : : BACKGROUND | ComponentAttr : : OUTLINE ) END ;
2023-12-20 19:45:49 -06:00
inventoryWindow - > ADD ( " itemName " , MenuLabel ) ( geom2d : : rect < float > ( vf2d { 2 , 90.f } , { windowSize . x - 4 , windowSize . y - 108 } ) , " " , 1 , ComponentAttr : : SHADOW ) END ;
inventoryWindow - > ADD ( " itemDescription " , MenuLabel ) ( geom2d : : rect < float > ( vf2d { 2 , 117.f } , { windowSize . x - 4 , windowSize . y - 108 } ) , " " , 1 , ComponentAttr : : SHADOW ) END ;
2023-11-14 23:20:13 -06:00
2024-01-16 00:20:30 -06:00
auto okButton = inventoryWindow - > ADD ( " OK Button " , MenuComponent ) ( geom2d : : rect < float > { { windowSize . x / 2 - 24 , 173.f } , { 48 , 12 } } , " Ok " , [ ] ( MenuFuncData data ) { Menu : : CloseMenu ( ) ; return true ; } ) END ;
2023-10-07 13:33:27 -05:00
}