From 62ac0dbff5c24071859b7a02fdffb485ba82181e Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Fri, 30 Sep 2005 10:49:23 +0000 Subject: [PATCH] support for centered text in scripts SVN-Revision: 2792 --- data/images/sprites.strf | 16 ++---- data/levels/test/default.nut | 10 ++++ data/levels/test/intro.stl | 115 +++++++++++++++++++++++++++++++++++++++++++ src/object/text_object.cpp | 12 ++++- src/object/text_object.hpp | 2 + src/scripting/text.hpp | 1 + src/scripting/wrapper.cpp | 20 ++++++++ 7 files changed, 164 insertions(+), 12 deletions(-) create mode 100644 data/levels/test/intro.stl diff --git a/data/images/sprites.strf b/data/images/sprites.strf index bbbc23692..336e28514 100644 --- a/data/images/sprites.strf +++ b/data/images/sprites.strf @@ -1208,11 +1208,8 @@ (fps 6) (x-offset 0) (y-offset 40) - (images "creatures/nolok/walk-0.png" - "creatures/nolok/walk-1.png" - "creatures/nolok/walk-2.png" - "creatures/nolok/walk-3.png" - "creatures/nolok/walk-4.png")) + (images "creatures/dummyguy/walk-1.png" + "creatures/dummyguy/walk-2.png")) (action (name "right") @@ -1225,23 +1222,20 @@ (name "stand") (x-offset 0) (y-offset 40) - (images "creatures/nolok/walk-0.png")) + (images "creatures/dummyguy/stand.png")) (action (name "throw") (fps 6) (x-offset 0) (y-offset 40) - (images "creatures/nolok/throw-0.png" - "creatures/nolok/throw-1.png")) + (images "creatures/dummyguy/throw.png")) (action (name "jump") (x-offset 0) (y-offset 40) - (images "creatures/nolok/jump-0.png" - "creatures/nolok/jump-1.png" - "creatures/nolok/jump-2.png")) + (images "creatures/dummyguy/jump.png")) (action (name "dead") diff --git a/data/levels/test/default.nut b/data/levels/test/default.nut index 71be66eab..42ba95d09 100644 --- a/data/levels/test/default.nut +++ b/data/levels/test/default.nut @@ -1,2 +1,12 @@ /* Default functions for the whole levelset */ +function intro() +{ + DisplayEffect.sixteen_to_nine(); + PENNY.set_animation("stand"); + Text.set_centered(true); + Text.set_text(translate("SuperTux\nMilestone 2")); + Text.fade_in(2); + wait(4); + Text.fade_out(1); +} \ No newline at end of file diff --git a/data/levels/test/intro.stl b/data/levels/test/intro.stl new file mode 100644 index 000000000..5566b52fd --- /dev/null +++ b/data/levels/test/intro.stl @@ -0,0 +1,115 @@ +;; Generated by Flexlay Editor +(supertux-level + (version 2) + (name (_ "SuperTux Intro")) + (author "SuperTux Team") + (sector + (name "main") + (music "theme.ogg") + (gravity 10.000000) + (tilemap + (layer "background") + (solid #f) + (speed 1.000000) + (width 25) + (height 20) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 1343 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + )) + (tilemap + (layer "interactive") + (solid #t) + (speed 1.000000) + (width 25) + (height 20) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 122 209 209 123 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 124 98 98 125 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 124 98 98 125 0 0 0 0 0 0 0 0 0 + 0 0 122 123 0 0 0 0 0 0 0 0 124 98 98 125 0 0 0 0 0 1348 0 0 0 + 0 0 124 125 0 0 0 0 0 0 0 0 124 98 98 125 0 0 122 123 0 79 0 0 0 + 0 0 124 125 0 0 0 0 0 0 0 0 124 98 98 125 0 0 124 125 0 79 0 0 0 + 0 0 1345 1344 0 0 0 0 0 0 0 0 1345 1346 1346 1344 0 0 1345 1344 0 1349 0 0 0 + 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 1342 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (tilemap + (layer "foreground") + (solid #f) + (speed 1.000000) + (width 25) + (height 20) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 1321 1322 1323 1324 0 0 0 0 0 0 0 0 0 1321 1322 1323 1324 0 0 0 0 0 0 0 + 0 1325 1326 1327 1328 0 0 0 0 0 0 0 0 0 1325 1326 1327 1328 0 0 0 0 0 0 0 + 0 1329 1330 1331 1332 0 0 1350 0 0 0 0 0 0 1329 1330 1331 1332 0 0 0 0 0 0 0 + 0 1333 1334 1335 1336 0 0 0 0 0 0 0 0 0 1333 1334 1335 1336 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (camera + (mode "normal") + ) + + (background + (image "semi_arctic.jpg") + (speed 0.500000) + ) + (spawnpoint (name "main") (x 220) (y 416)) + (particles-snow) + + (scriptedobject + (name "PENNY") + (x 390) + (y 510) + (sprite "dummyguy") + ) + (init-script "intro();") + ) + ) + +;; EOF ;; diff --git a/src/object/text_object.cpp b/src/object/text_object.cpp index 706b2fb17..9d2dd3313 100644 --- a/src/object/text_object.cpp +++ b/src/object/text_object.cpp @@ -8,6 +8,7 @@ TextObject::TextObject() : fading(0), fadetime(0), visible(false) { font = blue_text; + centered = false; } TextObject::~TextObject() @@ -62,6 +63,12 @@ TextObject::set_visible(bool visible) } void +TextObject::set_centered(bool centered) +{ + this->centered = centered; +} + +void TextObject::draw(DrawingContext& context) { context.push_transform(); @@ -78,7 +85,10 @@ TextObject::draw(DrawingContext& context) context.draw_filled_rect(Vector(125, 50), Vector(550, 120), Color(150, 180, 200, 125), LAYER_GUI-50); - context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40); + if (centered) { + context.draw_center_text(font, text, Vector(0, 50+35), LAYER_GUI-40); + } + else context.draw_text(font, text, Vector(125+35, 50+35), LEFT_ALLIGN, LAYER_GUI-40); context.pop_transform(); } diff --git a/src/object/text_object.hpp b/src/object/text_object.hpp index 352696df7..194dc94ba 100644 --- a/src/object/text_object.hpp +++ b/src/object/text_object.hpp @@ -18,6 +18,7 @@ public: void fade_in(float fadetime); void fade_out(float fadetime); void set_visible(bool visible); + void set_centered(bool centered); bool is_visible(); void draw(DrawingContext& context); @@ -29,6 +30,7 @@ private: float fading; float fadetime; bool visible; + bool centered; }; #endif diff --git a/src/scripting/text.hpp b/src/scripting/text.hpp index 92a67fe18..50b88d3db 100644 --- a/src/scripting/text.hpp +++ b/src/scripting/text.hpp @@ -17,6 +17,7 @@ public: virtual void fade_in(float fadetime) = 0; virtual void fade_out(float fadetime) = 0; virtual void set_visible(bool visible) = 0; + virtual void set_centered(bool centered) = 0; }; } diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 56d56b2c9..4554f5457 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -430,6 +430,18 @@ static int Text_set_visible_wrapper(HSQUIRRELVM v) return 0; } +static int Text_set_centered_wrapper(HSQUIRRELVM v) +{ + Scripting::Text* _this; + sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); + SQBool arg0; + sq_getbool(v, 2, &arg0); + + _this->set_centered(arg0); + + return 0; +} + static int Player_release_hook(SQUserPointer ptr, int ) { Scripting::Player* _this = reinterpret_cast (ptr); @@ -1120,6 +1132,14 @@ void register_supertux_wrapper(HSQUIRRELVM v) throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "set_centered", -1); + sq_newclosure(v, &Text_set_centered_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'set_centered'"; + throw SquirrelError(v, msg.str()); + } + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Text'"; -- 2.11.0