From 923422e6a71f57b8fa24b826d1e2914faa144081 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 10 Aug 2012 22:17:20 +0200 Subject: [PATCH] added escape title frame, text, and font --- src/battle/Resources.h | 10 ++++++++++ src/battle/states/RunState.cpp | 15 +++++++++++++++ src/battle/states/RunState.h | 3 +++ src/main.cpp | 20 ++++++++++++++++++++ test-data/large-font.png | Bin 0 -> 539 bytes test-data/title-frame.png | Bin 0 -> 160 bytes 6 files changed, 48 insertions(+) create mode 100644 test-data/large-font.png create mode 100644 test-data/title-frame.png diff --git a/src/battle/Resources.h b/src/battle/Resources.h index 89c99ef..5cc8903 100644 --- a/src/battle/Resources.h +++ b/src/battle/Resources.h @@ -31,6 +31,9 @@ struct Resources { graphics::Sprite *attackIcons; graphics::Sprite *attackChoiceIcons; + graphics::Frame *titleFrame; + graphics::Font *titleFont; + graphics::Frame *heroTagFrame; graphics::Frame *activeHeroTagFrame; @@ -62,6 +65,8 @@ struct Resources { graphics::Menu ikariMenuPrototype; const char *noEquipmentText; + const char *escapeText; + graphics::Sprite *weaponMenuIcon; graphics::Sprite *armorMenuIcon; graphics::Sprite *shieldMenuIcon; @@ -76,6 +81,9 @@ struct Resources { , attackIcons(0) , attackChoiceIcons(0) + , titleFrame(0) + , titleFont(0) + , heroTagFrame(0) , activeHeroTagFrame(0) @@ -102,6 +110,8 @@ struct Resources { , ikariMenuHeadline("") , noEquipmentText("") + , escapeText("") + , weaponMenuIcon(0) , armorMenuIcon(0) , shieldMenuIcon(0) diff --git a/src/battle/states/RunState.cpp b/src/battle/states/RunState.cpp index 08c45e8..7fdc066 100644 --- a/src/battle/states/RunState.cpp +++ b/src/battle/states/RunState.cpp @@ -12,6 +12,10 @@ #include "../../app/Input.h" #include "../../geometry/operators.h" #include "../../geometry/Point.h" +#include "../../graphics/Font.h" +#include "../../graphics/Frame.h" + +#include using app::Application; using app::Input; @@ -61,6 +65,17 @@ void RunState::Render(SDL_Surface *screen) { battle->RenderMonsters(screen, offset); battle->RenderHeroes(screen, offset); // render small tags + RenderTitleBar(screen, offset); +} + +void RunState::RenderTitleBar(SDL_Surface *screen, const Vector &offset) { + int height(battle->Res().titleFrame->BorderHeight() * 2 + battle->Res().titleFont->CharHeight()); + battle->Res().titleFrame->Draw(screen, Point(offset.X(), offset.Y()), battle->BackgroundWidth(), height); + + Point textPosition( + (battle->BackgroundWidth() - (std::strlen(battle->Res().escapeText) * battle->Res().titleFont->CharWidth())) / 2, + battle->Res().titleFrame->BorderHeight()); + battle->Res().titleFont->DrawString(battle->Res().escapeText, screen, textPosition + offset); } } diff --git a/src/battle/states/RunState.h b/src/battle/states/RunState.h index 870f48d..61c5270 100644 --- a/src/battle/states/RunState.h +++ b/src/battle/states/RunState.h @@ -35,6 +35,9 @@ public: virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); +private: + void RenderTitleBar(SDL_Surface *screen, const geometry::Vector &offset); + private: app::Application *ctrl; BattleState *battle; diff --git a/src/main.cpp b/src/main.cpp index 28656c3..e39d318 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -147,6 +147,24 @@ int main(int argc, char **argv) { SDL_Surface *moveIconsImg(IMG_Load("test-data/move-icons.png")); Sprite moveIconsSprite(moveIconsImg, 32, 32); battleRes.moveIcons = &moveIconsSprite; + + SDL_Surface *titleFrameImg(IMG_Load("test-data/title-frame.png")); + Frame titleFrame(titleFrameImg, 16, 16); + battleRes.titleFrame = &titleFrame; + + SDL_Surface *largeFontImg(IMG_Load("test-data/large-font.png")); + Sprite largeFontSprite(largeFontImg, 16, 32); + Font largeFont(&largeFontSprite); + largeFont.MapRange('A', 'M', 0, 1); + largeFont.MapRange('N', 'Z', 0, 2); + largeFont.MapRange('a', 'm', 0, 3); + largeFont.MapRange('n', 'z', 0, 4); + largeFont.MapChar(':', 10, 0); + largeFont.MapChar('!', 11, 0); + largeFont.MapChar('?', 12, 0); + // TODO: add '.' and '-' characters + battleRes.titleFont = &largeFont; + SDL_Surface *heroTagImg(IMG_Load("test-data/hero-tag-sprites.png")); Sprite heroTagSprite(heroTagImg, 32, 16); battleRes.heroTagLabels = &heroTagSprite; @@ -540,6 +558,8 @@ int main(int argc, char **argv) { battleRes.noEquipmentText = "No equip"; battleRes.ikariMenuPrototype = Menu(&normalFont, &disabledFont, &handCursorSprite, 12, 6, normalFont.CharHeight() / 2, normalFont.CharWidth(), 1, normalFont.CharWidth() * 2, 0, ':', 12, normalFont.CharWidth()); + battleRes.escapeText = "Escapes."; + BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes)); battleState->AddMonster(monster); battleState->AddMonster(monster); diff --git a/test-data/large-font.png b/test-data/large-font.png new file mode 100644 index 0000000000000000000000000000000000000000..c01542a7aa7f44cfea9ad7c323923dabeefde6ba GIT binary patch literal 539 zcmeAS@N?(olHy`uVBq!ia0vp^7l3#H2OE&AZF{tpfr0Unr;B4q#jUq@9oHRF5Md3- z-qpx==RcEd38z(nx=X9pqs4QKP2#;h<;?#u*~$R*;Q}|>J;m>=dH(g&$?wxHFXCq} zyTbZmXQa4?h>C!QLV&}91_o9ZE)EeO$AQt&bl$G}xv|{oN122;_NC~~NpWOqWMTp- z0I76f1ad?Kt~_4(dv5W=2@bfdL=iVwqWL$$cK!77_z1t#R~9Ay&pW>Q_4Zx$zY4Cf z24o&N+xsi}-@5B%PwKv3|K88Sw5a#b#dqF9ij5DvKkpU{``*CPRL1$mV_x`q>u>XX zCW&*htQFRnZnJp9B?eBgyL$}TPyPH_zg(`k|I*Hgx0bi}ukUARdMNUq-OK&Om(RBr zy<^WRtyK{~a?}Cg#BW=cSld+B+WWse7yG;O+rc`88^KIZ-CnFn7tG0>ZY-)Iz?0v1 zZNZ(6Jzu}fS)l@S80!-5SLa*zJalAav_02YHT7KP9BuVR22K&>iSy1*Rhh`b#3|zW z(mJX-zOw7Fi*ArXg@6C_v{Cy4Yg{b>kv zI{e|kgLPA;K?@7_PN}`S&n0%`>KaQqDl&36CjZs6cyOVJG8{jglE+Rh22cjWk