summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2017-05-18 01:14:45 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2017-05-18 11:02:48 +0200
commitdd60176ff5a63222cac047b9a0236753d25dca89 (patch)
tree2a550f9afb057e73eed1cb8fed99f9973421a4f6
parent02b5cb01952f8a2941e3c7c3af3a6c4e968091c8 (diff)
downloadDTMenuDebug.c4d-dd60176ff5a63222cac047b9a0236753d25dca89.tar.gz
DTMenuDebug.c4d-dd60176ff5a63222cac047b9a0236753d25dca89.zip
Fix AdaptorEnumSubmenuFactory; Add Menu_Adaptor_EnumAllowUnknown and Menu_Adaptor_EnumInline
-rw-r--r--Script.c62
1 files changed, 47 insertions, 15 deletions
diff --git a/Script.c b/Script.c
index 86f7da6..9a7acf6 100644
--- a/Script.c
+++ b/Script.c
@@ -136,6 +136,8 @@ static const DT_Menu_Adaptor_Args = 11;
static const DT_Menu_Adaptor_EnumSubmenu = 12;
static const DT_Menu_Adaptor_EnumSubmenuCaption = 13;
static const DT_Menu_Adaptor_EnumSubmenuSymbol = 14;
+static const DT_Menu_Adaptor_EnumAllowUnknown = 15;
+static const DT_Menu_Adaptor_EnumInline = 16;
static const Menu_Layout_Symbol = 1;
static const Menu_Layout_InfoCaption = 2;
@@ -895,6 +897,8 @@ global func Menu_Adaptor_Callbacks(array Callbacks) { return [DT_Menu_Adaptor_Ca
global func Menu_Adaptor_MessageBoardText(string MessageBoardText) { return [DT_Menu_Adaptor_MessageBoardText, MessageBoardText]; }
global func Menu_Adaptor_WrapAround(bool WrapAround) { return [DT_Menu_Adaptor_WrapAround, WrapAround]; }
global func Menu_Adaptor_EnumSubmenuSymbol(id EnumSubmenuSymbol) { return [DT_Menu_Adaptor_EnumSubmenuSymbol, EnumSubmenuSymbol]; }
+global func Menu_Adaptor_EnumAllowUnknown(bool EnumAllowUnknown) { return [DT_Menu_Adaptor_EnumAllowUnknown, EnumAllowUnknown]; }
+global func Menu_Adaptor_EnumInline(bool EnumInline) { return [DT_Menu_Adaptor_EnumInline, EnumInline]; }
global func Menu_Adaptor_EnumSubmenu(int callbackType) { if(!((callbackType & ~Menu_CallbackType_All) == 0)) { FatalError("Assertion failed: Menu_Adaptor_EnumSubmenu: invalid callback type(s) used; assertion code: (callbackType & ~Menu_CallbackType_All) == 0"); }return [DT_Menu_Adaptor_EnumSubmenu, callbackType]; }
global func Menu_Adaptor_Limits(int min, int max) { if(!(min <= max)) { FatalError("Assertion failed: Menu_Adaptor_Limits: max cannot be smaller than min; assertion code: min <= max"); }return [DT_Menu_Adaptor_Limits, [min, max]]; }
global func Menu_Adaptor_StepSize(int step, force) { if(!(step > 0)) { FatalError("Assertion failed: negative or zero step doesn't make sense; assertion code: step > 0"); } if(!(force >= 0)) { FatalError("Assertion failed: negative force step doesn't make sense; assertion code: force >= 0"); }return [DT_Menu_Adaptor_StepSize, [step, force]]; }
@@ -1020,7 +1024,7 @@ global func Menu_Adaptor(array entrySettings, array adaptorSettings)
return Menu_Factory([MN7I->MenuObjectCallback("AdaptorFactory")], [Menu_Entry(entrySettings)[1], adaptorArgs, entrySettings]);
}
-func EnumValPos(array enumVals, array layout, val)
+func EnumValPos(array enumVals, array layout, val, bool allowUnknown)
{
for(var i = 0; i < GetLength(enumVals); ++i)
{
@@ -1029,7 +1033,10 @@ func EnumValPos(array enumVals, array layout, val)
return i;
}
}
- Log("WARNING: DT_Menu::EnumValPos: Current value %v is not in enum: %v", val, enumVals);
+ if(!allowUnknown)
+ {
+ Log("WARNING: DT_Menu::EnumValPos: Current value %v is not in enum: %v", val, enumVals);
+ }
return -1;
}
@@ -1151,15 +1158,23 @@ func AdaptorFactory(args, int entryIndex)
}
else if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_Enum)
{
+ if(args[DT_Menu_Adaptor_EnumInline])
+ {
+ return AdaptorEnumSubmenuFactory([args, entry]);
+ }
+
var layoutVals = args[DT_Menu_Adaptor_LayoutVals];
var layout = layoutVals[1];
layoutVals = layoutVals[0];
- var index = EnumValPos(layoutVals, layout, val);
+ var index = EnumValPos(layoutVals, layout, val, args[DT_Menu_Adaptor_EnumAllowUnknown]);
if(index == -1)
{
- ScopedVar(args[DT_Menu_Adaptor_Variable]) = layoutVals[0][layout[Menu_Layout__ValuePos] - 1];
+ if(!args[DT_Menu_Adaptor_EnumAllowUnknown])
+ {
+ ScopedVar(args[DT_Menu_Adaptor_Variable]) = layoutVals[0][layout[Menu_Layout__ValuePos] - 1];
+ }
index = 0;
}
@@ -1200,21 +1215,29 @@ func AdaptorEnumSubmenuFactory(array args)
var submenuCaption = args[DT_Menu_Adaptor_EnumSubmenuCaption];
var submenuSymbol = [];
- var index = EnumValPos(layoutVals, layout, ScopedVar(args[DT_Menu_Adaptor_Variable]));
+ if(submenuCaption && submenuCaption[0])
+ {
+ entry[DT_Menu_Entry_Caption] = submenuCaption[0];
+ }
+
+ var index = EnumValPos(layoutVals, layout, ScopedVar(args[DT_Menu_Adaptor_Variable]), args[DT_Menu_Adaptor_EnumAllowUnknown]);
var symbol, infoCaption;
EnumEntrySettings(submenuCaption, symbol, infoCaption, index, args, entry);
- if(submenuCaption && submenuCaption[0])
+ var ret;
+ if(args[DT_Menu_Adaptor_EnumInline])
{
- submenuCaption = submenuCaption[0];
+ ret = [];
+ }
+ else
+ {
+ ret = [
+ Menu_Selection(index),
+ Menu_KeepParentOnClose(),
+ Menu_DontKeepOpen(),
+ Menu_Caption(submenuCaption)
+ ];
}
-
- var ret = [
- Menu_Selection(index),
- Menu_KeepParentOnClose(),
- Menu_DontKeepOpen(),
- Menu_Caption(submenuCaption)
- ];
if(args[DT_Menu_Adaptor_EnumSubmenuSymbol])
{
@@ -1242,6 +1265,10 @@ func AdaptorEnumSubmenuFactory(array args)
{
symbol = 0;
EnumEntrySettings(caption, symbol, infoCaption, i, args, entry);
+ if(args[DT_Menu_Adaptor_EnumInline])
+ {
+ BooleanToggleCaption(i == index, caption, symbol);
+ }
ArrayAppend(ret, Menu_Entry([Menu_Entry_Caption(caption), Menu_Entry_Symbol(symbol), Menu_Entry_InfoCaption(infoCaption), Menu_Entry_Callbacks([Menu_Callback(MenuObjectCallback("AdaptorEnumSubmenuItem"), Menu_CallbackType_Defaults, [Menu_CallbackArg_Args, Menu_CallbackArg_All])]), Menu_Entry_Args([i, args])]));
}
@@ -1271,6 +1298,11 @@ func AdaptorEnumSubmenuItem(args, array allArgs)
return reaction;
}
+ if(args[DT_Menu_Adaptor_EnumInline])
+ {
+ return Menu_React_Refresh;
+ }
+
return Menu_React_Back;
}
@@ -1499,7 +1531,7 @@ func AdaptorCommand(int action, object obj, args, array allArgs)
var layout = enumVals[1];
enumVals = enumVals[0];
- var index = EnumValPos(enumVals, layout, val);
+ var index = EnumValPos(enumVals, layout, val, args[DT_Menu_Adaptor_EnumAllowUnknown]);
var wrapAround = args[DT_Menu_Adaptor_WrapAround];
if(action & (Menu_CallbackType_Normal | Menu_CallbackType_Special2))