summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2017-05-23 13:14:51 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2017-05-23 13:14:51 +0200
commitd239b218d8854393e182a40c9fc342f2451fbc27 (patch)
treead4ccae23d3d8577d09a549a83614030115b01e4
parentdd60176ff5a63222cac047b9a0236753d25dca89 (diff)
downloadDTMenuDebug.c4d-d239b218d8854393e182a40c9fc342f2451fbc27.tar.gz
DTMenuDebug.c4d-d239b218d8854393e182a40c9fc342f2451fbc27.zip
Add possibilty to use callbacks for Menu_Adaptor_Limits
-rw-r--r--Script.c48
1 files changed, 44 insertions, 4 deletions
diff --git a/Script.c b/Script.c
index 9a7acf6..a8630f1 100644
--- a/Script.c
+++ b/Script.c
@@ -900,7 +900,27 @@ global func Menu_Adaptor_EnumSubmenuSymbol(id EnumSubmenuSymbol) { return [DT_Me
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_Limits(min, max, args)
+{
+ if((!min || GetType(min) == C4V_Int) && (!max || GetType(max) == C4V_Int))
+{
+ if(!(min <= max)) { FatalError("Assertion failed: Menu_Adaptor_Limits: max cannot be smaller than min; assertion code: min <= max"); }
+}
+else
+{
+ if(min && GetType(min) != C4V_Int)
+ {
+ if(!(MN7I->CheckCallback(min))) { FatalError(Format("Assertion failed: Menu_Adaptor_Limits: invalid callback used for min: %v; assertion code: MN7I->CheckCallback(min)", min)); }
+ }
+
+ if(max && GetType(max) != C4V_Int)
+ {
+ if(!(MN7I->CheckCallback(max))) { FatalError(Format("Assertion failed: Menu_Adaptor_Limits: invalid callback used for max: %v; assertion code: MN7I->CheckCallback(max)", max)); }
+ }
+}
+
+ return [DT_Menu_Adaptor_Limits, [min, max, args]];
+}
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]]; }
global func Menu_Adaptor_Enum(array enumVals, array layout, bool valuesAsSeparateLists)
{
@@ -1098,6 +1118,26 @@ func EnumEntrySettings(string& caption, &symbol, string& infoCaption, int index,
}
}
+func AdaptorGetLimits(array limits)
+{
+ var ret = CreateArray(2);
+
+ for(var i = 0; i < 2; ++i)
+ {
+ if(!limits[i] || GetType(limits[i]) == C4V_Int)
+ {
+ ret[i] = limits[i];
+ }
+ else
+ {
+ ret[i] = Call(limits[i], limits[3]);
+ if(!(!ret[i] || GetType(ret[i]) == C4V_Int)) { FatalError(Format("Assertion failed: Menu_Adaptor_Limits: Got invalid callback value for %s: %v; assertion code: !ret[i] || GetType(ret[i]) == C4V_Int", ["min", "max"][i], ret[i])); }
+ }
+ }
+
+ return ret;
+}
+
func AdaptorFactory(args, int entryIndex)
{
var origArgs = args;
@@ -1129,7 +1169,7 @@ func AdaptorFactory(args, int entryIndex)
else if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_Integer)
{
if(!(GetType(val) == C4V_Any || GetType(val) == C4V_Int)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_Int"); }
- var limits = args[DT_Menu_Adaptor_Limits], max, min;
+ var limits = AdaptorGetLimits(args[DT_Menu_Adaptor_Limits]), max, min;
var wrapAround = args[DT_Menu_Adaptor_WrapAround];
if(limits && !wrapAround)
{
@@ -1432,7 +1472,7 @@ func AdaptorCommand(int action, object obj, args, array allArgs)
}
else if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_Integer)
{
- var limits = args[DT_Menu_Adaptor_Limits];
+ var limits = AdaptorGetLimits(args[DT_Menu_Adaptor_Limits]);
var wrapAround = args[DT_Menu_Adaptor_WrapAround];
var step = args[DT_Menu_Adaptor_StepSize];
var stepSize = 1;
@@ -1596,7 +1636,7 @@ func InputCallback(string input, int plr)
if(msgBoardMode - 1 == Menu_AdaptorType_Integer)
{
var int = ParseInt(input);
- var limits = args[DT_Menu_Adaptor_Limits];
+ var limits = AdaptorGetLimits(args[DT_Menu_Adaptor_Limits]);
var step = args[DT_Menu_Adaptor_StepSize];
if(GetType(int) == C4V_Int || GetType(int) == C4V_Any)
{