From aa8612e35d2e3dad533aa574a182e16c7e44431f Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Fri, 21 Dec 2018 22:23:59 +0100 Subject: Fix OnMenuSelection endless recursion when the top or bottom entry can't be selected --- Script.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'Script.c') diff --git a/Script.c b/Script.c index 46f289b..db790a4 100644 --- a/Script.c +++ b/Script.c @@ -340,6 +340,28 @@ func SelectEntry(indexOrChain, int column) } } +func SelectTopEntry(int column) +{ + for(var i = 0; i < GetLength(columnEntries[column]); ++i) + { + if(columnEntries[column][i][DT_Menu_Entry_Placeholder]) + { + return SelectEntry(i, column); + } + } +} + +func SelectBottomEntry(int column) +{ + for(var i = GetLength(columnEntries[column]) - 1; i >= 0; --i) + { + if(columnEntries[column][i][DT_Menu_Entry_Placeholder]) + { + return SelectEntry(i, column); + } + } +} + func ActivateEntry(int action, indexOrChain, int column) { SelectEntry(indexOrChain); @@ -733,6 +755,8 @@ func AddEntries() entry[DT_Menu_Entry_Extra] |= C4MN_Add_ForceNoDesc; } + entry[DT_Menu_Entry_Placeholder] = !noCommand; + columnEntries[j][rowIndex] = entry; var showDesc = !(entry[DT_Menu_Entry_Extra] & C4MN_Add_ForceNoDesc); @@ -938,12 +962,12 @@ func OnMenuSelection(int selection, object menuObject) if(oldColumnSelection == 0) { // wrap around if the last selection was the top already - SelectEntry(GetLength(columnEntries[column]) - 1, column); + SelectBottomEntry(column); } else { // otherwise maybe wrapped around from the bottom or just hovered it with the mouse - SelectEntry(0, column); + SelectTopEntry(column); } return; } @@ -957,18 +981,18 @@ func OnMenuSelection(int selection, object menuObject) if(oldColumnSelection == GetLength(columnEntries[column]) - 1) { // wrap around if the last selection was the bottom already - SelectEntry(0, column); + SelectTopEntry(column); } else { // otherwise maybe wrapped around from the top or just hovered it with the mouse - SelectEntry(GetLength(columnEntries[column]) - 1, column); + SelectBottomEntry(column); } return; } else if(multiColumnMode) { - SelectEntry(GetLength(columnEntries[column]) - 1, column); + SelectBottomEntry(column); return; } skipHandling = true; -- cgit v1.2.3-54-g00ecf