summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2018-12-21 22:24:06 +0100
committerMarkus Mittendrein <git@maxmitti.tk>2018-12-21 22:24:06 +0100
commitc70d9fab0d9d745ffc4faf04a363b700573da62b (patch)
treeb990d1e8490ac0152a8315ff76df0fc7b159e10d
parent63ae14a44eda45ba50994d8ca7b89dd6ce15ad32 (diff)
downloadDTMenu.c4d-c70d9fab0d9d745ffc4faf04a363b700573da62b.tar.gz
DTMenu.c4d-c70d9fab0d9d745ffc4faf04a363b700573da62b.zip
Fix OnMenuSelection endless recursion when the top or bottom entry can't be selected
-rw-r--r--Script.c34
1 files changed, 29 insertions, 5 deletions
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;