The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
5.6 KiB
119 lines
5.6 KiB
#pragma region License
|
|
/*
|
|
License (OLC-3)
|
|
~~~~~~~~~~~~~~~
|
|
|
|
Copyright 2018 - 2023 OneLoneCoder.com
|
|
|
|
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.
|
|
|
|
Portions of this software are copyright © 2023 The FreeType
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
All rights reserved.
|
|
*/
|
|
#pragma endregion
|
|
#pragma once
|
|
#include "Menu.h"
|
|
#include "BitwiseEnum.h"
|
|
|
|
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.
|
|
};
|
|
|
|
class MenuComponent:public IAttributable{
|
|
friend class Menu;
|
|
friend class MenuItemButton;
|
|
friend class ScrollableWindowComponent;
|
|
friend class InventoryScrollableWindowComponent;
|
|
friend class MenuItemItemButton;
|
|
MenuType menuDest;
|
|
private:
|
|
virtual bool GetHoverState(Crawler*game);
|
|
std::pair<MenuType,std::string>memoryLeakInfo; //Used to identify memory leak hints for this component.
|
|
virtual void BeforeUpdate(Crawler*game);
|
|
void _Update(Crawler*game);
|
|
void _Draw(Crawler*game);
|
|
void _Draw(Crawler*game,vf2d parentPos);
|
|
void _DrawDecal(Crawler*game,bool focused);
|
|
void _DrawDecal(Crawler*game,vf2d parentPos,bool focused);
|
|
protected:
|
|
int depth=0;
|
|
float hoverEffect=0;
|
|
std::string name="";
|
|
geom2d::rect<float>rect;
|
|
std::string label;
|
|
bool border=true;
|
|
bool draggable=false;
|
|
bool background=true;
|
|
bool showDefaultLabel=true;
|
|
MenuFunc onClick;
|
|
bool hovered=false;
|
|
bool selectable=true;
|
|
bool selectableViaKeyboard=true;
|
|
bool disabled=false; //If set to true, this component will not be rendered or updated.
|
|
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.
|
|
bool valid=true; //If set to false, this would cause the component to be removed.
|
|
bool decal=false; //If set to true, will use decal rendering (For foreground shenanigans)
|
|
virtual void Update(Crawler*game);
|
|
virtual void Draw(Crawler*game,vf2d parentPos);
|
|
virtual void DrawDecal(Crawler*game,vf2d parentPos,bool focused);
|
|
virtual bool GetHoverState(Crawler*game,MenuComponent*child);
|
|
virtual void AfterCreate(); //Called after the creation of all menus finish.
|
|
//CALL THIS FOR A PARENT to check a child's DrawDecal validity!
|
|
virtual bool PointWithinParent(MenuComponent*child,vi2d drawPos);
|
|
public:
|
|
MenuType parentMenu=MenuType::ENUM_END;
|
|
MenuComponent*parentComponent=nullptr;
|
|
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);
|
|
virtual ~MenuComponent();
|
|
vf2d GetPos();
|
|
//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.
|
|
//WARNING!!! This allocates a brand new component when successful!!! Be prepared to clear it!
|
|
virtual MenuComponent*PickUpDraggableItem();
|
|
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
|
|
virtual bool DropDraggableItem(MenuComponent*draggable);
|
|
//A notification that a button outside the region has been selected. Return false if it's not allowed.
|
|
virtual bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
|
//Called whenever an inventory slot gets updated, whether it's adding or removing an item.
|
|
virtual void OnInventorySlotsUpdate(ITCategory cat);
|
|
//Called whenever equipment and base stats are updated, notifying a component that numbers that may be displayed have changed.
|
|
virtual void OnEquipStatsUpdate();
|
|
std::string GetLabel();
|
|
std::string GetName();
|
|
virtual void Enable(bool enabled);
|
|
virtual void Cleanup();
|
|
}; |