From c70d9fab0d9d745ffc4faf04a363b700573da62b Mon Sep 17 00:00:00 2001 From: Markus Mittendrein Date: Fri, 21 Dec 2018 22:24:06 +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 534cdf1..1ed8ab6 100644 --- a/Script.c +++ b/Script.c @@ -322,6 +322,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); @@ -701,6 +723,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); @@ -906,12 +930,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; } @@ -925,18 +949,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