Implemented color code text in PGE.

pull/28/head
sigonasr2 1 year ago
parent e615831ded
commit 808cc32418
  1. 28
      Crawler/CharacterMenuWindow.cpp
  2. 2
      Crawler/MonsterAttribute.h
  3. 1
      Crawler/State_GameRun.cpp
  4. 2
      Crawler/Version.h
  5. 3
      Crawler/VisualNovel.h
  6. 14
      Crawler/olcPGEX_TTF.h
  7. 169
      Crawler/olcPixelGameEngine.h

@ -84,7 +84,7 @@ void Menu::InitializeCharacterMenuWindow(){
characterMenuWindow->AddComponent("Equip Selection Bottom Outline",equipSelectionBottomOutline);
characterMenuWindow->AddComponent("Equip Selection Select Button",equipSelectionSelectButton);
const std::array<ItemAttribute,7>displayAttrs{
const static std::array<ItemAttribute,7>displayAttrs{
ItemAttribute::health,
ItemAttribute::attack,
ItemAttribute::defense,
@ -133,43 +133,22 @@ void Menu::InitializeCharacterMenuWindow(){
},[&](MenuFuncData data){
MenuItemItemButton*button=(MenuItemItemButton*)data.component;
Item&buttonItem=button->GetItem();
const std::array<ItemAttribute,7>displayAttrs{
ItemAttribute::health,
ItemAttribute::attack,
ItemAttribute::defense,
ItemAttribute::moveSpdPct,
ItemAttribute::cdrPct,
ItemAttribute::critPct,
ItemAttribute::critDmgPct,
};
for(ItemAttribute attribute:displayAttrs){
int stat=buttonItem.GetStats().get(attribute);
if(stat>0){
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
std::string baseLabel=statDisplayLabel->S(Attribute::DISPLAY_TEXT);
std::string newLabel=baseLabel+" (+"+std::to_string(stat)+")";
statDisplayLabel->SetLabel(newLabel);
statDisplayLabel->I(Attribute::STAT_CHANGE)=stat;
}
}
return true;
},[&](MenuFuncData data){
MenuItemItemButton*button=(MenuItemItemButton*)data.component;
Item&buttonItem=button->GetItem();
const std::array<ItemAttribute,7>displayAttrs{
ItemAttribute::health,
ItemAttribute::attack,
ItemAttribute::defense,
ItemAttribute::moveSpdPct,
ItemAttribute::cdrPct,
ItemAttribute::critPct,
ItemAttribute::critDmgPct,
};
for(ItemAttribute attribute:displayAttrs){
int stat=buttonItem.GetStats().get(attribute);
if(stat>0){
MenuLabel*statDisplayLabel=Component<MenuLabel>(CHARACTER_MENU,"Attribute "+ItemAttributable::GetDisplayInfo(attribute).name+" Label");
std::string baseLabel=statDisplayLabel->S(Attribute::DISPLAY_TEXT);
statDisplayLabel->SetLabel(baseLabel);
statDisplayLabel->I(Attribute::STAT_CHANGE)=stat;
}
}
return true;
@ -206,7 +185,6 @@ void Menu::InitializeCharacterMenuWindow(){
attrStr+="%";
}
MenuLabel*attrLabel=NEW MenuLabel(CHARACTER_MENU,{{245,36+2+float(yOffset)},{62,18}},attrStr,1,ComponentAttr::SHADOW|ComponentAttr::LEFT_ALIGN);
attrLabel->S(Attribute::DISPLAY_TEXT)=attrStr;
yOffset+=20;
characterMenuWindow->AddComponent("Attribute "+data.name+" Label",attrLabel);
}

@ -70,5 +70,5 @@ enum class Attribute{
LOADOUT_SLOT, //Which loadout slot we are selecting an item for.
ALLOW_DRAGGING, //Whether or not to allow inventory dragging.
EQUIP_TYPE,
DISPLAY_TEXT,
STAT_CHANGE,
};

@ -40,6 +40,7 @@ All rights reserved.
#include "DEFINES.h"
#include "Menu.h"
#include "ItemDrop.h"
#include "VisualNovel.h"
INCLUDE_MONSTER_LIST
INCLUDE_game

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

@ -150,8 +150,9 @@ class VisualNovel{
std::string prevTheme="";
float textScrollTime=0;
static constexpr float maxTextScrollTime=1.0f;
public:
static Font font,narratorFont,locationFont;
private:
static std::set<std::string>graphicsToLoad;
static safemap<std::string,std::vector<std::unique_ptr<Command>>>storyLevelData;

@ -287,9 +287,21 @@ namespace olc {
olc::Font *prevToUse = nullptr;
Pixel textCol=color;
for (size_t i = 0; i < string.size(); i++) {
char32_t chr = string[i];
if(chr=='\r')continue;
else if (chr>=-128&&chr<-105)
{
textCol={PixelGameEngine::charToColor[chr].r,PixelGameEngine::charToColor[chr].g,PixelGameEngine::charToColor[chr].b,color.a};
continue;
}
else if (chr==Color::Reset[0])
{
textCol=color;
continue;
}
Font *toUse = this;
FT_UInt chrIndex = GetCharIndex(chr);
@ -328,7 +340,7 @@ namespace olc {
pen.x=rect.offset.x;
} else {
DrawBitmapTo(slot->bitmap_left,
pge->ScreenHeight() - slot->bitmap_top, bmp, color,
pge->ScreenHeight() - slot->bitmap_top, bmp, textCol,
sprite);
}
}

@ -1191,6 +1191,32 @@ namespace olc
int32_t TextEntryGetCursor() const;
bool IsTextEntryEnabled() const;
public:
static std::map<char,Pixel> charToColor;
static std::string Grey;
static std::string Dark_Grey;
static std::string Very_Dark_Grey;
static std::string Red;
static std::string Dark_Red;
static std::string Very_Dark_Red;
static std::string Yellow;
static std::string Dark_Yellow;
static std::string Very_Dark_Yellow;
static std::string Green;
static std::string Dark_Green;
static std::string Very_Dark_Green;
static std::string Cyan;
static std::string Dark_Cyan;
static std::string Very_Dark_Cyan;
static std::string Blue;
static std::string Dark_Blue;
static std::string Very_Dark_Blue;
static std::string Magenta;
static std::string Dark_Magenta;
static std::string Very_Dark_Magenta;
static std::string White;
static std::string Black;
static std::string Reset;
private:
@ -1479,6 +1505,31 @@ namespace olc
#pragma region pge_implementation
namespace olc
{
std::map<char,Pixel> PixelGameEngine::charToColor;
std::string PixelGameEngine::Grey;
std::string PixelGameEngine::Dark_Grey;
std::string PixelGameEngine::Very_Dark_Grey;
std::string PixelGameEngine::Red;
std::string PixelGameEngine::Dark_Red;
std::string PixelGameEngine::Very_Dark_Red;
std::string PixelGameEngine::Yellow;
std::string PixelGameEngine::Dark_Yellow;
std::string PixelGameEngine::Very_Dark_Yellow;
std::string PixelGameEngine::Green;
std::string PixelGameEngine::Dark_Green;
std::string PixelGameEngine::Very_Dark_Green;
std::string PixelGameEngine::Cyan;
std::string PixelGameEngine::Dark_Cyan;
std::string PixelGameEngine::Very_Dark_Cyan;
std::string PixelGameEngine::Blue;
std::string PixelGameEngine::Dark_Blue;
std::string PixelGameEngine::Very_Dark_Blue;
std::string PixelGameEngine::Magenta;
std::string PixelGameEngine::Dark_Magenta;
std::string PixelGameEngine::Very_Dark_Magenta;
std::string PixelGameEngine::White;
std::string PixelGameEngine::Black;
std::string PixelGameEngine::Reset; //Will render the original color provided when used.
// O------------------------------------------------------------------------------O
// | olc::Pixel IMPLEMENTATION |
// O------------------------------------------------------------------------------O
@ -3288,6 +3339,7 @@ namespace olc
void PixelGameEngine::DrawStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale)
{
olc::vf2d spos = { 0.0f, 0.0f };
Pixel textCol=col;
for (auto c : sText)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
@ -3299,11 +3351,19 @@ namespace olc
{
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
}
else if (c>=-128&&c<-105)
{
textCol={charToColor[c].r,charToColor[c].g,charToColor[c].b,col.a};
}
else if (c==Reset[0])
{
textCol=col;
}
else
{
int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), {float(ox) * 8.0f, float(oy) * 8.0f}, {8.0f, 8.0f}, scale, col);
DrawPartialDecal(pos + spos, fontRenderable.Decal(), {float(ox) * 8.0f, float(oy) * 8.0f}, {8.0f, 8.0f}, scale, textCol);
spos.x += 8.0f * scale.x;
}
}
@ -3312,6 +3372,7 @@ namespace olc
void PixelGameEngine::DrawStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const olc::vf2d& scale)
{
olc::vf2d spos = { 0.0f, 0.0f };
Pixel textCol=col;
for (auto c : sText)
{
if(c=='\r')continue; //Ignore carriage returns. Stupid Linux.
@ -3323,21 +3384,31 @@ namespace olc
{
spos.x += 8.0f * float(nTabSizeInSpaces) * scale.x;
}
else if (c>=-128&&c<-105)
{
textCol={charToColor[c].r,charToColor[c].g,charToColor[c].b,col.a};
}
else if (c==Reset[0])
{
textCol=col;
}
else
{
int32_t ox = (c - 32) % 16;
int32_t oy = (c - 32) / 16;
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, col);
DrawPartialDecal(pos + spos, fontRenderable.Decal(), { float(ox) * 8.0f + float(vFontSpacing[c - 32].x), float(oy) * 8.0f }, { float(vFontSpacing[c - 32].y), 8.0f }, scale, textCol);
spos.x += float(vFontSpacing[c - 32].y) * scale.x;
}
}
}
void PixelGameEngine::DrawShadowStringDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
std::string strippedText=sText;
std::erase_if(strippedText,[](char chr){return chr<0;});
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
if(x!=0||y!=0){
DrawStringDecal(pos+vf2d{x,y}, sText, shadowCol,scale);
DrawStringDecal(pos+vf2d{x,y}, strippedText, shadowCol,scale);
}
}
}
@ -3421,10 +3492,12 @@ namespace olc
}
void PixelGameEngine::DrawShadowStringPropDecal(const olc::vf2d& pos, const std::string& sText, const Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
std::string strippedText=sText;
std::erase_if(strippedText,[](char chr){return chr<0;});
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
if(x!=0||y!=0){
DrawStringPropDecal(pos+vf2d{x,y}, sText, shadowCol,scale);
DrawStringPropDecal(pos+vf2d{x,y}, strippedText, shadowCol,scale);
}
}
}
@ -3432,10 +3505,12 @@ namespace olc
}
void PixelGameEngine::DrawShadowString(const olc::vi2d& pos, const std::string& sText, Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
std::string strippedText=sText;
std::erase_if(strippedText,[](char chr){return chr<0;});
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
if(x!=0||y!=0){
DrawString(int32_t(pos.x+x),int32_t(pos.y+y), sText, shadowCol,int(scale.x));
DrawString(int32_t(pos.x+x),int32_t(pos.y+y), strippedText, shadowCol,int(scale.x));
}
}
}
@ -3443,10 +3518,12 @@ namespace olc
}
void PixelGameEngine::DrawShadowStringProp(const olc::vi2d& pos, const std::string& sText, Pixel col, const Pixel shadowCol, const olc::vf2d& scale,const float shadowSizeFactor){
std::string strippedText=sText;
std::erase_if(strippedText,[](char chr){return chr<0;});
for(float y=-shadowSizeFactor;y<=shadowSizeFactor+0.1;y+=shadowSizeFactor/2){
for(float x=-shadowSizeFactor;x<=shadowSizeFactor+0.1;x+=shadowSizeFactor/2){
if(x!=0||y!=0){
DrawStringProp(int32_t(pos.x+x),int32_t(pos.y+y), sText, shadowCol,int(scale.x));
DrawStringProp(int32_t(pos.x+x),int32_t(pos.y+y), strippedText, shadowCol,int(scale.x));
}
}
}
@ -3545,6 +3622,7 @@ namespace olc
int32_t sx = 0;
int32_t sy = 0;
Pixel::Mode m = nPixelMode;
Pixel textCol=col;
// Thanks @tucna, spotted bug with col.ALPHA :P
if (m != Pixel::CUSTOM) // Thanks @Megarev, required for "shaders"
{
@ -3562,6 +3640,14 @@ namespace olc
{
sx += 8 * nTabSizeInSpaces * scale;
}
else if (c>=-128&&c<-105)
{
textCol={charToColor[c].r,charToColor[c].g,charToColor[c].b,col.a};
}
else if (c==Reset[0])
{
textCol=col;
}
else
{
int32_t ox = (c - 32) % 16;
@ -3574,14 +3660,14 @@ namespace olc
if (fontRenderable.Sprite()->GetPixel(i + ox * 8, j + oy * 8).r > 0)
for (uint32_t is = 0; is < scale; is++)
for (uint32_t js = 0; js < scale; js++)
Draw(x + sx + (i * scale) + is, y + sy + (j * scale) + js, col);
Draw(x + sx + (i * scale) + is, y + sy + (j * scale) + js, textCol);
}
else
{
for (uint32_t i = 0; i < 8; i++)
for (uint32_t j = 0; j < 8; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 8, j + oy * 8).r > 0)
Draw(x + sx + i, y + sy + j, col);
Draw(x + sx + i, y + sy + j, textCol);
}
sx += 8 * scale;
}
@ -3615,7 +3701,7 @@ namespace olc
int32_t sx = 0;
int32_t sy = 0;
Pixel::Mode m = nPixelMode;
Pixel textCol=col;
if (m != Pixel::CUSTOM)
{
if (col.a != 255) SetPixelMode(Pixel::ALPHA);
@ -3632,6 +3718,14 @@ namespace olc
{
sx += 8 * nTabSizeInSpaces * scale;
}
else if (c>=-128&&c<-105)
{
textCol={charToColor[c].r,charToColor[c].g,charToColor[c].b,col.a};
}
else if (c==Reset[0])
{
textCol=col;
}
else
{
int32_t ox = (c - 32) % 16;
@ -3644,14 +3738,14 @@ namespace olc
if (fontRenderable.Sprite()->GetPixel(i + ox * 8 + vFontSpacing[c - 32].x, j + oy * 8).r > 0)
for (int32_t is = 0; is < int(scale); is++)
for (int32_t js = 0; js < int(scale); js++)
Draw(x + sx + (i * scale) + is, y + sy + (j * scale) + js, col);
Draw(x + sx + (i * scale) + is, y + sy + (j * scale) + js, textCol);
}
else
{
for (int32_t i = 0; i < vFontSpacing[c - 32].y; i++)
for (int32_t j = 0; j < 8; j++)
if (fontRenderable.Sprite()->GetPixel(i + ox * 8 + vFontSpacing[c - 32].x, j + oy * 8).r > 0)
Draw(x + sx + i, y + sy + j, col);
Draw(x + sx + i, y + sy + j, textCol);
}
sx += vFontSpacing[c - 32].y * scale;
}
@ -4021,6 +4115,55 @@ namespace olc
// Start OpenGL, the context is owned by the game thread
if (platform->CreateGraphics(bFullScreen, bEnableVSYNC, vViewPos, vViewSize) == olc::FAIL) return;
charToColor[-128]=GREY;
charToColor[-127]=DARK_GREY;
charToColor[-126]=VERY_DARK_GREY;
charToColor[-125]=RED;
charToColor[-124]=DARK_RED;
charToColor[-123]=VERY_DARK_RED;
charToColor[-122]=YELLOW;
charToColor[-121]=DARK_YELLOW;
charToColor[-120]=VERY_DARK_YELLOW;
charToColor[-119]=GREEN;
charToColor[-118]=DARK_GREEN;
charToColor[-117]=VERY_DARK_GREEN;
charToColor[-116]=CYAN;
charToColor[-115]=DARK_CYAN;
charToColor[-114]=VERY_DARK_CYAN;
charToColor[-113]=BLUE;
charToColor[-112]=DARK_BLUE;
charToColor[-111]=VERY_DARK_BLUE;
charToColor[-110]=MAGENTA;
charToColor[-109]=DARK_MAGENTA;
charToColor[-108]=VERY_DARK_MAGENTA;
charToColor[-107]=WHITE;
charToColor[-106]=BLACK;
Grey =std::string(1,char(-128));
Dark_Grey =std::string(1,char(-127));
Very_Dark_Grey =std::string(1,char(-126));
Red =std::string(1,char(-125));
Dark_Red =std::string(1,char(-124));
Very_Dark_Red =std::string(1,char(-123));
Yellow =std::string(1,char(-122));
Dark_Yellow =std::string(1,char(-121));
Very_Dark_Yellow =std::string(1,char(-120));
Green =std::string(1,char(-119));
Dark_Green =std::string(1,char(-118));
Very_Dark_Green =std::string(1,char(-117));
Cyan =std::string(1,char(-116));
Dark_Cyan =std::string(1,char(-115));
Very_Dark_Cyan =std::string(1,char(-114));
Blue =std::string(1,char(-113));
Dark_Blue =std::string(1,char(-112));
Very_Dark_Blue =std::string(1,char(-111));
Magenta =std::string(1,char(-110));
Dark_Magenta =std::string(1,char(-109));
Very_Dark_Magenta =std::string(1,char(-108));
White =std::string(1,char(-107));
Black =std::string(1,char(-106));
Reset =std::string(1,char(-105));
// Construct default font sheet
olc_ConstructFontSheet();
@ -6954,4 +7097,6 @@ namespace olc
using namespace olc;
#define PI 3.14159f
#define PI 3.14159f
using Color=PixelGameEngine;
Loading…
Cancel
Save