|
|
|
#pragma region License
|
|
|
|
/*
|
|
|
|
License (OLC-3)
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Copyright 2024 Joshua 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 "MenuComponent.h"
|
|
|
|
#include "ClassInfo.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
INCLUDE_ANIMATION_DATA
|
|
|
|
|
|
|
|
class LoadFileButton:public MenuComponent{
|
|
|
|
double playTime=-1;
|
|
|
|
int chapter=-1;
|
|
|
|
int level=-1;
|
|
|
|
std::string className="";
|
|
|
|
std::string saveFileName="";
|
|
|
|
int saveFileID=-1;
|
|
|
|
float animationTime=0;
|
|
|
|
public:
|
|
|
|
inline LoadFileButton(geom2d::rect<float>rect,const utils::datafile&metadata,const int saveFileID,MenuFunc onClick,ButtonAttr attributes)
|
|
|
|
:MenuComponent(rect,"",onClick,attributes),playTime(metadata.GetReal(0U)),chapter(metadata.GetInt(1U)),level(metadata.GetInt(2U)),className(metadata.GetString(3U)),saveFileName(metadata.GetString(4U)),saveFileID(saveFileID){
|
|
|
|
showDefaultLabel=false;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void Update(AiL*game)override{
|
|
|
|
MenuComponent::Update(game);
|
|
|
|
if(playTime==-1){
|
|
|
|
grayedOut=true;
|
|
|
|
}
|
|
|
|
animationTime+=game->GetElapsedTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void DrawDecal(ViewPort&window,bool focused)override{
|
|
|
|
MenuComponent::DrawDecal(window,focused);
|
|
|
|
|
|
|
|
if(playTime==-1){
|
|
|
|
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},"UNKNOWN");
|
|
|
|
}else{
|
|
|
|
const std::map<std::string,std::string>classAnimations={
|
|
|
|
{Warrior::name,Warrior::walk_s},
|
|
|
|
{Ranger::name,Ranger::walk_s},
|
|
|
|
{Wizard::name,Wizard::walk_s},
|
|
|
|
{Thief::name,Thief::walk_s},
|
|
|
|
{Trapper::name,Trapper::walk_s},
|
|
|
|
{Witch::name,Witch::walk_s},
|
|
|
|
};
|
|
|
|
|
|
|
|
std::string chapterText=std::format("Ch.{}",chapter);
|
|
|
|
vf2d chapterTextSize=game->GetTextSize(chapterText);
|
|
|
|
window.DrawShadowStringDecal(rect.pos+vf2d{rect.size.x-chapterTextSize.x-2,2},chapterText);
|
|
|
|
|
|
|
|
|
|
|
|
vf2d saveFileNameSize=game->GetTextSizeProp(saveFileName);
|
|
|
|
float spaceAvailable=rect.size.x-chapterTextSize.x-8;
|
|
|
|
float scaleRatio=1.f;
|
|
|
|
if(saveFileNameSize.x>spaceAvailable){
|
|
|
|
scaleRatio=spaceAvailable/saveFileNameSize.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.DrawShadowStringPropDecal(rect.pos+vf2d{2,2},saveFileName,WHITE,BLACK,vf2d{scaleRatio,1.f});
|
|
|
|
|
|
|
|
const Animate2D::Frame&frame=ANIMATION_DATA[classAnimations.at(className)].GetFrame(animationTime);
|
|
|
|
geom2d::rect<int>sprRect=frame.GetSourceRect();
|
|
|
|
window.DrawPartialDecal(rect.pos+vf2d{rect.size.x-26,rect.size.y-36},sprRect.size,frame.GetSourceImage()->Decal(),sprRect.pos,sprRect.size);
|
|
|
|
std::string levelClassText=std::format("Lv{} {}",level,className);
|
|
|
|
vf2d levelClassTextSize=game->GetTextSize(levelClassText);
|
|
|
|
window.DrawShadowStringDecal(rect.pos+vf2d{rect.size.x-levelClassTextSize.x-2,rect.size.y-10},levelClassText);
|
|
|
|
|
|
|
|
window.DrawShadowStringDecal(rect.pos+vf2d{2,12},util::timerStr(playTime));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline const int&getSaveFileID()const{
|
|
|
|
return saveFileID;
|
|
|
|
}
|
|
|
|
};
|