2024-06-30 11:18:48 +02:00
|
|
|
function NodeTool(name, spr, contextString = instanceof(other)) constructor {
|
|
|
|
ctx = contextString;
|
|
|
|
context = noone;
|
|
|
|
|
2023-10-04 05:52:20 +02:00
|
|
|
self.name = name;
|
|
|
|
self.spr = spr;
|
2023-03-11 01:40:17 +01:00
|
|
|
|
|
|
|
subtools = is_array(spr)? array_length(spr) : 0;
|
|
|
|
selecting = 0;
|
|
|
|
settings = [];
|
|
|
|
attribute = {};
|
|
|
|
|
2024-04-13 07:32:04 +02:00
|
|
|
toolObject = noone;
|
|
|
|
toolFn = noone;
|
|
|
|
toolFnParam = {};
|
|
|
|
|
2024-06-30 11:18:48 +02:00
|
|
|
static checkHotkey = function() { INLINE return getToolHotkey(ctx, name); }
|
2023-10-04 05:52:20 +02:00
|
|
|
|
2024-06-30 11:18:48 +02:00
|
|
|
static setContext = function(context) { self.context = context; return self; }
|
2024-04-13 07:32:04 +02:00
|
|
|
static setToolObject = function(toolObject) { self.toolObject = toolObject; return self; }
|
2024-04-13 14:14:42 +02:00
|
|
|
static setToolFn = function(toolFn) { self.toolFn = toolFn; return self; }
|
2023-10-04 07:21:45 +02:00
|
|
|
|
2024-04-13 07:32:04 +02:00
|
|
|
static getName = function(index = 0) { return is_array(name)? array_safe_get_fast(name, index, "") : name; }
|
|
|
|
|
|
|
|
static getToolObject = function() { return is_array(toolObject)? toolObject[selecting] : toolObject; }
|
|
|
|
|
2023-10-04 07:21:45 +02:00
|
|
|
static getDisplayName = function(index = 0) {
|
|
|
|
var _nme = getName(index);
|
2024-05-11 04:56:08 +02:00
|
|
|
var _key = checkHotkey();
|
2023-10-04 05:52:20 +02:00
|
|
|
|
2024-06-30 11:18:48 +02:00
|
|
|
if(_key == noone) return _nme;
|
|
|
|
return new tooltipHotkey(_nme).setKey(_key.getName());
|
2023-07-15 20:01:29 +02:00
|
|
|
}
|
|
|
|
|
2024-01-16 09:56:20 +01:00
|
|
|
static setSetting = function(sets) { array_push(settings, sets); return self; }
|
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
static addSetting = function(name, type, onEdit, keyAttr, val) {
|
|
|
|
var w;
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case VALUE_TYPE.float :
|
|
|
|
w = new textBox(TEXTBOX_INPUT.number, onEdit);
|
2024-01-16 09:56:20 +01:00
|
|
|
w.font = f_p3;
|
2023-03-11 01:40:17 +01:00
|
|
|
break;
|
|
|
|
case VALUE_TYPE.boolean :
|
|
|
|
w = new checkBox(onEdit);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_push(settings, [ name, w, keyAttr, attribute ]);
|
|
|
|
attribute[$ keyAttr] = val;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2023-07-14 20:34:35 +02:00
|
|
|
static toggle = function(index = 0) {
|
2024-04-13 07:32:04 +02:00
|
|
|
if(toolFn != noone) {
|
2024-06-30 11:18:48 +02:00
|
|
|
if(subtools == 0) toolFn(context);
|
|
|
|
else toolFn[index](context);
|
2024-04-13 07:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-11 01:40:17 +01:00
|
|
|
if(subtools == 0) {
|
|
|
|
PANEL_PREVIEW.tool_current = PANEL_PREVIEW.tool_current == self? noone : self;
|
|
|
|
} else {
|
2023-07-14 20:34:35 +02:00
|
|
|
if(PANEL_PREVIEW.tool_current == self && index == selecting) {
|
2023-03-11 01:40:17 +01:00
|
|
|
PANEL_PREVIEW.tool_current = noone;
|
2023-07-14 20:34:35 +02:00
|
|
|
selecting = 0;
|
|
|
|
} else {
|
2023-03-11 01:40:17 +01:00
|
|
|
PANEL_PREVIEW.tool_current = self;
|
2023-07-14 20:34:35 +02:00
|
|
|
selecting = index;
|
|
|
|
}
|
2023-03-11 01:40:17 +01:00
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
|
|
|
|
if(PANEL_PREVIEW.tool_current == self)
|
|
|
|
onToggle();
|
2024-04-13 07:32:04 +02:00
|
|
|
|
|
|
|
var _obj = getToolObject();
|
2024-06-30 11:18:48 +02:00
|
|
|
if(_obj) _obj.init(context);
|
2023-03-11 01:40:17 +01:00
|
|
|
}
|
2023-06-17 14:30:49 +02:00
|
|
|
|
2023-10-04 05:52:20 +02:00
|
|
|
static toggleKeyboard = function() {
|
2024-06-30 11:18:48 +02:00
|
|
|
HOTKEY_BLOCK = true;
|
|
|
|
|
2023-10-04 05:52:20 +02:00
|
|
|
if(subtools == 0) {
|
|
|
|
PANEL_PREVIEW.tool_current = PANEL_PREVIEW.tool_current == self? noone : self;
|
2024-06-30 11:18:48 +02:00
|
|
|
|
2023-10-04 05:52:20 +02:00
|
|
|
} else if(PANEL_PREVIEW.tool_current != self) {
|
|
|
|
PANEL_PREVIEW.tool_current = self;
|
|
|
|
selecting = 0;
|
2024-06-30 11:18:48 +02:00
|
|
|
|
2023-10-04 05:52:20 +02:00
|
|
|
} else if(selecting == subtools - 1) {
|
|
|
|
PANEL_PREVIEW.tool_current = noone;
|
|
|
|
selecting = 0;
|
2024-06-30 11:18:48 +02:00
|
|
|
|
2023-10-04 05:52:20 +02:00
|
|
|
} else
|
|
|
|
selecting++;
|
|
|
|
|
|
|
|
if(PANEL_PREVIEW.tool_current == self)
|
|
|
|
onToggle();
|
2024-06-30 12:05:27 +02:00
|
|
|
|
|
|
|
var _obj = getToolObject();
|
|
|
|
if(_obj) _obj.init(context);
|
2023-10-04 05:52:20 +02:00
|
|
|
}
|
|
|
|
|
2023-06-17 14:30:49 +02:00
|
|
|
static onToggle = function() {}
|
2023-03-11 01:40:17 +01:00
|
|
|
}
|