From 7f20f12bf667109ec22136f9484fb3e23c832ddf Mon Sep 17 00:00:00 2001 From: dgengin Date: Sun, 10 Jul 2016 07:43:36 -0700 Subject: [PATCH] - update font code - update gamefiles --- gamefiles/res/level/bigtgoldCharMap.bin | Bin 0 -> 128 bytes gamefiles/res/level/bigtgoldSize.bin | Bin 258 -> 128 bytes gamefiles/res/level/fonts.json | 11 +- gamefiles/res/level/medtextsCharMap.bin | Bin 0 -> 128 bytes gamefiles/res/level/medtextsSize.bin | Bin 0 -> 128 bytes gamefiles/res/level/smaltextCharMap.bin | Bin 0 -> 128 bytes gamefiles/res/level/smaltextSize.bin | Bin 0 -> 128 bytes gamefiles/ui/level/charPanelLabels.json | 25 +++ gamefiles/ui/level/charPanelQuests.json | 7 +- gamefiles/ui/level/gameMenu.json | 15 +- gamefiles/ui/level/gameMenu2.json | 9 +- gamefiles/ui/level/gameMenuCommon.json | 4 +- gamefiles/ui/level/gamePanel.json | 13 +- gamefiles/ui/level/showText.json | 16 +- src/Actions/ActText.h | 29 ++- src/BitmapFont.cpp | 253 ++++++++++++------------ src/BitmapFont.h | 9 +- src/BitmapText.cpp | 13 +- src/BitmapText.h | 34 +++- src/CelUtils.cpp | 43 ++-- src/DrawableText.h | 3 +- src/FileUtils.cpp | 12 ++ src/FileUtils.h | 1 + src/Parser/ParseAction.cpp | 18 +- src/Parser/ParseBitmapFont.cpp | 2 +- src/Parser/ParseCursor.cpp | 2 +- src/Parser/ParseCursor.h | 0 src/Parser/ParseMenu.cpp | 13 +- src/Parser/ParseMenuButton.cpp | 11 +- src/Parser/ParseMenuButton.h | 8 +- src/Parser/ParseMenuQuests.cpp | 11 +- src/Parser/ParseMenuQuests.h | 8 +- src/Parser/ParseMenuSaveGames.cpp | 11 +- src/Parser/ParseMenuSaveGames.h | 8 +- src/Parser/ParseText.cpp | 5 +- src/StringText.h | 23 +-- src/Text2.h | 7 +- 37 files changed, 371 insertions(+), 253 deletions(-) create mode 100755 gamefiles/res/level/bigtgoldCharMap.bin create mode 100755 gamefiles/res/level/medtextsCharMap.bin create mode 100755 gamefiles/res/level/medtextsSize.bin create mode 100755 gamefiles/res/level/smaltextCharMap.bin create mode 100755 gamefiles/res/level/smaltextSize.bin mode change 100644 => 100755 src/Parser/ParseCursor.cpp mode change 100644 => 100755 src/Parser/ParseCursor.h diff --git a/gamefiles/res/level/bigtgoldCharMap.bin b/gamefiles/res/level/bigtgoldCharMap.bin new file mode 100755 index 0000000000000000000000000000000000000000..c826757537efabb4553912253810e2f276d0ab52 GIT binary patch literal 128 zcmezWp8!xXQ2no_uBWM`p<}FVVx}x5Eh8%@ub`-8WcXkAzv+JlMkZz!RyKAHPA+a9 eUOs*SK_OugQ894|NzMOSK(len3;!4S{~rLzG&3>) literal 0 HcmV?d00001 diff --git a/gamefiles/res/level/bigtgoldSize.bin b/gamefiles/res/level/bigtgoldSize.bin index ba9193bf14f6d62c44b52157eedbd371b2d58494..58602f61a587dbac7d71b49df67e43c131130c1a 100755 GIT binary patch literal 128 zcmZ{cF%Ezr5Cpg8jzob2A(sexrSbpI(}u#rZDx{57MQ!Hd>EW0*iN3;z@AE{lCxwH fafAheAx&d!mAJ-3d+M6h&U=i_gWs$Ft}x&MdIty$ literal 258 zcmajZ!43i;3xeVEUhdk%^gwm5rT)lZ%^& emycgSP)JxrR7_k#QuDtS&}`iD`u`37{|5kEb}`EU literal 0 HcmV?d00001 diff --git a/gamefiles/res/level/medtextsSize.bin b/gamefiles/res/level/medtextsSize.bin new file mode 100755 index 0000000000000000000000000000000000000000..2609c83389d2310fb6999ff22e5b325f7a3599dc GIT binary patch literal 128 zcmZ{c!3w}I3_`smTeWH0!S?^3x?FnLVS=bU5ZJnR`J@?%E8YF19oEw%v8*DELNW$h V)D&k-X6IPzSyK+LtA9=qcmccf1M2_) literal 0 HcmV?d00001 diff --git a/gamefiles/res/level/smaltextCharMap.bin b/gamefiles/res/level/smaltextCharMap.bin new file mode 100755 index 0000000000000000000000000000000000000000..1b4eb90006fc361602bec9951dfce94c6ab0cea8 GIT binary patch literal 128 zcmezWp8zn`wy-oe(^J>5QZrOBGFFz7mXVc{S5Q>aH?UTMC+6cQE@6%&_`)U?yGcleK6Ufof{=|2Ffe=NKJ literal 0 HcmV?d00001 diff --git a/gamefiles/res/level/smaltextSize.bin b/gamefiles/res/level/smaltextSize.bin new file mode 100755 index 0000000000000000000000000000000000000000..bac9f5c2e3b6e929313326573c0a2d41a36effad GIT binary patch literal 128 zcmZ{cF%E!048tnYOWG9v|6O#$4GegRrAUrA_{e7qBy9j9@{*TS+5owdZFPxNKylja PW{)3_lHeWx|8B+$ek=l~ literal 0 HcmV?d00001 diff --git a/gamefiles/ui/level/charPanelLabels.json b/gamefiles/ui/level/charPanelLabels.json index 65062305..cd3cf14d 100755 --- a/gamefiles/ui/level/charPanelLabels.json +++ b/gamefiles/ui/level/charPanelLabels.json @@ -7,6 +7,7 @@ "position": [84, 20], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.name|" }, { @@ -15,6 +16,7 @@ "position": [236, 20], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.class|" }, { @@ -23,6 +25,7 @@ "position": [85, 56], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.level|" }, { @@ -31,6 +34,7 @@ "position": [256, 56], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.experience|" }, { @@ -39,6 +43,7 @@ "position": [256, 84], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.expNextLevel|" }, { @@ -47,6 +52,7 @@ "position": [256, 134], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.gold|" }, { @@ -55,6 +61,7 @@ "position": [108, 144], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.strengthBase|" }, { @@ -63,6 +70,7 @@ "position": [156, 144], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.strengthNow|" }, { @@ -71,6 +79,7 @@ "position": [108, 172], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.magicBase|" }, { @@ -79,6 +88,7 @@ "position": [156, 172], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.magicNow|" }, { @@ -87,6 +97,7 @@ "position": [108, 200], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.dexterityBase|" }, { @@ -95,6 +106,7 @@ "position": [156, 200], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.dexterityNow|" }, { @@ -103,6 +115,7 @@ "position": [108, 228], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.vitalityBase|" }, { @@ -111,6 +124,7 @@ "position": [156, 228], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.vitalityNow|" }, { @@ -119,6 +133,7 @@ "position": [108, 256], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.points|", "format": "" }, @@ -128,6 +143,7 @@ "position": [108, 292], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.lifeBase|" }, { @@ -136,6 +152,7 @@ "position": [156, 292], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.lifeNow|" }, { @@ -144,6 +161,7 @@ "position": [108, 320], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.manaBase|" }, { @@ -152,6 +170,7 @@ "position": [156, 320], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.manaNow|" }, { @@ -160,6 +179,7 @@ "position": [278, 172], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.armorClass|" }, { @@ -168,6 +188,7 @@ "position": [278, 200], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.toHit|", "format": "[1]%" }, @@ -177,6 +198,7 @@ "position": [278, 228], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": ["|currentLevel|currentPlayer.damageMin|", "|currentLevel|currentPlayer.damageMax|"], "format": "[1]-[2]" }, @@ -186,6 +208,7 @@ "position": [278, 266], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.resistMagic|", "format": "[1]%" }, @@ -195,6 +218,7 @@ "position": [278, 292], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.resistFire|", "format": "[1]%" }, @@ -204,6 +228,7 @@ "position": [278, 320], "anchor": "left", "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "binding": "|currentLevel|currentPlayer.resistLightning|", "format": "[1]%" } diff --git a/gamefiles/ui/level/charPanelQuests.json b/gamefiles/ui/level/charPanelQuests.json index f6ff4952..160bd285 100755 --- a/gamefiles/ui/level/charPanelQuests.json +++ b/gamefiles/ui/level/charPanelQuests.json @@ -56,9 +56,10 @@ "menu": { "id": "menuQuests", "bitmapFont": "smaltext", - "position": [162, 128], + "position": [160, 135], "horizontalAlign": "center", "verticalAlign": "center", + "horizontalSpaceOffset": 1, "anchor": "left", "focus": true, "focusSound": "titlemov", @@ -89,7 +90,9 @@ "bitmapFont": "smaltext", "focus": true, "focusSound": "titlemov", - "position": [92, 297], + "position": [160, 298], + "horizontalAlign": "center", + "horizontalSpaceOffset": 1, "sound": "titlslct", "text": "Close Quest Log", "onClick": [ diff --git a/gamefiles/ui/level/gameMenu.json b/gamefiles/ui/level/gameMenu.json index 1ac5d40f..165f298c 100755 --- a/gamefiles/ui/level/gameMenu.json +++ b/gamefiles/ui/level/gameMenu.json @@ -8,9 +8,10 @@ "focus": true, "focusSound": "titlemov", "text": "Save Game", - "position": [319, 116], + "position": [321, 116], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onFocus": [ "anchorLeftPentagram", "anchorRightPentagram" @@ -23,9 +24,10 @@ "focus": true, "focusSound": "titlemov", "text": "Options", - "position": [319, 161], + "position": [321, 161], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onClick": [ { "name": "resource.pop" }, { "name": "load", "file": "ui/level/gameMenu2.json" } @@ -42,9 +44,10 @@ "focus": true, "focusSound": "titlemov", "text": "New Game", - "position": [319, 206], + "position": [321, 206], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onClick": [ { "name": "resource.popAll" }, { "name": "game.setProperty", "property": "musicVolume", "value": 100 }, @@ -64,9 +67,10 @@ "focus": true, "focusSound": "titlemov", "text": "Load Game", - "position": [319, 251], + "position": [320, 251], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onFocus": [ "anchorLeftPentagram", "anchorRightPentagram" @@ -79,9 +83,10 @@ "focus": true, "focusSound": "titlemov", "text": "Quit Diablo", - "position": [319, 296], + "position": [321, 296], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onClick": [ { "name": "game.fadeOut", diff --git a/gamefiles/ui/level/gameMenu2.json b/gamefiles/ui/level/gameMenu2.json index 6794e92d..b83533fc 100755 --- a/gamefiles/ui/level/gameMenu2.json +++ b/gamefiles/ui/level/gameMenu2.json @@ -214,6 +214,7 @@ "focusOnClick": false, "text": "Music", "position": [75, 116], + "horizontalSpaceOffset": 2, "anchor": "none", "onClick": [ "anchorLeftPentagram", @@ -244,6 +245,7 @@ "text": "Sound", "position": [75, 161], "anchor": "none", + "horizontalSpaceOffset": 2, "onClick": [ "anchorLeftPentagram", { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar2", "anchor": "right" }, @@ -273,6 +275,7 @@ "text": "Gamma", "position": [75, 206], "anchor": "none", + "horizontalSpaceOffset": 2, "onClick": [ "anchorLeftPentagram", { "name": "drawable.anchor", "id": "pent2", "idAnchor": "optbar3", "anchor": "right" }, @@ -300,9 +303,10 @@ "focus": true, "focusSound": "titlemov", "text": "Color Cycling On", - "position": [319, 251], + "position": [320, 251], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onClick": [ { "name": "button.setText", "id": "colorCycling", "text": "Color Cycling Off" }, "anchorLeftPentagram", @@ -325,9 +329,10 @@ "focus": true, "focusSound": "titlemov", "text": "Previous Menu", - "position": [319, 296], + "position": [320, 296], "anchor": "none", "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "onClick": [ { "name": "resource.pop" }, { "name": "load", "file": "ui/level/saveSettings.json" }, diff --git a/gamefiles/ui/level/gameMenuCommon.json b/gamefiles/ui/level/gameMenuCommon.json index 31780801..cdc31bf8 100755 --- a/gamefiles/ui/level/gameMenuCommon.json +++ b/gamefiles/ui/level/gameMenuCommon.json @@ -5,12 +5,12 @@ { "name": "action.set", "id": "anchorLeftPentagram", - "action": { "name": "drawable.anchorToFocused", "id": "pent1", "anchor": "left" } + "action": { "name": "drawable.anchorToFocused", "id": "pent1", "anchor": "left", "offset": [-1, 0] } }, { "name": "action.set", "id": "anchorRightPentagram", - "action": { "name": "drawable.anchorToFocused", "id": "pent2", "anchor": "right" } + "action": { "name": "drawable.anchorToFocused", "id": "pent2", "anchor": "right", "offset": [1, 0] } } ], "keyboard": [ diff --git a/gamefiles/ui/level/gamePanel.json b/gamefiles/ui/level/gamePanel.json index 5dc7c616..5dfbab84 100755 --- a/gamefiles/ui/level/gamePanel.json +++ b/gamefiles/ui/level/gamePanel.json @@ -63,7 +63,7 @@ "onHoverEnter": { "name": "text.setText", "id": "txtPanel", - "lineSpacing": 24, + "verticalSpaceOffset": 14, "text": "Character Information\nHotkey : 'C'" }, "onHoverLeave": { "name": "text.setText", "id": "txtPanel", "text": "" } @@ -93,7 +93,7 @@ "onHoverEnter": { "name": "text.setText", "id": "txtPanel", - "lineSpacing": 24, + "verticalSpaceOffset": 14, "text": "Quests Log\nHotkey : 'Q'" }, "onHoverLeave": { "name": "text.setText", "id": "txtPanel", "text": "" } @@ -119,7 +119,7 @@ "onHoverEnter": { "name": "text.setText", "id": "txtPanel", - "lineSpacing": 24, + "verticalSpaceOffset": 14, "text": "Inventory\nHotkey : 'I'" }, "onHoverLeave": { "name": "text.setText", "id": "txtPanel", "text": "" } @@ -145,7 +145,7 @@ "onHoverEnter": { "name": "text.setText", "id": "txtPanel", - "lineSpacing": 24, + "verticalSpaceOffset": 14, "text": "Spell Book\nHotkey : 'B'" }, "onHoverLeave": { "name": "text.setText", "id": "txtPanel", "text": "" } @@ -172,7 +172,7 @@ "onHoverEnter": { "name": "text.setText", "id": "txtPanel", - "lineSpacing": 24, + "verticalSpaceOffset": 14, "text": "Main Menu\nHotkey : Esc" }, "onHoverLeave": { "name": "text.setText", "id": "txtPanel", "text": "" } @@ -181,8 +181,9 @@ "id": "txtPanel", "bitmapFont": "smaltext", "anchor": "bottom", - "position": [320, 432], + "position": [320, 429], "horizontalAlign": "center", + "horizontalSpaceOffset": 2, "verticalAlign": "center" }, "keyboard": [ diff --git a/gamefiles/ui/level/showText.json b/gamefiles/ui/level/showText.json index ac4531da..1760bb93 100755 --- a/gamefiles/ui/level/showText.json +++ b/gamefiles/ui/level/showText.json @@ -1,10 +1,8 @@ { - "action": [ - { - "name": "resource.add", - "id": "{1}" - } - ], + "action": { + "name": "resource.add", + "id": "{1}" + }, "keyboard": { "key": ["enter", "esc", " "], "action": { "name": "button.click", "id": "textWallButton" } @@ -41,13 +39,15 @@ }, "scrollableText": { "id": "textBox", - "bitmapFont": "font30g", + "bitmapFont": "medtexts", "refresh": {2}, "file": "{3}", + "horizontalSpaceOffset": 2, + "verticalSpaceOffset": 17, "splitText": 40, "position": [48, 49], "anchor": "none", - "boxSize": [538, 257], + "boxSize": [550, 257], "onComplete": { "name": "resource.pop" } diff --git a/src/Actions/ActText.h b/src/Actions/ActText.h index 2e444f0c..aace3d88 100755 --- a/src/Actions/ActText.h +++ b/src/Actions/ActText.h @@ -9,20 +9,39 @@ class ActTextSetText : public Action private: std::string id; std::string text; - unsigned lineSpacing; + int horizSpaceOffset{ 0 }; + int vertSpaceOffset{ 0 }; + bool hasHorizSpaceOffset{ false }; + bool hasVertSpaceOffset{ false }; public: - ActTextSetText(const std::string& id_, const std::string& text_, unsigned lineSpacing_) - : id(id_), text(text_), lineSpacing(lineSpacing_) {} + ActTextSetText(const std::string& id_, const std::string& text_) + : id(id_), text(text_) {} + + void setHorizontalSpaceOffset(int offset) + { + horizSpaceOffset = offset; + hasHorizSpaceOffset = true; + } + + void setVerticalSpaceOffset(int offset) + { + vertSpaceOffset = offset; + hasVertSpaceOffset = true; + } virtual bool execute(Game& game) { auto item = game.Resources().getResource(id); if (item != nullptr) { - if (lineSpacing > 0) + if (hasHorizSpaceOffset == true) + { + item->setHorizontalSpaceOffset(horizSpaceOffset); + } + if (hasVertSpaceOffset == true) { - item->setLineSpacing(lineSpacing); + item->setVerticalSpaceOffset(vertSpaceOffset); } item->setText(game.getVariableString(text)); } diff --git a/src/BitmapFont.cpp b/src/BitmapFont.cpp index 94e2f1d4..6b92d679 100755 --- a/src/BitmapFont.cpp +++ b/src/BitmapFont.cpp @@ -189,98 +189,83 @@ BitmapFont::BitmapFont(const std::shared_ptr& tex, int rows_, int c int padding_, bool verticalDirection, const std::vector& charSizes) : texture(tex), rows(rows_), columns(columns_), padding(padding_) { - if (charSizes.size() == 258) + size_t charStartIdx = 0; + if (charSizes.size() == 130 || charSizes.size() == 258) { - int cellW = tex->getSize().x / columns; - int cellH = tex->getSize().y / rows; - int iRow = 0; - int iCol = 0; - for (auto i = 0; i < 256; i++) + charStartIdx = 2; + } + else if ((charSizes.size() == 128 || charSizes.size() == 256) == false) + { + this->calculateCharSizes(tex->copyToImage(), verticalDirection); + return; + } + + int cellW = tex->getSize().x / columns; + int cellH = tex->getSize().y / rows; + int iRow = 0; + int iCol = 0; + for (size_t i = 0; i < 256; i++) + { + chars[i].left = cellW * iCol; + chars[i].top = cellH * iRow; + auto charSizeIdx = i + charStartIdx; + if (charSizeIdx < charSizes.size()) { - chars[i].left = cellW * iCol; - chars[i].top = cellH * iRow; - chars[i].width = charSizes[i + 2]; - chars[i].height = cellH; + chars[i].width = charSizes[charSizeIdx]; + } + else + { + chars[i].width = 0; + } + chars[i].height = cellH; - if (verticalDirection == false) - { - iCol++; - if (iCol >= columns) - { - iCol = 0; - iRow++; - } - } - else + if (verticalDirection == false) + { + iCol++; + if (iCol >= columns) { + iCol = 0; iRow++; - if (iRow >= rows) - { - iRow = 0; - iCol++; - } } } - - space = charSizes[0]; - newLine = charSizes[1]; - } - else if (charSizes.size() == 256) - { - int cellW = tex->getSize().x / columns; - int cellH = tex->getSize().y / rows; - int iRow = 0; - int iCol = 0; - for (auto i = 0; i < 256; i++) + else { - chars[i].left = cellW * iCol; - chars[i].top = cellH * iRow; - chars[i].width = charSizes[i]; - chars[i].height = cellH; - - if (verticalDirection == false) + iRow++; + if (iRow >= rows) { + iRow = 0; iCol++; - if (iCol >= columns) - { - iCol = 0; - iRow++; - } - } - else - { - iRow++; - if (iRow >= rows) - { - iRow = 0; - iCol++; - } } } + } - space = charSizes[' ']; - newLine = charSizes['\n']; + if (charStartIdx > 0) + { + space = charSizes[0]; + newLine = charSizes[1]; } else { - this->calculateCharSizes(tex->copyToImage(), verticalDirection); + space = charSizes[' ']; + newLine = charSizes['\n']; } } -float BitmapFont::calculateLineLength(const char* text) const +float BitmapFont::calculateLineLength(const char* text, int horizSpaceOffset) const { + auto ch = text[0]; + if (ch == 0 || ch == '\n') + { + return 0.f; + } + //Temp offsets - float curX = 0; + float curX = 0.f; bool wasSpace = false; //Go through the text while (true) { - auto ch = text[0]; - if (ch == 0 || ch == '\n') - { - return curX; - } //If the current character is a space if (ch == ' ') { @@ -304,41 +289,41 @@ float BitmapFont::calculateLineLength(const char* text) const wasSpace = false; } text++; + ch = text[0]; + if (ch == 0 || ch == '\n') + { + return curX; + } + else + { + curX += (float)horizSpaceOffset; + } } } sf::Vector2f BitmapFont::calculateSize(const std::string& text) const { - return calculateSize(text, (float)newLine); + return calculateSize(text, 0, 0); } -sf::Vector2f BitmapFont::calculateSize(const std::string& text, const float newLine_) const +sf::Vector2f BitmapFont::calculateSize(const std::string& text, + int horizSpaceOffset, int vertSpaceOffset) const { //Temp offsets float maxX = 0, curX = 0, curY = 0; bool wasSpace = false; + auto textPtr = text.c_str(); + auto ch = textPtr[0]; + //Go through the text - for (auto ch : text) + while (ch != 0) { - //If the current character is a space - if (ch == ' ') - { - //Move over - curX += (float)space; - wasSpace = true; - } - //If the current character is a tab - else if (ch == '\t') - { - //Move over - curX += (float)chars['\t'].width; - } //If the current character is a newline - else if (ch == '\n') + if (ch == '\n') { //Move down - curY += newLine_; + curY += newLine + vertSpaceOffset; //Move back if (curX > maxX) @@ -350,27 +335,49 @@ sf::Vector2f BitmapFont::calculateSize(const std::string& text, const float newL } else { - //Get the ASCII value of the character - int ascii = (unsigned char)ch; + //If the current character is a space + if (ch == ' ') + { + //Move over + curX += (float)space; + wasSpace = true; + } + //If the current character is a tab + else if (ch == '\t') + { + //Move over + curX += (float)chars['\t'].width; + } + else + { + //Get the ASCII value of the character + int ascii = (unsigned char)ch; - //Move over the width of the character + padding - curX += (float)chars[ascii].width + (float)(wasSpace ? 0 : padding); - wasSpace = false; + //Move over the width of the character + padding + curX += (float)chars[ascii].width + (float)(wasSpace ? 0 : padding); + wasSpace = false; + } + if (textPtr[1] != 0) + { + curX += (float)horizSpaceOffset; + } } + textPtr++; + ch = textPtr[0]; } - return sf::Vector2f(std::max(maxX, curX), (newLine_ + curY)); + return sf::Vector2f(std::max(maxX, curX), (newLine + curY)); } void BitmapFont::draw(const sf::Vector2f& pos, const std::string& text, sf::RenderTarget& target, sf::RenderStates states, const sf::Color& color) const { - draw(pos, text, target, states, color, (float)newLine, 0.f, HorizontalAlign::Left); + draw(pos, text, target, states, color, 0, 0, 0.f, HorizontalAlign::Left); } void BitmapFont::draw(const sf::Vector2f& pos, const std::string& text, sf::RenderTarget& target, - sf::RenderStates states, const sf::Color& color, const float newLine_, - const float sizeX, const HorizontalAlign align) const + sf::RenderStates states, const sf::Color& color, int horizSpaceOffset, + int vertSpaceOffset, float sizeX, HorizontalAlign align) const { sf::Sprite sprite(*texture); sprite.setColor(color); @@ -381,61 +388,65 @@ void BitmapFont::draw(const sf::Vector2f& pos, const std::string& text, sf::Rend if (align == HorizontalAlign::Center) { - curX += std::round((sizeX / 2.f) - (calculateLineLength(&text.c_str()[0]) / 2.f)); + curX += std::round((sizeX / 2.f) - (calculateLineLength(&text.c_str()[0], horizSpaceOffset) / 2.f)); } else if (align == HorizontalAlign::Right) { - curX += (sizeX - calculateLineLength(&text.c_str()[0])); + curX += (sizeX - calculateLineLength(&text.c_str()[0], horizSpaceOffset)); } //Go through the text for (size_t i = 0; i < text.size(); i++) { auto ch = text[i]; - //If the current character is a space - if (ch == ' ') - { - //Move over - curX += (float)space; - wasSpace = true; - } - //If the current character is a tab - else if (ch == '\t') - { - //Move over - curX += (float)chars['\t'].width; - } //If the current character is a newline - else if (ch == '\n') + if (ch == '\n') { //Move down - curY += newLine_; + curY += newLine + vertSpaceOffset; //Move back curX = pos.x; if (align == HorizontalAlign::Center) { - curX += std::round((sizeX / 2.f) - (calculateLineLength(&text.c_str()[i + 1]) / 2.f)); + curX += std::round((sizeX / 2.f) - (calculateLineLength(&text.c_str()[i + 1], horizSpaceOffset) / 2.f)); } else if (align == HorizontalAlign::Right) { - curX += (sizeX - calculateLineLength(&text.c_str()[i + 1])); + curX += (sizeX - calculateLineLength(&text.c_str()[i + 1], horizSpaceOffset)); } wasSpace = false; } else { - //Get the ASCII value of the character - int ascii = (unsigned char)ch; + //If the current character is a space + if (ch == ' ') + { + //Move over + curX += (float)space; + wasSpace = true; + } + //If the current character is a tab + else if (ch == '\t') + { + //Move over + curX += (float)chars['\t'].width; + } + else + { + //Get the ASCII value of the character + int ascii = (unsigned char)ch; - //Show the character - sprite.setPosition(curX, curY); - sprite.setTextureRect(chars[ascii]); - target.draw(sprite, states); + //Show the character + sprite.setPosition(curX, curY); + sprite.setTextureRect(chars[ascii]); + target.draw(sprite, states); - //Move over the width of the character + padding - curX += (float)chars[ascii].width + (float)(wasSpace ? 0 : padding); - wasSpace = false; + //Move over the width of the character + padding + curX += (float)chars[ascii].width + (float)(wasSpace ? 0 : padding); + wasSpace = false; + } + curX += (float)horizSpaceOffset; } } } diff --git a/src/BitmapFont.h b/src/BitmapFont.h index a3961674..deba5786 100755 --- a/src/BitmapFont.h +++ b/src/BitmapFont.h @@ -18,6 +18,7 @@ class BitmapFont int padding; void calculateCharSizes(const sf::Image& img, bool verticalDirection); + float calculateLineLength(const char* text, int horizSpaceOffset) const; public: BitmapFont(const std::shared_ptr& tex, int rows_, int columns_, @@ -29,13 +30,13 @@ class BitmapFont int getNewLine() const { return newLine; } - float calculateLineLength(const char* text) const; sf::Vector2f calculateSize(const std::string& text) const; - sf::Vector2f calculateSize(const std::string& text, const float newLine_) const; + sf::Vector2f calculateSize(const std::string& text, + int horizSpaceOffset, int vertSpaceOffset) const; void draw(const sf::Vector2f& pos, const std::string& text, sf::RenderTarget& target, sf::RenderStates states, const sf::Color& color) const; void draw(const sf::Vector2f& pos, const std::string& text, sf::RenderTarget& target, - sf::RenderStates states, const sf::Color& color, const float newLine_, - const float sizeX, const HorizontalAlign align) const; + sf::RenderStates states, const sf::Color& color, int horizSpaceOffset, + int vertSpaceOffset, float sizeX, HorizontalAlign align) const; }; diff --git a/src/BitmapText.cpp b/src/BitmapText.cpp index f729536e..ef95be92 100755 --- a/src/BitmapText.cpp +++ b/src/BitmapText.cpp @@ -12,15 +12,7 @@ void BitmapText::calcDrawPos() void BitmapText::calcSize() { - if (lineSpacing > 0.f) - { - size = font->calculateSize(text, lineSpacing); - } - else - { - lineSpacing = 0.f; - size = font->calculateSize(text); - } + size = font->calculateSize(text, horizSpaceOffset, vertSpaceOffset); } void BitmapText::updateSize(const Game& game) @@ -37,7 +29,8 @@ void BitmapText::draw(sf::RenderTarget& target, sf::RenderStates states) const { if (visible == true) { - font->draw(drawPos, text, target, states, color, lineSpacing, size.x, horizAlign); + font->draw(drawPos, text, target, states, color, + horizSpaceOffset, vertSpaceOffset, size.x, horizAlign); } } diff --git a/src/BitmapText.h b/src/BitmapText.h index 1074e72a..db3c81fb 100755 --- a/src/BitmapText.h +++ b/src/BitmapText.h @@ -17,19 +17,20 @@ class BitmapText : public DrawableText VerticalAlign vertAlign{ VerticalAlign::Bottom }; Anchor anchor{ Anchor::Top | Anchor::Left }; sf::Color color{ sf::Color::White }; - float lineSpacing{ .0f }; + int horizSpaceOffset{ 0 }; + int vertSpaceOffset{ 0 }; bool visible{ true }; void calcDrawPos(); void calcSize(); public: - BitmapText(const std::string& text_, const std::shared_ptr font_) - : text(text_), font(font_) + BitmapText(const std::string& text_, const std::shared_ptr font_, + int horizSpaceOffset_ = 0, int vertSpaceOffset_ = 0) : text(text_), font(font_), + horizSpaceOffset(horizSpaceOffset_), vertSpaceOffset(vertSpaceOffset_) { calcSize(); calcDrawPos(); - lineSpacing = (float)font->getNewLine(); } virtual ~BitmapText() {} @@ -67,11 +68,6 @@ class BitmapText : public DrawableText virtual sf::Vector2f Size() const { return size; } virtual void Size(const sf::Vector2f& size) {} - virtual void setLineSpacing(unsigned lineSpacing_) - { - lineSpacing = (float)lineSpacing_; - calcSize(); - } virtual sf::FloatRect getLocalBounds() const { return sf::FloatRect(drawPos, size); } virtual sf::FloatRect getGlobalBounds() const { return sf::FloatRect(drawPos, size); } @@ -83,7 +79,6 @@ class BitmapText : public DrawableText calcDrawPos(); } } - virtual void setVerticalAlign(const VerticalAlign align) { if (vertAlign != align) @@ -93,6 +88,25 @@ class BitmapText : public DrawableText } } + virtual void setHorizontalSpaceOffset(int offset) + { + if (horizSpaceOffset != offset) + { + horizSpaceOffset = offset; + calcSize(); + calcDrawPos(); + } + } + virtual void setVerticalSpaceOffset(int offset) + { + if (vertSpaceOffset != offset) + { + vertSpaceOffset = offset; + calcSize(); + calcDrawPos(); + } + } + virtual bool Visible() const { return visible; } virtual void Visible(bool visible_) { visible = visible_; } diff --git a/src/CelUtils.cpp b/src/CelUtils.cpp index 44bec2f8..d24cfa82 100755 --- a/src/CelUtils.cpp +++ b/src/CelUtils.cpp @@ -108,41 +108,38 @@ sf::Image CelUtils::loadBitmapFontImage(const char* fileName, const char* fileNa CelFile celFile(fileName, isCl2, false); CelFrameCache cel(celFile, pal); - auto numFramesY = cel.size(); - - if (numFramesY == 0) + auto celSize = cel.size(); + if (celSize == 0) { return sf::Image(); } sf::Image img; img.create(cel[0].Width() * 16, cel[0].Height() * 16, sf::Color::Transparent); - auto charMapping = FileUtils::readChar(fileNameBin); - if (charMapping.size() >= 255) + auto charMapping = FileUtils::readChar(fileNameBin, 256); + + size_t xx = 0; + size_t yy = 0; + for (auto charMap : charMapping) { - size_t xx = 0; - size_t yy = 0; - for (auto charMap : charMapping) + if (charMap != 0xFF && charMap < celSize) { - if (charMap != 0xFF) - { - const auto& frame = cel[charMap]; + const auto& frame = cel[charMap]; - for (size_t j = 0; j < frame.Height(); j++) + for (size_t j = 0; j < frame.Height(); j++) + { + for (size_t i = 0; i < frame.Width(); i++) { - for (size_t i = 0; i < frame.Width(); i++) - { - const auto& color = frame[i][j]; - img.setPixel(frame.Width() * xx + i, frame.Height() * yy + j, color); - } + const auto& color = frame[i][j]; + img.setPixel(frame.Width() * xx + i, frame.Height() * yy + j, color); } } - xx++; - if (xx == 16) - { - xx = 0; - yy++; - } + } + xx++; + if (xx == 16) + { + xx = 0; + yy++; } } return img; diff --git a/src/DrawableText.h b/src/DrawableText.h index b7edf4bf..15b0c39b 100755 --- a/src/DrawableText.h +++ b/src/DrawableText.h @@ -12,7 +12,8 @@ class DrawableText : public UIObject virtual sf::FloatRect getLocalBounds() const = 0; virtual sf::FloatRect getGlobalBounds() const = 0; virtual void setColor(const sf::Color& color) = 0; - virtual void setLineSpacing(unsigned lineSpacing) = 0; virtual void setHorizontalAlign(const HorizontalAlign align) = 0; virtual void setVerticalAlign(const VerticalAlign align) = 0; + virtual void setHorizontalSpaceOffset(int offset) = 0; + virtual void setVerticalSpaceOffset(int offset) = 0; }; diff --git a/src/FileUtils.cpp b/src/FileUtils.cpp index 4fc260e5..7f4427c3 100755 --- a/src/FileUtils.cpp +++ b/src/FileUtils.cpp @@ -166,7 +166,19 @@ namespace FileUtils } std::vector data((size_t)ifs.getSize()); ifs.read(data.data(), ifs.getSize()); + return data; + } + std::vector readChar(const char* fileName, size_t maxNumBytes) + { + sf::PhysFSStream ifs(fileName); + if (ifs.hasError() == true) + { + return std::vector(); + } + auto size = std::min((size_t)ifs.getSize(), maxNumBytes); + std::vector data(size); + ifs.read(data.data(), size); return data; } diff --git a/src/FileUtils.h b/src/FileUtils.h index b02a5d8b..8a25c7a5 100755 --- a/src/FileUtils.h +++ b/src/FileUtils.h @@ -24,6 +24,7 @@ namespace FileUtils std::string readText(const char* fileName); std::vector readChar(const char* fileName); + std::vector readChar(const char* fileName, size_t maxNumBytes); const char* getSaveDir(); bool setSaveDir(const char* dirName); diff --git a/src/Parser/ParseAction.cpp b/src/Parser/ParseAction.cpp index 56c2666e..2e440b7c 100755 --- a/src/Parser/ParseAction.cpp +++ b/src/Parser/ParseAction.cpp @@ -294,7 +294,7 @@ namespace Parser getString(elem, "idAnchorTo"), getUInt(elem, "range"), getVariable(elem, "steps"), - getInt(elem, "stepOffset") ); + getInt(elem, "stepOffset")); } case str2int("drawable.moveStepY"): { @@ -695,10 +695,20 @@ namespace Parser } case str2int("text.setText"): { - return std::make_shared( + auto action = std::make_shared( getString(elem, "id"), - getString(elem, "text"), - getUInt(elem, "lineSpacing")); + getString(elem, "text")); + + if (elem.HasMember("horizontalSpaceOffset") == true) + { + action->setHorizontalSpaceOffset(getInt(elem["horizontalSpaceOffset"])); + } + if (elem.HasMember("verticalSpaceOffset") == true) + { + action->setVerticalSpaceOffset(getInt(elem["verticalSpaceOffset"])); + } + + return action; } case str2int("variable.clear"): { diff --git a/src/Parser/ParseBitmapFont.cpp b/src/Parser/ParseBitmapFont.cpp index 89f968f6..bfbce437 100755 --- a/src/Parser/ParseBitmapFont.cpp +++ b/src/Parser/ParseBitmapFont.cpp @@ -53,7 +53,7 @@ namespace Parser if (elem.HasMember("charSizeFile")) { - auto charSizes = FileUtils::readChar(elem["charSizeFile"].GetString()); + auto charSizes = FileUtils::readChar(elem["charSizeFile"].GetString(), 258); font = std::make_shared(texture, rows, cols, padding, isVertical, charSizes); } else diff --git a/src/Parser/ParseCursor.cpp b/src/Parser/ParseCursor.cpp old mode 100644 new mode 100755 index bc9d2fb7..af385367 --- a/src/Parser/ParseCursor.cpp +++ b/src/Parser/ParseCursor.cpp @@ -33,7 +33,7 @@ namespace Parser game.Window().setMouseCursorVisible(getBool(elem, "show")); - if (getBool(elem, "pop", false) == true) + if (getBool(elem, "pop") == true) { game.Resources().popCursor(); game.updateMouse(); diff --git a/src/Parser/ParseCursor.h b/src/Parser/ParseCursor.h old mode 100644 new mode 100755 diff --git a/src/Parser/ParseMenu.cpp b/src/Parser/ParseMenu.cpp index cd42b249..0cc7d5fd 100755 --- a/src/Parser/ParseMenu.cpp +++ b/src/Parser/ParseMenu.cpp @@ -26,6 +26,8 @@ namespace Parser auto color = getColor(elem, "color", sf::Color::White); auto horizAlign = GameUtils::getHorizontalAlignment(getString(elem, "horizontalAlign")); auto vertAlign = GameUtils::getVerticalAlignment(getString(elem, "verticalAlign")); + auto horizSpaceOffset = getInt(elem, "horizontalSpaceOffset"); + auto vertSpaceOffset = getInt(elem, "verticalSpaceOffset"); auto fontSize = getUInt(elem, "fontSize"); auto hasFocus = getBool(elem, "focus"); auto focusOnClick = getBool(elem, "focusOnClick", true); @@ -81,18 +83,19 @@ namespace Parser if (val.HasMember("%QUESTS%")) { parseMenuQuests(game, val, *menu, pos, anchor, color, horizAlign, - isTextFont, font, fontSize, bitmapFont, sound, - focusSound, clickUp, hasFocus, focusOnClick); + horizSpaceOffset, vertSpaceOffset, isTextFont, font, fontSize, + bitmapFont, sound, focusSound, clickUp, hasFocus, focusOnClick); } else if (val.HasMember("%SAVEGAMES%")) { parseMenuSaveGames(game, val, *menu, pos, anchor, color, horizAlign, - isTextFont, font, fontSize, bitmapFont, sound, - focusSound, clickUp, hasFocus, focusOnClick); + horizSpaceOffset, vertSpaceOffset, isTextFont, font, fontSize, + bitmapFont, sound, focusSound, clickUp, hasFocus, focusOnClick); } else { - auto button = parseMenuButton(anchor, color, horizAlign, isTextFont, font, + auto button = parseMenuButton(anchor, color, horizAlign, + horizSpaceOffset, vertSpaceOffset, isTextFont, font, fontSize, bitmapFont, sound, focusSound, clickUp); button->enable(getBool(val, "enable", true)); button->setText(getString(val, "text")); diff --git a/src/Parser/ParseMenuButton.cpp b/src/Parser/ParseMenuButton.cpp index ef937fa6..3e5008c2 100755 --- a/src/Parser/ParseMenuButton.cpp +++ b/src/Parser/ParseMenuButton.cpp @@ -10,10 +10,12 @@ namespace Parser std::shared_ptr parseMenuButton( Anchor anchor, const sf::Color& color, - const HorizontalAlign horizAlign, - const bool isTextFont, + HorizontalAlign horizAlign, + int horizSpaceOffset, + int vertSpaceOffset, + bool isTextFont, const std::shared_ptr& font, - const unsigned fontSize, + unsigned fontSize, const std::shared_ptr& bitmapFont, const std::shared_ptr& sound, const std::shared_ptr& focusSound, @@ -27,7 +29,8 @@ namespace Parser } else { - drawableText = std::make_unique("", bitmapFont); + drawableText = std::make_unique("", + bitmapFont, horizSpaceOffset, vertSpaceOffset); } button->setText(std::move(std::make_unique(std::move(drawableText)))); diff --git a/src/Parser/ParseMenuButton.h b/src/Parser/ParseMenuButton.h index 9e6687ad..7aba39a5 100755 --- a/src/Parser/ParseMenuButton.h +++ b/src/Parser/ParseMenuButton.h @@ -8,10 +8,12 @@ namespace Parser std::shared_ptr parseMenuButton( Anchor anchor, const sf::Color& color, - const HorizontalAlign horizAlign, - const bool isTextFont, + HorizontalAlign horizAlign, + int horizSpaceOffset, + int vertSpaceOffset, + bool isTextFont, const std::shared_ptr& font, - const unsigned fontSize, + unsigned fontSize, const std::shared_ptr& bitmapFont, const std::shared_ptr& sound, const std::shared_ptr& focusSound, diff --git a/src/Parser/ParseMenuQuests.cpp b/src/Parser/ParseMenuQuests.cpp index 542e7191..6493069c 100755 --- a/src/Parser/ParseMenuQuests.cpp +++ b/src/Parser/ParseMenuQuests.cpp @@ -46,10 +46,12 @@ namespace Parser const sf::Vector2f& pos, Anchor anchor, const sf::Color& color, - const HorizontalAlign horizAlign, - const bool isTextFont, + HorizontalAlign horizAlign, + int horizSpaceOffset, + int vertSpaceOffset, + bool isTextFont, const std::shared_ptr& font, - const unsigned fontSize, + unsigned fontSize, const std::shared_ptr& bitmapFont, const std::shared_ptr& sound, const std::shared_ptr& focusSound, @@ -63,7 +65,8 @@ namespace Parser MemoryPoolAllocator allocator; for (const auto& quest : level->Quests()) { - auto button = parseMenuButton(anchor, color, horizAlign, isTextFont, font, + auto button = parseMenuButton(anchor, color, horizAlign, + horizSpaceOffset, vertSpaceOffset, isTextFont, font, fontSize, bitmapFont, sound, focusSound, clickUp); button->setText(quest.Name()); button->Position(pos); diff --git a/src/Parser/ParseMenuQuests.h b/src/Parser/ParseMenuQuests.h index 12f36483..a2390491 100755 --- a/src/Parser/ParseMenuQuests.h +++ b/src/Parser/ParseMenuQuests.h @@ -12,10 +12,12 @@ namespace Parser const sf::Vector2f& pos, Anchor anchor, const sf::Color& color, - const HorizontalAlign horizAlign, - const bool isTextFont, + HorizontalAlign horizAlign, + int horizSpaceOffset, + int vertSpaceOffset, + bool isTextFont, const std::shared_ptr& font, - const unsigned fontSize, + unsigned fontSize, const std::shared_ptr& bitmapFont, const std::shared_ptr& sound, const std::shared_ptr& focusSound, diff --git a/src/Parser/ParseMenuSaveGames.cpp b/src/Parser/ParseMenuSaveGames.cpp index 7160fc82..af26d44d 100755 --- a/src/Parser/ParseMenuSaveGames.cpp +++ b/src/Parser/ParseMenuSaveGames.cpp @@ -14,10 +14,12 @@ namespace Parser const sf::Vector2f& pos, Anchor anchor, const sf::Color& color, - const HorizontalAlign horizAlign, - const bool isTextFont, + HorizontalAlign horizAlign, + int horizSpaceOffset, + int vertSpaceOffset, + bool isTextFont, const std::shared_ptr& font, - const unsigned fontSize, + unsigned fontSize, const std::shared_ptr& bitmapFont, const std::shared_ptr& sound, const std::shared_ptr& focusSound, @@ -57,7 +59,8 @@ namespace Parser for (const auto& dir : FileUtils::getSaveDirList()) { - auto button = parseMenuButton(anchor, color, horizAlign, isTextFont, font, + auto button = parseMenuButton(anchor, color, horizAlign, + horizSpaceOffset, vertSpaceOffset, isTextFont, font, fontSize, bitmapFont, sound, focusSound, clickUp); button->setText(dir); button->Position(pos); diff --git a/src/Parser/ParseMenuSaveGames.h b/src/Parser/ParseMenuSaveGames.h index debb40bf..d46e8db6 100755 --- a/src/Parser/ParseMenuSaveGames.h +++ b/src/Parser/ParseMenuSaveGames.h @@ -12,10 +12,12 @@ namespace Parser const sf::Vector2f& pos, Anchor anchor, const sf::Color& color, - const HorizontalAlign horizAlign, - const bool isTextFont, + HorizontalAlign horizAlign, + int horizSpaceOffset, + int vertSpaceOffset, + bool isTextFont, const std::shared_ptr& font, - const unsigned fontSize, + unsigned fontSize, const std::shared_ptr& bitmapFont, const std::shared_ptr& sound, const std::shared_ptr& focusSound, diff --git a/src/Parser/ParseText.cpp b/src/Parser/ParseText.cpp index d71799e2..6a5a5039 100755 --- a/src/Parser/ParseText.cpp +++ b/src/Parser/ParseText.cpp @@ -65,7 +65,10 @@ namespace Parser return nullptr; } - auto text = std::make_unique(displayText, font); + auto horizSpaceOffset = getInt(elem, "horizontalSpaceOffset"); + auto vertSpaceOffset = getInt(elem, "verticalSpaceOffset"); + + auto text = std::make_unique(displayText, font, horizSpaceOffset, vertSpaceOffset); text->setColor(getColor(elem, "color", sf::Color::White)); text->setHorizontalAlign(GameUtils::getHorizontalAlignment(getString(elem, "horizontalAlign"))); text->setVerticalAlign(GameUtils::getVerticalAlignment(getString(elem, "verticalAlign"))); diff --git a/src/StringText.h b/src/StringText.h index 3e351865..e81414f4 100755 --- a/src/StringText.h +++ b/src/StringText.h @@ -51,6 +51,16 @@ class StringText : public DrawableText virtual sf::FloatRect getLocalBounds() const { return text.getLocalBounds(); } virtual sf::FloatRect getGlobalBounds() const { return text.getGlobalBounds(); } + virtual const sf::Vector2f& DrawPosition() const { return text.getPosition(); } + virtual const sf::Vector2f& Position() const { return pos; } + virtual void Position(const sf::Vector2f& position) + { + pos = position; + calculateDrawPosition(); + } + virtual sf::Vector2f Size() const { return sf::Vector2f(text.getLocalBounds().width, text.getLocalBounds().height); } + virtual void Size(const sf::Vector2f& size) {} + virtual void setHorizontalAlign(const HorizontalAlign align) { if (horizAlign != align) @@ -59,7 +69,6 @@ class StringText : public DrawableText calculateDrawPosition(); } } - virtual void setVerticalAlign(const VerticalAlign align) { if (vertAlign != align) @@ -69,16 +78,8 @@ class StringText : public DrawableText } } - virtual const sf::Vector2f& DrawPosition() const { return text.getPosition(); } - virtual const sf::Vector2f& Position() const { return pos; } - virtual void Position(const sf::Vector2f& position) - { - pos = position; - calculateDrawPosition(); - } - virtual sf::Vector2f Size() const { return sf::Vector2f(text.getLocalBounds().width, text.getLocalBounds().height); } - virtual void Size(const sf::Vector2f& size) {} - virtual void setLineSpacing(unsigned lineSpacing) {} + virtual void setHorizontalSpaceOffset(int offset) {} + virtual void setVerticalSpaceOffset(int offset) {} void setRotation(float angle) { text.setRotation(angle); } void setScale(float factorX, float factorY) { text.setScale(factorX, factorY); } diff --git a/src/Text2.h b/src/Text2.h index cc1e2125..8b116244 100755 --- a/src/Text2.h +++ b/src/Text2.h @@ -11,8 +11,6 @@ class Text2 : public UIObject std::string format; std::vector bindings; - void setBindingHelper(const std::string& binding); - public: Text2(std::unique_ptr text_) : text(std::move(text_)) {} @@ -28,10 +26,11 @@ class Text2 : public UIObject void setBinding(const std::string& binding); void setBinding(const std::vector& bindings_); void setColor(const sf::Color& color) { text->setColor(color); } - void setHorizontalAlign(const HorizontalAlign align) { text->setHorizontalAlign(align); } - void setLineSpacing(unsigned lineSpacing) { text->setLineSpacing(lineSpacing); } void setFormat(const std::string& format_) { format = format_; } + void setHorizontalAlign(const HorizontalAlign align) { text->setHorizontalAlign(align); } void setVerticalAlign(const VerticalAlign align) { text->setVerticalAlign(align); } + void setHorizontalSpaceOffset(int offset) { text->setHorizontalSpaceOffset(offset); } + void setVerticalSpaceOffset(int offset) { text->setVerticalSpaceOffset(offset); } virtual void setAnchor(const Anchor anchor) { text->setAnchor(anchor); } virtual void updateSize(const Game& game) { text->updateSize(game); }