From f92e278da564dab15d984dcaba153c1a92752651 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 24 Aug 2013 21:06:51 +0300 Subject: add support for target cursor animations. updated target cursor to new images by Alige. --- data/graphics/gui/CMakeLists.txt | 6 ++ data/graphics/gui/Makefile.am | 6 ++ data/graphics/gui/target-cursor-in-range-l.png | Bin 23803 -> 44634 bytes data/graphics/gui/target-cursor-in-range-l.xml | 15 +++++ data/graphics/gui/target-cursor-in-range-m.png | Bin 18439 -> 17289 bytes data/graphics/gui/target-cursor-in-range-m.xml | 15 +++++ data/graphics/gui/target-cursor-in-range-s.png | Bin 8353 -> 8146 bytes data/graphics/gui/target-cursor-in-range-s.xml | 15 +++++ data/graphics/gui/target-cursor-normal-l.png | Bin 25586 -> 45741 bytes data/graphics/gui/target-cursor-normal-l.xml | 15 +++++ data/graphics/gui/target-cursor-normal-m.png | Bin 17950 -> 17268 bytes data/graphics/gui/target-cursor-normal-m.xml | 15 +++++ data/graphics/gui/target-cursor-normal-s.png | Bin 8361 -> 8129 bytes data/graphics/gui/target-cursor-normal-s.xml | 15 +++++ src/actorsprite.cpp | 83 ++++++++----------------- src/actorsprite.h | 19 ++---- 16 files changed, 133 insertions(+), 71 deletions(-) create mode 100644 data/graphics/gui/target-cursor-in-range-l.xml create mode 100644 data/graphics/gui/target-cursor-in-range-m.xml create mode 100644 data/graphics/gui/target-cursor-in-range-s.xml create mode 100644 data/graphics/gui/target-cursor-normal-l.xml create mode 100644 data/graphics/gui/target-cursor-normal-m.xml create mode 100644 data/graphics/gui/target-cursor-normal-s.xml diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index 5694f9a8d..439542f66 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -67,11 +67,17 @@ SET (FILES tab_selected.xml tab_unused.xml target-cursor-in-range-l.png + target-cursor-in-range-l.xml target-cursor-in-range-m.png + target-cursor-in-range-m.xml target-cursor-in-range-s.png + target-cursor-in-range-s.xml target-cursor-normal-l.png + target-cursor-normal-l.xml target-cursor-normal-m.png + target-cursor-normal-m.xml target-cursor-normal-s.png + target-cursor-normal-s.xml textfield.xml textpreview.xml unknown-item.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 9e3f83129..710cf0688 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -70,11 +70,17 @@ gui_DATA = \ tab_selected.xml \ tab_unused.xml \ target-cursor-in-range-l.png \ + target-cursor-in-range-l.xml \ target-cursor-in-range-m.png \ + target-cursor-in-range-m.xml \ target-cursor-in-range-s.png \ + target-cursor-in-range-s.xml \ target-cursor-normal-l.png \ + target-cursor-normal-l.xml \ target-cursor-normal-m.png \ + target-cursor-normal-m.xml \ target-cursor-normal-s.png \ + target-cursor-normal-s.xml \ textfield.xml \ textpreview.xml \ unknown-item.png \ diff --git a/data/graphics/gui/target-cursor-in-range-l.png b/data/graphics/gui/target-cursor-in-range-l.png index 77cdf4b6d..dcf09d024 100644 Binary files a/data/graphics/gui/target-cursor-in-range-l.png and b/data/graphics/gui/target-cursor-in-range-l.png differ diff --git a/data/graphics/gui/target-cursor-in-range-l.xml b/data/graphics/gui/target-cursor-in-range-l.xml new file mode 100644 index 000000000..ee7285b37 --- /dev/null +++ b/data/graphics/gui/target-cursor-in-range-l.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/data/graphics/gui/target-cursor-in-range-m.png b/data/graphics/gui/target-cursor-in-range-m.png index c0107357a..8429fd79a 100644 Binary files a/data/graphics/gui/target-cursor-in-range-m.png and b/data/graphics/gui/target-cursor-in-range-m.png differ diff --git a/data/graphics/gui/target-cursor-in-range-m.xml b/data/graphics/gui/target-cursor-in-range-m.xml new file mode 100644 index 000000000..ab6080f92 --- /dev/null +++ b/data/graphics/gui/target-cursor-in-range-m.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/data/graphics/gui/target-cursor-in-range-s.png b/data/graphics/gui/target-cursor-in-range-s.png index 3e81c75de..0c50430ee 100644 Binary files a/data/graphics/gui/target-cursor-in-range-s.png and b/data/graphics/gui/target-cursor-in-range-s.png differ diff --git a/data/graphics/gui/target-cursor-in-range-s.xml b/data/graphics/gui/target-cursor-in-range-s.xml new file mode 100644 index 000000000..206131bda --- /dev/null +++ b/data/graphics/gui/target-cursor-in-range-s.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/data/graphics/gui/target-cursor-normal-l.png b/data/graphics/gui/target-cursor-normal-l.png index 76d2101b1..5670380f8 100644 Binary files a/data/graphics/gui/target-cursor-normal-l.png and b/data/graphics/gui/target-cursor-normal-l.png differ diff --git a/data/graphics/gui/target-cursor-normal-l.xml b/data/graphics/gui/target-cursor-normal-l.xml new file mode 100644 index 000000000..1058d5906 --- /dev/null +++ b/data/graphics/gui/target-cursor-normal-l.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/data/graphics/gui/target-cursor-normal-m.png b/data/graphics/gui/target-cursor-normal-m.png index e2ab79c29..597eb4195 100644 Binary files a/data/graphics/gui/target-cursor-normal-m.png and b/data/graphics/gui/target-cursor-normal-m.png differ diff --git a/data/graphics/gui/target-cursor-normal-m.xml b/data/graphics/gui/target-cursor-normal-m.xml new file mode 100644 index 000000000..8091474b3 --- /dev/null +++ b/data/graphics/gui/target-cursor-normal-m.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/data/graphics/gui/target-cursor-normal-s.png b/data/graphics/gui/target-cursor-normal-s.png index 09195f440..abfb5e787 100644 Binary files a/data/graphics/gui/target-cursor-normal-s.png and b/data/graphics/gui/target-cursor-normal-s.png differ diff --git a/data/graphics/gui/target-cursor-normal-s.xml b/data/graphics/gui/target-cursor-normal-s.xml new file mode 100644 index 000000000..dea706a1e --- /dev/null +++ b/data/graphics/gui/target-cursor-normal-s.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 1e3f0ba07..7b9cb796c 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -42,8 +42,7 @@ #include "debug.h" -ImageSet *ActorSprite::targetCursorImages[2][NUM_TC]; -SimpleAnimation *ActorSprite::targetCursor[2][NUM_TC]; +AnimatedSprite *ActorSprite::targetCursor[2][NUM_TC]; bool ActorSprite::loaded = false; ActorSprite::ActorSprite(const int id) : @@ -57,6 +56,8 @@ ActorSprite::ActorSprite(const int id) : mStunMode(0), mUsedTargetCursor(nullptr), mActorSpriteListeners(), + mCursorPaddingX(0), + mCursorPaddingY(0), mMustResetParticles(false) { } @@ -93,10 +94,10 @@ bool ActorSprite::draw(Graphics *const graphics, if (mUsedTargetCursor) { - mUsedTargetCursor->reset(); mUsedTargetCursor->update(tick_time * MILLISECONDS_IN_A_TICK); - mUsedTargetCursor->draw(graphics, px + getTargetOffsetX(), - py + getTargetOffsetY()); + mUsedTargetCursor->draw(graphics, + px + getTargetOffsetX() - mCursorPaddingX, + py + getTargetOffsetY() - mCursorPaddingY); } return drawSpriteAt(graphics, px, py); @@ -152,10 +153,23 @@ void ActorSprite::controlParticle(Particle *const particle) void ActorSprite::setTargetType(const TargetCursorType type) { + static const int targetWidths[ActorSprite::NUM_TC] = {0, 0, 0}; + static const int targetHeights[ActorSprite::NUM_TC] = {0, -16, -32}; + if (type == TCT_NONE) + { untarget(); + } else - mUsedTargetCursor = targetCursor[type][getTargetCursorSize()]; + { + const TargetCursorSize sz = getTargetCursorSize(); + mUsedTargetCursor = targetCursor[type][sz]; + if (mUsedTargetCursor) + { + mCursorPaddingX = targetWidths[sz]; + mCursorPaddingY = targetHeights[sz]; + } + } } struct EffectDescription final @@ -351,18 +365,17 @@ static const char *cursorSize(const int size) void ActorSprite::initTargetCursor() { - static const std::string targetCursorFile = "target-cursor-%s-%s.png"; - static const int targetWidths[NUM_TC] = {44, 62, 82}; - static const int targetHeights[NUM_TC] = {35, 44, 60}; + static const std::string targetCursorFile = "%s/target-cursor-%s-%s.xml"; + const char *path = branding.getStringValue("guiPath").c_str(); // Load target cursors for (int size = TC_SMALL; size < NUM_TC; size++) { for (int type = TCT_NORMAL; type < NUM_TCT; type++) { - loadTargetCursor(strprintf(targetCursorFile.c_str(), - cursorType(type), cursorSize(size)), targetWidths[size], - targetHeights[size], type, size); + targetCursor[type][size] = AnimatedSprite::load(strprintf( + targetCursorFile.c_str(), path, cursorType(type), + cursorSize(size))); } } } @@ -378,52 +391,6 @@ void ActorSprite::cleanupTargetCursors() delete targetCursor[type][size]; targetCursor[type][size] = nullptr; } - if (targetCursorImages[type][size]) - { - targetCursorImages[type][size]->decRef(); - targetCursorImages[type][size] = nullptr; - } } } } - -void ActorSprite::loadTargetCursor(const std::string &filename, - const int width, const int height, - const int type, const int size) -{ - if (reportTrue(size < TC_SMALL || size >= NUM_TC)) - return; - - ImageSet *const currentImageSet = Theme::getImageSetFromTheme( - filename, width, height); - - if (!currentImageSet) - { - logger->log("Error loading target cursor: %s", filename.c_str()); - return; - } - - Animation *const anim = new Animation; - - const size_t sz = currentImageSet->size(); - for (size_t i = 0; i < sz; ++i) - { - anim->addFrame(currentImageSet->get(i), 75, - (16 - (currentImageSet->getWidth() / 2)), - (16 - (currentImageSet->getHeight() / 2)), - 100); - } - - SimpleAnimation *const currentCursor = new SimpleAnimation(anim); - - if (targetCursor[type][size]) - { - delete targetCursor[type][size]; - targetCursor[type][size] = nullptr; - if (targetCursorImages[type][size]) - targetCursorImages[type][size]->decRef(); - } - - targetCursorImages[type][size] = currentImageSet; - targetCursor[type][size] = currentCursor; -} diff --git a/src/actorsprite.h b/src/actorsprite.h index 345f4a31f..4b2b07c52 100644 --- a/src/actorsprite.h +++ b/src/actorsprite.h @@ -35,7 +35,7 @@ #include "localconsts.h" -class SimpleAnimation; +class AnimatedSprite; class StatusEffect; class ActorSpriteListener; @@ -223,28 +223,21 @@ private: /** Remove the target cursors from memory */ static void cleanupTargetCursors(); - /** - * Helper function for loading target cursors - */ - static void loadTargetCursor(const std::string &filename, - const int width, const int height, - const int type, const int size); - - /** Images of the target cursor. */ - static ImageSet *targetCursorImages[NUM_TCT][NUM_TC]; - /** Animated target cursors. */ - static SimpleAnimation *targetCursor[NUM_TCT][NUM_TC]; + static AnimatedSprite *targetCursor[NUM_TCT][NUM_TC]; static bool loaded; /** Target cursor being used */ - SimpleAnimation *mUsedTargetCursor; + AnimatedSprite *mUsedTargetCursor; typedef std::list ActorSpriteListeners; typedef ActorSpriteListeners::iterator ActorSpriteListenerIterator; ActorSpriteListeners mActorSpriteListeners; + int mCursorPaddingX; + int mCursorPaddingY; + /** Reset particle status effects on next redraw? */ bool mMustResetParticles; }; -- cgit v1.2.3-70-g09d2