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
2023-10-01 01:48:27 -05:00
# pragma once
2023-10-07 15:47:26 -05:00
# include "Menu.h"
2023-11-30 23:33:40 -06:00
# include "BitwiseEnum.h"
2023-10-01 01:48:27 -05:00
2023-11-06 01:00:17 -06:00
enum class ButtonAttr {
2023-12-19 17:10:04 -06:00
NONE = 0 b000 ,
UNSELECTABLE = 0 b001 , //Makes the component unselectable.
UNSELECTABLE_VIA_KEYBOARD = 0 b010 , //Makes the component unselectable via keyboard.
FIT_TO_LABEL = 0 b100 , //Scales the text horizontally to fit the label if the text takes up more space rather than wrapping.
2023-11-06 01:00:17 -06:00
} ;
enum class ComponentAttr {
2023-12-28 06:10:46 -06:00
NONE = 0 b0 ' 0000 ' 0000 ,
LEFT_ALIGN = 0 b0 ' 0000 ' 0001 , //Labels are centered by default.
2024-02-10 18:56:22 -06:00
RIGHT_ALIGN = 0 b0 ' 0000 ' 0010 , //Labels are centered by default.
SHADOW = 0 b0 ' 0000 ' 0100 , //Adds shadows to the label text.
OUTLINE = 0 b0 ' 0000 ' 1000 , //Adds an outline around the component.
BACKGROUND = 0 b0 ' 0001 ' 0000 , //Renders the background of the menu theme for this component.
FIT_TO_LABEL = 0 b0 ' 0010 ' 0000 , //Scales the text horizontally to fit the label if the text takes up more space rather than wrapping.
FIXED_WIDTH_FONT = 0 b0 ' 0100 ' 0000 , //Uses a fixed-width font (instead of a proportional one) for text rendering.
2024-02-29 03:55:15 -06:00
CENTER = 0 b0 ' 1000 ' 0000 , //Multi-line Centering for MenuLabels.
2023-11-06 01:00:17 -06:00
} ;
2023-12-10 23:02:16 -06:00
enum class SelectionType {
CROSSHAIR ,
HIGHLIGHT ,
INNER_BOX ,
2023-12-16 22:17:49 -06:00
NONE ,
2023-12-10 23:02:16 -06:00
} ;
2023-12-16 22:17:49 -06:00
using SelectionType : : CROSSHAIR ;
using SelectionType : : HIGHLIGHT ;
using SelectionType : : INNER_BOX ;
2023-12-10 23:02:16 -06:00
2023-12-27 20:40:01 -06:00
class InventoryScrollableWindowComponent ;
2023-12-08 16:36:51 -06:00
class MenuComponent : public IAttributable {
2023-10-01 01:48:27 -05:00
friend class Menu ;
2023-10-07 19:06:56 -05:00
friend class MenuItemButton ;
2023-10-12 18:35:45 -05:00
friend class ScrollableWindowComponent ;
2023-10-18 18:07:10 +00:00
friend class InventoryScrollableWindowComponent ;
2024-01-16 22:30:10 -06:00
friend class EncountersSpawnListScrollableWindowComponent ;
2023-11-14 23:20:13 -06:00
friend class MenuItemItemButton ;
2023-12-16 21:28:41 -06:00
friend class RowItemDisplay ;
2024-02-08 21:30:05 +00:00
friend class InventoryConsumableWindow ;
2024-02-29 03:55:15 -06:00
friend class FloatingMenuComponent ;
2023-12-16 21:28:41 -06:00
bool hoverState = false ;
bool runHoverFunctions = false ;
2023-10-01 01:48:27 -05:00
private :
2024-01-04 05:21:56 -06:00
virtual bool GetHoverState ( AiL * game ) ;
2023-10-23 00:05:30 -05:00
std : : pair < MenuType , std : : string > memoryLeakInfo ; //Used to identify memory leak hints for this component.
2024-01-04 05:21:56 -06:00
void _BeforeUpdate ( AiL * game ) ;
virtual void BeforeUpdate ( AiL * game ) ;
void _Update ( AiL * game ) ;
2023-12-14 04:18:05 -06:00
void _DrawDecal ( ViewPort & window , bool focused ) ;
2023-12-16 21:28:41 -06:00
void _OnMouseOut ( ) ;
void _OnHover ( ) ;
2023-12-10 23:02:16 -06:00
SelectionType selectionType = CROSSHAIR ;
2024-02-11 18:31:30 -06:00
bool disableOutsideWindow = false ; //If set to true, this component was automatically set to not be renderable outside the window.
bool disable = false ; //If set to true, this component will not be rendered or updated.
2024-02-17 00:32:38 -06:00
std : : string label = " " ;
2024-03-05 06:05:28 -06:00
std : : weak_ptr < MenuComponent > subcomponentParent ; //For subcomponents, this value provides the actual component this subcomponent was spawned from.
2023-10-01 01:48:27 -05:00
protected :
2023-12-09 01:58:46 -06:00
int depth = 0 ;
2023-10-24 04:52:24 -05:00
float hoverEffect = 0 ;
2023-10-15 14:59:35 -05:00
std : : string name = " " ;
2023-10-01 01:48:27 -05:00
geom2d : : rect < float > rect ;
2023-12-15 23:57:09 -06:00
vf2d originalPos ;
2023-10-03 02:34:26 -05:00
bool border = true ;
2023-10-07 16:26:03 -05:00
bool draggable = false ;
2023-10-22 10:35:53 -05:00
bool background = true ;
bool showDefaultLabel = true ;
2023-10-07 18:28:19 -05:00
MenuFunc onClick ;
2023-10-07 19:06:56 -05:00
bool hovered = false ;
2023-10-12 18:35:45 -05:00
bool selectable = true ;
2023-10-17 00:31:56 -05:00
bool selectableViaKeyboard = true ;
2023-12-16 22:17:49 -06:00
bool selected = false ;
2023-10-12 18:35:45 -05:00
bool renderInMain = true ; //If set to false, this component is the responsibility of some other windowing system and won't be rendered or updated via the main window loop.
2023-10-17 05:35:19 -05:00
bool valid = true ; //If set to false, this would cause the component to be removed.
2023-12-19 17:10:04 -06:00
bool fitToLabel = false ; //Will shrink text horizontally to fit the size of the label if the display text is too large.
2023-12-19 18:46:59 -06:00
bool grayedOut = false ; //If turned on, a button will appear grayed out and unresponsive.
2023-12-22 06:14:37 -06:00
int inventoryIndex = 0 ;
2024-01-30 17:43:21 +00:00
Pixel borderCol = WHITE ;
2023-12-10 20:14:32 -06:00
vf2d labelScaling = { 1 , 1 } ;
2024-01-04 05:21:56 -06:00
virtual void Update ( AiL * game ) ;
2023-12-15 23:57:09 -06:00
virtual void DrawDecal ( ViewPort & window , bool focused ) ;
2024-01-04 05:21:56 -06:00
virtual bool GetHoverState ( AiL * game , MenuComponent * child ) ;
2023-10-15 12:58:39 -05:00
virtual void AfterCreate ( ) ; //Called after the creation of all menus finish.
2023-11-14 23:20:13 -06:00
//CALL THIS FOR A PARENT to check a child's DrawDecal validity!
2023-12-14 01:43:42 -06:00
virtual bool PointWithinParent ( MenuComponent * child , vi2d drawPos ) ;
//CALL THIS FOR A PARENT to check a child's DrawDecal validity!
virtual bool PointWithinParent ( MenuComponent * child , geom2d : : rect < float > drawRect ) ;
2023-12-16 21:28:41 -06:00
virtual void OnMouseOut ( ) ;
virtual void OnHover ( ) ;
2024-02-11 18:31:30 -06:00
virtual void EnableOutsideWindow ( ) ;
virtual void DisableOutsideWindow ( ) ;
const bool IsEnabledOutsideWindow ( ) const ;
const bool IsDisabledOutsideWindow ( ) const ;
2024-09-11 19:35:41 -05:00
MenuFunc onHover = [ ] ( MenuFuncData dat ) { return true ; } ;
MenuFunc onMouseOut = [ ] ( MenuFuncData dat ) { return true ; } ;
2023-10-12 19:35:16 -05:00
public :
2023-12-08 16:36:51 -06:00
MenuType parentMenu = MenuType : : ENUM_END ;
2024-01-19 15:09:59 -06:00
std : : weak_ptr < ScrollableWindowComponent > parentComponent { } ;
2023-12-10 19:14:37 -06:00
MenuComponent ( geom2d : : rect < float > rect , std : : string label , MenuFunc onClick , ButtonAttr attributes = ButtonAttr : : NONE ) ;
2024-02-18 18:46:45 -06:00
MenuComponent ( geom2d : : rect < float > rect , std : : string label , MenuFunc onClick , vf2d labelScaling , ButtonAttr attributes = ButtonAttr : : NONE ) ;
2023-10-22 23:19:47 -05:00
virtual ~ MenuComponent ( ) ;
2023-10-17 05:35:19 -05:00
vf2d GetPos ( ) ;
2024-01-01 07:48:57 -06:00
const vf2d & GetSize ( ) const ;
2023-10-07 18:28:19 -05:00
//We picked up a draggable component, we should make a copy and return it here. If a nullptr is returned here, the pickup is not allowed.
2023-10-07 19:06:56 -05:00
//WARNING!!! This allocates a brand new component when successful!!! Be prepared to clear it!
2024-01-16 00:20:30 -06:00
virtual std : : unique_ptr < MenuComponent > PickUpDraggableItem ( ) ;
2023-10-07 18:28:19 -05:00
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
2024-01-16 00:20:30 -06:00
virtual bool DropDraggableItem ( std : : unique_ptr < MenuComponent > draggable ) ;
2023-10-17 00:50:58 -05:00
//A notification that a button outside the region has been selected. Return false if it's not allowed.
2024-01-16 00:20:30 -06:00
virtual bool HandleOutsideDisabledButtonSelection ( std : : weak_ptr < MenuComponent > disabledButton ) ;
2023-12-06 22:47:09 -06:00
//Called whenever equipment and base stats are updated, notifying a component that numbers that may be displayed have changed.
virtual void OnEquipStatsUpdate ( ) ;
2024-01-03 07:13:43 -06:00
virtual const std : : string & GetLabel ( ) const ;
2023-11-12 23:51:49 -06:00
std : : string GetName ( ) ;
2023-12-10 23:02:16 -06:00
virtual void SetSelected ( bool selected ) final ;
virtual void SetSelectionType ( SelectionType selectionType ) final ;
2024-02-11 18:31:30 -06:00
virtual void Enable ( ) ;
virtual void Disable ( ) ;
const bool IsEnabled ( ) const ;
const bool IsDisabled ( ) const ;
2024-02-16 17:58:10 -06:00
const bool IsGreyedOut ( ) const ;
2023-11-11 04:03:48 -06:00
virtual void Cleanup ( ) ;
2023-12-16 21:28:41 -06:00
virtual void SetHoverFunc ( std : : function < bool ( MenuFuncData ) > func ) ;
virtual void SetMouseOutFunc ( std : : function < bool ( MenuFuncData ) > func ) ;
2023-12-19 18:46:59 -06:00
void SetGrayedOut ( bool grayedOut ) ;
virtual void OnPlayerMoneyUpdate ( uint32_t newMoney ) ;
2023-12-29 01:00:42 -06:00
virtual void OnChapterUpdate ( uint8_t newChapter ) ;
2024-01-03 04:59:47 -06:00
virtual void Click ( ) ;
2024-01-29 23:55:40 -06:00
virtual void SetLabel ( std : : string newLabel ) ;
2024-03-05 06:05:28 -06:00
const std : : weak_ptr < MenuComponent > GetSubcomponentParent ( ) const ;
2023-11-30 23:33:40 -06:00
} ;