summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedja Beader <fedja@protonmail.ch>2025-06-23 19:37:57 +0000
committerFedja Beader <fedja@protonmail.ch>2025-06-23 19:37:57 +0000
commitfa395cc75eab39ea31b0eef71796ffa720e7f5a0 (patch)
tree397ae274f5503b86432c4fabb213ff0990b04c86
parente6ebd7ad4f69f9d0464f47a0b5c81aed68a8c464 (diff)
downloadmanaplus-fa395cc75eab39ea31b0eef71796ffa720e7f5a0.tar.gz
manaplus-fa395cc75eab39ea31b0eef71796ffa720e7f5a0.tar.bz2
manaplus-fa395cc75eab39ea31b0eef71796ffa720e7f5a0.tar.xz
manaplus-fa395cc75eab39ea31b0eef71796ffa720e7f5a0.zip
Use an array of char arrays to store server type list model texts
This brings it inline with how other models are implemented, and also makes code so much clearer. **** mana/plus!193
-rw-r--r--src/gui/models/typelistmodel.h32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/gui/models/typelistmodel.h b/src/gui/models/typelistmodel.h
index d32db564b..78ad39bfa 100644
--- a/src/gui/models/typelistmodel.h
+++ b/src/gui/models/typelistmodel.h
@@ -33,6 +33,16 @@
#define SERVER_TYPE_INDEX_OFFSET 1
#endif // TMWA_SUPPORT
+// No translations here.
+const char *SERVER_TYPE_TEXT[] =
+{
+#ifdef TMWA_SUPPORT
+ "TMW Athena",
+#endif // defined(TMWA_SUPPORT)
+ "Hercules",
+ "Evol2 Hercules",
+};
+
/**
* Server Type List Model
*/
@@ -49,27 +59,19 @@ class TypeListModel final : public ListModel
* Used to get number of line in the list
*/
int getNumberOfElements() override final A_WARN_UNUSED
-#if defined(TMWA_SUPPORT)
- { return 3; }
-#else // defined(TMWA_SUPPORT)
- { return 2; }
-#endif // defined(TMWA_SUPPORT)
+ {
+ return NUM_ELEMENTS(SERVER_TYPE_TEXT);
+ }
/**
* Used to get an element from the list
*/
- std::string getElementAt(int elementIndex)
+ std::string getElementAt(int index)
override final A_WARN_UNUSED
{
- switch (elementIndex)
- {
-#ifdef TMWA_SUPPORT
- case 0: return "TMW Athena"; break;
-#endif // defined(TMWA_SUPPORT)
- case 1 - SERVER_TYPE_INDEX_OFFSET: return "Hercules"; break;
- case 2 - SERVER_TYPE_INDEX_OFFSET: return "Evol2 Hercules"; break;
- default: return "Unknown"; break;
- }
+ if (0 <= index && index < getNumberOfElements())
+ return SERVER_TYPE_TEXT[index];
+ return "Unknown";
}
};