2023-10-01 01:48:27 -05:00
#pragma once
2023-10-07 15:47:26 -05:00
#include "Menu.h"
2023-10-01 01:48:27 -05:00
2023-11-06 01:00:17 -06:00
enum class ButtonAttr {
NONE = 0b00 ,
UNSELECTABLE = 0b01 , //Makes the component unselectable.
UNSELECTABLE_VIA_KEYBOARD = 0b10 , //Makes the component unselectable via keyboard.
};
enum class ComponentAttr {
NONE = 0b0000 ,
LEFT_ALIGN = 0b0001 , //Labels are centered by default.
SHADOW = 0b0010 , //Adds shadows to the label text.
OUTLINE = 0b0100 , //Adds an outline around the component.
BACKGROUND = 0b1000 , //Renders the background of the menu theme for this component.
};
2023-10-12 21:12:10 -05:00
class MenuComponent : 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 ;
2023-10-01 01:48:27 -05:00
MenuType menuDest ;
private :
2023-10-12 19:35:16 -05:00
virtual bool GetHoverState ( Crawler * game );
2023-10-12 20:16:22 -05:00
//CALL THIS FOR A PARENT to check a child's DrawDecal validity!
virtual bool PointWithinParent ( MenuComponent * child , vi2d drawPos );
2023-10-23 00:05:30 -05:00
std :: pair < MenuType , std :: string > memoryLeakInfo ; //Used to identify memory leak hints for this component.
2023-10-01 01:48:27 -05:00
protected :
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-10-03 02:34:26 -05:00
std :: string label ;
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
MenuType parentMenu = MenuType :: ENUM_END ;
2023-10-12 19:35:16 -05:00
MenuComponent * parentComponent = nullptr ;
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-10-12 19:35:16 -05:00
bool disabled = false ; //If set to true, this component will not be rendered or updated.
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-10-01 01:48:27 -05:00
virtual void Update ( Crawler * game );
2023-10-24 04:52:24 -05:00
virtual void Draw ( Crawler * game , vf2d parentPos );
2023-10-11 19:50:12 -05:00
virtual void DrawDecal ( Crawler * game , vf2d parentPos , bool focused );
2023-10-12 19:35:16 -05:00
virtual bool GetHoverState ( Crawler * game , MenuComponent * child );
2023-10-15 12:58:39 -05:00
virtual void AfterCreate (); //Called after the creation of all menus finish.
2023-10-12 19:35:16 -05:00
public :
2023-11-06 01:00:17 -06:00
MenuComponent ( MenuType parent , geom2d :: rect < float > rect , std :: string label , MenuFunc onClick , ButtonAttr attributes = ButtonAttr :: NONE );
MenuComponent ( MenuType parent , geom2d :: rect < float > rect , std :: string label , MenuType menuDest , MenuFunc onClick , ButtonAttr attributes = ButtonAttr :: NONE );
2023-10-22 23:19:47 -05:00
virtual ~ MenuComponent ();
2023-10-12 19:35:16 -05:00
void _Update ( Crawler * game );
2023-11-06 00:05:09 -06:00
void _Draw ( Crawler * game );
2023-10-24 04:52:24 -05:00
void _Draw ( Crawler * game , vf2d parentPos );
2023-11-06 00:05:09 -06:00
void _DrawDecal ( Crawler * game , bool focused );
2023-10-12 19:35:16 -05:00
void _DrawDecal ( Crawler * game , vf2d parentPos , bool focused );
2023-10-17 05:35:19 -05:00
vf2d GetPos ();
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!
2023-10-07 18:28:19 -05:00
virtual MenuComponent * PickUpDraggableItem ();
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
virtual bool DropDraggableItem ( 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.
virtual bool HandleOutsideDisabledButtonSelection ( MenuComponent * disabledButton );
2023-10-18 16:06:08 +00:00
//Called whenever an inventory slot gets updated, whether it's adding or removing an item.
virtual void OnInventorySlotsUpdate ( ITCategory cat );
2023-10-24 03:03:34 -05:00
std :: string GetLabel ();
2023-10-24 04:52:24 -05:00
void Enable ( bool enabled );
2023-11-06 01:00:17 -06:00
};
constexpr auto operator | ( ButtonAttr attribute , ButtonAttr attribute2 ) noexcept
{
return ButtonAttr ( static_cast < std :: underlying_type_t < ButtonAttr >> ( attribute ) | static_cast < std :: underlying_type_t < ButtonAttr >> ( attribute2 ));
}
constexpr auto operator & ( ButtonAttr attribute , ButtonAttr attribute2 ) noexcept
{
return static_cast < std :: underlying_type_t < ButtonAttr >> ( attribute ) & static_cast < std :: underlying_type_t < ButtonAttr >> ( attribute2 );
}
constexpr auto operator | ( ComponentAttr attribute , ComponentAttr attribute2 ) noexcept
{
return ComponentAttr ( static_cast < std :: underlying_type_t < ComponentAttr >> ( attribute ) | static_cast < std :: underlying_type_t < ComponentAttr >> ( attribute2 ));
}
constexpr auto operator & ( ComponentAttr attribute , ComponentAttr attribute2 ) noexcept
{
return static_cast < std :: underlying_type_t < ComponentAttr >> ( attribute ) & static_cast < std :: underlying_type_t < ComponentAttr >> ( attribute2 );
}