Fixed up menu components to not rely on old parent positions.

pull/28/head
sigonasr2 12 months ago
parent 7a46f79f2b
commit 44fcbc80cd
  1. 10
      Crawler/CharacterAbilityPreviewComponent.h
  2. 8
      Crawler/CharacterRotatingDisplay.h
  3. 8
      Crawler/Crawler.vcxproj
  4. 9
      Crawler/MenuComponent.cpp
  5. 1
      Crawler/MenuLabel.h
  6. 2
      Crawler/Version.h
  7. 26
      Crawler/olcPGEX_ViewPort.h
  8. BIN
      x64/Release/Crawler.exe

@ -55,13 +55,21 @@ protected:
MenuLabel::Update(game);
}
virtual void inline DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{
MenuLabel::DrawDecal(window,parentPos,focused);
vi2d iconPos=parentPos+rect.pos+vi2d{5,5};
vi2d textPos=iconPos+vi2d{12,12};
vi2d textPos=iconPos;
float textWidth=game->GetTextSizeProp(ability->input->GetDisplayName()).x*0.5f+4;
float boxWidth=rect.size.y-4; //No, the y is not a typo. It's a square, we use the y to determine the x.
window.DrawRectDecal(parentPos+rect.pos+vi2d{2,2},vi2d{int(rect.size.y)-4,int(rect.size.y)-4});
window.DrawDecal(iconPos,GFX[ability->icon].Decal());
vi2d descriptionPos=iconPos+vi2d{int(rect.size.y)-2,-1};
window.DrawShadowStringPropDecal(descriptionPos,util::WrapText(game,ability->description,int(rect.size.x-(descriptionPos.x-rect.pos.x)),true,{0.8f,1.0f}),WHITE,BLACK,{0.8f,1.f});
if(textWidth>boxWidth){
window.DrawShadowStringPropDecal(textPos,ability->input->GetDisplayName(),WHITE,BLACK,{boxWidth/textWidth*0.5f,0.5});
}else{

@ -64,10 +64,10 @@ protected:
}
virtual inline void DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{
window.DrawWarpedDecal(icon,std::array<vf2d,4>{
Menu::menus[parentMenu]->pos+rect.pos+vf2d{abs(sin(timer)),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor},
Menu::menus[parentMenu]->pos+rect.pos+vf2d{0,rect.size.y}+vf2d{abs(sin(timer)),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor},
Menu::menus[parentMenu]->pos+rect.pos+rect.size+vf2d{-abs(sin(float(timer+PI))),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor},
Menu::menus[parentMenu]->pos+rect.pos+vf2d{rect.size.x,0}+vf2d{-abs(sin(float(timer+PI))),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor},
rect.pos+vf2d{abs(sin(timer)),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor},
rect.pos+vf2d{0,rect.size.y}+vf2d{abs(sin(timer)),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor},
rect.pos+rect.size+vf2d{-abs(sin(float(timer+PI))),sin(float(timer+PI))}*vf2d{rotatingFactor,perspectiveFactor},
rect.pos+vf2d{rect.size.x,0}+vf2d{-abs(sin(float(timer+PI))),sin(timer)}*vf2d{rotatingFactor,perspectiveFactor},
});
}
};

@ -154,12 +154,14 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>freetype.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File update_version.ps1 "./version.h"</Command>
@ -175,12 +177,14 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>freetype.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File update_version.ps1 "./version.h"</Command>
@ -220,12 +224,14 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>freetype.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File update_version.ps1 "./version.h"</Command>
@ -244,12 +250,14 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpp20</LanguageStandard>
<AdditionalOptions>/MP8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>C:\Users\sigon\Documents\include;</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>freetype.lib;$(CoreLibraryDependencies);%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<PreBuildEvent>
<Command>powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive -File update_version.ps1 "./version.h"</Command>

@ -96,7 +96,6 @@ void MenuComponent::_Update(Crawler*game){
void MenuComponent::OnEquipStatsUpdate(){}
void MenuComponent::DrawDecal(ViewPort&window,vf2d parentPos,bool focused){
parentPos+=Menu::menus[parentMenu]->pos;
if(background){
window.FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),hoverEffect/"ThemeGlobal.HighlightTime"_F));
}
@ -104,10 +103,10 @@ void MenuComponent::DrawDecal(ViewPort&window,vf2d parentPos,bool focused){
window.FillRectDecal(rect.pos+parentPos,rect.size,PixelLerp(Menu::themes[Menu::themeSelection].GetButtonCol(),Menu::themes[Menu::themeSelection].GetHighlightCol(),util::lerp(0.75f,1.0f,hoverEffect/"ThemeGlobal.HighlightTime"_F)));
}
if(border){
window.FillRectDecal(rect.pos+parentPos,{rect.size.x,1});
window.FillRectDecal(rect.pos+parentPos,{1,rect.size.y});
window.FillRectDecal(rect.pos+parentPos+vf2d{rect.size.x-1,0},{1,rect.size.y});
window.FillRectDecal(rect.pos+parentPos+vf2d{0,rect.size.y-1},{rect.size.x,1});
window.FillRectDecal(rect.pos+parentPos,{rect.size.x+1,1});
window.FillRectDecal(rect.pos+parentPos,{1,rect.size.y+1});
window.FillRectDecal(rect.pos+parentPos+vf2d{rect.size.x-1+1,0},{1,rect.size.y+1});
window.FillRectDecal(rect.pos+parentPos+vf2d{0,rect.size.y-1+1},{rect.size.x+1,1});
}
if(showDefaultLabel){
window.DrawStringPropDecal(rect.pos+parentPos+rect.size/2-vf2d(game->GetTextSizeProp(label))/2.f*labelScaling,label,WHITE,labelScaling);

@ -66,7 +66,6 @@ protected:
}
virtual void inline DrawDecal(ViewPort&window,vf2d parentPos,bool focused)override{
MenuComponent::DrawDecal(window,parentPos,focused);
parentPos+=Menu::menus[parentMenu]->pos;
std::string wrappedText=util::WrapText(game,label,int(rect.size.x),true,{float(scale),float(scale)});
vf2d drawPos=parentPos+rect.middle()-vf2d{game->GetTextSizeProp(wrappedText)}*float(scale)/2; //Assume centered.
if(!centered){

@ -39,7 +39,7 @@ All rights reserved.
#define VERSION_MAJOR 0
#define VERSION_MINOR 2
#define VERSION_PATCH 1
#define VERSION_BUILD 3881
#define VERSION_BUILD 3909
#define stringify(a) stringify_(a)
#define stringify_(a) #a

@ -2,6 +2,7 @@
#include "olcPixelGameEngine.h"
#include "olcPGEX_TTF.h"
#include "olcUTIL_Geometry2D.h"
#include <algorithm>
#include <array>
@ -9,6 +10,7 @@
#include <cstdint>
#include <iostream>
#include <vector>
#include <limits>
// Declarations
namespace olc {
@ -16,6 +18,7 @@ namespace olc {
public:
ViewPort();
ViewPort(std::vector<vf2d> vertices, vf2d offset = {0, 0});
geom2d::rect<float>rect;
virtual ~ViewPort();
void addPoint(vf2d point);
void clear();
@ -178,13 +181,15 @@ void olc::ViewPort::setOffset(vf2d offset) {
olc::ViewPort
olc::ViewPort::rectViewPort(vf2d topLeft, vf2d size, olc::vf2d offset) {
return {{
olc::ViewPort newPort={{
topLeft,
{topLeft.x, topLeft.y + size.y},
topLeft + size,
{topLeft.x + size.x, topLeft.y},
},
offset};
newPort.rect={topLeft,size};
return newPort;
}
void olc::ViewPort::DrawDecal(const olc::vf2d &pos,
@ -527,6 +532,15 @@ void olc::ViewPort::drawClippedDecal(Decal *decal,
std::vector<float> outputWs{ws, ws + elements};
std::vector<Pixel> outputCols{col, col + elements};
vf2d min={std::numeric_limits<float>::max(),std::numeric_limits<float>::max()},max;
bool pointsOutside=false;
for(vf2d&points:outputList){
if(!geom2d::contains(rect,points)){
pointsOutside=true;
break;
}
}
if(!pointsOutside)goto render;
for (auto i = 0u; i < clipVertices.size(); i++) {
auto clipA = clipVertices[i];
auto clipB = clipVertices[(i + 1) % 4];
@ -585,6 +599,8 @@ void olc::ViewPort::drawClippedDecal(Decal *decal,
return;
}
render:
for (auto &point : outputList) {
point += offset;
}
@ -833,10 +849,10 @@ void olc::ViewPort::DrawDropShadowStringDecal(Font&font, const olc::vf2d& pos, c
}
void olc::ViewPort::DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col)const{
FillRectDecal(pos,{size.x,float(pge->GetPixelSize().y)},col);
FillRectDecal(pos+vf2d{0,size.y-float(pge->GetPixelSize().y)},{size.x,float(pge->GetPixelSize().y)},col);
FillRectDecal(pos+vf2d{0,float(pge->GetPixelSize().y)},{float(pge->GetPixelSize().x),size.y-float(pge->GetPixelSize().y)*2},col);
FillRectDecal(pos+vf2d{size.x-float(pge->GetPixelSize().x),float(pge->GetPixelSize().y)},{float(pge->GetPixelSize().x),size.y-float(pge->GetPixelSize().y)*2},col);
FillRectDecal(pos,{size.x+1,1},col);
FillRectDecal(pos+vf2d{0,size.y-1+1},{size.x+1,1},col);
FillRectDecal(pos+vf2d{0,1},{1,size.y-1*2+1},col);
FillRectDecal(pos+vf2d{size.x-1+1,1},{1,size.y-1*2+1},col);
}
#endif

Binary file not shown.
Loading…
Cancel
Save