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.
157 lines
7.3 KiB
157 lines
7.3 KiB
1 year ago
|
#pragma region License
|
||
1 year ago
|
/*
|
||
|
License (OLC-3)
|
||
|
~~~~~~~~~~~~~~~
|
||
|
|
||
11 months ago
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
||
1 year ago
|
|
||
|
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.
|
||
1 year ago
|
|
||
|
Portions of this software are copyright © 2023 The FreeType
|
||
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
||
|
All rights reserved.
|
||
1 year ago
|
*/
|
||
1 year ago
|
#pragma endregion
|
||
1 year ago
|
#pragma once
|
||
1 year ago
|
#include "Menu.h"
|
||
1 year ago
|
#include "BitwiseEnum.h"
|
||
1 year ago
|
|
||
1 year ago
|
enum class ButtonAttr{
|
||
12 months ago
|
NONE= 0b000,
|
||
|
UNSELECTABLE= 0b001, //Makes the component unselectable.
|
||
|
UNSELECTABLE_VIA_KEYBOARD= 0b010, //Makes the component unselectable via keyboard.
|
||
|
FIT_TO_LABEL= 0b100, //Scales the text horizontally to fit the label if the text takes up more space rather than wrapping.
|
||
1 year ago
|
};
|
||
|
|
||
|
enum class ComponentAttr{
|
||
11 months ago
|
NONE= 0b0'0000'0000,
|
||
|
LEFT_ALIGN= 0b0'0000'0001, //Labels are centered by default.
|
||
|
SHADOW= 0b0'0000'0010, //Adds shadows to the label text.
|
||
|
OUTLINE= 0b0'0000'0100, //Adds an outline around the component.
|
||
|
BACKGROUND= 0b0'0000'1000, //Renders the background of the menu theme for this component.
|
||
|
FIT_TO_LABEL= 0b0'0001'0000, //Scales the text horizontally to fit the label if the text takes up more space rather than wrapping.
|
||
|
FIXED_WIDTH_FONT= 0b0'0010'0000, //Uses a fixed-width font (instead of a proportional one) for text rendering.
|
||
1 year ago
|
};
|
||
|
|
||
12 months ago
|
enum class SelectionType{
|
||
|
CROSSHAIR,
|
||
|
HIGHLIGHT,
|
||
|
INNER_BOX,
|
||
12 months ago
|
NONE,
|
||
12 months ago
|
};
|
||
|
|
||
12 months ago
|
using SelectionType::CROSSHAIR;
|
||
|
using SelectionType::HIGHLIGHT;
|
||
|
using SelectionType::INNER_BOX;
|
||
12 months ago
|
|
||
11 months ago
|
class InventoryScrollableWindowComponent;
|
||
|
|
||
12 months ago
|
class MenuComponent:public IAttributable{
|
||
1 year ago
|
friend class Menu;
|
||
1 year ago
|
friend class MenuItemButton;
|
||
1 year ago
|
friend class ScrollableWindowComponent;
|
||
1 year ago
|
friend class InventoryScrollableWindowComponent;
|
||
1 year ago
|
friend class MenuItemItemButton;
|
||
12 months ago
|
friend class RowItemDisplay;
|
||
1 year ago
|
MenuType menuDest;
|
||
12 months ago
|
MenuFunc onHover=[](MenuFuncData dat){return true;};
|
||
|
MenuFunc onMouseOut=[](MenuFuncData dat){return true;};
|
||
|
bool hoverState=false;
|
||
|
bool runHoverFunctions=false;
|
||
1 year ago
|
private:
|
||
11 months ago
|
virtual bool GetHoverState(AiL*game);
|
||
1 year ago
|
std::pair<MenuType,std::string>memoryLeakInfo; //Used to identify memory leak hints for this component.
|
||
11 months ago
|
void _BeforeUpdate(AiL*game);
|
||
|
virtual void BeforeUpdate(AiL*game);
|
||
|
void _Update(AiL*game);
|
||
12 months ago
|
void _DrawDecal(ViewPort&window,bool focused);
|
||
12 months ago
|
void _OnMouseOut();
|
||
|
void _OnHover();
|
||
12 months ago
|
SelectionType selectionType=CROSSHAIR;
|
||
1 year ago
|
protected:
|
||
12 months ago
|
int depth=0;
|
||
1 year ago
|
float hoverEffect=0;
|
||
1 year ago
|
std::string name="";
|
||
1 year ago
|
geom2d::rect<float>rect;
|
||
12 months ago
|
vf2d originalPos;
|
||
1 year ago
|
std::string label;
|
||
|
bool border=true;
|
||
1 year ago
|
bool draggable=false;
|
||
1 year ago
|
bool background=true;
|
||
|
bool showDefaultLabel=true;
|
||
1 year ago
|
MenuFunc onClick;
|
||
1 year ago
|
bool hovered=false;
|
||
1 year ago
|
bool selectable=true;
|
||
1 year ago
|
bool selectableViaKeyboard=true;
|
||
12 months ago
|
bool selected=false;
|
||
1 year ago
|
bool disabled=false; //If set to true, this component will not be rendered or updated.
|
||
1 year ago
|
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.
|
||
1 year ago
|
bool valid=true; //If set to false, this would cause the component to be removed.
|
||
12 months ago
|
bool fitToLabel=false; //Will shrink text horizontally to fit the size of the label if the display text is too large.
|
||
12 months ago
|
bool grayedOut=false; //If turned on, a button will appear grayed out and unresponsive.
|
||
11 months ago
|
int inventoryIndex=0;
|
||
12 months ago
|
vf2d labelScaling={1,1};
|
||
11 months ago
|
virtual void Update(AiL*game);
|
||
12 months ago
|
virtual void DrawDecal(ViewPort&window,bool focused);
|
||
11 months ago
|
virtual bool GetHoverState(AiL*game,MenuComponent*child);
|
||
1 year ago
|
virtual void AfterCreate(); //Called after the creation of all menus finish.
|
||
1 year ago
|
//CALL THIS FOR A PARENT to check a child's DrawDecal validity!
|
||
12 months ago
|
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);
|
||
12 months ago
|
virtual void OnMouseOut();
|
||
|
virtual void OnHover();
|
||
1 year ago
|
public:
|
||
12 months ago
|
MenuType parentMenu=MenuType::ENUM_END;
|
||
|
MenuComponent*parentComponent=nullptr;
|
||
12 months ago
|
MenuComponent(geom2d::rect<float>rect,std::string label,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
|
||
|
MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,ButtonAttr attributes=ButtonAttr::NONE);
|
||
12 months ago
|
MenuComponent(geom2d::rect<float>rect,std::string label,MenuType menuDest,MenuFunc onClick,vf2d labelScaling,ButtonAttr attributes=ButtonAttr::NONE);
|
||
1 year ago
|
virtual ~MenuComponent();
|
||
1 year ago
|
vf2d GetPos();
|
||
11 months ago
|
const vf2d&GetSize()const;
|
||
1 year ago
|
//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.
|
||
1 year ago
|
//WARNING!!! This allocates a brand new component when successful!!! Be prepared to clear it!
|
||
1 year ago
|
virtual MenuComponent*PickUpDraggableItem();
|
||
|
//We are attempting to drop draggable onto this item. If it's not allowed, return false.
|
||
|
virtual bool DropDraggableItem(MenuComponent*draggable);
|
||
1 year ago
|
//A notification that a button outside the region has been selected. Return false if it's not allowed.
|
||
|
virtual bool HandleOutsideDisabledButtonSelection(MenuComponent*disabledButton);
|
||
12 months ago
|
//Called whenever equipment and base stats are updated, notifying a component that numbers that may be displayed have changed.
|
||
|
virtual void OnEquipStatsUpdate();
|
||
11 months ago
|
virtual const std::string&GetLabel()const;
|
||
1 year ago
|
std::string GetName();
|
||
12 months ago
|
virtual void SetSelected(bool selected)final;
|
||
|
virtual void SetSelectionType(SelectionType selectionType)final;
|
||
1 year ago
|
virtual void Enable(bool enabled);
|
||
1 year ago
|
virtual void Cleanup();
|
||
12 months ago
|
virtual void SetHoverFunc(std::function<bool(MenuFuncData)>func);
|
||
|
virtual void SetMouseOutFunc(std::function<bool(MenuFuncData)>func);
|
||
12 months ago
|
void SetGrayedOut(bool grayedOut);
|
||
|
virtual void OnPlayerMoneyUpdate(uint32_t newMoney);
|
||
11 months ago
|
virtual void OnChapterUpdate(uint8_t newChapter);
|
||
11 months ago
|
virtual void Click();
|
||
1 year ago
|
};
|