111 lines
4.9 KiB
C++
111 lines
4.9 KiB
C++
#pragma region License
|
|
/*
|
|
License (OLC-3)
|
|
~~~~~~~~~~~~~~~
|
|
|
|
Copyright 2026 Amy Sigona <sigonasr2@gmail.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 © 2024 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 "MenuLabel.h"
|
|
#include "MenuItemButton.h"
|
|
#include "DEFINES.h"
|
|
#include "AdventuresInLestoria.h"
|
|
#include "Item.h"
|
|
#include "safemap.h"
|
|
|
|
INCLUDE_game
|
|
INCLUDE_ITEM_DATA
|
|
|
|
class MenuFragmentItemButton:public MenuItemItemButton{
|
|
protected:
|
|
ItemInfo*fragment;
|
|
public:
|
|
inline MenuFragmentItemButton(geom2d::rect<float>rect,const std::optional<std::string>fragmentName,MenuFunc onClick,IconButtonAttr attributes=IconButtonAttr::SELECTABLE)
|
|
:MenuItemItemButton(rect,{},onClick,DO_NOTHING,DO_NOTHING,"","",attributes),fragment(fragmentName?&ITEM_DATA[*fragmentName]:nullptr){
|
|
draggable=false;
|
|
if(fragment&&!fragment->IsFragmentOf())ERR("WARNING! Item is not a proper fragment! Only item fragments should be using MenuFragmentItemButtons!");
|
|
}
|
|
inline const ItemInfo&GetItemInfo()const{
|
|
return *fragment;
|
|
}
|
|
inline const ItemInfo&SetItemFragment(const std::string newFragmentName,bool labelUpdate=true){
|
|
fragment=&ITEM_DATA[newFragmentName];
|
|
if(labelUpdate){
|
|
UpdateLabel();
|
|
}
|
|
return GetItemInfo();
|
|
}
|
|
protected:
|
|
inline void UpdateLabel(){
|
|
std::string labelNameText;
|
|
std::string labelDescriptionText;
|
|
|
|
labelNameText=GetItemInfo().Name();
|
|
labelDescriptionText=GetItemInfo().Description();
|
|
|
|
if(hideDetails){
|
|
std::for_each(labelNameText.begin(),labelNameText.end(),[](char&c){c='?';});
|
|
std::for_each(labelDescriptionText.begin(),labelDescriptionText.end(),[](char&c){c='?';});
|
|
}
|
|
if(itemNameLabelName!=""){
|
|
Component<MenuLabel>(parentMenu,itemNameLabelName)->SetLabel(labelNameText);
|
|
Component<MenuLabel>(parentMenu,itemNameLabelName)->SetBorderCol(borderCol);
|
|
Component<MenuLabel>(parentMenu,itemNameLabelName)->Enable();
|
|
}
|
|
if(itemDescriptionLabelName!=""){
|
|
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->SetLabel(labelDescriptionText);
|
|
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->SetBorderCol(borderCol);
|
|
Component<MenuLabel>(parentMenu,itemDescriptionLabelName)->Enable();
|
|
}
|
|
}
|
|
virtual inline void Update(AiL*game)override{
|
|
MenuIconButton::Update(game);
|
|
UpdateLabel();
|
|
}
|
|
virtual inline void DrawDecal(ViewPort&window,bool focused)override{
|
|
MenuComponent::DrawDecal(window,focused);
|
|
if(valid&&!hideQty){
|
|
if(!ISBLANK(itemRef)&&!itemRef.lock()->IsEquippable()){
|
|
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,quantityTextScale);
|
|
}
|
|
}
|
|
}
|
|
if(fragment)window.DrawRotatedDecal(rect.middle(),fragment->Icon().Decal(),0.f,fragment->Icon().Sprite()->Size()/2,iconScale,tint);
|
|
}
|
|
}; |