From 3e20df73f50d15e8d60d90ff11f8760413a26a30 Mon Sep 17 00:00:00 2001 From: Tanasart <22589759+Ttanasart-pt@users.noreply.github.com> Date: Fri, 29 Sep 2023 07:13:17 +0700 Subject: [PATCH] - [Code editor] Autocomplete now can be apply with enter key and mouse click. --- objects/_p_dialog/Create_0.gml | 16 +++++++++---- objects/_p_dialog/Step_1.gml | 3 ++- .../Create_0.gml | 17 ++++++++----- .../o_dialog_textbox_autocomplete/Draw_64.gml | 1 + .../o_dialog_textbox_autocomplete.yy | 5 +++- scripts/addon_lua/addon_lua.gml | 2 ++ scripts/textArea/textArea.gml | 24 ++++++++++++------- 7 files changed, 48 insertions(+), 20 deletions(-) diff --git a/objects/_p_dialog/Create_0.gml b/objects/_p_dialog/Create_0.gml index cacf92741..a1fa50d74 100644 --- a/objects/_p_dialog/Create_0.gml +++ b/objects/_p_dialog/Create_0.gml @@ -4,12 +4,13 @@ other.depth = min(depth - 1, other.depth); ds_list_add(DIALOGS, self); - dialog_w = 320; - dialog_h = 320; + active = true; + dialog_w = 320; + dialog_h = 320; _dialog_w = 320; _dialog_h = 320; - dialog_x = 0; - dialog_y = 0; + dialog_x = 0; + dialog_y = 0; title_height = 64; padding = 24; @@ -35,6 +36,8 @@ dialog_drag_my = 0; function doDrag() { + if(!active) return; + mouse_active = true; if(!draggable) return; @@ -71,6 +74,7 @@ onResize = -1; function doResize() { + if(!active) return; if(!dialog_resizable) return; if(dialog_resizing & 1 << 0 != 0) { @@ -121,6 +125,7 @@ #region focus function checkFocus() { + if(!active) return; var x0 = dialog_x - dialog_resizable * 6; var x1 = dialog_x + dialog_w + dialog_resizable * 6; var y0 = dialog_y - dialog_resizable * 6; @@ -135,6 +140,7 @@ } function checkDepth() { + if(!active) return; if(HOVER != self.id) return; if(mouse_press(mb_any)) { @@ -145,6 +151,7 @@ } function resetPosition() { + if(!active) return; if(anchor == ANCHOR.none) { dialog_x = xstart - dialog_w / 2; dialog_y = ystart - dialog_h / 2; @@ -160,6 +167,7 @@ } function checkMouse() { + if(!active) return; if(!DIALOG_CLICK) { //printIf(mouse_press(mb_any), $"Check {object_get_name(object_index)} : Click"); return; diff --git a/objects/_p_dialog/Step_1.gml b/objects/_p_dialog/Step_1.gml index c69be3427..80d10ac68 100644 --- a/objects/_p_dialog/Step_1.gml +++ b/objects/_p_dialog/Step_1.gml @@ -1,5 +1,6 @@ /// @description init -if !ready exit; +if !ready exit; +if !active exit; #region window control if(sFOCUS) { diff --git a/objects/o_dialog_textbox_autocomplete/Create_0.gml b/objects/o_dialog_textbox_autocomplete/Create_0.gml index 421dab17e..9269ef223 100644 --- a/objects/o_dialog_textbox_autocomplete/Create_0.gml +++ b/objects/o_dialog_textbox_autocomplete/Create_0.gml @@ -1,4 +1,6 @@ /// @description +event_inherited(); + #region data depth = -9999; @@ -13,6 +15,9 @@ prompt = ""; data = []; + destroy_on_escape = false; + destroy_on_click_out = false; + sc_content = new scrollPane(dialog_w, dialog_h, function(_y, _m) { draw_clear_alpha(COLORS.panel_bg_clear, 0); var hght = line_get_height(f_p0, 8); @@ -23,19 +28,19 @@ for(var i = 0; i < array_length(data); i++) { var _dat = data[i]; - //if(point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) { - // selecting = i; + if(sHOVER && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) { + selecting = i; - // if(mouse_press(mb_left)) - // applyAutoComplete(_dat[3]); - //} + if(mouse_press(mb_left)) + applyAutoComplete(_dat[3]); + } if(selecting == i) { WIDGET_TAB_BLOCK = true; draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1); - if(keyboard_check_pressed(vk_tab)) + if(keyboard_check_pressed(vk_tab) || keyboard_check_pressed(vk_enter)) applyAutoComplete(_dat[3]); } diff --git a/objects/o_dialog_textbox_autocomplete/Draw_64.gml b/objects/o_dialog_textbox_autocomplete/Draw_64.gml index 396d3ad07..a4202319f 100644 --- a/objects/o_dialog_textbox_autocomplete/Draw_64.gml +++ b/objects/o_dialog_textbox_autocomplete/Draw_64.gml @@ -31,6 +31,7 @@ if(textbox != WIDGET_CURRENT) exit; #region draw draw_sprite_stretched(THEME.textbox, 3, dialog_x, dialog_y, dialog_w, dialog_h); + sc_content.setFocusHover(sFOCUS, sHOVER); sc_content.draw(dialog_x, dialog_y); draw_sprite_stretched(THEME.textbox, 1, dialog_x, dialog_y, dialog_w, dialog_h); #endregion diff --git a/objects/o_dialog_textbox_autocomplete/o_dialog_textbox_autocomplete.yy b/objects/o_dialog_textbox_autocomplete/o_dialog_textbox_autocomplete.yy index 918ef45b3..312babc26 100644 --- a/objects/o_dialog_textbox_autocomplete/o_dialog_textbox_autocomplete.yy +++ b/objects/o_dialog_textbox_autocomplete/o_dialog_textbox_autocomplete.yy @@ -12,7 +12,10 @@ "name": "widget", "path": "folders/dialog/widget.yy", }, - "parentObjectId": null, + "parentObjectId": { + "name": "_p_dialog", + "path": "objects/_p_dialog/_p_dialog.yy", + }, "persistent": false, "physicsAngularDamping": 0.1, "physicsDensity": 0.5, diff --git a/scripts/addon_lua/addon_lua.gml b/scripts/addon_lua/addon_lua.gml index 96c68575a..011f45830 100644 --- a/scripts/addon_lua/addon_lua.gml +++ b/scripts/addon_lua/addon_lua.gml @@ -1,3 +1,5 @@ +// feather ignore all + #region setup function __addon_lua_setup(lua, context) { __addon_lua_setup_functions(lua); diff --git a/scripts/textArea/textArea.gml b/scripts/textArea/textArea.gml index 730404bad..d1ee2aa19 100644 --- a/scripts/textArea/textArea.gml +++ b/scripts/textArea/textArea.gml @@ -161,6 +161,16 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod return ch == " " || ch == "\n"; } #endregion + static keyboardEnter = function() { #region + if(!keyboard_check_pressed(vk_enter)) + return 0; + + if(use_autocomplete && autocomplete_box.active) + return 0; + + return 1 + ((shift_new_line && key_mod_press(SHIFT)) || (!shift_new_line && !key_mod_press(SHIFT))); + } #endregion + static onKey = function(key) { #region if(key == vk_left) { if(key_mod_press(SHIFT)) { @@ -367,8 +377,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod if(keyboard_check_pressed(vk_escape)) { } else if(keyboard_check_pressed(vk_tab)) { - } else if(( shift_new_line && keyboard_check_pressed(vk_enter) && key_mod_press(SHIFT)) || - (!shift_new_line && keyboard_check_pressed(vk_enter) && !key_mod_press(SHIFT))) { + } else if(keyboardEnter() == 2) { var ch = "\n"; if(cursor_select == -1) { var str_before = string_copy(_input_text, 1, cursor); @@ -521,8 +530,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod _input_text = _last_value; cut_line(); deactivate(); - } else if(( shift_new_line && keyboard_check_pressed(vk_enter) && !key_mod_press(SHIFT)) || - (!shift_new_line && keyboard_check_pressed(vk_enter) && key_mod_press(SHIFT))) { + } else if(keyboardEnter() == 1) { deactivate(); } } #endregion @@ -628,14 +636,14 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod } } - if(target != -999) { - if(mouse_press(mb_left, active) || click_block == 1) { + if(target != -999 && mouse_press(mb_left, active) && HOVER != autocomplete_box.id) { + if(click_block == 1) { cursor = target; cursor_select = -1; click_block = 0; autocomplete_box.active = false; - } else if(mouse_click(mb_left, active) && cursor != target) { + } else if(cursor != target) { if(cursor_select == -1) cursor_select = cursor; cursor = target; @@ -798,7 +806,7 @@ function textArea(_input, _onModify, _extras = noone) : textInput(_input, _onMod } #endregion - if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left)) { + if(!point_in_rectangle(_m[0], _m[1], _x, _y, _x + _w, _y + hh) && mouse_press(mb_left) && HOVER != autocomplete_box.id) { deactivate(); } } else {