2023-09-28 21:13:04 +00:00
#pragma once
2023-10-17 05:35:19 -05:00
#include "Item.h"
2023-09-28 21:13:04 +00:00
#include <stack>
2023-10-03 02:34:26 -05:00
#include "safemap.h"
#include "Theme.h"
#include "Attributable.h"
2023-10-07 15:47:26 -05:00
#include "olcUTIL_Geometry2D.h"
2023-10-01 01:48:27 -05:00
2023-09-28 21:13:04 +00:00
class Crawler ;
2023-10-07 15:47:26 -05:00
class MenuComponent ;
enum MenuType {
TEST ,
TEST_2 ,
INVENTORY ,
///////////////////////////////////////////////////////////
/*DO NOT REMOVE!!*/ ENUM_END ////////////////////////////////
///////////////////////////////////////////////////////////
};
2023-09-28 21:13:04 +00:00
2023-10-03 02:34:26 -05:00
class Menu : IAttributable {
2023-09-29 00:03:20 -05:00
friend class Crawler ;
friend class Player ;
2023-10-01 01:11:53 -05:00
2023-10-06 17:19:02 -05:00
float buttonHoldTime = 0 ;
2023-10-03 02:34:26 -05:00
std :: vector < MenuComponent *> displayComponents ; //Components that are only for displaying purposes.
2023-10-01 01:11:53 -05:00
vi2d selection = { - 1 , - 1 };
2023-10-17 01:21:00 -05:00
vi2d lastActiveMousePos = {};
2023-10-06 17:19:02 -05:00
MenuComponent * draggingComponent = nullptr ;
2023-10-11 19:50:12 -05:00
Renderable r , overlay ;
2023-09-29 00:03:20 -05:00
public :
2023-10-15 12:58:39 -05:00
//The constructor is private. Use CreateMenu() instead!
Menu () = default ;
virtual ~ Menu () = default ;
2023-10-03 02:34:26 -05:00
void AddComponent ( std :: string key , MenuComponent * button );
2023-09-29 00:03:20 -05:00
void Update ( Crawler * game );
2023-09-28 21:13:04 +00:00
void Draw ( Crawler * game );
2023-09-29 00:03:20 -05:00
static void InitializeMenus ();
static void OpenMenu ( MenuType menu );
static std :: vector < Menu *> stack ;
2023-10-03 02:34:26 -05:00
static std :: string themeSelection ;
2023-10-03 04:09:42 -05:00
static safeunorderedmap < std :: string , Theme > themes ;
2023-10-06 15:00:27 -05:00
static const vf2d CENTERED ;
2023-10-07 19:06:56 -05:00
safemap < std :: string , MenuComponent *> components ; //A friendly way to interrogate any component we are interested in.
2023-10-11 19:50:12 -05:00
static std :: map < MenuType , Menu *> menus ;
vf2d pos ; //Specify the upper-left corner of the window. Using CENTERED will always put this where the upper-left corner would center the window.
vf2d size ; //Size in tiles (24x24), every menu will be tile-based
2023-10-17 05:35:19 -05:00
safemap < int /*Y*/ , std :: vector < MenuComponent *>> buttons ; //Buttons are stored in rows followed by their column order.
safemap < int /*Y*/ , std :: vector < MenuComponent *>> keyboardButtons ; //Button ordered storage for keyboard/menu
2023-10-07 15:47:26 -05:00
2023-10-15 14:59:35 -05:00
static Theme & GetCurrentTheme ();
2023-10-17 01:21:00 -05:00
bool UsingMouseNavigation ();
void SetMouseNavigation ( bool mouseNavigation );
2023-10-17 05:35:19 -05:00
static void InventorySlotsUpdated ( ITCategory cat ); //Called whenever an inventory item gets added to the player's inventory, thus increasing the total number of slots in our bag.
2023-09-29 00:03:20 -05:00
private :
2023-10-15 12:58:39 -05:00
Menu ( vf2d pos , vf2d size );
2023-10-06 17:19:02 -05:00
void HoverMenuSelect ( Crawler * game );
2023-09-29 00:03:20 -05:00
void MenuSelect ( Crawler * game );
2023-10-06 17:19:02 -05:00
void CheckClickAndPerformMenuSelect ( Crawler * game );
2023-10-15 12:58:39 -05:00
//Mandatory before any menu operations! This creates and sets up the menu in memory.
static Menu * CreateMenu ( MenuType type , vf2d pos , vf2d size );
static void InitializeTestMenu ();
static void InitializeTestSubMenu ();
static void InitializeInventoryWindow ();
2023-10-17 05:35:19 -05:00
static void InitializeCharacterInfoWindow ();
2023-10-02 19:54:21 +00:00
//X (0-3), Y (0-2) for specific 9-patch tile (tiled version).
static Renderable & GetPatchPart ( int x , int y );
2023-10-01 01:11:53 -05:00
2023-10-02 16:50:53 +00:00
void KeyboardButtonNavigation ( Crawler * game , vf2d menuPos );
2023-10-11 19:50:12 -05:00
void DrawScaledWindowBackground ( Crawler * game , vf2d menuPos );
void DrawTiledWindowBackground ( Crawler * game , vf2d menuPos );
void DrawScaledWindowBorder ( Crawler * game , vf2d menuPos );
void DrawTiledWindowBorder ( Crawler * game , vf2d menuPos );
2023-10-05 00:42:28 -05:00
2023-10-17 00:50:58 -05:00
//This triggers if we use a keyboard/controller input to try and select some off-screen menu item. We should ideally follow the menu cursor.
bool HandleOutsideDisabledButtonSelection ( MenuComponent * disabledButton );
2023-10-05 00:42:28 -05:00
Pixel GetRenderColor ();
2023-10-17 01:21:00 -05:00
static bool MOUSE_NAVIGATION ;
2023-09-28 21:13:04 +00:00
};
2023-10-07 15:47:26 -05:00
struct MenuFuncData {
Menu & menu ;
Crawler * game ;
MenuComponent * component ;
};
typedef std :: function < void ( MenuFuncData ) > MenuFunc ;