From cb2f6ce0928f013087ef130ad9f7abcb19e15d8a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 30 Sep 2007 12:35:37 +0000 Subject: Fixed action lists to sort correctly for non-English languages svn-id: r29144 --- engines/lure/menu.cpp | 35 ++++++++++++++++++++++++----------- engines/lure/res_struct.cpp | 4 ---- engines/lure/res_struct.h | 2 -- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/engines/lure/menu.cpp b/engines/lure/menu.cpp index 1a03118476..77705d22d4 100644 --- a/engines/lure/menu.cpp +++ b/engines/lure/menu.cpp @@ -381,12 +381,18 @@ uint16 PopupMenu::ShowItems(Action contextAction, uint16 roomNumber) { return result; } +static int entryCompare(const char **p1, const char **p2) { + return strcmp(*p1, *p2); +} + +typedef int (*CompareMethod)(const void*, const void*); + Action PopupMenu::Show(uint32 actionMask) { StringList &stringList = Resources::getReference().stringList(); int numEntries = 0; uint32 v = actionMask; int index; - const Action *currentAction; + int currentAction; uint16 resultIndex; Action resultAction; @@ -395,26 +401,33 @@ Action PopupMenu::Show(uint32 actionMask) { } const char **strList = (const char **) Memory::alloc(sizeof(char *) * numEntries); - Action *actionSet = (Action *) Memory::alloc(sizeof(Action) * numEntries); int strIndex = 0; - for (currentAction = &sortedActions[0]; *currentAction != NONE; ++currentAction) { - if ((actionMask & (1 << (*currentAction - 1))) != 0) { - strList[strIndex] = stringList.getString(*currentAction); - actionSet[strIndex] = *currentAction; + for (currentAction = 0; currentAction < (int)EXAMINE; ++currentAction) { + if ((actionMask & (1 << currentAction)) != 0) { + strList[strIndex] = stringList.getString(currentAction); ++strIndex; } } + // Sort the list + qsort(strList, numEntries, sizeof(const char *), (CompareMethod) entryCompare); + + // Show the entries resultIndex = Show(numEntries, strList); - if (resultIndex == 0xffff) - resultAction = NONE; - else - resultAction = actionSet[resultIndex]; + resultAction = NONE; + if (resultIndex != 0xffff) { + // Scan through the list of actions to find the selected entry + for (currentAction = 0; currentAction < (int)EXAMINE; ++currentAction) { + if (strList[resultIndex] == stringList.getString(currentAction)) { + resultAction = (Action) (currentAction + 1); + break; + } + } + } Memory::dealloc(strList); - Memory::dealloc(actionSet); return resultAction; } diff --git a/engines/lure/res_struct.cpp b/engines/lure/res_struct.cpp index 5eb7cb2aa0..eace23798e 100644 --- a/engines/lure/res_struct.cpp +++ b/engines/lure/res_struct.cpp @@ -30,10 +30,6 @@ namespace Lure { -extern const Action sortedActions[] = {ASK, BRIBE, BUY, CLOSE, DRINK, EXAMINE, GET, GIVE, - GO_TO, LOCK, LOOK, LOOK_AT, LOOK_THROUGH, OPEN, OPERATE, PULL, PUSH, RETURN, - STATUS, TALK_TO, TELL, UNLOCK, USE, NONE}; - extern const int actionNumParams[NPC_JUMP_ADDRESS+1] = {0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 0, 1, 0, 1, 1, 1, 1, 0, 0, 2, 1, 1, 0, 0, 1, 1, 2, 2, 5, 2, 2, 1}; diff --git a/engines/lure/res_struct.h b/engines/lure/res_struct.h index 0f73bd019d..9fa0dad982 100644 --- a/engines/lure/res_struct.h +++ b/engines/lure/res_struct.h @@ -34,8 +34,6 @@ namespace Lure { using namespace Common; -extern const Action sortedActions[]; - /*-------------------------------------------------------------------------*/ /* Structure definitions */ /* */ -- cgit v1.2.3