diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-17 20:16:14 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-17 20:16:14 +0300 |
commit | 995bc5ba7d1b5e38cf294d6fa27db7ee89886a28 (patch) | |
tree | e4d553b28cc68de9a629d0174503146624c63f27 | |
parent | 21fa38275fc8ec00d32dd1b2f7fe211a7925a596 (diff) | |
download | mv-995bc5ba7d1b5e38cf294d6fa27db7ee89886a28.tar.gz mv-995bc5ba7d1b5e38cf294d6fa27db7ee89886a28.tar.bz2 mv-995bc5ba7d1b5e38cf294d6fa27db7ee89886a28.tar.xz mv-995bc5ba7d1b5e38cf294d6fa27db7ee89886a28.zip |
Use magic command properties only if compiled for tmwa.
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/enums/magicschool.h | 3 | ||||
-rw-r--r-- | src/gui/windows/textcommandeditor.cpp | 89 | ||||
-rw-r--r-- | src/gui/windows/textcommandeditor.h | 10 | ||||
-rw-r--r-- | src/resources/db/commandsdb.cpp | 4 | ||||
-rw-r--r-- | src/spellmanager.cpp | 52 | ||||
-rw-r--r-- | src/textcommand.cpp | 13 | ||||
-rw-r--r-- | src/textcommand.h | 45 |
8 files changed, 159 insertions, 59 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 483e8d634..a046f422a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -695,7 +695,6 @@ manaplus_SOURCES += main.cpp \ enums/equipslot.h \ enums/guildpositionflags.h \ enums/inventorytype.h \ - enums/magicschool.h \ spellshortcut.cpp \ spellshortcut.h \ statuseffect.cpp \ @@ -1290,6 +1289,7 @@ manaplus_SOURCES += main.cpp \ if ENABLE_TMWA manaplus_CXXFLAGS += -DTMWA_SUPPORT manaplus_SOURCES += \ + enums/magicschool.h \ gui/widgets/tabs/chat/emulateguildtab.cpp \ gui/widgets/tabs/chat/emulateguildtab.h \ gui/windows/shopselldialog.cpp \ diff --git a/src/enums/magicschool.h b/src/enums/magicschool.h index 1a12b9539..a46795e43 100644 --- a/src/enums/magicschool.h +++ b/src/enums/magicschool.h @@ -21,6 +21,8 @@ #ifndef ENUMS_MAGICSCHOOL_H #define ENUMS_MAGICSCHOOL_H +#ifdef TMWA_SUPPORT + #include "enums/simpletypes/enumdefines.h" enumStart(MagicSchool) @@ -34,4 +36,5 @@ enumStart(MagicSchool) } enumEnd(MagicSchool); +#endif // TMWA_SUPPORT #endif // ENUMS_MAGICSCHOOL_H diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp index bf5e8e00b..048752187 100644 --- a/src/gui/windows/textcommandeditor.cpp +++ b/src/gui/windows/textcommandeditor.cpp @@ -46,13 +46,17 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : // TRANSLATORS: command editor name Window(_("Command Editor"), Modal_false, nullptr, "commandeditor.xml"), ActionListener(), +#ifdef TMWA_SUPPORT mIsMagicCommand(command ? (command->getCommandType() == TextCommandType::Magic) : false), +#endif mCommand(command), +#ifdef TMWA_SUPPORT // TRANSLATORS: command editor button mIsMagic(new RadioButton(this, _("magic"), "magic", mIsMagicCommand)), // TRANSLATORS: command editor button mIsOther(new RadioButton(this, _("other"), "magic", !mIsMagicCommand)), +#endif // TRANSLATORS: command editor label mSymbolLabel(new Label(this, _("Symbol:"))), mSymbolTextField(new TextField(this)), @@ -70,6 +74,7 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : // TRANSLATORS: command editor label mIconLabel(new Label(this, _("Icon:"))), mIconDropDown(new DropDown(this, mIconsModel)), +#ifdef TMWA_SUPPORT // TRANSLATORS: command editor label mManaLabel(new Label(this, _("Mana:"))), mManaField(new IntTextField(this, 0)), @@ -83,6 +88,7 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : // TRANSLATORS: command editor label mSchoolLvlLabel(new Label(this, _("School level:"))), mSchoolLvlField(new IntTextField(this, 0)), +#endif // TRANSLATORS: command editor button mCancelButton(new Button(this, _("Cancel"), "cancel", this)), // TRANSLATORS: command editor button @@ -99,6 +105,7 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : setWindowName("TextCommandEditor"); setDefaultSize(w, h, ImageRect::CENTER); +#ifdef TMWA_SUPPORT mIsMagic->setActionEventId("magic"); mIsMagic->addActionListener(this); @@ -108,13 +115,6 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : mManaField->setRange(0, 500); mManaField->setWidth(20); - mTypeDropDown->setActionEventId("type"); - mTypeDropDown->addActionListener(this); - - mIconDropDown->setActionEventId("icon"); - mIconDropDown->addActionListener(this); - mIconDropDown->setSelectedString(mCommand->getIcon()); - mMagicLvlField->setRange(0, 5); mMagicLvlField->setWidth(20); @@ -124,6 +124,14 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : mSchoolLvlField->setRange(0, 5); mSchoolLvlField->setWidth(20); +#endif + + mTypeDropDown->setActionEventId("type"); + mTypeDropDown->addActionListener(this); + + mIconDropDown->setActionEventId("icon"); + mIconDropDown->addActionListener(this); + mIconDropDown->setSelectedString(mCommand->getIcon()); mSaveButton->adjustSize(); mCancelButton->adjustSize(); @@ -131,25 +139,30 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : if (command) { +#ifdef TMWA_SUPPORT if (command->getCommandType() == TextCommandType::Magic) showControls(Visible_true); else showControls(Visible_false); +#endif mSymbolTextField->setText(command->getSymbol()); mCommandTextField->setText(command->getCommand()); mCommentTextField->setText(command->getComment()); - mManaField->setValue(command->getMana()); mTypeDropDown->setSelected(static_cast<int>(command->getTargetType())); +#ifdef TMWA_SUPPORT + mManaField->setValue(command->getMana()); mMagicLvlField->setValue(command->getBaseLvl()); mSchoolDropDown->setSelected(static_cast<int>(command->getSchool()) - MAGIC_START_ID); mSchoolLvlField->setValue(command->getSchoolLvl()); +#endif } ContainerPlacer placer; placer = getPlacer(0, 0); +#ifdef TMWA_SUPPORT placer(0, 0, mIsMagic, 1); placer(2, 0, mIsOther, 1); placer(0, 1, mSymbolLabel, 2).setPadding(3); @@ -179,6 +192,25 @@ TextCommandEditor::TextCommandEditor(TextCommand *const command) : placer(0, 10, mSaveButton, 2).setPadding(3); placer(2, 10, mCancelButton, 2).setPadding(3); placer(4, 10, mDeleteButton, 2).setPadding(3); +#else + placer(0, 0, mSymbolLabel, 2).setPadding(3); + placer(2, 0, mSymbolTextField, 3).setPadding(3); + placer(0, 1, mCommandLabel, 2).setPadding(3); + placer(2, 1, mCommandTextField, 4).setPadding(3); + + placer(0, 2, mCommentLabel, 2).setPadding(3); + placer(2, 2, mCommentTextField, 4).setPadding(3); + + placer(0, 3, mTypeLabel, 2).setPadding(3); + placer(2, 3, mTypeDropDown, 3).setPadding(3); + + placer(0, 4, mIconLabel, 2).setPadding(3); + placer(2, 4, mIconDropDown, 3).setPadding(3); + + placer(0, 5, mSaveButton, 2).setPadding(3); + placer(2, 5, mCancelButton, 2).setPadding(3); + placer(4, 5, mDeleteButton, 2).setPadding(3); +#endif setWidth(w); setHeight(h); @@ -199,23 +231,15 @@ TextCommandEditor::~TextCommandEditor() { delete2(mIconsModel); delete2(mTargetTypeModel); +#ifdef TMWA_SUPPORT delete2(mMagicSchoolModel); +#endif } void TextCommandEditor::action(const ActionEvent &event) { const std::string &eventId = event.getId(); - if (eventId == "magic") - { - mIsMagicCommand = true; - showControls(Visible_true); - } - else if (eventId == "other") - { - mIsMagicCommand = false; - showControls(Visible_false); - } - else if (eventId == "save") + if (eventId == "save") { save(); scheduleDelete(); @@ -229,8 +253,21 @@ void TextCommandEditor::action(const ActionEvent &event) deleteCommand(); scheduleDelete(); } +#ifdef TMWA_SUPPORT + else if (eventId == "magic") + { + mIsMagicCommand = true; + showControls(Visible_true); + } + else if (eventId == "other") + { + mIsMagicCommand = false; + showControls(Visible_false); + } +#endif } +#ifdef TMWA_SUPPORT void TextCommandEditor::showControls(const Visible show) { mManaField->setVisible(show); @@ -242,6 +279,7 @@ void TextCommandEditor::showControls(const Visible show) mSchoolLvlLabel->setVisible(show); mSchoolLvlField->setVisible(show); } +#endif void TextCommandEditor::scheduleDelete() { @@ -251,38 +289,45 @@ void TextCommandEditor::scheduleDelete() void TextCommandEditor::save() { +#ifdef TMWA_SUPPORT if (mIsMagicCommand) mCommand->setCommandType(TextCommandType::Magic); else mCommand->setCommandType(TextCommandType::Text); +#endif mCommand->setSymbol(mSymbolTextField->getText()); mCommand->setCommand(mCommandTextField->getText()); mCommand->setComment(mCommentTextField->getText()); - mCommand->setMana(mManaField->getValue()); mCommand->setTargetType( static_cast<CommandTargetT>(mTypeDropDown->getSelected())); mCommand->setIcon(mIconDropDown->getSelectedString()); + +#ifdef TMWA_SUPPORT + mCommand->setMana(mManaField->getValue()); mCommand->setBaseLvl(mMagicLvlField->getValue()); mCommand->setSchool(static_cast<MagicSchoolT>( mSchoolDropDown->getSelected() + MAGIC_START_ID)); mCommand->setSchoolLvl(mSchoolLvlField->getValue()); +#endif if (spellManager) spellManager->save(); } void TextCommandEditor::deleteCommand() { - mCommand->setCommandType(TextCommandType::Text); mCommand->setSymbol(""); mCommand->setCommand(""); mCommand->setComment(""); - mCommand->setMana(0); mCommand->setTargetType(CommandTarget::NoTarget); mCommand->setIcon(""); +#ifdef TMWA_SUPPORT + mCommand->setCommandType(TextCommandType::Text); + mCommand->setMana(0); mCommand->setBaseLvl(0); mCommand->setSchool(MagicSchool::SkillMagic); mCommand->setSchoolLvl(0); +#endif if (spellManager) spellManager->save(); } diff --git a/src/gui/windows/textcommandeditor.h b/src/gui/windows/textcommandeditor.h index 2e04e4fbf..0baa9a62c 100644 --- a/src/gui/windows/textcommandeditor.h +++ b/src/gui/windows/textcommandeditor.h @@ -32,7 +32,9 @@ class DropDown; class IconsModel; class IntTextField; class Label; +#ifdef TMWA_SUPPORT class MagicSchoolModel; +#endif class RadioButton; class TargetTypeModel; class TextCommand; @@ -61,16 +63,22 @@ class TextCommandEditor final : public Window, void scheduleDelete() override final; private: +#ifdef TMWA_SUPPORT void showControls(const Visible show); +#endif void save(); void deleteCommand(); +#ifdef TMWA_SUPPORT bool mIsMagicCommand; +#endif TextCommand* mCommand; +#ifdef TMWA_SUPPORT RadioButton* mIsMagic A_NONNULLPOINTER; +#endif RadioButton* mIsOther A_NONNULLPOINTER; Label* mSymbolLabel A_NONNULLPOINTER; TextField* mSymbolTextField A_NONNULLPOINTER; @@ -84,6 +92,7 @@ class TextCommandEditor final : public Window, IconsModel* mIconsModel A_NONNULLPOINTER; Label* mIconLabel A_NONNULLPOINTER; DropDown* mIconDropDown A_NONNULLPOINTER; +#ifdef TMWA_SUPPORT Label* mManaLabel A_NONNULLPOINTER; IntTextField* mManaField A_NONNULLPOINTER; Label* mMagicLvlLabel A_NONNULLPOINTER; @@ -93,6 +102,7 @@ class TextCommandEditor final : public Window, DropDown* mSchoolDropDown A_NONNULLPOINTER; Label* mSchoolLvlLabel A_NONNULLPOINTER; IntTextField* mSchoolLvlField A_NONNULLPOINTER; +#endif Button* mCancelButton A_NONNULLPOINTER; Button* mSaveButton A_NONNULLPOINTER; Button* mDeleteButton A_NONNULLPOINTER; diff --git a/src/resources/db/commandsdb.cpp b/src/resources/db/commandsdb.cpp index 69c918f86..992d194df 100644 --- a/src/resources/db/commandsdb.cpp +++ b/src/resources/db/commandsdb.cpp @@ -103,6 +103,7 @@ void CommandsDB::loadXmlFile(const std::string &fileName) commandNode, "target", "")); const std::string icon = XML::getProperty( commandNode, "icon", ""); +#ifdef TMWA_SUPPORT const int skill1 = XML::getIntProperty( commandNode, "skill1", 0, 0, 1000000); const int level1 = XML::getIntProperty( @@ -113,8 +114,10 @@ void CommandsDB::loadXmlFile(const std::string &fileName) commandNode, "level2", 0, 0, 1000); const int mana = XML::getIntProperty( commandNode, "mana", 0, 0, 100000); +#endif TextCommand *cmd = nullptr; +#ifdef TMWA_SUPPORT if (skill1) { cmd = new TextCommand(id, @@ -129,6 +132,7 @@ void CommandsDB::loadXmlFile(const std::string &fileName) mana); } else +#endif { cmd = new TextCommand(id, name, diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index 316ca5530..50530e059 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -134,23 +134,32 @@ void SpellManager::invoke(const int spellId) const if (!playerHandler || spell->getCommand().empty()) return; - if (spell->getCommandType() == TextCommandType::Text - || (playerHandler->canUseMagic() - && PlayerInfo::getSkillLevel(static_cast<int>(MagicSchool::SkillMagic)) - >= static_cast<signed>(spell->getBaseLvl()) - && PlayerInfo::getSkillLevel(static_cast<int>( +#ifdef TMWA_SUPPORT + if (spell->getCommandType() == TextCommandType::Text || + (playerHandler->canUseMagic() && + PlayerInfo::getSkillLevel(static_cast<int>(MagicSchool::SkillMagic)) + >= static_cast<signed>(spell->getBaseLvl()) && + PlayerInfo::getSkillLevel(static_cast<int>( spell->getSchool())) >= static_cast<signed>(spell->getSchoolLvl()) - && PlayerInfo::getAttribute(Attributes::MP) >= spell->getMana())) + && PlayerInfo::getAttribute(Attributes::MP) >= spell->getMana()) + ) +#endif { const Being *const target = localPlayer->getTarget(); if (spell->getTargetType() == CommandTarget::NoTarget) { invokeSpell(spell); } - if ((target && (target->getType() != ActorType::Monster - || spell->getCommandType() == TextCommandType::Text)) - && (spell->getTargetType() == CommandTarget::AllowTarget - || spell->getTargetType() == CommandTarget::NeedTarget)) +#ifdef TMWA_SUPPORT + if ((target && (target->getType() != ActorType::Monster || + spell->getCommandType() == TextCommandType::Text)) && + (spell->getTargetType() == CommandTarget::AllowTarget || + spell->getTargetType() == CommandTarget::NeedTarget)) +#else + if (target && + (spell->getTargetType() == CommandTarget::AllowTarget || + spell->getTargetType() == CommandTarget::NeedTarget)) +#endif { invokeSpell(spell, target); } @@ -284,6 +293,7 @@ void SpellManager::load(const bool oldConfig) std::string icon = cfg->getValue("commandShortcutIcon" + toString(i), ""); +#ifdef TMWA_SUPPORT if (static_cast<TextCommandTypeT>(commandType) == TextCommandType::Magic) { @@ -292,6 +302,7 @@ void SpellManager::load(const bool oldConfig) static_cast<MagicSchoolT>(school), schoolLvl, mana)); } else +#endif { addSpell(new TextCommand(i, symbol, cmd, comment, static_cast<CommandTargetT>(targetType), icon)); @@ -319,13 +330,24 @@ void SpellManager::save() const setOrDel("commandShortcutIcon", getIcon); if (spell->getCommand() != "" && spell->getSymbol() != "") { +#ifdef TMWA_SUPPORT serverConfig.setValue("commandShortcutFlags" + toString(i), - strprintf("%u %u %u %u %u %u", static_cast<unsigned>( - spell->getCommandType()), static_cast<unsigned>( - spell->getTargetType()), spell->getBaseLvl(), + strprintf("%u %u %u %u %u %u", + static_cast<unsigned>(spell->getCommandType()), + static_cast<unsigned>(spell->getTargetType()), + spell->getBaseLvl(), static_cast<unsigned>(spell->getSchool()), - spell->getSchoolLvl(), static_cast<unsigned>( - spell->getMana()))); + spell->getSchoolLvl(), + static_cast<unsigned>(spell->getMana()))); +#else + serverConfig.setValue("commandShortcutFlags" + toString(i), + strprintf("%u %u %u %u %u %u", 1U, + static_cast<unsigned>(spell->getTargetType()), + 0U, + 0U, + 0U, + 0U)); +#endif } else { diff --git a/src/textcommand.cpp b/src/textcommand.cpp index 04d479ece..3674ac9dc 100644 --- a/src/textcommand.cpp +++ b/src/textcommand.cpp @@ -34,6 +34,7 @@ #include "debug.h" +#ifdef TMWA_SUPPORT TextCommand::TextCommand(const unsigned int id, const std::string &symbol, const std::string &command, @@ -59,23 +60,27 @@ TextCommand::TextCommand(const unsigned int id, { loadImage(); } +#endif - -TextCommand::TextCommand(const unsigned int id, const std::string &symbol, +TextCommand::TextCommand(const unsigned int id, + const std::string &symbol, const std::string &command, const std::string &comment, - const CommandTargetT type, const std::string &icon) : + const CommandTargetT type, + const std::string &icon) : mCommand(command), mComment(comment), mSymbol(symbol), mTargetType(type), mIcon(icon), mId(id), +#ifdef TMWA_SUPPORT mMana(0), mSchool(MagicSchool::SkillMagic), mBaseLvl(0), mSchoolLvl(0), mCommandType(TextCommandType::Text), +#endif mImage(nullptr) { loadImage(); @@ -88,11 +93,13 @@ TextCommand::TextCommand(const unsigned int id) : mTargetType(CommandTarget::NoTarget), mIcon(""), mId(id), +#ifdef TMWA_SUPPORT mMana(0), mSchool(MagicSchool::SkillMagic), mBaseLvl(0), mSchoolLvl(0), mCommandType(TextCommandType::Text), +#endif mImage(nullptr) { loadImage(); diff --git a/src/textcommand.h b/src/textcommand.h index 1b5bad71b..73a214a41 100644 --- a/src/textcommand.h +++ b/src/textcommand.h @@ -41,6 +41,7 @@ class Image; class TextCommand final { public: +#ifdef TMWA_SUPPORT /** * Constructor. */ @@ -54,13 +55,17 @@ class TextCommand final const MagicSchoolT school = MagicSchool::SkillMagic, const unsigned int schoolLvl = 0, const int mana = 0); +#endif /** * Constructor. */ - TextCommand(const unsigned int id, const std::string &symbol, - const std::string &command, const std::string &comment, - const CommandTargetT type, const std::string &icon); + TextCommand(const unsigned int id, + const std::string &symbol, + const std::string &command, + const std::string &comment, + const CommandTargetT type, + const std::string &icon); /** * Constructor. @@ -95,6 +100,7 @@ class TextCommand final std::string getIcon() const A_WARN_UNUSED { return mIcon; } +#ifdef TMWA_SUPPORT int getMana() const A_WARN_UNUSED { return mMana; } @@ -107,9 +113,25 @@ class TextCommand final unsigned getSchoolLvl() const A_WARN_UNUSED { return mSchoolLvl; } + void setMana(const unsigned int mana) + { mMana = mana; } + + void setSchool(const MagicSchoolT school) + { mSchool = school; } + + void setBaseLvl(const unsigned int baseLvl) + { mBaseLvl = baseLvl; } + + void setSchoolLvl(const unsigned int schoolLvl) + { mSchoolLvl = schoolLvl; } + TextCommandTypeT getCommandType() const A_WARN_UNUSED { return mCommandType; } + void setCommandType(const TextCommandTypeT commandType) + { mCommandType = commandType; } +#endif + void setCommand(const std::string &command) { mCommand = command; } @@ -128,21 +150,6 @@ class TextCommand final void setIcon(const std::string &icon) { mIcon = icon; loadImage(); } - void setMana(const unsigned int mana) - { mMana = mana; } - - void setSchool(const MagicSchoolT school) - { mSchool = school; } - - void setBaseLvl(const unsigned int baseLvl) - { mBaseLvl = baseLvl; } - - void setSchoolLvl(const unsigned int schoolLvl) - { mSchoolLvl = schoolLvl; } - - void setCommandType(const TextCommandTypeT commandType) - { mCommandType = commandType; } - bool isEmpty() const A_WARN_UNUSED { return mCommand.empty() && mSymbol.empty(); } @@ -159,11 +166,13 @@ class TextCommand final CommandTargetT mTargetType; std::string mIcon; unsigned int mId; +#ifdef TMWA_SUPPORT int mMana; MagicSchoolT mSchool; unsigned mBaseLvl; unsigned mSchoolLvl; TextCommandTypeT mCommandType; +#endif Image *mImage; }; |