2023-11-20 23:25:36 -06:00
|
|
|
#pragma region License
|
2023-11-14 23:20:13 -06:00
|
|
|
/*
|
|
|
|
License (OLC-3)
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
2024-01-02 00:46:32 -06:00
|
|
|
Copyright 2024 Joshua Sigona <sigonasr2@gmail.com>
|
2023-11-14 23:20:13 -06:00
|
|
|
|
|
|
|
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.
|
2023-11-29 00:50:00 -06:00
|
|
|
|
|
|
|
Portions of this software are copyright © 2023 The FreeType
|
|
|
|
Project (www.freetype.org). Please see LICENSE_FT.txt for more information.
|
|
|
|
All rights reserved.
|
2023-11-14 23:20:13 -06:00
|
|
|
*/
|
2023-11-20 23:25:36 -06:00
|
|
|
#pragma endregion
|
2023-11-14 23:20:13 -06:00
|
|
|
#pragma once
|
|
|
|
#include "Menu.h"
|
|
|
|
#include "MenuLabel.h"
|
|
|
|
#include "MenuItemButton.h"
|
|
|
|
#include "DEFINES.h"
|
2024-01-04 05:21:56 -06:00
|
|
|
#include "AdventuresInLestoria.h"
|
2023-11-14 23:20:13 -06:00
|
|
|
#include "Item.h"
|
|
|
|
#include "safemap.h"
|
|
|
|
|
|
|
|
INCLUDE_game
|
|
|
|
INCLUDE_ITEM_DATA
|
|
|
|
|
|
|
|
class MenuItemItemButton:public MenuIconButton{
|
|
|
|
private:
|
2023-11-16 17:36:36 -06:00
|
|
|
std::string itemNameLabelName;
|
|
|
|
std::string itemDescriptionLabelName;
|
2023-12-06 22:47:09 -06:00
|
|
|
bool hideQty=false;
|
2023-12-09 06:08:13 -06:00
|
|
|
CompactText compact=COMPACT;
|
2023-12-29 01:00:42 -06:00
|
|
|
bool hideDetails=false;
|
2023-12-31 18:05:41 -06:00
|
|
|
protected:
|
|
|
|
std::weak_ptr<Item>itemRef;
|
2023-11-14 23:20:13 -06:00
|
|
|
public:
|
2023-12-22 06:14:37 -06:00
|
|
|
inline MenuItemItemButton(geom2d::rect<float>rect,const std::weak_ptr<Item>itemRef,MenuType menuDest,MenuFunc onClick,std::string itemNameLabelName,std::string itemDescriptionLabelName,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
|
|
|
|
:MenuIconButton(rect,!ISBLANK(itemRef)?const_cast<Decal*>(itemRef.lock()->Decal()):nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
|
2023-12-05 23:07:49 -06:00
|
|
|
draggable=false;
|
2023-12-22 06:14:37 -06:00
|
|
|
valid=!ISBLANK(itemRef);
|
2023-12-05 23:07:49 -06:00
|
|
|
}
|
2023-12-22 06:14:37 -06:00
|
|
|
inline MenuItemItemButton(geom2d::rect<float>rect,const std::weak_ptr<Item>itemRef,MenuType menuDest,MenuFunc onClick,MenuFunc onHover,MenuFunc onMouseOut,std::string itemNameLabelName="",std::string itemDescriptionLabelName="",IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
|
|
|
|
:MenuIconButton(rect,!ISBLANK(itemRef)?const_cast<Decal*>(itemRef.lock()->Decal()):nullptr,menuDest,onClick,attributes),itemRef(itemRef),itemNameLabelName(itemNameLabelName),itemDescriptionLabelName(itemDescriptionLabelName){
|
2023-12-05 23:07:49 -06:00
|
|
|
runHoverFunctions=true;
|
2023-11-14 23:20:13 -06:00
|
|
|
draggable=false;
|
2023-12-22 06:14:37 -06:00
|
|
|
valid=!ISBLANK(itemRef);
|
2023-12-16 21:28:41 -06:00
|
|
|
SetHoverFunc(onHover);
|
|
|
|
SetMouseOutFunc(onMouseOut);
|
2023-11-14 23:20:13 -06:00
|
|
|
}
|
2023-12-22 06:14:37 -06:00
|
|
|
inline const std::weak_ptr<Item>GetItem(){
|
|
|
|
return itemRef;
|
2023-12-06 22:47:09 -06:00
|
|
|
}
|
2023-12-31 23:36:09 -06:00
|
|
|
inline const std::weak_ptr<Item>SetItem(const std::weak_ptr<Item>newItem,bool labelUpdate=true){
|
2023-12-28 02:55:59 -06:00
|
|
|
itemRef=newItem;
|
2023-12-31 23:36:09 -06:00
|
|
|
if(labelUpdate){
|
|
|
|
UpdateLabel();
|
|
|
|
}
|
2023-12-28 02:55:59 -06:00
|
|
|
UpdateIcon();
|
|
|
|
return itemRef;
|
2023-12-06 22:47:09 -06:00
|
|
|
}
|
|
|
|
inline void SetShowQuantity(bool show){
|
|
|
|
this->hideQty=!show;
|
2023-12-02 00:40:07 -06:00
|
|
|
}
|
2023-12-09 06:08:13 -06:00
|
|
|
inline void SetCompactDescriptions(bool compact){
|
|
|
|
if(compact)this->compact=COMPACT;
|
|
|
|
else this->compact=NON_COMPACT;
|
|
|
|
}
|
2023-12-17 00:44:22 -06:00
|
|
|
inline void UpdateIcon(){
|
2023-12-22 06:14:37 -06:00
|
|
|
if(ISBLANK(itemRef)){
|
2023-12-17 00:44:22 -06:00
|
|
|
icon=nullptr;
|
|
|
|
return;
|
|
|
|
}
|
2023-12-22 06:14:37 -06:00
|
|
|
icon=const_cast<Decal*>(itemRef.lock()->Decal());
|
2023-12-17 00:44:22 -06:00
|
|
|
}
|
2023-12-29 01:00:42 -06:00
|
|
|
inline void SetHideDetails(bool hideDetails){
|
|
|
|
this->hideDetails=hideDetails;
|
|
|
|
if(hideDetails){
|
|
|
|
tint=BLACK;
|
|
|
|
}else{
|
|
|
|
tint=WHITE;
|
|
|
|
}
|
|
|
|
}
|
2023-11-14 23:20:13 -06:00
|
|
|
protected:
|
2023-12-16 21:28:41 -06:00
|
|
|
virtual inline void OnMouseOut()override{
|
|
|
|
if(itemNameLabelName!=""){
|
|
|
|
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(false);
|
|
|
|
}
|
|
|
|
if(itemDescriptionLabelName!=""){
|
|
|
|
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(false);
|
2023-12-08 16:36:51 -06:00
|
|
|
}
|
|
|
|
}
|
2023-12-16 21:28:41 -06:00
|
|
|
virtual inline void OnHover()override{
|
|
|
|
UpdateLabel();
|
|
|
|
}
|
2023-12-16 23:07:54 -06:00
|
|
|
inline void UpdateLabel(){
|
2023-12-05 23:07:49 -06:00
|
|
|
std::string labelNameText;
|
|
|
|
std::string labelDescriptionText;
|
2023-12-16 23:07:54 -06:00
|
|
|
|
2023-12-22 06:14:37 -06:00
|
|
|
if(ISBLANK(itemRef)){
|
2023-11-14 23:20:13 -06:00
|
|
|
icon=nullptr;
|
2023-12-05 23:07:49 -06:00
|
|
|
labelNameText="";
|
|
|
|
labelDescriptionText="";
|
2023-12-16 23:07:54 -06:00
|
|
|
return;
|
2023-12-05 23:07:49 -06:00
|
|
|
}
|
2023-12-16 23:07:54 -06:00
|
|
|
|
2023-12-22 06:14:37 -06:00
|
|
|
icon=const_cast<Decal*>(itemRef.lock()->Decal());
|
|
|
|
labelNameText=itemRef.lock()->DisplayName();
|
|
|
|
labelDescriptionText=itemRef.lock()->Description(compact);
|
2023-12-29 01:00:42 -06:00
|
|
|
if(hideDetails){
|
|
|
|
std::for_each(labelNameText.begin(),labelNameText.end(),[](char&c){c='?';});
|
|
|
|
std::for_each(labelDescriptionText.begin(),labelDescriptionText.end(),[](char&c){c='?';});
|
|
|
|
}
|
2023-12-16 22:17:49 -06:00
|
|
|
if(itemNameLabelName!=""){
|
2023-12-16 21:28:41 -06:00
|
|
|
Component<MenuLabel>(parentMenu,itemNameLabelName)->label=labelNameText;
|
|
|
|
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable(true);
|
|
|
|
}
|
2023-12-16 22:17:49 -06:00
|
|
|
if(itemDescriptionLabelName!=""){
|
2023-12-16 21:28:41 -06:00
|
|
|
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->label=labelDescriptionText;
|
|
|
|
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable(true);
|
|
|
|
}
|
|
|
|
}
|
2024-01-04 05:21:56 -06:00
|
|
|
virtual inline void Update(AiL*game)override{
|
2023-12-16 21:28:41 -06:00
|
|
|
MenuIconButton::Update(game);
|
2023-12-22 06:14:37 -06:00
|
|
|
valid=!ISBLANK(itemRef);
|
|
|
|
|
|
|
|
if(!valid){
|
|
|
|
icon=nullptr;
|
|
|
|
}
|
2023-12-05 23:07:49 -06:00
|
|
|
if(hovered){
|
2023-12-16 21:28:41 -06:00
|
|
|
UpdateLabel();
|
2023-11-14 23:20:13 -06:00
|
|
|
}
|
|
|
|
}
|
2023-12-15 23:57:09 -06:00
|
|
|
virtual inline void DrawDecal(ViewPort&window,bool focused)override{
|
|
|
|
MenuIconButton::DrawDecal(window,focused);
|
2023-12-06 22:47:09 -06:00
|
|
|
if(valid&&!hideQty){
|
2023-12-29 06:25:54 -06:00
|
|
|
if(!ISBLANK(itemRef)&&!itemRef.lock()->IsEquippable()){
|
2023-12-26 01:54:14 -06:00
|
|
|
std::string quantityText="x"+std::to_string(itemRef.lock()->Amt());
|
|
|
|
vf2d quantityTextScale=rect.size/48.f;
|
|
|
|
vf2d textSize=vf2d(game->GetTextSizeProp(quantityText))*quantityTextScale;
|
|
|
|
vf2d drawPos=rect.pos+rect.size-textSize;
|
|
|
|
if(itemRef.lock()->Amt()!=INFINITE){
|
|
|
|
window.DrawShadowStringDecal(drawPos,quantityText,WHITE,BLACK,quantityTextScale);
|
|
|
|
}
|
2023-12-19 18:46:59 -06:00
|
|
|
}
|
2023-11-14 23:20:13 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|