[Preference] Fix crash when displaying string based hotkey.

This commit is contained in:
Tanasart 2024-12-24 09:20:55 +07:00
parent 89149e7dec
commit ce9b7b866e
8 changed files with 40 additions and 80 deletions

View file

@ -410,7 +410,6 @@
{"$GMIncludedFile":"","%Name":"Nodes.zip","CopyToMask":-1,"filePath":"datafiles/data","name":"Nodes.zip","resourceType":"GMIncludedFile","resourceVersion":"2.0",},
{"$GMIncludedFile":"","%Name":"related_node.json","CopyToMask":-1,"filePath":"datafiles/data","name":"related_node.json","resourceType":"GMIncludedFile","resourceVersion":"2.0",},
{"$GMIncludedFile":"","%Name":"tileset_gamemaker2_room.yy","CopyToMask":-1,"filePath":"datafiles/data/TemplateStrings","name":"tileset_gamemaker2_room.yy","resourceType":"GMIncludedFile","resourceVersion":"2.0",},
{"$GMIncludedFile":"","%Name":"Theme.zip","CopyToMask":-1,"filePath":"datafiles/data","name":"Theme.zip","resourceType":"GMIncludedFile","resourceVersion":"2.0",},
{"$GMIncludedFile":"","%Name":"Tooltip.zip","CopyToMask":-1,"filePath":"datafiles/data","name":"Tooltip.zip","resourceType":"GMIncludedFile","resourceVersion":"2.0",},
{"$GMIncludedFile":"","%Name":"Node_2D_light.png","CopyToMask":-1,"filePath":"datafiles/data/Tooltip","name":"Node_2D_light.png","resourceType":"GMIncludedFile","resourceVersion":"2.0",},
{"$GMIncludedFile":"","%Name":"Node_9Slice.png","CopyToMask":-1,"filePath":"datafiles/data/Tooltip","name":"Node_9Slice.png","resourceType":"GMIncludedFile","resourceVersion":"2.0",},

View file

@ -780,9 +780,9 @@ event_inherited();
for (var j = 0, m = array_length(_list); j < m; j++) {
var key = _list[j];
var name = __txt(key.name);
var dk = key_get_name(key.key, key.modi);
var key = _list[j];
var name = __txt(key.name);
var dk = key_get_name(key.key, key.modi);
if(_search != "" && string_pos(_search, string_lower(name)) == 0
&& string_pos(_search, string_lower(dk)) == 0)

View file

@ -75,54 +75,42 @@ function getToolHotkey(_group, _key) {
return _grp[$ _key];
}
function hotkeySimple(_context, _name, _key, modi = MOD_KEY.none) { return new HotkeySimple(_context, _name, _key, modi); }
function HotkeySimple(_context, _name, _key, modi = MOD_KEY.none) constructor {
function hotkeySimple(_context, _name, _key, _mod = MOD_KEY.none) { return new HotkeySimple(_context, _name, _key, _mod); }
function HotkeySimple(_context, _name, _key, _mod = MOD_KEY.none) constructor {
context = _context;
name = _name;
self.key = key_get_index(_key);
self.modi = modi;
dKey = key;
dModi = modi;
key = key_get_index(_key);
modi = _mod;
dKey = key;
dModi = _mod;
if(!struct_has(HOTKEYS_CUSTOM, context)) HOTKEYS_CUSTOM[$ context] = {};
HOTKEYS_CUSTOM[$ context][$ name] = self;
static isPressing = function() {
if(is_string(key)) key = key_get_index(key);
return key == noone? false : key_press(key, modi);
}
static isPressing = function() /*=>*/ {return key == noone? false : key_press(key, modi)};
static getName = function() /*=>*/ {return key_get_name(key, modi)};
static getName = function() {
if(is_string(key)) key = key_get_index(key);
return key_get_name(key, modi);
}
static serialize = function() { return { context, name, key, modi } }
static deserialize = function(ll) { if(!is_struct(ll)) return; key = ll.key; modi = ll.modi; }
var _loadKey = $"{context}_{name}";
if(struct_has(HOTKEYS_DATA, _loadKey)) deserialize(HOTKEYS_DATA[$ _loadKey]);
static serialize = function() /*=>*/ { return { context, name, key, modi } }
static deserialize = function(l) /*=>*/ { if(!is_struct(l)) return; key = l.key; modi = l.modi; if(is_string(key)) key = key_get_index(key); }
if(struct_has(HOTKEYS_DATA, $"{context}_{name}")) deserialize(HOTKEYS_DATA[$ $"{context}_{name}"]);
}
function hotkeyObject(_context, _name, _key, _mod = MOD_KEY.none, _action = noone) constructor {
context = _context;
name = _name;
key = _key;
modi = _mod;
action = _action;
key = _key;
modi = _mod;
dKey = _key;
dModi = _mod;
static full_name = function() { return string_to_var(context == ""? $"global.{name}" : $"{context}.{name}"); }
static full_name = function() /*=>*/ {return string_to_var(context == ""? $"global.{name}" : $"{context}.{name}")};
static serialize = function() { return { context, name, key, modi } }
static deserialize = function(ll) { if(!is_struct(ll)) return; key = ll.key; modi = ll.modi; }
var _loadKey = $"{context}_{name}";
if(struct_has(HOTKEYS_DATA, _loadKey)) deserialize(HOTKEYS_DATA[$ _loadKey]);
static serialize = function() /*=>*/ { return { context, name, key, modi } }
static deserialize = function(l) /*=>*/ { if(!is_struct(l)) return; key = l.key; modi = l.modi; }
if(struct_has(HOTKEYS_DATA, $"{context}_{name}")) deserialize(HOTKEYS_DATA[$ $"{context}_{name}"]);
}
function addHotkey(_context, _name, _key, _mod, _action) {
@ -218,28 +206,12 @@ function hotkey_draw(keyStr, _x, _y, _status = 0) {
var tc = c_white;
switch(_status) {
case 0 :
bc = CDEF.main_dkgrey;
tc = COLORS._main_text_sub;
break;
case 1 :
bc = CDEF.main_ltgrey;
tc = CDEF.main_ltgrey;
break;
case 2 :
bc = COLORS._main_accent;
tc = COLORS._main_text_accent;
break;
case 0 : bc = CDEF.main_dkgrey; tc = COLORS._main_text_sub; break;
case 1 : bc = CDEF.main_ltgrey; tc = CDEF.main_ltgrey; break;
case 2 : bc = COLORS._main_accent; tc = COLORS._main_text_accent; break;
}
draw_set_text(f_p2, fa_right, fa_center, tc);
var _tw = string_width( keyStr);
var _th = string_height(keyStr);
// draw_sprite_stretched_ext(THEME.ui_panel, 1, _x - _tw - ui(4), _y - _th / 2 - ui(5), _tw + ui(8), _th + ui(6), bc, 0.5);
draw_text(_x, _y - ui(2), keyStr);
}
@ -283,25 +255,7 @@ function hotkey_deserialize() {
var map = json_load_struct(path);
if(!is_struct(map)) return;
if(struct_has(map, "context")) {
var _ctx = map.context;
for(var i = 0; i < array_length(_ctx); i++) {
var key_list = _ctx[i];
var _context = key_list.context;
var name = key_list.name;
HOTKEYS_DATA[$ $"{_context}_{name}"] = key_list;
}
}
if(struct_has(map, "node")) {
var _ctx = map.node;
for(var i = 0; i < array_length(_ctx); i++) {
var key_list = _ctx[i];
var _context = key_list.context;
var name = key_list.name;
HOTKEYS_DATA[$ $"{_context}_{name}"] = key_list;
}
}
var fn = function(n) /*=>*/ { HOTKEYS_DATA[$ $"{n.context}_{n.name}"] = n; };
if(struct_has(map, "context")) array_foreach(map.context, fn);
if(struct_has(map, "node")) array_foreach(map.node, fn);
}

View file

@ -94,7 +94,7 @@
#region get name
function key_get_name(_key, _mod) {
if(_key <= 0 && _mod == MOD_KEY.none)
if(!is_real(_key) || (_key <= 0 && _mod == MOD_KEY.none))
return "";
var dk = "";

View file

@ -55,13 +55,15 @@ If set, then strength value control how many times the effect applies on itself.
newInput(18, nodeValue_Int("Iteration", self, 32));
newInput(19, nodeValue_Bool("Fade distance", self, false));
newInput(19, nodeValue_Bool("Fade Distance", self, true));
newInput(20, nodeValue_Bool("Reposition", self, false));
input_display_list = [ 10, 12,
["Surfaces", true], 0, 8, 9, 13, 14,
["Strength", false], 1, 17, 3, 15, 4,
["Displacement", false], 5, 16, 2,
["Algorithm", true], 6, 11, 18, 19,
["Algorithm", true], 6, 11, 18, 19, 20,
];
newOutput(0, nodeValue_Output("Surface out", self, VALUE_TYPE.surface, noone));
@ -128,9 +130,10 @@ If set, then strength value control how many times the effect applies on itself.
shader_set_i("sepAxis", _data[16]);
shader_set_i("iterate", _data[ 6]);
shader_set_f("iteration", _data[18]);
shader_set_i("blendMode", _data[11]);
shader_set_i("fadeDist", _data[19]);
shader_set_f("iteration", _data[18]);
shader_set_i("reposition", _data[20]);
draw_surface_safe(_data[0]);
surface_reset_shader();

View file

@ -148,7 +148,7 @@ function Node_Path_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) construc
break;
}
point_vec2_rotate(out, posx, posy, rot);
// point_vec2_rotate(out, posx, posy, rot);
return out;
}
@ -356,6 +356,7 @@ function Node_Path_Shape(_x, _y, _group = noone) : Node(_x, _y, _group) construc
break;
}
array_map_ext(points, function(p) /*=>*/ {return point_rotate(p[0], p[1], posx, posy, rot, p)});
var n = array_length(points);
lengths = array_create(n + loop);

View file

@ -268,7 +268,7 @@
if(file_exists(_pth_h)) file_copy(_pth_h, PREFERENCES_DIR + "hotkeys.json");
if(file_exists(_pth_d)) file_copy(_pth_d, PREFERENCES_DIR + "default_project.json");
}
}
},
];
function PREF_UPDATE() {

View file

@ -106,6 +106,7 @@ uniform int iterate;
uniform float iteration;
uniform int blendMode;
uniform int fadeDist;
uniform int reposition;
uniform vec2 strength;
uniform int strengthUseSurf;
@ -202,9 +203,11 @@ void main() {
float str;
vec4 c;
if(reposition == 1) stren /= iteration;
for(float i = 0.; i < iteration; i++) {
str = stren * (i * _t);
samPos = shiftMap(v_vTexcoord, str);
samPos = shiftMap(reposition == 1? samPos : v_vTexcoord, str);
c = sampleTexture( gm_BaseTexture, samPos );
if(fadeDist == 1) c.rgb *= 1. - i * _t;