Fixed clashing key names for text with the same information but differing widths. Corrected all GUI mispositioned text or incorrect wrapping on equip screens.

pull/28/head
sigonasr2 11 months ago
parent c795e7f891
commit 4c290e81aa
  1. 2
      Crawler/CharacterMenuWindow.cpp
  2. 50
      Crawler/Crawler.cpp
  3. 7
      Crawler/Item.cpp
  4. 4
      Crawler/Player.cpp
  5. 2
      Crawler/Player.h
  6. 2
      Crawler/State_GameRun.cpp
  7. 2
      Crawler/Version.h
  8. 24
      Crawler/olcPGEX_TransformedView.h
  9. 2
      Crawler/olcPGEX_ViewPort.h
  10. 2
      Crawler/olcPixelGameEngine.h

@ -135,7 +135,7 @@ void Menu::InitializeCharacterMenuWindow(){
equipList->RemoveAllComponents();
for(int counter=0;Item&it:availableEquipment){
Item&itemInvRef=Inventory::GetItem(it.ActualName());
auto equip=equipList->ADD("Equip Item "+std::to_string(counter),RowItemDisplay)({{2,2+counter*28.f},{120-15,28}},itemInvRef,
auto equip=equipList->ADD("Equip Item "+std::to_string(counter),RowItemDisplay)({{2,2+counter*29.f},{120-15,28}},itemInvRef,
[](MenuFuncData data){
RowItemDisplay*comp=dynamic_cast<RowItemDisplay*>(data.component);
if(comp!=nullptr){

@ -1305,9 +1305,9 @@ void Crawler::RenderCooldowns(){
if(loadoutSlot!=-1){
uint32_t itemAmt=GetLoadoutItem(loadoutSlot).Amt();
if(itemAmt>0){
std::string amtString="x"+std::to_string(itemAmt);
vf2d qtySize=vf2d{GetTextSize(amtString)}*vf2d{0.5f,0.75f};
DrawShadowStringDecal(pos+vf2d{20,20}-qtySize/2,amtString,WHITE,BLACK,{0.5f,0.75f});
std::string amtString="x"+std::to_string(itemAmt);
vf2d qtySize=vf2d{GetTextSize(amtString)}*vf2d{0.5f,0.75f};
DrawShadowStringDecal(pos+vf2d{20,20}-qtySize/2,amtString,WHITE,BLACK,{0.5f,0.75f});
}else{
DrawDecal(pos,GFX["square_skill_overlay_icon_empty.png"].Decal(),{1,1},DARK_RED);
shortNameCol=RED;
@ -1491,6 +1491,7 @@ void Crawler::InitializeLevel(std::string mapFile,MapName map){
void Crawler::LoadLevel(MapName map){
SPAWNER_LIST.clear();
foregroundTileGroups.clear();
MONSTER_LIST.clear();
currentLevel=map;
levelTime=0;
bossName="";
@ -1500,6 +1501,8 @@ void Crawler::LoadLevel(MapName map){
totalBossEncounterMobs=0;
Inventory::Clear("Monster Loot");
Inventory::Clear("Stage Loot");
GetPlayer()->SetState(State::NORMAL);
GetPlayer()->GetCastInfo()={};
#pragma region Monster Spawn Data Setup
for(auto&[key,value]:MAP_DATA[map].SpawnerData){
@ -2265,8 +2268,7 @@ void Crawler::SetLoadoutItem(int slot,std::string itemName){
bool Crawler::UseLoadoutItem(int slot){
if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+").");
if(GetLoadoutItem(slot).Amt()>0){
Inventory::UseItem(loadout[slot].ActualName());
GetLoadoutItem(slot).OnUseAction();
Inventory::UseItem(GetLoadoutItem(slot).ActualName());
GetLoadoutItem(slot).amt--;
return true;
}
@ -2276,6 +2278,44 @@ bool Crawler::UseLoadoutItem(int slot){
void Crawler::ClearLoadoutItem(int slot){
if(slot<0||slot>loadout.size()-1)ERR("Invalid inventory slot "+std::to_string(slot)+", please choose a slot in range (0-"+std::to_string(loadout.size()-1)+").");
loadout[slot].it=nullptr;
InputGroup*inputGroup=nullptr;
switch(slot){
case 0:{
inputGroup=&Player::KEY_ITEM1;
}break;
case 1:{
inputGroup=&Player::KEY_ITEM2;
}break;
case 2:{
inputGroup=&Player::KEY_ITEM3;
}break;
}
Ability itemAbility{"???","","",0,0,inputGroup,""};
switch(slot){
case 0:{
itemAbility.action=[&](Player*p,vf2d pos={}){
bool itemUsed=game->UseLoadoutItem(0);
return itemUsed;
};
game->GetPlayer()->SetItem1UseFunc(itemAbility);
Component<MenuItemItemButton>(MenuType::ITEM_LOADOUT,"Loadout Item 1")->UpdateIcon();
}break;
case 1:{
itemAbility.action=[&](Player*p,vf2d pos={}){
return game->UseLoadoutItem(1);
};
game->GetPlayer()->SetItem2UseFunc(itemAbility);
Component<MenuItemItemButton>(MenuType::ITEM_LOADOUT,"Loadout Item 2")->UpdateIcon();
}break;
case 2:{
itemAbility.action=[&](Player*p,vf2d pos={}){
return game->UseLoadoutItem(2);
};
game->GetPlayer()->SetItem3UseFunc(itemAbility);
Component<MenuItemItemButton>(MenuType::ITEM_LOADOUT,"Loadout Item 3")->UpdateIcon();
}break;
}
}
void Crawler::RenderFadeout(){

@ -318,17 +318,20 @@ bool Inventory::RemoveItem(IT it,ITCategory inventory,uint32_t amt){
if (!itemAmt)return false;
if (amt>=itemAmt){
inv.erase(inv.begin()+count);
if(!eraseFromLootWindow){
_inventory.erase(it);
}else{
inv.erase(inv.begin()+count);
}
//Callback for GUI inventories.
Menu::InventorySlotsUpdated(inventory);
return true;
}else{
inv.at(count).amt-=amt;
if(!eraseFromLootWindow){
_inventory.at(it).amt-=amt;
}else{
inv.at(count).amt-=amt;
}
return false;
}

@ -438,10 +438,6 @@ void Player::Update(float fElapsedTime){
if(CanAct(ability)){
if(ability.cooldown==0&&GetMana()>=ability.manaCost){
if(key.Held()||key.Released()&&&ability==castPrepAbility&&GetState()==State::PREP_CAST){
if(GetState()==State::CASTING){
SetState(State::NORMAL);
castInfo.castTimer=castInfo.castTotalTime=0;
}
if(AllowedToCast(ability)&&ability.action(this,{})){
ability.cooldown=ability.COOLDOWN_TIME;
ConsumeMana(ability.manaCost);

@ -55,7 +55,7 @@ struct DamageNumber;
class MenuComponent;
struct CastInfo{
std::string name;
std::string name="???";
float castTimer;
float castTotalTime;
vf2d castPos;

@ -91,7 +91,7 @@ void State_GameRun::OnUserUpdate(Crawler*game){
}
void State_GameRun::Draw(Crawler*game){
game->RenderHud();
FontTest(); //Enable to test font coloring.
//FontTest(); //Enable to test font coloring.
//FontSpriteTest(); //Enable to test font coloring.
}

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

@ -178,10 +178,10 @@ namespace olc
void DrawRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center = { 0.0f, 0.0f }, const olc::vf2d& scale = { 1.0f,1.0f }, const olc::Pixel& tint = olc::WHITE);
void DrawPartialRotatedDecal(const olc::vf2d& pos, olc::Decal* decal, const float fAngle, const olc::vf2d& center, const olc::vf2d& source_pos, const olc::vf2d& source_size, const olc::vf2d& scale = { 1.0f, 1.0f }, const olc::Pixel& tint = olc::WHITE);
// Draws a multiline string as a decal, with tiniting and scaling
void DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f });
void DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float shadowSizeFactor=1);
void DrawStringDecal(const olc::vf2d& pos, std::string_view sText, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max());
void DrawStringPropDecal(const olc::vf2d& pos, std::string_view sText, const olc::Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max());
void DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1);
void DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col = olc::WHITE, const Pixel shadowCol = olc::BLACK, const olc::vf2d& scale = { 1.0f, 1.0f },const float width=std::numeric_limits<float>::max(),const float shadowSizeFactor=1);
// Draws a single shaded filled rectangle as a decal
void FillRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
void DrawRectDecal(const olc::vf2d& pos, const olc::vf2d& size, const olc::Pixel col = olc::WHITE);
@ -624,22 +624,22 @@ namespace olc
pge->DrawPartialRotatedDecal(WorldToScreen(pos), decal, fAngle, center, source_pos, source_size, scale * m_vWorldScale * m_vRecipPixel, tint);
}
void TransformedView::DrawStringDecal(const olc::vf2d & pos, const std::string & sText, const olc::Pixel col, const olc::vf2d & scale)
void TransformedView::DrawStringDecal(const olc::vf2d & pos, std::string_view sText, const olc::Pixel col, const olc::vf2d & scale,const float width)
{
pge->DrawStringDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel);
pge->DrawStringDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel,width);
}
void TransformedView::DrawStringPropDecal(const olc::vf2d & pos, const std::string & sText, const olc::Pixel col, const olc::vf2d & scale )
void TransformedView::DrawStringPropDecal(const olc::vf2d & pos, std::string_view sText, const olc::Pixel col, const olc::vf2d & scale,const float width )
{
pge->DrawStringPropDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel);
pge->DrawStringPropDecal(WorldToScreen(pos), sText, col, scale * m_vWorldScale * m_vRecipPixel,width);
}
void TransformedView::DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
pge->DrawShadowStringDecal(WorldToScreen(pos),sText,col,shadowCol,scale,shadowSizeFactor);
void TransformedView::DrawShadowStringDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
pge->DrawShadowStringDecal(WorldToScreen(pos),sText,col,shadowCol,scale,width,shadowSizeFactor);
}
void TransformedView::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
pge->DrawShadowStringPropDecal(WorldToScreen(pos),sText,col,shadowCol,scale,shadowSizeFactor);
void TransformedView::DrawShadowStringPropDecal(const olc::vf2d& pos, std::string_view sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float width,const float shadowSizeFactor){
pge->DrawShadowStringPropDecal(WorldToScreen(pos),sText,col,shadowCol,scale,width,shadowSizeFactor);
}
void TransformedView::FillRectDecal(const olc::vf2d & pos, const olc::vf2d & size, const olc::Pixel col)

@ -636,6 +636,7 @@ void olc::ViewPort::DrawStringDecal(const olc::vf2d& pos, std::string_view sText
if(sText.length()==0)return;
static std::map<std::string,DecalData>garbageCollector;
std::string key{sText};
key+=std::to_string(width);
if(!disableDynamicScaling){
key+=scale.str();
}
@ -690,6 +691,7 @@ void olc::ViewPort::DrawStringPropDecal(const olc::vf2d& pos, std::string_view s
if(sText.length()==0)return;
static std::map<std::string,DecalData>garbageCollector;
std::string key{sText};
key+=std::to_string(width);
if(!disableDynamicScaling){
key+=scale.str();
}

@ -3361,6 +3361,7 @@ namespace olc
if(sText.length()==0)return;
static std::map<std::string,DecalData>garbageCollector;
std::string key{sText};
key+=std::to_string(width);
if(!disableDynamicScaling){
key+=scale.str();
}
@ -3394,6 +3395,7 @@ namespace olc
if(sText.length()==0)return;
static std::map<std::string,DecalData>garbageCollector;
std::string key{sText};
key+=std::to_string(width);
if(!disableDynamicScaling){
key+=scale.str();
}

Loading…
Cancel
Save