Skip to content

Commit

Permalink
Added support for weird punctuation characters
Browse files Browse the repository at this point in the history
  • Loading branch information
DMD authored and DMD committed Sep 5, 2016
1 parent a5748fc commit f8119f8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
5 changes: 4 additions & 1 deletion TemplePlus/feat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,10 @@ uint32_t _FeatPrereqsCheck(objHndl objHnd, feat_enums featIdx, feat_enums * feat
else if (featReqCode == 266)
{
#pragma region BAB Requirement
if ((int) templeFuncs.ObjGetBABAfterLevelling(objHnd, classCodeBeingLevelledUp) < featReqCodeArg){ return 0; }
auto babAfterLvl = critterSys.GetBaseAttackBonus(objHnd, classCodeBeingLevelledUp);
if (babAfterLvl < featReqCodeArg)
return 0;
// if ((int) templeFuncs.ObjGetBABAfterLevelling(objHnd, classCodeBeingLevelledUp) < featReqCodeArg){ return 0; }
#pragma endregion
}
else if (featReqCode >= stat_strength && featReqCode <= stat_charisma)
Expand Down
3 changes: 2 additions & 1 deletion TemplePlus/fonts/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Separates a block of text given flags into words split up
on lines and renders them.
*/
class TextLayouter {
friend class FontRenderer;
public:
TextLayouter(gfx::RenderingDevice& device, gfx::ShapeRenderer2d& shapeRenderer);
~TextLayouter();
Expand All @@ -56,7 +57,7 @@ class TextLayouter {

private:
void DrawBackgroundOrOutline(const TigRect& rect, const TigTextStyle& style);
int GetGlyphIdx(char ch, const char *text) const;
static int GetGlyphIdx(char ch, const char *text);
ScanWordResult ScanWord(const char* text,
int firstIdx,
int textLength,
Expand Down
40 changes: 36 additions & 4 deletions TemplePlus/fonts/fonts_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void TextLayouter::DrawBackgroundOrOutline(const TigRect& rect, const TigTextSty

}

int TextLayouter::GetGlyphIdx(char ch, const char* text) const {
int TextLayouter::GetGlyphIdx(char ch, const char* text) {

// First character found in the FNT files
constexpr auto FirstFontChar = '!';
Expand All @@ -281,11 +281,43 @@ int TextLayouter::GetGlyphIdx(char ch, const char* text) const {

auto glyphIdx = ch - FirstFontChar;

auto chUns = (unsigned char)ch;
if (chUns <= (unsigned char)'~')
return glyphIdx;

if (tig_font_is_english) {

if ( (unsigned char)ch >= FirstNonEnglish){
glyphIdx = (unsigned char)ch - ( (unsigned char)FirstNonEnglish - FirstNonEnglishIdx);

if (chUns >= FirstNonEnglish) {
glyphIdx = chUns - ((unsigned char)FirstNonEnglish - FirstNonEnglishIdx);
}
else
{
switch(chUns)
{
case 0x82:
return GetGlyphIdx(',', text);
case 0x83:
return GetGlyphIdx('f', text);
case 0x84:
return GetGlyphIdx(',', text);
case 0x85: // elipsis
return GetGlyphIdx(';', text);
case 0x91:
case 0x92:
return GetGlyphIdx('\'', text);
case 0x93:
case 0x94:
return GetGlyphIdx('"', text);
case 0x95:
return GetGlyphIdx('·', text);
case 0x96:
case 0x97:
return GetGlyphIdx('-', text);
default:
return GetGlyphIdx(' ', text); // speak english or die!!!
}
}

if ((glyphIdx < -1 || ch > '~') && ch != '\n') {
logger->warn("Tried to display character {} in text '{}'", glyphIdx, text);
glyphIdx = -1;
Expand Down
3 changes: 2 additions & 1 deletion TemplePlus/fonts/fonts_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using namespace gfx;

// First character found in the FNT files
constexpr auto FirstFontChar = '!';
const unsigned char FirstNonEnglishIdx = 92;

#pragma pack(push, 1)
struct GlyphVertex2d {
Expand Down Expand Up @@ -145,7 +146,7 @@ void FontRenderer::RenderRun(cstring_span<> text,
continue;
}

auto glyphIdx = *it - FirstFontChar;
auto glyphIdx = TextLayouter::GetGlyphIdx(*it, nullptr); //*it - FirstFontChar;

if ((unsigned char)*it == 0x20) {
glyphIdx = '-' - '!';
Expand Down
2 changes: 1 addition & 1 deletion tpdata/tprules/feat_properties.tab
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@
651 Improved Critical 524290 266 8 -1 -1 0 0 0 0 -1 0 0 0 0 0 0 0
652 Martial Weapon Proficiency 524290 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
653 Skill Focus 524290 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
654 Weapon Finesse 524290 -1 -1 581 1 587 2 588 1 221 5 -1 -1 0 0 0 0
654 Weapon Finesse 524290 266 1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0
655 Weapon Focus 524290 266 1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0
656 Greater Weapon Focus 524290 11 4 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0
657 Weapon Specialization 524290 11 8 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0
Expand Down

0 comments on commit f8119f8

Please sign in to comment.