From: Daniel Karbach Date: Sun, 2 Sep 2012 15:23:34 +0000 (+0200) Subject: moved menu prototypes to test.l2s X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=1aa61eca26f5b4a4cb856a39e802f5899548b691;p=l2e.git moved menu prototypes to test.l2s --- diff --git a/src/loader/Interpreter.cpp b/src/loader/Interpreter.cpp index 79fe4f3..372a114 100644 --- a/src/loader/Interpreter.cpp +++ b/src/loader/Interpreter.cpp @@ -19,6 +19,7 @@ #include "../graphics/Font.h" #include "../graphics/Frame.h" #include "../graphics/Gauge.h" +#include "../graphics/Menu.h" #include "../graphics/SimpleAnimation.h" #include "../graphics/Sprite.h" @@ -76,6 +77,9 @@ Interpreter::~Interpreter() { for (vector::const_iterator i(items.begin()), end(items.end()); i != end; ++i) { delete *i; } + for (vector::const_iterator i(menuProperties.begin()), end(menuProperties.end()); i != end; ++i) { + delete *i; + } for (vector::const_iterator i(monsters.begin()), end(monsters.end()); i != end; ++i) { delete *i; } @@ -219,6 +223,19 @@ Item *Interpreter::GetItem(const std::string &name) { } } +graphics::MenuProperties *Interpreter::GetMenuProperties(const std::string &name) { + map::const_iterator i(parsedDefinitions.find(name)); + if (i != parsedDefinitions.end()) { + if (i->second.type == MENU_PROPERTIES) { + return menuProperties[i->second.index]; + } else { + throw Error("cannot cast " + i->second.dfn->TypeName() + " to MenuProperties"); + } + } else { + throw Error("access to undefined MenuProperties " + name); + } +} + Monster *Interpreter::GetMonster(const std::string &name) { map::const_iterator i(parsedDefinitions.find(name)); if (i != parsedDefinitions.end()) { @@ -521,6 +538,28 @@ Item *Interpreter::GetItem(const Value &v) { } } +graphics::MenuProperties *Interpreter::GetMenuProperties(const Value &v) { + if (v.IsLiteral()) { + graphics::MenuProperties *m(new graphics::MenuProperties); + ReadMenuProperties(*m, *v.GetLiteral().GetProperties()); + return m; + } else { + ReadDefinition(source.GetDefinition(v.GetIdentifier())); + return GetMenuProperties(v.GetIdentifier()); + } +} + +Monster *Interpreter::GetMonster(const Value &v) { + if (v.IsLiteral()) { + Monster *m(new Monster); + ReadMonster(*m, *v.GetLiteral().GetProperties()); + return m; + } else { + ReadDefinition(source.GetDefinition(v.GetIdentifier())); + return GetMonster(v.GetIdentifier()); + } +} + int Interpreter::GetNumber(const Value &v) { if (v.IsLiteral()) { return v.GetLiteral().GetNumber(); @@ -669,6 +708,12 @@ void Interpreter::ReadObject(const Definition &dfn) { items.push_back(item); ReadItem(*item, *dfn.GetProperties()); parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, ITEM, index))); + } else if (dfn.TypeName() == "MenuProperties") { + graphics::MenuProperties *mprops(new graphics::MenuProperties); + int index(menuProperties.size()); + menuProperties.push_back(mprops); + ReadMenuProperties(*mprops, *dfn.GetProperties()); + parsedDefinitions.insert(make_pair(dfn.Identifier(), ParsedDefinition(&dfn, MENU_PROPERTIES, index))); } else if (dfn.TypeName() == "Monster") { Monster *monster(new Monster); int index(monsters.size()); @@ -876,6 +921,40 @@ void Interpreter::ReadHero(Hero &h, const PropertyList &props) { } } +void Interpreter::ReadMenuProperties(graphics::MenuProperties &mprops, const PropertyList &props) { + for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { + if (i->first == "font") { + mprops.font = GetFont(*i->second); + } else if (i->first == "disabledFont") { + mprops.disabledFont = GetFont(*i->second); + } else if (i->first == "cursor") { + mprops.cursor = GetSprite(*i->second); + } else if (i->first == "charsPerEntry") { + mprops.charsPerEntry = GetNumber(*i->second); + } else if (i->first == "rows") { + mprops.rows = GetNumber(*i->second); + } else if (i->first == "rowGap") { + mprops.rowGap = GetNumber(*i->second); + } else if (i->first == "iconSpace") { + mprops.iconSpace = GetNumber(*i->second); + } else if (i->first == "cols") { + mprops.cols = GetNumber(*i->second); + } else if (i->first == "colGap") { + mprops.colGap = GetNumber(*i->second); + } else if (i->first == "delimiter") { + mprops.delimiter = *GetString(*i->second); + } else if (i->first == "charsPerNumber") { + mprops.charsPerNumber = GetNumber(*i->second); + } else if (i->first == "charsPerAdditionalText") { + mprops.charsPerAdditionalText = GetNumber(*i->second); + } else if (i->first == "additionalTextGap") { + mprops.additionalTextGap = GetNumber(*i->second); + } else { + throw Error("unknown MenuProperties property: " + i->first); + } + } +} + void Interpreter::ReadMonster(Monster &m, const PropertyList &props) { for (PropertyList::ConstIterator i(props.Begin()), end(props.End()); i != end; ++i) { if (i->first == "name") { diff --git a/src/loader/Interpreter.h b/src/loader/Interpreter.h index b91e478..e72d4da 100644 --- a/src/loader/Interpreter.h +++ b/src/loader/Interpreter.h @@ -37,6 +37,7 @@ namespace graphics { class Font; class Frame; class Gauge; + struct MenuProperties; class SimpleAnimation; class Sprite; } @@ -76,6 +77,7 @@ public: battle::Hero *GetHero(const std::string &name); common::Ikari *GetIkari(const std::string &name); common::Item *GetItem(const std::string &name); + graphics::MenuProperties *GetMenuProperties(const std::string &name); battle::Monster *GetMonster(const std::string &name); int GetNumber(const std::string &name) const; battle::PartyLayout *GetPartyLayout(const std::string &name); @@ -97,6 +99,7 @@ public: const std::vector &Ikaris() const { return ikaris; } const std::vector &Images() const { return images; } const std::vector &Items() const { return items; } + const std::vector &MenuProperties() const { return menuProperties; } const std::vector &Monsters() const { return monsters; } const std::vector &Numbers() const { return numbers; } const std::vector &PartyLayouts() const { return partyLayouts; } @@ -122,6 +125,8 @@ private: common::Ikari *GetIkari(const Value &); SDL_Surface *GetImage(const Value &); common::Item *GetItem(const Value &); + graphics::MenuProperties *GetMenuProperties(const Value &); + battle::Monster *GetMonster(const Value &); int GetNumber(const Value &); battle::PartyLayout *GetPartyLayout(const Value &); const PropertyList *GetPropertyList(const Value &); @@ -142,6 +147,7 @@ private: void ReadHero(battle::Hero &, const PropertyList &); void ReadIkari(common::Ikari &, const PropertyList &); void ReadItem(common::Item &, const PropertyList &); + void ReadMenuProperties(graphics::MenuProperties &, const PropertyList &); void ReadMonster(battle::Monster &, const PropertyList &); void ReadPartyLayout(battle::PartyLayout &, const PropertyList &); void ReadSimpleAnimation(graphics::SimpleAnimation &, const PropertyList &); @@ -163,6 +169,7 @@ private: IKARI, IMAGE, ITEM, + MENU_PROPERTIES, MONSTER, NUMBER, PARTY_LAYOUT, @@ -197,6 +204,7 @@ private: std::vector ikaris; std::vector images; std::vector items; + std::vector menuProperties; std::vector monsters; std::vector numbers; std::vector partyLayouts; diff --git a/src/main.cpp b/src/main.cpp index daeb3c4..a1fbfaf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -162,7 +162,7 @@ int main(int argc, char **argv) { selan.AddSpell(valorSpell); battleRes.spellMenuHeadline = intp.GetString("spellMenuHeadline"); - battleRes.spellMenuPrototype = Menu(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 9, 6, 8, 0, 2, 32, 2, ':'); + battleRes.spellMenuPrototype = Menu(*intp.GetMenuProperties("spellMenuPrototype")); battleRes.weaponMenuIcon = intp.GetSprite("swordIcon"); battleRes.armorMenuIcon = intp.GetSprite("armorIcon"); @@ -181,7 +181,7 @@ int main(int argc, char **argv) { battleRes.inventory = &inventory; battleRes.itemMenuHeadline = intp.GetString("itemMenuHeadline"); - battleRes.itemMenuPrototype = Menu(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 15, 6, 8, 16, 1, 32, 2, ':'); + battleRes.itemMenuPrototype = Menu(*intp.GetMenuProperties("itemMenuPrototype")); maxim.SetWeapon(intp.GetItem("zircoSwordItem")); maxim.SetArmor(intp.GetItem("zirconArmorItem")); @@ -214,7 +214,7 @@ int main(int argc, char **argv) { battleRes.ikariMenuHeadline = intp.GetString("ikariMenuHeadline"); battleRes.noEquipmentText = intp.GetString("noEquipmentText"); - battleRes.ikariMenuPrototype = Menu(intp.GetFont("normalFont"), intp.GetFont("disabledFont"), intp.GetSprite("handCursor"), 12, 6, intp.GetFont("normalFont")->CharHeight() / 2, intp.GetFont("normalFont")->CharWidth(), 1, intp.GetFont("normalFont")->CharWidth() * 2, 0, ':', 12, intp.GetFont("normalFont")->CharWidth()); + battleRes.ikariMenuPrototype = Menu(*intp.GetMenuProperties("ikariMenuPrototype")); battleRes.escapeText = intp.GetString("escapeText"); BattleState *battleState(new BattleState(bg, monstersLayout, heroesLayout, &battleRes)); diff --git a/test-data/test.l2s b/test-data/test.l2s index 9cd2d0c..65da87a 100644 --- a/test-data/test.l2s +++ b/test-data/test.l2s @@ -515,7 +515,49 @@ export Sprite itemTargetCursor { } export String spellMenuHeadline "Please choose a spell." +export MenuProperties spellMenuPrototype { + font: normalFont, + disabledFont: disabledFont, + cursor: handCursor, + charsPerEntry: 9, + rows: 6, + rowGap: 8, + iconSpace: 0, + cols: 2, + colGap: 32, + charsPerNumber: 2, + delimiter: ":" +} + export String itemMenuHeadline "Please choose an item." +export MenuProperties itemMenuPrototype { + font: normalFont, + disabledFont: disabledFont, + cursor: handCursor, + charsPerEntry: 15, + rows: 6, + rowGap: 8, + iconSpace: 16, + cols: 1, + colGap: 32, + charsPerNumber: 2, + delimiter: ":" +} + export String ikariMenuHeadline "Please choose equipment." +export MenuProperties ikariMenuPrototype { + font: normalFont, + disabledFont: disabledFont, + cursor: handCursor, + charsPerEntry: 12, + rows: 6, + rowGap: 8, + iconSpace: 16, + cols: 1, + colGap: 32, + charsPerAdditionalText: 12, + additionalTextGap: 16 +} export String noEquipmentText "No equip" + export String escapeText "Escapes."