diff options
Diffstat (limited to 'Script.c')
| -rw-r--r-- | Script.c | 37 |
1 files changed, 25 insertions, 12 deletions
@@ -253,6 +253,11 @@ func ActivateEntry(int index, int action) MenuItemCommand(entry[DT_Menu_Entry_Symbol], index, action); } +func SubMenu() +{ + return subMenu; +} + func &Var(int index) { return vars[index]; @@ -604,10 +609,10 @@ func SubmenuItemCallback(int action, object menuObject, args, array allArgs) func MenuQueryCancel(int selection, object menuObject) { + var reaction; if(selection != -1) { var entry = entries[selection]; - var reaction; if(CheckCondition(entry)) { reaction = CallCallbacks(entry[DT_Menu_Entry_Callbacks], Menu_CallbackType_Close, [Menu_CallbackType_Close, entry[DT_Menu_Entry_Symbol], settings[DT_Menu_Settings_Object], entry[DT_Menu_Entry_Args]]); @@ -616,7 +621,7 @@ func MenuQueryCancel(int selection, object menuObject) React(reaction, selection, true); } - if(settings[DT_Menu_Settings_KeepOpen] != DT_Menu_KeepOpen_Not && settings[DT_Menu_Settings_KeepOpen] != DT_Menu_KeepOpen_Permanent) + if((settings[DT_Menu_Settings_KeepOpen] != DT_Menu_KeepOpen_Not && settings[DT_Menu_Settings_KeepOpen] != DT_Menu_KeepOpen_Permanent) || (reaction == Menu_React_KeepOpen)) { return true; } @@ -723,8 +728,8 @@ global func Menu_Permanent() { return Menu__KeepOpen(DT_Menu_KeepOpen_Permanent) global func Menu_ConditionAllowSelection() { return Menu__Setting([DT_Menu_Settings_ConditionAllowSelection, true]);} global func Menu_ConditionDenySelection() { return Menu__Setting([DT_Menu_Settings_ConditionAllowSelection, false]);} -global func Menu_Callbacks(array callbacks) { MN7I->ValidateMenuCallbacks(callbacks); return Menu__Setting([DT_Menu_Settings_Callbacks, callbacks]); } -global func Menu_Decoration(id decoration) { MN7I->ValidateDeco(decoration); return Menu__Setting([DT_Menu_Settings_Decoration, decoration]); } +global func Menu_Callbacks(array callbacks) { if(!(MN7I->ValidateMenuCallbacks(callbacks))) { FatalError("Assertion failed: Menu_Callbacks: Invalid callbacks used; assertion code: MN7I->ValidateMenuCallbacks(callbacks)"); }return Menu__Setting([DT_Menu_Settings_Callbacks, callbacks]); } +global func Menu_Decoration(id decoration) { if(!(MN7I->ValidateDeco(decoration))) { FatalError("Assertion failed: Menu_Decoration: Invalid decoration used; assertion code: MN7I->ValidateDeco(decoration)"); }return Menu__Setting([DT_Menu_Settings_Decoration, decoration]); } global func Menu_RequireAction(string action, object target) { if(!(action)) { FatalError("Assertion failed: Menu_RequireAction: action is mandatory; assertion code: action"); }return Menu__Setting([DT_Menu_Settings_RequireAction, [action, target]]); } global func Menu_KeepParentOnClose(bool dontKeep) { return Menu__Setting([DT_Menu_Settings_KeepParentOnClose, !dontKeep]); } global func Menu_ConditionDisableMode(mode) { if(!(!mode || (GetType(mode) == C4V_Int && mode >= 0 && mode <= Menu_ConditionReact_Max) || (GetType(mode) == C4V_Array && mode[0] == Menu_ConditionReact_CustomFormat && GetType(mode[1]) == C4V_String))) { FatalError("Assertion failed: Menu_ConditionDisableMode: invalid mode; assertion code: !mode || (GetType(mode) == C4V_Int && mode >= 0 && mode <= Menu_ConditionReact_Max) || (GetType(mode) == C4V_Array && mode[0] == Menu_ConditionReact_CustomFormat && GetType(mode[1]) == C4V_String)"); }return Menu__Setting([DT_Menu_Settings_ConditionDisableMode, mode]);} @@ -792,10 +797,10 @@ global func Menu_Entry_Symbol(symbol, extra, int color) return [DT_Menu_Entry_Symbol, [symbol, extra, color]]; } } -global func Menu_Entry_Condition(callback, int allowDisabledSelection) { MN7I->CheckCallback(callback); return [DT_Menu_Entry_Condition, [callback, allowDisabledSelection]]; } +global func Menu_Entry_Condition(callback, int allowDisabledSelection) { if(!(MN7I->CheckCallback(callback))) { FatalError("Assertion failed: Menu_Entry_Condition: invalid callback used; assertion code: MN7I->CheckCallback(callback)"); }return [DT_Menu_Entry_Condition, [callback, allowDisabledSelection]]; } global func Menu_Entry_VariableCondition(array scopedVar, compare, int disableMode, bool invert, int allowDisabledSelection) { - MN7I->CheckScopedVar(scopedVar); + if(!(MN7I->CheckScopedVar(scopedVar))) { FatalError("Assertion failed: Menu_Entry_VariableCondition: Invalid scopedVar used; assertion code: MN7I->CheckScopedVar(scopedVar)"); } if(!(!disableMode || (GetType(disableMode) == C4V_Int && disableMode >= 0 && disableMode <= Menu_ConditionReact_Max) || (GetType(disableMode) == C4V_Array && disableMode[0] == Menu_ConditionReact_CustomFormat && GetType(disableMode[1]) == C4V_String))) { FatalError("Assertion failed: Menu_ConditionDisableMode: invalid disableMode; assertion code: !disableMode || (GetType(disableMode) == C4V_Int && disableMode >= 0 && disableMode <= Menu_ConditionReact_Max) || (GetType(disableMode) == C4V_Array && disableMode[0] == Menu_ConditionReact_CustomFormat && GetType(disableMode[1]) == C4V_String)"); } if(!(!allowDisabledSelection || (GetType(allowDisabledSelection) == C4V_Int && allowDisabledSelection >= 0 && allowDisabledSelection <= Menu_Condition_Max))) { FatalError("Assertion failed: Menu_ConditionAllowSelection: invalid allowDisabledSelection value; assertion code: !allowDisabledSelection || (GetType(allowDisabledSelection) == C4V_Int && allowDisabledSelection >= 0 && allowDisabledSelection <= Menu_Condition_Max)"); } return Menu_Entry_Condition(BindCallback(MN7I->MenuObjectCallback("VariableCondition"), [Bind(scopedVar), Bind(compare), Bind(disableMode), Bind(invert)]), allowDisabledSelection); @@ -1013,7 +1018,7 @@ func AdaptorLayout(array& layout, array& vals, bool valuesAsSeparateLists) for(var fieldPart in vals) { - if(layout[Menu_Layout_Symbol]) { Menu_Entry_Symbol(fieldPart[layout[Menu_Layout_Symbol] - 1]); } + if(layout[Menu_Layout_Symbol]) { Menu_Entry_Symbol(fieldPart[layout[Menu_Layout_Symbol] - 1]); } // this debug checks the symbol } } @@ -1121,6 +1126,10 @@ func EnumEntrySettings(string& caption, &symbol, string& infoCaption, int index, func AdaptorGetLimits(array limits) { var ret = CreateArray(2); + if(!limits) + { + limits = [Menu_Adaptor_Limits_Min, Menu_Adaptor_Limits_Max]; + } for(var i = 0; i < 2; ++i) { @@ -1157,18 +1166,18 @@ func AdaptorFactory(args, int entryIndex) args[DT_Menu_Adaptor_Callbacks] = args[DT_Menu_Adaptor_Callbacks] || []; if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_Boolean) { - if(!(GetType(val) == C4V_Any || GetType(val) == C4V_Bool)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_Bool"); } + if(!(GetType(val) == C4V_Any || GetType(val) == C4V_Bool)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_Bool"); } BooleanToggleCaption(val, caption, symbol); } else if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_String) { - if(!(GetType(val) == C4V_Any || GetType(val) == C4V_String)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_String"); } + if(!(GetType(val) == C4V_Any || GetType(val) == C4V_String)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_String"); } caption = Format(entry[DT_Menu_Entry_Caption], val); defaultMsgboardText = "$EnterText$"; } 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"); } + 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 = AdaptorGetLimits(args[DT_Menu_Adaptor_Limits]), max, min; var wrapAround = args[DT_Menu_Adaptor_WrapAround]; if(limits && !wrapAround) @@ -1188,7 +1197,7 @@ func AdaptorFactory(args, int entryIndex) } else if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_ID) { - if(!(GetType(val) == C4V_Any || GetType(val) == C4V_C4ID)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_C4ID"); } + if(!(GetType(val) == C4V_Any || GetType(val) == C4V_C4ID)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(val) == C4V_Any || GetType(val) == C4V_C4ID"); } caption = Format(entry[DT_Menu_Entry_Caption], val && GetName(0, val) || ""); if(val) { @@ -1356,7 +1365,7 @@ func AdaptorBitFieldItemsFactory(args) var infoCaption = entry[DT_Menu_Entry_InfoCaption]; var symbol = entry[DT_Menu_Entry_Symbol]; var fieldValue = ScopedVar(args[DT_Menu_Adaptor_Variable]); - if(!(GetType(fieldValue) == C4V_Any || GetType(fieldValue) == C4V_Int)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(fieldValue) == C4V_Any || GetType(fieldValue) == C4V_Int"); } + if(!(GetType(fieldValue) == C4V_Any || GetType(fieldValue) == C4V_Int)) { FatalError("Assertion failed: AdaptorFactory: Value of Menu_Adaptor_Variable has wrong type; assertion code: GetType(fieldValue) == C4V_Any || GetType(fieldValue) == C4V_Int"); } var layoutVals = args[DT_Menu_Adaptor_LayoutVals]; var layout = layoutVals[1]; @@ -1514,6 +1523,10 @@ func AdaptorCommand(int action, object obj, args, array allArgs) return reaction; } } + else + { + return Menu_React_KeepOpen; + } } else if(args[DT_Menu_Adaptor_Type] == Menu_AdaptorType_String) { |
