2023-05-03 21:42:17 +02:00
|
|
|
function addonContextGenerator(_addon, _function) constructor {
|
|
|
|
self._addon = _addon;
|
|
|
|
self._function = _function;
|
|
|
|
|
|
|
|
static populate = function() {
|
|
|
|
var _items = lua_call(_addon.thread, _function);
|
|
|
|
var arr = [];
|
|
|
|
|
|
|
|
for( var i = 0; i < array_length(_items); i++ ) {
|
|
|
|
var _item = _items[i];
|
|
|
|
if(_item == -1)
|
|
|
|
array_push(arr, -1);
|
|
|
|
else {
|
2023-05-07 20:55:13 +02:00
|
|
|
if(struct_has(_item, "callback")) {
|
|
|
|
var _addonItem = new addonContextItem(_addon, _item.name, _item.callback);
|
|
|
|
array_push(arr, _addonItem.menu_item);
|
|
|
|
} else if(struct_has(_item, "content")) {
|
|
|
|
var _subArr = []
|
|
|
|
for( var j = 0; j < array_length(_item.content); j++ ) {
|
2023-05-16 21:28:16 +02:00
|
|
|
var _it = _item.content[j];
|
|
|
|
if(_it == -1)
|
|
|
|
array_push(_subArr, -1);
|
|
|
|
else if(struct_has(_it, "callback")) {
|
|
|
|
var _addonItem = new addonContextItem(_addon, _it.name, _it.callback);
|
|
|
|
array_push(_subArr, _addonItem.menu_item);
|
|
|
|
}
|
2023-05-07 20:55:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var _addonItem = new addonContextSubMenu(_item.name, _subArr);
|
|
|
|
array_push(arr, _addonItem.menu_item);
|
|
|
|
}
|
|
|
|
}
|
2023-05-03 21:42:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addonContextItem(_addon, _name, _function) constructor {
|
|
|
|
self._addon = _addon;
|
|
|
|
self._name = _name;
|
|
|
|
self._function = _function;
|
|
|
|
|
2023-05-07 20:55:13 +02:00
|
|
|
menu_item = menuItem(_name, function(_data) {
|
|
|
|
lua_call(_addon.thread, self._function, lua_byref(_data.context, true));
|
2023-05-16 21:28:16 +02:00
|
|
|
})//.setColor(COLORS._main_accent);
|
2023-05-03 21:42:17 +02:00
|
|
|
}
|
|
|
|
|
2023-05-07 20:55:13 +02:00
|
|
|
function addonContextSubMenu(_name, _content) constructor {
|
|
|
|
self.name = _name;
|
|
|
|
self.content = _content;
|
|
|
|
|
|
|
|
menu_item = menuItem(name, function(_dat) {
|
|
|
|
return submenuCall(_dat, content);
|
2023-05-16 21:28:16 +02:00
|
|
|
})//.setColor(COLORS._main_accent)
|
2023-05-07 20:55:13 +02:00
|
|
|
.setIsShelf();
|
|
|
|
}
|
|
|
|
|
|
|
|
function addonTrigger(_addon, _openDialog = true) {
|
2023-05-03 21:42:17 +02:00
|
|
|
var _name = filename_name_only(_addon);
|
|
|
|
with(_addon_custom) {
|
|
|
|
if(name != _name)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
instance_destroy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var addonPath = DIRECTORY + "Addons\\" + _name;
|
2023-05-07 20:55:13 +02:00
|
|
|
if(!directory_exists(addonPath)) return;
|
|
|
|
|
2023-05-03 21:42:17 +02:00
|
|
|
with(instance_create(0, 0, _addon_custom))
|
2023-05-07 20:55:13 +02:00
|
|
|
init(addonPath, _openDialog);
|
2023-05-03 21:42:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function addonActivated(_addon) {
|
|
|
|
var _name = filename_name_only(_addon);
|
|
|
|
with(_addon_custom) if(name == _name) return true;
|
|
|
|
return false;
|
|
|
|
}
|