2023-07-12 16:28:32 +02:00
|
|
|
/// @description
|
2023-09-29 02:13:17 +02:00
|
|
|
event_inherited();
|
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
#region data
|
|
|
|
depth = -9999;
|
|
|
|
|
|
|
|
dialog_x = 0;
|
|
|
|
dialog_y = 0;
|
|
|
|
dialog_w = 300;
|
|
|
|
dialog_h = 160;
|
2024-04-10 05:02:23 +02:00
|
|
|
on_top = true;
|
2023-07-12 16:28:32 +02:00
|
|
|
|
|
|
|
selecting = 0;
|
|
|
|
textbox = noone;
|
|
|
|
prompt = "";
|
|
|
|
data = [];
|
2024-12-23 04:59:30 +01:00
|
|
|
font = f_code;
|
|
|
|
pre_mx = 0;
|
|
|
|
pre_my = 0;
|
|
|
|
|
|
|
|
show_items = 8;
|
|
|
|
pad_item = 6;
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-09-29 02:13:17 +02:00
|
|
|
destroy_on_escape = false;
|
|
|
|
destroy_on_click_out = false;
|
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
function activate(_textbox) {
|
|
|
|
textbox = _textbox;
|
|
|
|
selecting = 0;
|
2023-11-08 08:38:04 +01:00
|
|
|
}
|
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
function deactivate(_textbox) {
|
|
|
|
if(textbox != _textbox) return;
|
|
|
|
textbox = noone;
|
2023-11-08 08:38:04 +01:00
|
|
|
}
|
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
sc_content = new scrollPane(dialog_w, dialog_h, function(_y, _m) {
|
2024-12-23 04:59:30 +01:00
|
|
|
draw_clear_alpha(COLORS.panel_bg_clear, 1);
|
|
|
|
var hght = line_get_height(font, pad_item);
|
2023-07-12 16:28:32 +02:00
|
|
|
var _dw = sc_content.surface_w;
|
|
|
|
var _h = 0;
|
|
|
|
var _ly = _y;
|
2024-12-23 04:59:30 +01:00
|
|
|
var _mmove = pre_mx != _m[0] || pre_my != _m[1];
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
gpu_set_tex_filter(true);
|
|
|
|
for( var i = 0, n = array_length(data); i < n; i++ ) {
|
2023-07-12 16:28:32 +02:00
|
|
|
var _dat = data[i];
|
|
|
|
|
2023-09-29 02:13:17 +02:00
|
|
|
if(sHOVER && point_in_rectangle(_m[0], _m[1], 0, _ly + 1, _dw, _ly + hght - 1)) {
|
2024-12-23 04:59:30 +01:00
|
|
|
if(_mmove) selecting = i;
|
|
|
|
if(mouse_press(mb_left)) { applyAutoComplete(_dat[3]); MOUSE_BLOCK = true; break; }
|
2023-09-29 02:13:17 +02:00
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
|
|
|
if(selecting == i) {
|
2023-09-08 19:47:48 +02:00
|
|
|
WIDGET_TAB_BLOCK = true;
|
2023-07-12 16:28:32 +02:00
|
|
|
draw_sprite_stretched_ext(THEME.textbox, 3, 0, _ly, _dw, hght, COLORS.dialog_menubox_highlight, 1);
|
2024-12-23 04:59:30 +01:00
|
|
|
if(keyboard_check_pressed(vk_tab) || keyboard_check_pressed(vk_enter)) { applyAutoComplete(_dat[3]); break; }
|
2023-07-12 16:28:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var icn = _dat[0][0];
|
2024-12-23 04:59:30 +01:00
|
|
|
if(sprite_exists(icn)) {
|
|
|
|
var ss = (hght - ui(8)) / sprite_get_width(icn);
|
|
|
|
draw_sprite_ext(icn, _dat[0][1], ui(4 + 12), _ly + hght / 2, ss, ss, 0, c_white, 1);
|
|
|
|
}
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
BLEND_ALPHA_MULP
|
|
|
|
draw_set_text(font, fa_right, fa_center, COLORS._main_text_sub);
|
|
|
|
draw_text(round(_dw - ui(8)), round(_ly + hght / 2), _dat[2]);
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
draw_set_text(font, fa_left, fa_center, CDEF.main_white);
|
|
|
|
draw_text(round(ui(4 + 24 + 4)), round(_ly + hght / 2), _dat[1]);
|
|
|
|
BLEND_NORMAL
|
2023-07-12 16:28:32 +02:00
|
|
|
|
|
|
|
_ly += hght;
|
|
|
|
_h += hght;
|
|
|
|
}
|
2024-12-23 04:59:30 +01:00
|
|
|
gpu_set_tex_filter(false);
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
if(KEYBOARD_PRESSED == vk_up) {
|
|
|
|
selecting = (selecting - 1 + n) % n;
|
|
|
|
sc_content.scroll_y_to = max(sc_content.scroll_y_to, -selecting * hght);
|
|
|
|
if(selecting == n - 1) sc_content.scroll_y_to = -(selecting - show_items + 1) * hght;
|
2023-07-12 16:28:32 +02:00
|
|
|
}
|
2024-12-23 04:59:30 +01:00
|
|
|
|
|
|
|
if(KEYBOARD_PRESSED == vk_down) {
|
|
|
|
selecting = (selecting + 1) % n;
|
|
|
|
sc_content.scroll_y_to = min(sc_content.scroll_y_to, -(selecting - show_items + 1) * hght);
|
|
|
|
if(selecting == 0) sc_content.scroll_y_to = -selecting * hght;
|
2023-07-12 16:28:32 +02:00
|
|
|
}
|
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
pre_mx = _m[0];
|
|
|
|
pre_my = _m[1];
|
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
return _h;
|
|
|
|
});
|
|
|
|
|
2024-12-23 04:59:30 +01:00
|
|
|
sc_content.scroll_inertia = 0;
|
|
|
|
|
2023-07-12 16:28:32 +02:00
|
|
|
function applyAutoComplete(rep) {
|
2023-09-15 20:12:02 +02:00
|
|
|
var _totAmo = string_length(textbox._input_text);
|
|
|
|
var _prmAmo = string_length(prompt);
|
|
|
|
var _repAmo = string_length(rep);
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
var _sPreC = string_copy(textbox._input_text, 1, textbox.cursor - _prmAmo);
|
|
|
|
var _sPosC = string_copy(textbox._input_text, textbox.cursor + 1, _totAmo - textbox.cursor);
|
2023-07-12 16:28:32 +02:00
|
|
|
|
2023-09-15 20:12:02 +02:00
|
|
|
textbox._input_text = $"{_sPreC}{rep}{_sPosC}";
|
|
|
|
textbox.cursor += _repAmo - _prmAmo;
|
2023-07-12 16:28:32 +02:00
|
|
|
textbox.cut_line();
|
2023-11-26 13:16:38 +01:00
|
|
|
textbox.autocomplete_delay = 0;
|
2023-11-08 08:38:04 +01:00
|
|
|
textbox = noone;
|
2023-11-26 13:16:38 +01:00
|
|
|
|
|
|
|
prompt = "";
|
|
|
|
data = [];
|
2023-07-12 16:28:32 +02:00
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|