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-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-01 01:48:27 -05:00
MenuType menuDest ;
private :
float hoverEffect = 0 ;
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-01 01:48:27 -05:00
protected :
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-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-05 00:42:28 -05:00
virtual void Draw ( Crawler * game , vf2d parentPos , bool focused ) ;
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-10-17 00:31:56 -05:00
MenuComponent ( MenuType parent , geom2d : : rect < float > rect , std : : string label , MenuFunc onClick , bool selectable = true , bool selectableViaKeyboard = true ) ;
MenuComponent ( MenuType parent , geom2d : : rect < float > rect , std : : string label , MenuType menuDest , MenuFunc onClick , bool selectable = true , bool selectableViaKeyboard = true ) ;
2023-10-12 19:35:16 -05:00
void _Update ( Crawler * game ) ;
void _Draw ( Crawler * game , vf2d parentPos , bool focused ) ;
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-01 01:48:27 -05:00
} ;