From: Daniel Karbach Date: Sun, 16 Dec 2012 21:45:19 +0000 (+0100) Subject: added capsule wheel and table X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=6dff93b1a6e9b727dbe26747456f4b23efca86da;p=l2e.git added capsule wheel and table --- diff --git a/src/common/Capsule.cpp b/src/common/Capsule.cpp index 8fa1ca9..302af8f 100644 --- a/src/common/Capsule.cpp +++ b/src/common/Capsule.cpp @@ -23,6 +23,8 @@ Capsule::Capsule() : name("") , alignment("") +, alignmentSprite(0) + , maxHealth(0) , level(1) @@ -33,7 +35,7 @@ Capsule::Capsule() , classes(0) , numClasses(0) -, curClass(0) +, curClass(-1) , maxClass(0) { } @@ -78,6 +80,11 @@ int Capsule::NextLevel() const { } } +void Capsule::UpgradeClass() { + ++maxClass; + ++curClass; +} + Sprite *Capsule::BattleSprite() { return GetClass().battleSprite; @@ -136,6 +143,9 @@ void Capsule::CreateTypeDescription() { td.AddField("name", FieldDescription(((char *)&c.name) - ((char *)&c), Interpreter::STRING_ID).SetReferenced()); td.AddField("alignment", FieldDescription(((char *)&c.alignment) - ((char *)&c), Interpreter::STRING_ID).SetReferenced()); + td.AddField("alignmentCursor", FieldDescription(((char *)&c.alignmentCursor) - ((char *)&c), Interpreter::VECTOR_ID)); + td.AddField("alignmentSprite", FieldDescription(((char *)&c.alignmentSprite) - ((char *)&c), Sprite::TYPE_ID).SetReferenced()); + td.AddField("maxHealth", FieldDescription(((char *)&c.maxHealth) - ((char *)&c), Interpreter::NUMBER_ID)); td.AddField("stats", FieldDescription(((char *)&c.stats) - ((char *)&c), Stats::TYPE_ID)); diff --git a/src/common/Capsule.h b/src/common/Capsule.h index 8d4791d..c70d07f 100644 --- a/src/common/Capsule.h +++ b/src/common/Capsule.h @@ -7,6 +7,7 @@ namespace graphics { } #include "../common/Stats.h" +#include "../geometry/Vector.h" #include @@ -31,6 +32,15 @@ public: const Spell *Attack2() const; const Spell *Attack3() const; + int NumClasses() const { return numClasses; } + int MaxClass() const { return maxClass; } + int CurrentClass() const { return curClass; } + + const geometry::Vector &AlignmentOffset() const { return alignmentCursor; } + const graphics::Sprite *AlignmentSprite() const { return alignmentSprite; } + + void UpgradeClass(); + Uint16 MaxHealth() const; Stats GetStats() const; @@ -75,6 +85,9 @@ private: const char *name; const char *alignment; + geometry::Vector alignmentCursor; + const graphics::Sprite *alignmentSprite; + int maxHealth; Stats stats; diff --git a/src/common/GameState.h b/src/common/GameState.h index 4e2570d..4080630 100644 --- a/src/common/GameState.h +++ b/src/common/GameState.h @@ -14,10 +14,12 @@ struct GameState { GameState(); Hero heroes[7]; + int NumHeroes() const { return 7; } Hero *party[4]; int partySize; Capsule capsules[7]; + int NumCapsules() const { return 7; } Capsule *capsule; Inventory inventory; diff --git a/src/main.cpp b/src/main.cpp index 2ecd30a..ca54210 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -196,8 +196,9 @@ int main(int argc, char **argv) { gameState.party[3] = &gameState.heroes[3]; gameState.partySize = 4; - gameState.capsules[0] = *caster.GetCapsule("flash"); - gameState.capsule = gameState.capsules; + gameState.capsules[1] = *caster.GetCapsule("flash"); + gameState.capsules[1].UpgradeClass(); + gameState.capsule = &gameState.capsules[1]; GameConfig gameConfig; gameConfig.state = &gameState; diff --git a/src/menu/CapsuleChangeMenu.cpp b/src/menu/CapsuleChangeMenu.cpp index 3b161ad..cac2056 100644 --- a/src/menu/CapsuleChangeMenu.cpp +++ b/src/menu/CapsuleChangeMenu.cpp @@ -10,6 +10,7 @@ #include "../common/GameState.h" #include "../graphics/Font.h" #include "../graphics/Frame.h" +#include "../graphics/Texture.h" using app::Input; using common::Capsule; @@ -69,18 +70,76 @@ void CapsuleChangeMenu::Render(SDL_Surface *screen) { 12 * font.CharWidth(), 2 * font.CharHeight() - font.CharHeight() / 8); // TODO: wheel offset: top left, center, or center bottom? - const Vector wheelOffset; + const Vector wheelOffset( + 6 * font.CharWidth(), + 19 * font.CharHeight() - font.CharHeight() / 8); + const Vector classesOffset( + 12 * font.CharWidth(), + 13 * font.CharHeight() - font.CharHeight() / 8); const Vector menuOffset( - font.CharWidth(), - 24 * font.CharHeight() - font.CharHeight() / 8); + font.CharWidth(), + 24 * font.CharHeight() - font.CharHeight() / 8); parent->RenderBackground(screen); parent->RenderCapsule(screen, offset + capsuleOffset); parent->RenderInfo(screen, offset + infoOffset); parent->RenderWheel(screen, offset + wheelOffset); + RenderClasses(screen, offset + classesOffset); parent->RenderMenu(screen, offset + menuOffset); } +void CapsuleChangeMenu::RenderClasses(SDL_Surface *screen, const Vector &offset) const { + Vector cursor(offset); + + int numClasses = 0; + for (int i = 0; i < parent->Game().state->NumCapsules(); ++i) { + if (numClasses < parent->Game().state->capsules[i].NumClasses()) { + numClasses = parent->Game().state->capsules[i].NumClasses(); + } + } + + parent->Res().capsuleSelectTopLeft->Draw(screen, cursor); + cursor.Y() += parent->Res().capsuleSelectTopLeft->Height(); + Vector target( + cursor.X() + parent->Res().capsuleSelectTopLeft->Width(), + cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height()); + parent->Res().capsuleSelectLeftRepeat->Render(screen, cursor, target); + cursor.Y() = target.Y(); + parent->Res().capsuleSelectBottomLeft->Draw(screen, cursor); + cursor.X() += parent->Res().capsuleSelectTopLeft->Width(); + + for (int i = 0; i < parent->Game().state->NumCapsules(); ++i) { + cursor.Y() = offset.Y(); + parent->Res().capsuleSelectTopRepeat->Draw(screen, cursor); + cursor.Y() += parent->Res().capsuleSelectTopRepeat->Height(); + for (int j = numClasses - 1; j >= 0; --j) { + parent->Res().capsuleSelectLadder->Draw( + screen, cursor, + j < parent->Game().state->capsules[i].MaxClass(), j); + if (&parent->Game().state->capsules[i] == parent->Game().state->capsule + && parent->Game().state->capsules[i].CurrentClass() == j) { + parent->Res().capsuleSelectCursor->Draw(screen, cursor); + } + cursor.Y() += parent->Res().capsuleSelectLadder->Height(); + } + parent->Res().capsuleSelectBottomRepeat->Draw(screen, cursor); + if (parent->Game().state->capsules[i].AlignmentSprite()) { + parent->Game().state->capsules[i].AlignmentSprite()->Draw(screen, cursor); + } + cursor.X() += parent->Res().capsuleSelectLadder->Width(); + } + + cursor.Y() = offset.Y(); + parent->Res().capsuleSelectTopRight->Draw(screen, cursor); + cursor.Y() += parent->Res().capsuleSelectTopRight->Height(); + target = Vector( + cursor.X() + parent->Res().capsuleSelectTopRight->Width(), + cursor.Y() + numClasses * parent->Res().capsuleSelectLadder->Height()); + parent->Res().capsuleSelectRightRepeat->Render(screen, cursor, target); + cursor.Y() = target.Y(); + parent->Res().capsuleSelectBottomRight->Draw(screen, cursor); +} + int CapsuleChangeMenu::Width() const { return parent->Width(); diff --git a/src/menu/CapsuleChangeMenu.h b/src/menu/CapsuleChangeMenu.h index 5ac40fb..0f8888f 100644 --- a/src/menu/CapsuleChangeMenu.h +++ b/src/menu/CapsuleChangeMenu.h @@ -21,6 +21,8 @@ public: virtual void UpdateWorld(float deltaT); virtual void Render(SDL_Surface *); + void RenderClasses(SDL_Surface *, const geometry::Vector &) const; + public: int Width() const; int Height() const; diff --git a/src/menu/CapsuleMenu.cpp b/src/menu/CapsuleMenu.cpp index dd61dbd..5a800a3 100644 --- a/src/menu/CapsuleMenu.cpp +++ b/src/menu/CapsuleMenu.cpp @@ -97,7 +97,9 @@ void CapsuleMenu::Render(SDL_Surface *screen) { 12 * font.CharWidth(), 2 * font.CharHeight() - font.CharHeight() / 8); // TODO: wheel offset: top left, center, or center bottom? - const Vector wheelOffset; + const Vector wheelOffset( + 6 * font.CharWidth(), + 19 * font.CharHeight() - font.CharHeight() / 8); const Vector statsOffset( 12 * font.CharWidth(), 15 * font.CharHeight() - font.CharHeight() / 8); @@ -177,7 +179,8 @@ void CapsuleMenu::RenderInfo(SDL_Surface *screen, const Vector &offset) con } void CapsuleMenu::RenderWheel(SDL_Surface *screen, const Vector &offset) const { - // later + Res().capsuleAlignmentWheel->DrawCenter(screen, offset); + Res().capsuleAlignmentCursor->DrawCenter(screen, offset + Game().state->capsule->AlignmentOffset()); } void CapsuleMenu::RenderStats(SDL_Surface *screen, const Vector &offset) const { diff --git a/src/menu/Resources.cpp b/src/menu/Resources.cpp index 74e4ccd..548afc3 100644 --- a/src/menu/Resources.cpp +++ b/src/menu/Resources.cpp @@ -122,6 +122,20 @@ Resources::Resources() , capsuleNameCharSelectTemplate(0) +, capsuleSelectTopLeft(0) +, capsuleSelectTopRight(0) +, capsuleSelectTopRepeat(0) +, capsuleSelectBottomLeft(0) +, capsuleSelectBottomRight(0) +, capsuleSelectBottomRepeat(0) +, capsuleSelectLeftRepeat(0) +, capsuleSelectRightRepeat(0) +, capsuleSelectLadder(0) +, capsuleSelectCursor(0) + +, capsuleAlignmentWheel(0) +, capsuleAlignmentCursor(0) + { } @@ -231,6 +245,20 @@ void Resources::CreateTypeDescription() { td.AddField("capsuleNotHungryText", FieldDescription(((char *)&r.capsuleNotHungryText) - ((char *)&r), Interpreter::STRING_ID).SetReferenced()); td.AddField("capsuleNameSelect", FieldDescription(((char *)&r.capsuleNameCharSelectTemplate) - ((char *)&r), CharSelect::TYPE_ID).SetReferenced().SetDescription("properties of the letter array for changing the capsule name")); + + td.AddField("capsuleSelectTopLeft", FieldDescription(((char *)&r.capsuleSelectTopLeft) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectTopRight", FieldDescription(((char *)&r.capsuleSelectTopRight) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectTopRepeat", FieldDescription(((char *)&r.capsuleSelectTopRepeat) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectBottomLeft", FieldDescription(((char *)&r.capsuleSelectBottomLeft) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectBottomRight", FieldDescription(((char *)&r.capsuleSelectBottomRight) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectBottomRepeat", FieldDescription(((char *)&r.capsuleSelectBottomRepeat) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectLeftRepeat", FieldDescription(((char *)&r.capsuleSelectLeftRepeat) - ((char *)&r), Texture::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectRightRepeat", FieldDescription(((char *)&r.capsuleSelectRightRepeat) - ((char *)&r), Texture::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectLadder", FieldDescription(((char *)&r.capsuleSelectLadder) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleSelectCursor", FieldDescription(((char *)&r.capsuleSelectCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + + td.AddField("capsuleAlignmentWheel", FieldDescription(((char *)&r.capsuleAlignmentWheel) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); + td.AddField("capsuleAlignmentCursor", FieldDescription(((char *)&r.capsuleAlignmentCursor) - ((char *)&r), Sprite::TYPE_ID).SetReferenced()); } void Resources::Construct(void *data) { diff --git a/src/menu/Resources.h b/src/menu/Resources.h index 6fc0641..1f6d207 100644 --- a/src/menu/Resources.h +++ b/src/menu/Resources.h @@ -110,6 +110,20 @@ struct Resources { graphics::CharSelect *capsuleNameCharSelectTemplate; + graphics::Sprite *capsuleSelectTopLeft; + graphics::Sprite *capsuleSelectTopRight; + graphics::Sprite *capsuleSelectTopRepeat; + graphics::Sprite *capsuleSelectBottomLeft; + graphics::Sprite *capsuleSelectBottomRight; + graphics::Sprite *capsuleSelectBottomRepeat; + graphics::Texture *capsuleSelectLeftRepeat; + graphics::Texture *capsuleSelectRightRepeat; + graphics::Sprite *capsuleSelectLadder; + graphics::Sprite *capsuleSelectCursor; + + graphics::Sprite *capsuleAlignmentWheel; + graphics::Sprite *capsuleAlignmentCursor; + Resources(); static void CreateTypeDescription(); diff --git a/test-data/capsule-sprites.png b/test-data/capsule-sprites.png new file mode 100644 index 0000000..9884464 Binary files /dev/null and b/test-data/capsule-sprites.png differ diff --git a/test-data/capsules.l2s b/test-data/capsules.l2s index a4f525e..866e76f 100644 --- a/test-data/capsules.l2s +++ b/test-data/capsules.l2s @@ -6,6 +6,12 @@ Sprite flashSprite { export Capsule flash { name: "Flash", alignment: "LIGHT", + alignmentCursor: <-32, 0>, + alignmentSprite: Sprite { + image: :"capsule-sprites.png", + size: <32, 32>, + offset: <0, 96> + }, maxHealth: 5, stats: Stats { atp: 12, @@ -17,6 +23,101 @@ export Capsule flash { mgr: 11 }, classes: [ CapsuleClass + { + name: "1 TODO", + tribe: "Shaggy", + battleSprite: flashSprite, + meleeAnimation: SimpleAnimation { + sprite: Sprite { + image: :"melee-maxim.png", + size: <96,96> + }, + frametime: 66, // two "frames" + framecount: 4 + }, + attackAnimation: ComplexAnimation { + sprite: flashSprite, + frametime: fourFramesTime, + repeat: false, + frames: + [ ComplexAnimationFrame + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> }, + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> } + ] + } + }, + { + name: "2 TODO", + tribe: "Sprite", + battleSprite: flashSprite, + meleeAnimation: SimpleAnimation { + sprite: Sprite { + image: :"melee-maxim.png", + size: <96,96> + }, + frametime: 66, // two "frames" + framecount: 4 + }, + attackAnimation: ComplexAnimation { + sprite: flashSprite, + frametime: fourFramesTime, + repeat: false, + frames: + [ ComplexAnimationFrame + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> }, + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> } + ] + }, + healthBoost: 208, + statBoost: Stats { + atp: 38, + dfp: 71, + str: 24, + agl: 78, + int: 195, + gut: 12, // TODO: this is probably higher, but clipped at 199 + mgr: 135 + } + }, + { + name: "3 TODO", + tribe: "Cupid", + battleSprite: flashSprite, + meleeAnimation: SimpleAnimation { + sprite: Sprite { + image: :"melee-maxim.png", + size: <96,96> + }, + frametime: 66, // two "frames" + framecount: 4 + }, + attackAnimation: ComplexAnimation { + sprite: flashSprite, + frametime: fourFramesTime, + repeat: false, + frames: + [ ComplexAnimationFrame + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> }, + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> } + ] + }, + healthBoost: 208, + statBoost: Stats { + atp: 38, + dfp: 71, + str: 24, + agl: 78, + int: 195, + gut: 12, // TODO: this is probably higher, but clipped at 199 + mgr: 135 + } + }, { name: "4", tribe: "Twinkle", @@ -51,6 +152,41 @@ export Capsule flash { gut: 12, // TODO: this is probably higher, but clipped at 199 mgr: 135 } + }, + { + name: "M TODO", + tribe: "Twinkle", + battleSprite: flashSprite, + meleeAnimation: SimpleAnimation { + sprite: Sprite { + image: :"melee-maxim.png", + size: <96,96> + }, + frametime: 66, // two "frames" + framecount: 4 + }, + attackAnimation: ComplexAnimation { + sprite: flashSprite, + frametime: fourFramesTime, + repeat: false, + frames: + [ ComplexAnimationFrame + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> }, + { column: 0, row: 1, disposition: < 0, -16> }, + { column: 0, row: 0, disposition: < 0, -16> } + ] + }, + healthBoost: 208, + statBoost: Stats { + atp: 38, + dfp: 71, + str: 24, + agl: 78, + int: 195, + gut: 12, // TODO: this is probably higher, but clipped at 199 + mgr: 135 + } } ] } diff --git a/test-data/test.l2s b/test-data/test.l2s index 44ffc60..c691e17 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -884,5 +884,64 @@ export MenuResources menuResources { chars: "0123456789ABCDEabcdeFGHIJfghijKLMNOklmnoPQRSTpqrstUVWXYuvwxyZ!? z!? ", width: 10, groupX: 5 + }, + capsuleSelectTopLeft: Sprite { + image: :"capsule-sprites.png", + size: <32, 8>, + offset: <64, 0> + }, + capsuleSelectTopRight: Sprite { + image: :"capsule-sprites.png", + size: <32, 8>, + offset: <128, 0> + }, + capsuleSelectTopRepeat: Texture { + image: :"capsule-sprites.png", + size: <32, 8>, + offset: <96, 0> + }, + capsuleSelectBottomLeft: Sprite { + image: :"capsule-sprites.png", + size: <32, 32>, + offset: <0, 32> + }, + capsuleSelectBottomRight: Sprite { + image: :"capsule-sprites.png", + size: <32, 32>, + offset: <128, 64> + }, + capsuleSelectBottomRepeat: Sprite { + image: :"capsule-sprites.png", + size: <32, 32>, + offset: <0, 64> + }, + capsuleSelectLeftRepeat: Texture { + image: :"capsule-sprites.png", + size: <32, 32> + }, + capsuleSelectRightRepeat: Texture { + image: :"capsule-sprites.png", + size: <32, 32>, + offset: <128, 32> + }, + capsuleSelectLadder: Sprite { + image: :"capsule-sprites.png", + size: <32, 24>, + offset: <64, 8> + }, + capsuleSelectCursor: Sprite { + image: :"capsule-sprites.png", + size: <32, 24>, + offset: <128, 8> + }, + capsuleAlignmentWheel: Sprite { + image: :"capsule-sprites.png", + size: <128, 128>, + offset: <0, 128> + }, + capsuleAlignmentCursor: Sprite { + image: :"capsule-sprites.png", + size: <32, 32>, + offset: <128, 128> } }