diff options
Diffstat (limited to 'src/gui/models')
36 files changed, 2685 insertions, 0 deletions
diff --git a/src/gui/models/avatarlistmodel.h b/src/gui/models/avatarlistmodel.h new file mode 100644 index 000000000..2bbd64878 --- /dev/null +++ b/src/gui/models/avatarlistmodel.h @@ -0,0 +1,40 @@ +/* + * The ManaPlus Client + * Copyright (C) 2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_AVATARLISTMODEL_H +#define GUI_MODELS_AVATARLISTMODEL_H + +#include "avatar.h" + +#include "gui/models/listmodel.h" + +#include <string> + +class AvatarListModel : public ListModel +{ + public: + virtual Avatar *getAvatarAt(const int i) A_WARN_UNUSED = 0; + + std::string getElementAt(int i) override final A_WARN_UNUSED + { return getAvatarAt(i)->getName(); } +}; + +#endif // GUI_MODELS_AVATARLISTMODEL_H diff --git a/src/gui/models/beingslistmodel.h b/src/gui/models/beingslistmodel.h new file mode 100644 index 000000000..9f3c48bcc --- /dev/null +++ b/src/gui/models/beingslistmodel.h @@ -0,0 +1,62 @@ +/* + * The ManaPlus Client + * Copyright (C) 2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_BEINGSLISTMODEL_H +#define GUI_MODELS_BEINGSLISTMODEL_H + +#include "gui/models/avatarlistmodel.h" + +class BeingsListModel final : public AvatarListModel +{ + public: + BeingsListModel() : + AvatarListModel(), + mMembers() + { + } + + A_DELETE_COPY(BeingsListModel) + + ~BeingsListModel() + { + delete_all(mMembers); + mMembers.clear(); + } + + std::vector<Avatar*> *getMembers() + { + return &mMembers; + } + + Avatar *getAvatarAt(int index) override final + { + return mMembers[index]; + } + + int getNumberOfElements() override final + { + return static_cast<int>(mMembers.size()); + } + + std::vector<Avatar*> mMembers; +}; + +#endif // GUI_MODELS_BEINGSLISTMODEL_H diff --git a/src/gui/models/colorlistmodel.h b/src/gui/models/colorlistmodel.h new file mode 100644 index 000000000..d4b2e4237 --- /dev/null +++ b/src/gui/models/colorlistmodel.h @@ -0,0 +1,81 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_COLORLISTMODEL_H +#define GUI_MODELS_COLORLISTMODEL_H + +#include "gui/models/listmodel.h" + +#include "utils/gettext.h" + +const char *COLOR_NAME[14] = +{ + // TRANSLATORS: chat color + N_("default"), + // TRANSLATORS: chat color + N_("black"), + // TRANSLATORS: chat color + N_("red"), + // TRANSLATORS: chat color + N_("green"), + // TRANSLATORS: chat color + N_("blue"), + // TRANSLATORS: chat color + N_("gold"), + // TRANSLATORS: chat color + N_("yellow"), + // TRANSLATORS: chat color + N_("pink"), + // TRANSLATORS: chat color + N_("purple"), + // TRANSLATORS: chat color + N_("grey"), + // TRANSLATORS: chat color + N_("brown"), + // TRANSLATORS: chat color + N_("rainbow 1"), + // TRANSLATORS: chat color + N_("rainbow 2"), + // TRANSLATORS: chat color + N_("rainbow 3"), +}; + +class ColorListModel final : public ListModel +{ + public: + ~ColorListModel() + { } + + int getNumberOfElements() + { + return 14; + } + + std::string getElementAt(int i) + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + return gettext(COLOR_NAME[i]); + } +}; + +#endif // GUI_MODELS_COLORLISTMODEL_H diff --git a/src/gui/models/colormodel.cpp b/src/gui/models/colormodel.cpp new file mode 100644 index 000000000..47486d735 --- /dev/null +++ b/src/gui/models/colormodel.cpp @@ -0,0 +1,94 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/models/colormodel.h" + +#include "gui/widgets/widget2.h" + +#include "utils/gettext.h" + +#include "debug.h" + +ColorModel::ColorModel() : + mNames(), + mColors() +{ +} + +ColorModel::~ColorModel() +{ +} + +int ColorModel::getNumberOfElements() +{ + return static_cast<int>(mNames.size()); +} + +std::string ColorModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return "???"; + return mNames[i]; +} + +const ColorPair *ColorModel::getColorAt(const int i) const +{ + if (i >= static_cast<int>(mColors.size()) || i < 0) + return nullptr; + + return &mColors[i]; +} + +void ColorModel::add(const std::string &name, const Color *const color1, + const Color *const color2) +{ + mNames.push_back(name); + mColors.push_back(ColorPair(color1, color2)); +} + +#define addColor(name, color) \ + model->add(name, &widget->getThemeColor(Theme::color), \ + &widget->getThemeColor(Theme::color##_OUTLINE)); + +ColorModel *ColorModel::createDefault(const Widget2 *const widget) +{ + ColorModel *const model = new ColorModel(); + // TRANSLATORS: color name + addColor(_("black"), BLACK); + // TRANSLATORS: color name + addColor(_("red"), RED); + // TRANSLATORS: color name + addColor(_("green"), GREEN); + // TRANSLATORS: color name + addColor(_("blue"), BLUE); + // TRANSLATORS: color name + addColor(_("gold"), ORANGE); + // TRANSLATORS: color name + addColor(_("yellow"), YELLOW); + // TRANSLATORS: color name + addColor(_("pink"), PINK); + // TRANSLATORS: color name + addColor(_("purple"), PURPLE); + // TRANSLATORS: color name + addColor(_("grey"), GRAY); + // TRANSLATORS: color name + addColor(_("brown"), BROWN); + return model; +} diff --git a/src/gui/models/colormodel.h b/src/gui/models/colormodel.h new file mode 100644 index 000000000..f3d6f3617 --- /dev/null +++ b/src/gui/models/colormodel.h @@ -0,0 +1,76 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_COLORMODEL_H +#define GUI_MODELS_COLORMODEL_H + +#include "utils/stringvector.h" + +#include "gui/models/listmodel.h" + +#include "localconsts.h" + +class Color; +class Widget2; + +struct ColorPair +{ + ColorPair(const Color* c1, const Color* c2) : + color1(c1), + color2(c2) + { + } + + const Color* color1; + const Color* color2; +}; + +class ColorModel : public ListModel +{ + public: + ColorModel(); + + A_DELETE_COPY(ColorModel) + + virtual ~ColorModel(); + + virtual int getNumberOfElements() override final A_WARN_UNUSED; + + virtual std::string getElementAt(int i) override final A_WARN_UNUSED; + + virtual const ColorPair *getColorAt(const int i) const A_WARN_UNUSED; + + StringVect &getNames() A_WARN_UNUSED + { return mNames; } + + size_t size() A_WARN_UNUSED + { return mNames.size(); } + + void add(const std::string &name, const Color *const color1, + const Color *const color2); + + static ColorModel *createDefault(const Widget2 *const widget); + + protected: + StringVect mNames; + std::vector<ColorPair> mColors; +}; + +#endif // GUI_MODELS_COLORMODEL_H diff --git a/src/gui/models/extendedlistmodel.h b/src/gui/models/extendedlistmodel.h new file mode 100644 index 000000000..5d859e781 --- /dev/null +++ b/src/gui/models/extendedlistmodel.h @@ -0,0 +1,34 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_EXTENDEDLISTMODEL_H +#define GUI_MODELS_EXTENDEDLISTMODEL_H + +#include "resources/image.h" + +#include "gui/models/listmodel.h" + +class ExtendedListModel : public ListModel +{ + public: + virtual const Image *getImageAt(int i) A_WARN_UNUSED = 0; +}; + +#endif // GUI_MODELS_EXTENDEDLISTMODEL_H diff --git a/src/gui/models/extendednamesmodel.cpp b/src/gui/models/extendednamesmodel.cpp new file mode 100644 index 000000000..c986085db --- /dev/null +++ b/src/gui/models/extendednamesmodel.cpp @@ -0,0 +1,65 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/models/extendednamesmodel.h" + +#include "debug.h" + +ExtendedNamesModel::ExtendedNamesModel() : + mNames(), + mImages() +{ +} + +ExtendedNamesModel::~ExtendedNamesModel() +{ + clear(); +} + +int ExtendedNamesModel::getNumberOfElements() +{ + return static_cast<int>(mNames.size()); +} + +std::string ExtendedNamesModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return "???"; + return mNames[i]; +} + +const Image *ExtendedNamesModel::getImageAt(int i) +{ + if (i >= static_cast<int>(mImages.size()) || i < 0) + return nullptr; + + return mImages[i]; +} + +void ExtendedNamesModel::clear() +{ + mNames.clear(); + FOR_EACH (std::vector<Image*>::iterator, it, mImages) + { + if (*it) + (*it)->decRef(); + } + mImages.clear(); +} diff --git a/src/gui/models/extendednamesmodel.h b/src/gui/models/extendednamesmodel.h new file mode 100644 index 000000000..383a93951 --- /dev/null +++ b/src/gui/models/extendednamesmodel.h @@ -0,0 +1,59 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_EXTENDEDNAMESMODEL_H +#define GUI_MODELS_EXTENDEDNAMESMODEL_H + +#include "utils/stringvector.h" + +#include "gui/models/extendedlistmodel.h" + +class ExtendedNamesModel : public ExtendedListModel +{ + public: + ExtendedNamesModel(); + + A_DELETE_COPY(ExtendedNamesModel) + + virtual ~ExtendedNamesModel(); + + virtual int getNumberOfElements() override final A_WARN_UNUSED; + + virtual std::string getElementAt(int i) override final A_WARN_UNUSED; + + virtual const Image *getImageAt(int i) override final A_WARN_UNUSED; + + StringVect &getNames() A_WARN_UNUSED + { return mNames; } + + std::vector<Image*> &getImages() A_WARN_UNUSED + { return mImages; } + + size_t size() A_WARN_UNUSED + { return mNames.size(); } + + void clear(); + + protected: + StringVect mNames; + std::vector<Image*> mImages; +}; + +#endif // GUI_MODELS_EXTENDEDNAMESMODEL_H diff --git a/src/gui/models/fontsmodel.h b/src/gui/models/fontsmodel.h new file mode 100644 index 000000000..036e3f9c4 --- /dev/null +++ b/src/gui/models/fontsmodel.h @@ -0,0 +1,42 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_FONTSMODEL_H +#define GUI_MODELS_FONTSMODEL_H + +#include "gui/theme.h" + +#include "gui/models/namesmodel.h" + +#include "localconsts.h" + +class FontsModel final : public NamesModel +{ + public: + FontsModel() : + NamesModel() + { Theme::fillFontsList(mNames); } + + ~FontsModel() + { } +}; + +#endif // GUI_MODELS_FONTSMODEL_H diff --git a/src/gui/models/iconsmodel.h b/src/gui/models/iconsmodel.h new file mode 100644 index 000000000..c3031169c --- /dev/null +++ b/src/gui/models/iconsmodel.h @@ -0,0 +1,84 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_ICONSMODEL_H +#define GUI_MODELS_ICONSMODEL_H + +#include "gui/models/listmodel.h" + +#include "resources/iteminfo.h" + +#include "resources/db/itemdb.h" + +#include "localconsts.h" + +class IconsModel final : public ListModel +{ + public: + IconsModel() : + mStrings() + { + const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos(); + std::list<std::string> tempStrings; + + for (std::map<int, ItemInfo*>::const_iterator + i = items.begin(), i_end = items.end(); + i != i_end; ++i) + { + if (i->first < 0) + continue; + + const ItemInfo &info = (*i->second); + const std::string name = info.getName(); + if (name != "unnamed" && !info.getName().empty() + && info.getName() != "unnamed") + { + tempStrings.push_back(name); + } + } + tempStrings.sort(); + mStrings.push_back(""); + FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings) + mStrings.push_back(*i); + } + + A_DELETE_COPY(IconsModel) + + ~IconsModel() + { } + + int getNumberOfElements() override final + { + return static_cast<int>(mStrings.size()); + } + + std::string getElementAt(int i) override final + { + if (i < 0 || i >= getNumberOfElements()) + return "???"; + return mStrings.at(i); + } + private: + StringVect mStrings; +}; + +#endif // GUI_MODELS_ICONSMODEL_H diff --git a/src/gui/models/ignorechoiceslistmodel.h b/src/gui/models/ignorechoiceslistmodel.h new file mode 100644 index 000000000..8ba3eadb1 --- /dev/null +++ b/src/gui/models/ignorechoiceslistmodel.h @@ -0,0 +1,55 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_IGNORECHOICESLISTMODEL_H +#define GUI_MODELS_IGNORECHOICESLISTMODEL_H + +#include "being/playerrelations.h" + +#include "gui/models/playerrelationlistmodel.h" + +/** + * Class for choosing one of the various `what to do when ignoring a player' options + */ +class IgnoreChoicesListModel final : public ListModel +{ + public: + ~IgnoreChoicesListModel() + { } + + int getNumberOfElements() override final + { + return static_cast<int>(player_relations. + getPlayerIgnoreStrategies()->size()); + } + + std::string getElementAt(int i) override final + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + + return (*player_relations.getPlayerIgnoreStrategies()) + [i]->mDescription; + } +}; + +#endif // GUI_MODELS_IGNORECHOICESLISTMODEL_H diff --git a/src/gui/models/itemsmodel.h b/src/gui/models/itemsmodel.h new file mode 100644 index 000000000..808ae0f04 --- /dev/null +++ b/src/gui/models/itemsmodel.h @@ -0,0 +1,86 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_ITEMSMODEL_H +#define GUI_MODELS_ITEMSMODEL_H + +#include "gui/models/listmodel.h" + +#include "resources/iteminfo.h" + +#include "resources/db/itemdb.h" + +#include "utils/gettext.h" + +#include "localconsts.h" + +class ItemsModal final : public ListModel +{ + public: + ItemsModal() : + mStrings() + { + const std::map<int, ItemInfo*> &items = ItemDB::getItemInfos(); + std::list<std::string> tempStrings; + + for (std::map<int, ItemInfo*>::const_iterator + i = items.begin(), i_end = items.end(); + i != i_end; ++i) + { + if (i->first < 0) + continue; + + const ItemInfo &info = *i->second; + const std::string name = info.getName(); + if (name != "unnamed" && !info.getName().empty() + && info.getName() != "unnamed") + { + tempStrings.push_back(name); + } + } + tempStrings.sort(); + FOR_EACH (std::list<std::string>::const_iterator, i, tempStrings) + mStrings.push_back(*i); + } + + A_DELETE_COPY(ItemsModal) + + ~ItemsModal() + { } + + int getNumberOfElements() override final + { + return static_cast<int>(mStrings.size()); + } + + std::string getElementAt(int i) override final + { + if (i < 0 || i >= getNumberOfElements()) + return "???"; + return mStrings.at(i); + } + + private: + StringVect mStrings; +}; + +#endif // GUI_MODELS_ITEMSMODEL_H diff --git a/src/gui/models/listmodel.h b/src/gui/models/listmodel.h new file mode 100644 index 000000000..dfce6d4d5 --- /dev/null +++ b/src/gui/models/listmodel.h @@ -0,0 +1,103 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * + * + * Per Larsson a.k.a finalman + * Olof Naessén a.k.a jansem/yakslem + * + * Visit: http://guichan.sourceforge.net + * + * License: (BSD) + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of Guichan nor the names of its contributors may + * be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef GUI_MODELS_LISTMODEL_H +#define GUI_MODELS_LISTMODEL_H + +#include <string> + +#include "localconsts.h" + +/** + * An interface for a model that represents a list. It is + * used in certain widgets, like the ListBox, to handle a + * lists with string elements. If you want to use widgets + * like ListBox, make a derived class from this class that + * represents your list. + */ +class ListModel +{ + public: + /** + * Destructor. + */ + virtual ~ListModel() + { } + + /** + * Gets the number of elements in the list. + * + * @return The number of elements in the list + */ + virtual int getNumberOfElements() A_WARN_UNUSED = 0; + + /** + * Gets an element at a certain index in the list. + * + * @param i An index in the list. + * @return An element as a string at the a certain index. + */ + virtual std::string getElementAt(int i) A_WARN_UNUSED = 0; +}; + +#endif // GUI_MODELS_LISTMODEL_H diff --git a/src/gui/models/magicschoolmodel.h b/src/gui/models/magicschoolmodel.h new file mode 100644 index 000000000..1f7c4f0f7 --- /dev/null +++ b/src/gui/models/magicschoolmodel.h @@ -0,0 +1,67 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_MAGICSCHOOLMODEL_H +#define GUI_MODELS_MAGICSCHOOLMODEL_H + +#include "gui/models/listmodel.h" + +#include "utils/gettext.h" + +#include "localconsts.h" + +const char *MAGIC_SCHOOL_TEXT[6] = +{ + // TRANSLATORS: magic school + N_("General Magic"), + // TRANSLATORS: magic school + N_("Life Magic"), + // TRANSLATORS: magic school + N_("War Magic"), + // TRANSLATORS: magic school + N_("Transmute Magic"), + // TRANSLATORS: magic school + N_("Nature Magic"), + // TRANSLATORS: magic school + N_("Astral Magic") +}; + +class MagicSchoolModel final : public ListModel +{ + public: + ~MagicSchoolModel() + { } + + int getNumberOfElements() override final + { + return 6; + } + + std::string getElementAt(int i) override final + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + return MAGIC_SCHOOL_TEXT[i]; + } +}; + +#endif // GUI_MODELS_MAGICSCHOOLMODEL_H diff --git a/src/gui/models/namesmodel.cpp b/src/gui/models/namesmodel.cpp new file mode 100644 index 000000000..54a10c2cf --- /dev/null +++ b/src/gui/models/namesmodel.cpp @@ -0,0 +1,52 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/models/namesmodel.h" + +#include "utils/gettext.h" + +#include "debug.h" + +NamesModel::NamesModel() : + mNames() +{ +} + +NamesModel::~NamesModel() +{ +} + +int NamesModel::getNumberOfElements() +{ + return static_cast<int>(mNames.size()); +} + +std::string NamesModel::getElementAt(int i) +{ + if (i >= getNumberOfElements() || i < 0) + return "???"; + return mNames[i]; +} + +void NamesModel::fillFromArray(const char *const *const arr, std::size_t sz) +{ + for (size_t f = 0; f < sz; f ++) + mNames.push_back(gettext(arr[f])); +} diff --git a/src/gui/models/namesmodel.h b/src/gui/models/namesmodel.h new file mode 100644 index 000000000..96d16de36 --- /dev/null +++ b/src/gui/models/namesmodel.h @@ -0,0 +1,61 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_NAMESMODEL_H +#define GUI_MODELS_NAMESMODEL_H + +#include "utils/stringvector.h" + +#include "gui/models/listmodel.h" + +#include "localconsts.h" + +class NamesModel : public ListModel +{ + public: + NamesModel(); + + A_DELETE_COPY(NamesModel) + + virtual ~NamesModel(); + + virtual int getNumberOfElements() override final A_WARN_UNUSED; + + virtual std::string getElementAt(int i) override final A_WARN_UNUSED; + + StringVect &getNames() A_WARN_UNUSED + { return mNames; } + + size_t size() const A_WARN_UNUSED + { return mNames.size(); } + + void clear() + { mNames.clear(); } + + void add(const std::string &str) + { mNames.push_back(str); } + + void fillFromArray(const char *const *const arr, std::size_t size); + + protected: + StringVect mNames; +}; + +#endif // GUI_MODELS_NAMESMODEL_H diff --git a/src/gui/models/playerrelationlistmodel.h b/src/gui/models/playerrelationlistmodel.h new file mode 100644 index 000000000..bc343de02 --- /dev/null +++ b/src/gui/models/playerrelationlistmodel.h @@ -0,0 +1,67 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_PLAYERRELATIONLISTMODEL_H +#define GUI_MODELS_PLAYERRELATIONLISTMODEL_H + +#include "being/playerrelations.h" + +#include "utils/gettext.h" + +static const char *const RELATION_NAMES[PlayerRelation::RELATIONS_NR] = +{ + // TRANSLATORS: relation type + N_("Neutral"), + // TRANSLATORS: relation type + N_("Friend"), + // TRANSLATORS: relation type + N_("Disregarded"), + // TRANSLATORS: relation type + N_("Ignored"), + // TRANSLATORS: relation type + N_("Erased"), + // TRANSLATORS: relation type + N_("Blacklisted"), + // TRANSLATORS: relation type + N_("Enemy") +}; + +class PlayerRelationListModel final : public ListModel +{ + public: + ~PlayerRelationListModel() + { } + + int getNumberOfElements() override final + { + return PlayerRelation::RELATIONS_NR; + } + + std::string getElementAt(int i) override final + { + if (i >= getNumberOfElements() || i < 0) + return ""; + return gettext(RELATION_NAMES[i]); + } +}; + +#endif // GUI_MODELS_PLAYERRELATIONLISTMODEL_H diff --git a/src/gui/models/questsmodel.h b/src/gui/models/questsmodel.h new file mode 100644 index 000000000..d9421f402 --- /dev/null +++ b/src/gui/models/questsmodel.h @@ -0,0 +1,40 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_QUESTSMODEL_H +#define GUI_MODELS_QUESTSMODEL_H + +#include "gui/models/extendednamesmodel.h" + +class QuestsModel final : public ExtendedNamesModel +{ + public: + QuestsModel() : + ExtendedNamesModel() + { + } + + A_DELETE_COPY(QuestsModel) + + ~QuestsModel() + { } +}; + +#endif // GUI_MODELS_QUESTSMODEL_H diff --git a/src/gui/models/serverslistmodel.h b/src/gui/models/serverslistmodel.h new file mode 100644 index 000000000..630d9664e --- /dev/null +++ b/src/gui/models/serverslistmodel.h @@ -0,0 +1,109 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_SERVERSLISTMODEL_H +#define GUI_MODELS_SERVERSLISTMODEL_H + +#include "net/serverinfo.h" + +#include "utils/mutex.h" + +#include "gui/models/listmodel.h" + +#include "net/serverinfo.h" + +#include <string> +#include <vector> + +class ServerDialog; + +/** + * Server and Port List Model + */ +class ServersListModel final : public ListModel +{ + public: + typedef std::pair<int, std::string> VersionString; + + ServersListModel(ServerInfos *const servers, + ServerDialog *const parent) : + mServers(servers), + mVersionStrings(servers->size(), VersionString(0, "")), + mParent(parent) + { + } + + A_DELETE_COPY(ServersListModel) + + /** + * Used to get number of line in the list + */ + int getNumberOfElements() override final A_WARN_UNUSED + { + MutexLocker lock = mParent->lock(); + return static_cast<int>(mServers->size()); + } + + /** + * Used to get an element from the list + */ + std::string getElementAt(int elementIndex) + override final A_WARN_UNUSED + { + MutexLocker lock = mParent->lock(); + const ServerInfo &server = mServers->at(elementIndex); + std::string myServer; + myServer.append(server.hostname); + return myServer; + } + + /** + * Used to get the corresponding Server struct + */ + const ServerInfo &getServer(const int elementIndex) const A_WARN_UNUSED + { return mServers->at(elementIndex); } + + void setVersionString(const int index, const std::string &version) + { + if (index < 0 || index >= static_cast<int>(mVersionStrings.size())) + return; + + if (version.empty() || !gui) + { + mVersionStrings[index] = VersionString(0, ""); + } + else + { + mVersionStrings[index] = VersionString( + gui->getFont()->getWidth(version), version); + } + } + + private: + typedef std::vector<VersionString> VersionStrings; + + ServerInfos *mServers; + VersionStrings mVersionStrings; + ServerDialog *mParent; +}; + +#endif // GUI_MODELS_SERVERSLISTMODEL_H diff --git a/src/gui/models/shopitems.cpp b/src/gui/models/shopitems.cpp new file mode 100644 index 000000000..492409e76 --- /dev/null +++ b/src/gui/models/shopitems.cpp @@ -0,0 +1,132 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/models/shopitems.h" + +#include "shopitem.h" + +#include "utils/dtor.h" + +#include "debug.h" + +ShopItems::ShopItems(const bool mergeDuplicates) : + mShopItems(), + mMergeDuplicates(mergeDuplicates) +{ +} + +ShopItems::~ShopItems() +{ + clear(); +} + +std::string ShopItems::getElementAt(int i) +{ + if (i < 0 || static_cast<unsigned>(i) >= mShopItems.size() + || !mShopItems.at(i)) + { + return ""; + } + + return mShopItems.at(i)->getDisplayName(); +} + +void ShopItems::addItem(const int id, const unsigned char color, + const int amount, const int price) +{ + mShopItems.push_back(new ShopItem(-1, id, color, amount, price)); +} + +void ShopItems::addItemNoDup(const int id, const unsigned char color, + const int amount, const int price) +{ + const ShopItem *const item = findItem(id, color); + if (!item) + mShopItems.push_back(new ShopItem(-1, id, color, amount, price)); +} + +void ShopItems::addItem2(const int inventoryIndex, const int id, + const unsigned char color, + const int quantity, const int price) +{ + ShopItem *item = nullptr; + if (mMergeDuplicates) + item = findItem(id, color); + + if (item) + { + item->addDuplicate(inventoryIndex, quantity); + } + else + { + item = new ShopItem(inventoryIndex, id, color, quantity, price); + mShopItems.push_back(item); + } +} + +ShopItem *ShopItems::at(unsigned int i) const +{ + if (i >= mShopItems.size()) + return nullptr; + + return mShopItems.at(i); +} + +void ShopItems::erase(const unsigned int i) +{ + if (i >= mShopItems.size()) + return; + + mShopItems.erase(mShopItems.begin() + i); +} + +void ShopItems::del(const unsigned int i) +{ + if (i >= mShopItems.size()) + return; + + ShopItem *item = *(mShopItems.begin() + i); + mShopItems.erase(mShopItems.begin() + i); + delete item; +} + +void ShopItems::clear() +{ + delete_all(mShopItems); + mShopItems.clear(); +} + +ShopItem *ShopItems::findItem(const int id, const unsigned char color) const +{ + std::vector<ShopItem*>::const_iterator it = mShopItems.begin(); + const std::vector<ShopItem*>::const_iterator e = mShopItems.end(); + while (it != e) + { + ShopItem *const item = *it; + if (item->getId() == id && item->getColor() == color) + return item; + + ++it; + } + + return nullptr; +} diff --git a/src/gui/models/shopitems.h b/src/gui/models/shopitems.h new file mode 100644 index 000000000..925354960 --- /dev/null +++ b/src/gui/models/shopitems.h @@ -0,0 +1,141 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_SHOPITEMS_H +#define GUI_MODELS_SHOPITEMS_H + +#include "gui/models/listmodel.h" + +#include <string> +#include <vector> + +#include "localconsts.h" + +class ShopItem; + +/** + * This class handles the list of items available in a shop. + * + * The addItem routine can automatically check, if an item already exists and + * only adds duplicates to the old item, if one is found. The original + * distribution of the duplicates can be retrieved from the item. + * + * This functionality can be enabled in the constructor. + */ +class ShopItems final : public ListModel +{ + public: + /** + * Constructor. + * + * @param mergeDuplicates lets the Shop look for duplicate entries and + * merges them to one item. + */ + explicit ShopItems(const bool mergeDuplicates = false); + + A_DELETE_COPY(ShopItems) + + ~ShopItems(); + + /** + * Adds an item to the list. + */ + void addItem(const int id, const unsigned char color, + const int amount, const int price); + + /** + * Adds an item to the list (used by sell dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item + */ + void addItem2(const int inventoryIndex, const int id, + const unsigned char color, + const int amount, const int price); + + void addItemNoDup(const int id, const unsigned char color, + const int amount, const int price); + + /** + * Returns the number of items in the shop. + */ + int getNumberOfElements() override final A_WARN_UNUSED + { return static_cast<int>(mShopItems.size()); } + + bool empty() const A_WARN_UNUSED + { return mShopItems.empty(); } + + /** + * Returns the name of item number i in the shop. + * + * @param i the index to retrieve + */ + std::string getElementAt(int i) override final A_WARN_UNUSED; + + /** + * Returns the item number i in the shop. + */ + ShopItem *at(unsigned int i) const A_WARN_UNUSED; + + /** + * Removes an element from the shop. + * + * @param i index to remove + */ + void erase(const unsigned int i); + + /** + * Removes an element from the shop and destroy it. + * + * @param i index to remove + */ + void del(const unsigned int i); + + /** + * Clears the list of items in the shop. + */ + void clear(); + + std::vector<ShopItem*> &items() A_WARN_UNUSED + { return mShopItems; } + + private: + /** + * Searches the current items in the shop for the specified + * id and returns the item if found, or 0 else. + * + * @return the item found or 0 + */ + ShopItem *findItem(const int id, + const unsigned char color) const A_WARN_UNUSED; + + /** The list of items in the shop. */ + std::vector<ShopItem*> mShopItems; + + /** Look for duplicate entries on addition. */ + bool mMergeDuplicates; +}; + +#endif // GUI_MODELS_SHOPITEMS_H diff --git a/src/gui/models/skillmodel.cpp b/src/gui/models/skillmodel.cpp new file mode 100644 index 000000000..706bbdee2 --- /dev/null +++ b/src/gui/models/skillmodel.cpp @@ -0,0 +1,62 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/models/skillmodel.h" + +#include "gui/widgets/skilldata.h" + +#include <string> + +#include "debug.h" + +SkillModel::SkillModel() : + mSkills(), + mVisibleSkills() +{ +} + +SkillInfo *SkillModel::getSkillAt(const int i) const +{ + if (i < 0 || i >= static_cast<int>(mVisibleSkills.size())) + return nullptr; + return mVisibleSkills.at(i); +} + +std::string SkillModel::getElementAt(int i) +{ + const SkillInfo *const info = getSkillAt(i); + if (info) + return info->data->name; + else + return std::string(); +} + +void SkillModel::updateVisibilities() +{ + mVisibleSkills.clear(); + + FOR_EACH (SkillList::const_iterator, it, mSkills) + { + if ((*it) && (*it)->visible) + mVisibleSkills.push_back((*it)); + } +} diff --git a/src/gui/models/skillmodel.h b/src/gui/models/skillmodel.h new file mode 100644 index 000000000..11746118e --- /dev/null +++ b/src/gui/models/skillmodel.h @@ -0,0 +1,55 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_SKILLMODEL_H +#define GUI_MODELS_SKILLMODEL_H + +#include "gui/widgets/skillinfo.h" +#include "gui/models/listmodel.h" + +#include <string> + +#include "localconsts.h" + +class SkillModel final : public ListModel +{ + public: + SkillModel(); + + SkillInfo *getSkillAt(const int i) const; + + std::string getElementAt(int i) override final; + + int getNumberOfElements() override final + { return static_cast<int>(mVisibleSkills.size()); } + + void addSkill(SkillInfo *const info) + { mSkills.push_back(info); } + + void updateVisibilities(); + + private: + SkillList mSkills; + SkillList mVisibleSkills; +}; + +#endif // GUI_MODELS_SKILLMODEL_H diff --git a/src/gui/models/sortlistmodelbuy.h b/src/gui/models/sortlistmodelbuy.h new file mode 100644 index 000000000..1647ae822 --- /dev/null +++ b/src/gui/models/sortlistmodelbuy.h @@ -0,0 +1,65 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_SORTLISTMODELBUY_H +#define GUI_MODELS_SORTLISTMODELBUY_H + +#include "gui/models/listmodel.h" + +#include "utils/gettext.h" + +static const char *const SORT_NAME_BUY[7] = +{ + // TRANSLATORS: buy dialog sort type. + N_("unsorted"), + // TRANSLATORS: buy dialog sort type. + N_("by price"), + // TRANSLATORS: buy dialog sort type. + N_("by name"), + // TRANSLATORS: buy dialog sort type. + N_("by id"), + // TRANSLATORS: buy dialog sort type. + N_("by weight"), + // TRANSLATORS: buy dialog sort type. + N_("by amount"), + // TRANSLATORS: buy dialog sort type. + N_("by type") +}; + +class SortListModelBuy final : public ListModel +{ + public: + ~SortListModelBuy() + { } + + int getNumberOfElements() + { return 7; } + + std::string getElementAt(int i) + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + return gettext(SORT_NAME_BUY[i]); + } +}; + +#endif // GUI_MODELS_SORTLISTMODELBUY_H diff --git a/src/gui/models/sortlistmodelinv.h b/src/gui/models/sortlistmodelinv.h new file mode 100644 index 000000000..ae0982af6 --- /dev/null +++ b/src/gui/models/sortlistmodelinv.h @@ -0,0 +1,65 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_SORTLISTMODELINV_H +#define GUI_MODELS_SORTLISTMODELINV_H + +#include "gui/models/listmodel.h" + +#include "utils/gettext.h" + +#include <string> + +static const char *const SORT_NAME_INVENTORY[6] = +{ + // TRANSLATORS: inventory sort mode + N_("default"), + // TRANSLATORS: inventory sort mode + N_("by name"), + // TRANSLATORS: inventory sort mode + N_("by id"), + // TRANSLATORS: inventory sort mode + N_("by weight"), + // TRANSLATORS: inventory sort mode + N_("by amount"), + // TRANSLATORS: inventory sort mode + N_("by type") +}; + +class SortListModelInv final : public ListModel +{ + public: + ~SortListModelInv() + { } + + int getNumberOfElements() override final + { return 6; } + + std::string getElementAt(int i) override final + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + + return gettext(SORT_NAME_INVENTORY[i]); + } +}; + +#endif // GUI_MODELS_SORTLISTMODELINV_H diff --git a/src/gui/models/soundsmodel.h b/src/gui/models/soundsmodel.h new file mode 100644 index 000000000..3ac679d37 --- /dev/null +++ b/src/gui/models/soundsmodel.h @@ -0,0 +1,47 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_SOUNDSMODEL_H +#define GUI_MODELS_SOUNDSMODEL_H + +#include "gui/theme.h" + +#include "gui/models/namesmodel.h" + +#include "utils/gettext.h" + +#include "localconsts.h" + +class SoundsModel final : public NamesModel +{ + public: + SoundsModel() : + NamesModel() + { + mNames.push_back(gettext("(no sound)")); + Theme::fillSoundsList(mNames); + } + + ~SoundsModel() + { } +}; + +#endif // GUI_MODELS_SOUNDSMODEL_H diff --git a/src/gui/models/tablemodel.cpp b/src/gui/models/tablemodel.cpp new file mode 100644 index 000000000..aad66a6ad --- /dev/null +++ b/src/gui/models/tablemodel.cpp @@ -0,0 +1,180 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/models/tablemodel.h" + +#include "utils/dtor.h" + +#include "gui/widgets/widget.h" + +#include "debug.h" + +void TableModel::installListener(TableModelListener *const listener) +{ + if (listener) + listeners.insert(listener); +} + +void TableModel::removeListener(TableModelListener *const listener) +{ + if (listener) + listeners.erase(listener); +} + +void TableModel::signalBeforeUpdate() +{ + for (std::set<TableModelListener *>::const_iterator it = listeners.begin(); + it != listeners.end(); ++it) + { + (*it)->modelUpdated(false); + } +} + +void TableModel::signalAfterUpdate() +{ + for (std::set<TableModelListener *>::const_iterator it = listeners.begin(); + it != listeners.end(); ++it) + { + if (*it) + (*it)->modelUpdated(true); + } +} + + +#define WIDGET_AT(row, column) (((row) * mColumns) + (column)) +#define DYN_SIZE(h) ((h) >= 0) + +StaticTableModel::StaticTableModel(const int row, const int column) : + TableModel(), + mRows(row), + mColumns(column), + mHeight(1), + mTableModel(), + mWidths() +{ + mTableModel.resize(row * column, nullptr); + mWidths.resize(column, 1); +} + +StaticTableModel::~StaticTableModel() +{ + delete_all(mTableModel); + mTableModel.clear(); +} + +void StaticTableModel::resize() +{ + mRows = getRows(); + mColumns = getColumns(); + mTableModel.resize(mRows * mColumns, nullptr); +} + +void StaticTableModel::set(const int row, const int column, + Widget *const widget) +{ + if (!widget || row >= mRows || row < 0 + || column >= mColumns || column < 0) + { + // raise exn? + return; + } + + if (DYN_SIZE(mHeight) + && widget->getHeight() > mHeight) + { + mHeight = widget->getHeight(); + } + + if (DYN_SIZE(mWidths[column]) + && widget->getWidth() > mWidths[column]) + { + mWidths[column] = widget->getWidth(); + } + + signalBeforeUpdate(); + + delete mTableModel[WIDGET_AT(row, column)]; + + mTableModel[WIDGET_AT(row, column)] = widget; + + signalAfterUpdate(); +} + +Widget *StaticTableModel::getElementAt(const int row, + const int column) const +{ + return mTableModel[WIDGET_AT(row, column)]; +} + +void StaticTableModel::fixColumnWidth(const int column, const int width) +{ + if (width < 0 || column < 0 || column >= mColumns) + return; + + mWidths[column] = -width; // Negate to tag as fixed +} + +void StaticTableModel::fixRowHeight(const int height) +{ + if (height < 0) + return; + + mHeight = -height; +} + +int StaticTableModel::getRowHeight() const +{ + return abs(mHeight); +} + +int StaticTableModel::getColumnWidth(const int column) const +{ + if (column < 0 || column >= mColumns) + return 0; + + return abs(mWidths[column]); +} + +int StaticTableModel::getRows() const +{ + return mRows; +} + +int StaticTableModel::getColumns() const +{ + return mColumns; +} + +int StaticTableModel::getWidth() const +{ + int width = 0; + + for (size_t i = 0, sz = mWidths.size(); i < sz; i++) + width += mWidths[i]; + + return width; +} + +int StaticTableModel::getHeight() const +{ + return mColumns * mHeight; +} diff --git a/src/gui/models/tablemodel.h b/src/gui/models/tablemodel.h new file mode 100644 index 000000000..032facadd --- /dev/null +++ b/src/gui/models/tablemodel.h @@ -0,0 +1,163 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_TABLEMODEL_H +#define GUI_MODELS_TABLEMODEL_H + +#include <set> +#include <vector> + +#include "localconsts.h" + +class Widget; + +class TableModelListener +{ +public: + /** + * Must be invoked by the TableModel whenever a global change is about to + * occur or has occurred (e.g., when a row or column is being removed or + * added). + * + * This method is triggered twice, once before and once after the update. + * + * \param completed whether we are signalling the end of the update + */ + virtual void modelUpdated(const bool completed) = 0; + + virtual ~TableModelListener() + { } +}; + +/** + * A model for a regular table of widgets. + */ +class TableModel +{ +public: + virtual ~TableModel() + { } + + /** + * Determines the number of rows (lines) in the table + */ + virtual int getRows() const A_WARN_UNUSED = 0; + + /** + * Determines the number of columns in each row + */ + virtual int getColumns() const A_WARN_UNUSED = 0; + + /** + * Determines the height for each row + */ + virtual int getRowHeight() const A_WARN_UNUSED = 0; + + /** + * Determines the width of each individual column + */ + virtual int getColumnWidth(const int index) const A_WARN_UNUSED = 0; + + /** + * Retrieves the widget stored at the specified location within the table. + */ + virtual Widget *getElementAt(const int row, const int column) + const A_WARN_UNUSED = 0; + + virtual void installListener(TableModelListener *const listener); + + virtual void removeListener(TableModelListener *const listener); + +protected: + TableModel() : + listeners() + { + } + + /** + * Tells all listeners that the table is about to see an update + */ + virtual void signalBeforeUpdate(); + + /** + * Tells all listeners that the table has seen an update + */ + virtual void signalAfterUpdate(); + +private: + std::set<TableModelListener *> listeners; +}; + + +class StaticTableModel final : public TableModel +{ +public: + StaticTableModel(const int width, const int height); + + A_DELETE_COPY(StaticTableModel) + + ~StaticTableModel(); + + /** + * Inserts a widget into the table model. + * The model is resized to accomodate the widget's width and height, + * unless column width / row height have been fixed. + */ + void set(const int row, const int column, Widget *const widget); + + /** + * Fixes the column width for a given column; this overrides dynamic width + * inference. + * + * Semantics are undefined for width 0. + */ + void fixColumnWidth(const int column, const int width); + + /** + * Fixes the row height; this overrides dynamic height inference. + * + * Semantics are undefined for width 0. + */ + void fixRowHeight(const int height); + + /** + * Resizes the table model + */ + void resize(); + + int getRows() const override final A_WARN_UNUSED; + int getColumns() const override final A_WARN_UNUSED; + int getRowHeight() const override final A_WARN_UNUSED; + int getWidth() const A_WARN_UNUSED; + int getHeight() const A_WARN_UNUSED; + int getColumnWidth(const int index) const override final A_WARN_UNUSED; + Widget *getElementAt(const int row, + const int column) const override final A_WARN_UNUSED; + +protected: + int mRows, mColumns; + int mHeight; + std::vector<Widget *> mTableModel; + std::vector<int> mWidths; +}; + +#endif // GUI_MODELS_TABLEMODEL_H diff --git a/src/gui/models/targettypemodel.h b/src/gui/models/targettypemodel.h new file mode 100644 index 000000000..d049585a5 --- /dev/null +++ b/src/gui/models/targettypemodel.h @@ -0,0 +1,58 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_TARGETTYPEMODEL_H +#define GUI_MODELS_TARGETTYPEMODEL_H + +#include "gui/models/listmodel.h" + +#include "utils/gettext.h" + +const char *TARGET_TYPE_TEXT[3] = +{ + // TRANSLATORS: target type + N_("No Target"), + // TRANSLATORS: target type + N_("Allow Target"), + // TRANSLATORS: target type + N_("Need Target") +}; + +class TargetTypeModel final : public ListModel +{ + public: + ~TargetTypeModel() + { } + + int getNumberOfElements() override final + { + return 3; + } + + std::string getElementAt(int i) override final + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + return TARGET_TYPE_TEXT[i]; + } +}; + +#endif // GUI_MODELS_TARGETTYPEMODEL_H diff --git a/src/gui/models/themesmodel.h b/src/gui/models/themesmodel.h new file mode 100644 index 000000000..7f76534f0 --- /dev/null +++ b/src/gui/models/themesmodel.h @@ -0,0 +1,47 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 Andrei Karas + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_THEMESMODEL_H +#define GUI_MODELS_THEMESMODEL_H + +#include "gui/theme.h" + +#include "gui/models/namesmodel.h" + +#include "utils/gettext.h" + +#include "localconsts.h" + +class ThemesModel final : public NamesModel +{ + public: + ThemesModel() : + NamesModel() + { + mNames.push_back(gettext("(default)")); + Theme::fillSkinsList(mNames); + } + + ~ThemesModel() + { } +}; + +#endif // GUI_MODELS_THEMESMODEL_H diff --git a/src/gui/models/touchactionmodel.cpp b/src/gui/models/touchactionmodel.cpp new file mode 100644 index 000000000..b32d1479f --- /dev/null +++ b/src/gui/models/touchactionmodel.cpp @@ -0,0 +1,84 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "gui/setupactiondata.h" + +#include "gui/models/touchactionmodel.h" + +#include <algorithm> + +#include "debug.h" + +static class SortTouchActionFunctor final +{ + public: + bool operator() (const SetupActionData *const data1, + const SetupActionData *const data2) const + { + if (!data1 || !data2) + return false; + return data1->name < data2->name; + } +} touchActionSorter; + +TouchActionsModel::TouchActionsModel() : + NamesModel(), + mActionId(), + mActionToSelection() +{ + std::vector<SetupActionData*> data; + + for (int f = 0, sz = touchActionDataSize; f < sz; f ++) + { + int k = 0; + while (!touchActionData[f][k].name.empty()) + { + data.push_back(&touchActionData[f][k]); + k ++; + } + } + + std::sort(data.begin(), data.end(), touchActionSorter); + int cnt = 0; + FOR_EACH (std::vector<SetupActionData*>::iterator, it, data) + { + const SetupActionData *const data1 = *it; + mNames.push_back(data1->name); + mActionId.push_back(data1->actionId); + mActionToSelection[data1->actionId] = cnt; + cnt ++; + } +} + +int TouchActionsModel::getActionFromSelection(const int sel) const +{ + if (sel < 0 || sel > static_cast<signed int>(mActionId.size())) + return -1; + return mActionId[sel]; +} + +int TouchActionsModel::getSelectionFromAction(const int action) const +{ + const std::map<int, int>::const_iterator it + = mActionToSelection.find(action); + if (it == mActionToSelection.end()) + return 0; + return (*it).second; +} diff --git a/src/gui/models/touchactionmodel.h b/src/gui/models/touchactionmodel.h new file mode 100644 index 000000000..00abe89e2 --- /dev/null +++ b/src/gui/models/touchactionmodel.h @@ -0,0 +1,47 @@ +/* + * The ManaPlus Client + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_TOUCHACTIONMODEL_H +#define GUI_MODELS_TOUCHACTIONMODEL_H + +#include "gui/models/namesmodel.h" + +#include "gui/widgets/setupitem.h" + +class TouchActionsModel final : public NamesModel +{ + public: + TouchActionsModel(); + + A_DELETE_COPY(TouchActionsModel) + + ~TouchActionsModel() + { } + + int getActionFromSelection(const int sel) const; + + int getSelectionFromAction(const int action) const; + + private: + std::vector<int> mActionId; + std::map<int, int> mActionToSelection; +}; + +#endif // GUI_MODELS_TOUCHACTIONMODEL_H diff --git a/src/gui/models/typelistmodel.h b/src/gui/models/typelistmodel.h new file mode 100644 index 000000000..f9c005f8f --- /dev/null +++ b/src/gui/models/typelistmodel.h @@ -0,0 +1,65 @@ +/* + * The Mana Client + * Copyright (C) 2011-2012 The Mana Developers + * Copyright (C) 2012-2014 The ManaPlus Developers + * + * This file is part of The Mana Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_TYPELISTMODEL_H +#define GUI_MODELS_TYPELISTMODEL_H + +#include "gui/models/listmodel.h" + +/** + * Server Type List Model + */ +class TypeListModel : public ListModel +{ + public: + TypeListModel() + { } + + /** + * Used to get number of line in the list + */ + int getNumberOfElements() override final A_WARN_UNUSED +#ifdef EATHENA_SUPPORT + { return 3; } +#else + { return 2; } +#endif + + /** + * Used to get an element from the list + */ + std::string getElementAt(int elementIndex) + override final A_WARN_UNUSED + { + if (elementIndex == 0) + return "TmwAthena"; + else if (elementIndex == 1) + return "Evol"; +#ifdef EATHENA_SUPPORT + else if (elementIndex == 2) + return "eAthena"; +#endif + else + return "Unknown"; + } +}; + +#endif // GUI_MODELS_TYPELISTMODEL_H diff --git a/src/gui/models/updatelistmodel.h b/src/gui/models/updatelistmodel.h new file mode 100644 index 000000000..2e1d2a7d5 --- /dev/null +++ b/src/gui/models/updatelistmodel.h @@ -0,0 +1,66 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_UPDATELISTMODEL_H +#define GUI_MODELS_UPDATELISTMODEL_H + +#include "gui/models/listmodel.h" + +#include "net/logindata.h" + +#include "utils/gettext.h" + +#include "localconsts.h" + +class UpdateListModel final : public ListModel +{ + public: + explicit UpdateListModel(LoginData *const data) : + ListModel(), + mLoginData(data) + { + } + + A_DELETE_COPY(UpdateListModel) + + ~UpdateListModel() + { } + + int getNumberOfElements() override final + { + if (!mLoginData) + return 0; + return static_cast<int>(mLoginData->updateHosts.size()); + } + + std::string getElementAt(int i) override final + { + if (!mLoginData || i >= getNumberOfElements() || i < 0) + return "???"; + return mLoginData->updateHosts[i]; + } + + protected: + LoginData *mLoginData; +}; + +#endif // GUI_MODELS_UPDATELISTMODEL_H diff --git a/src/gui/models/updatetypemodel.h b/src/gui/models/updatetypemodel.h new file mode 100644 index 000000000..f96c11e87 --- /dev/null +++ b/src/gui/models/updatetypemodel.h @@ -0,0 +1,63 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_UPDATETYPEMODEL_H +#define GUI_MODELS_UPDATETYPEMODEL_H + +#include "utils/gettext.h" + +#include "gui/models/listmodel.h" + +const char *UPDATE_TYPE_TEXT[3] = +{ + // TRANSLATORS: update type + N_("Normal"), + // TRANSLATORS: update type + N_("Auto Close"), + // TRANSLATORS: update type + N_("Skip"), +}; + +class UpdateTypeModel final : public ListModel +{ + public: + UpdateTypeModel() + { } + + A_DELETE_COPY(UpdateTypeModel) + + ~UpdateTypeModel() + { } + + int getNumberOfElements() override final + { + return 3; + } + + std::string getElementAt(int i) override final + { + if (i >= getNumberOfElements() || i < 0) + return "???"; + return gettext(UPDATE_TYPE_TEXT[i]); + } +}; + +#endif // GUI_MODELS_UPDATETYPEMODEL_H diff --git a/src/gui/models/worldlistmodel.h b/src/gui/models/worldlistmodel.h new file mode 100644 index 000000000..7d9dc322c --- /dev/null +++ b/src/gui/models/worldlistmodel.h @@ -0,0 +1,68 @@ +/* + * The ManaPlus Client + * Copyright (C) 2004-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011-2014 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef GUI_MODELS_WORLDLISTMODEL_H +#define GUI_MODELS_WORLDLISTMODEL_H + +#include "gui/models/listmodel.h" + +#include "net/worldinfo.h" + +/** + * The list model for the server list. + */ +class WorldListModel final : public ListModel +{ + public: + explicit WorldListModel(Worlds worlds) : + mWorlds(worlds) + { + } + + A_DELETE_COPY(WorldListModel) + + ~WorldListModel() + { } + + int getNumberOfElements() override final + { + return static_cast<int>(mWorlds.size()); + } + + std::string getElementAt(int i) override final + { + const WorldInfo *const si = mWorlds[i]; + if (si) + { + return std::string(si->name).append(" (").append( + toString(si->online_users)).append(")"); + } + else + { + return "???"; + } + } + private: + Worlds mWorlds; +}; + +#endif // GUI_MODELS_WORLDLISTMODEL_H |