diff options
author | Markus Mittendrein <git@maxmitti.tk> | 2018-12-21 22:23:59 +0100 |
---|---|---|
committer | Markus Mittendrein <git@maxmitti.tk> | 2018-12-21 22:23:59 +0100 |
commit | aa8612e35d2e3dad533aa574a182e16c7e44431f (patch) | |
tree | daae97a328f28e4c396fc0ebb40c6d90e033def4 | |
parent | 39d81696dd8b0d8fd861ee4dffcff44e6e79b55e (diff) | |
download | DTMenuDebug.c4d-aa8612e35d2e3dad533aa574a182e16c7e44431f.tar.gz DTMenuDebug.c4d-aa8612e35d2e3dad533aa574a182e16c7e44431f.zip |
Fix OnMenuSelection endless recursion when the top or bottom entry can't be selected
-rw-r--r-- | Script.c | 34 |
1 files changed, 29 insertions, 5 deletions
@@ -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; |