Skip to content

Commit 3d28330

Browse files
committed
add key config
1 parent c711406 commit 3d28330

File tree

14 files changed

+146
-35
lines changed

14 files changed

+146
-35
lines changed

current-scripts/Demos/useful-scripts/objects/obj_column_menu/Draw_0.gml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
draw_set_font(menu_font);
2+
var _x = x + cursor_width + cursor_padding;
3+
14
for (var i=0; i<num_items; i++) {
25
var _item = items[| i];
36
var _type = _item.types[| ds_list_size(_item.types)-1];
47

8+
var _y = y + (item_height + line_spacing) * i;
9+
510
switch (_type) {
611
case "item":
712
case "selectable":
8-
draw_text(x + cursor_width + cursor_padding, y + (item_height + line_spacing) * i, _item.label);
13+
draw_text(_x, _y, _item.label);
914
break;
1015

1116
case "spinner":
12-
draw_text(x + cursor_width + cursor_padding, y + (item_height + line_spacing) * i, _item.get_full_label());
17+
draw_text(_x, _y, _item.get_full_label());
18+
break;
19+
20+
case "keyconfig":
21+
draw_text(_x, _y, _item.get_full_label());
1322
break;
1423

1524
default:
16-
draw_text(x + cursor_width + cursor_padding, y + (item_height + line_spacing) * i, _item.label);
25+
draw_text(_x, _y, _item.label);
1726
}
1827
}
1928

current-scripts/Demos/useful-scripts/objects/obj_column_menu/Step_1.gml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
if (keyboard_check_pressed(vk_anykey)) {
2+
if (active_key_config != noone) {
3+
self.handle_key_config(active_key_config);
4+
}
5+
}
6+
7+
8+
if (!enabled) exit;
9+
110
control_state.poll_input();
211

312
if (control_state.pressed_state[MENU_CONTROLS.UP]) {
@@ -29,4 +38,7 @@ if (control_state.pressed_state[MENU_CONTROLS.CONFIRM]) {
2938

3039
if (ds_list_find_index(_item.types, "selectable") != -1)
3140
self.handle_selectable(_item);
41+
42+
else if (ds_list_find_index(_item.types, "keyconfig") != -1)
43+
self.handle_key_config(_item);
3244
}
Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1+
draw_set_font(menu_font);
12
for (var i=0; i<ds_grid_width(items); i++) {
2-
for (j=0; j<ds_grid_height(items); j++) {
3+
var _x = x + (cursor_width + cursor_padding) * (i+1) + column_width * i;
4+
5+
for (var j=0; j<ds_grid_height(items); j++) {
36
var _item = items[# i, j];
47
if (!is_struct(_item)) continue;
58

69
var _type = _item.types[| ds_list_size(_item.types)-1];
10+
var _y = y + (item_height + line_spacing) * j;
711

812
switch (_type) {
913
case "item":
1014
case "selectable":
11-
draw_text(x + (cursor_width + cursor_padding) * (i+1) + column_width * i, y + (item_height + line_spacing) * j, _item.label);
15+
draw_text(_x, _y, _item.label);
1216
break;
1317

1418
case "spinner":
15-
draw_text(x + (cursor_width + cursor_padding) * (i+1) + column_width * i, y + (item_height + line_spacing) * j, _item.get_full_label());
19+
draw_text(_x, _y, _item.get_full_label());
20+
break;
21+
22+
case "keyconfig":
23+
draw_text(_x, _y, _item.get_full_label());
1624
break;
1725

1826
default:
19-
draw_text(x + (cursor_width + cursor_padding) * (i+1) + column_width * i, y + (item_height + line_spacing) * j, _item.label);
27+
draw_text(_x, _y, _item.label);
2028
}
2129
}
2230
}
2331

2432
draw_sprite(cursor_spr, 0,
2533
x + (cursor_width + cursor_padding + column_width) * pos.x,
2634
y + (item_height + line_spacing) * pos.y
27-
);
28-
draw_text(0, 320, string(pos.x) + ", " + string(pos.y));
35+
);

current-scripts/Demos/useful-scripts/objects/obj_grid_menu/Step_1.gml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
if (keyboard_check_pressed(vk_anykey)) {
2+
if (active_key_config != noone) {
3+
self.handle_key_config(active_key_config);
4+
}
5+
}
6+
7+
if (!enabled) exit;
8+
19
control_state.poll_input();
210

311
if (control_state.pressed_state[MENU_CONTROLS.UP]) {
@@ -38,4 +46,7 @@ if (control_state.pressed_state[MENU_CONTROLS.CONFIRM]) {
3846

3947
if (ds_list_find_index(_item.types, "selectable") != -1)
4048
self.handle_selectable(_item);
49+
50+
else if (ds_list_find_index(_item.types, "keyconfig") != -1)
51+
self.handle_key_config(_item);
4152
}

current-scripts/Demos/useful-scripts/objects/obj_grid_menu_demo/Create_0.gml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ menu = instance_create_layer(32, 32, layer, obj_grid_menu);
22
menu.grid_menu_init({
33
width: 2,
44
height: 3,
5-
column_width: 160,
5+
column_width: 80,
66
font: fnt_demo,
77
cursor_spr: spr_arrow,
88
cursor_move_sfx: snd_menu_move,
@@ -27,16 +27,11 @@ menu.grid_menu_add_selectable(0, 0, {
2727
// - {boolean} silent_on_confirm
2828
// - {boolean} silent_on_change
2929

30-
menu.grid_menu_add_spinner(0, 1, {
30+
menu.grid_menu_add_selectable(0, 1, {
3131
label: "Bar",
32-
values: ["A", 1, "B", 2, "C", 3],
33-
init_index: 0,
34-
on_confirm_func: -1,
35-
on_confirm_args: [],
36-
on_change_func: -1,
37-
on_change_args: [],
38-
silent_on_confirm: false,
39-
silent_on_change: false
32+
on_confirm_func: "menu_demo_on_confirm",
33+
on_confirm_args: ["Bar"],
34+
silent_on_confirm: false
4035
});
4136

4237
menu.grid_menu_add_selectable(1, 0, {
@@ -46,9 +41,10 @@ menu.grid_menu_add_selectable(1, 0, {
4641
silent_on_confirm: false
4742
});
4843

49-
menu.grid_menu_add_selectable(1, 1, {
44+
menu.grid_menu_add_key_config(1, 1, {
5045
label: "Qux",
51-
on_confirm_func: "menu_demo_on_confirm",
52-
on_confirm_args: ["Qux"],
46+
inital_keycode: vk_space,
47+
on_confirm_func: -1,
48+
on_confirm_args: [-1],
5349
silent_on_confirm: false
5450
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
enabled = true;
2+
13
draw_set_font(menu_font);
24
item_height = string_height("Ij");
35
cursor_width = sprite_get_width(cursor_spr);
46

57
control_state = new MenuControlState();
8+
active_key_config = noone;
69

710
menu_base_functions();

current-scripts/Demos/useful-scripts/objects/obj_menu_base/obj_menu_base.yy

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

current-scripts/Demos/useful-scripts/scripts/column_menu_functions/column_menu_functions.gml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ function column_menu_add_spinner(_config) {
4141
var _new = new MenuSpinner(_config);
4242
ds_list_add(items, _new);
4343
num_items++;
44+
}
45+
46+
/// @param column_menu_add_key_config(config)
47+
/// @param config
48+
// - {string} label
49+
// - {array} inital_keycode
50+
// - {function} on_confirm_func
51+
// - {array} on_confirm_args
52+
// - {boolean} silent_on_confirm
53+
function column_menu_add_key_config(_config) {
54+
var _new = new MenuKeyConfig(_config);
55+
ds_list_add(items, _new);
56+
num_items++;
4457
}

current-scripts/Demos/useful-scripts/scripts/grid_menu_functions/grid_menu_functions.gml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,22 @@ function grid_menu_add_spinner(_x, _y, _config) {
5757

5858
var _new = new MenuSpinner(_config);
5959
items[# _x, _y] = _new;
60+
}
61+
62+
/// @param grid_menu_add_key_config(x, y, config)
63+
/// @param x
64+
/// @param y
65+
/// @param config
66+
// - {string} label
67+
// - {array} inital_keycode
68+
// - {function} on_confirm_func
69+
// - {array} on_confirm_args
70+
// - {boolean} silent_on_confirm
71+
function grid_menu_add_key_config(_x, _y, _config) {
72+
if (_x < 0 || _x >= ds_grid_width(items)
73+
|| _y < 0 || _x >= ds_grid_height(items))
74+
return;
75+
76+
var _new = new MenuKeyConfig(_config);
77+
items[# _x, _y] = _new;
6078
}

current-scripts/Demos/useful-scripts/scripts/menu_base_functions/menu_base_functions.gml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@ function handle_spinner(_item, _direction) {
2424
if (!_item.silent_on_change && audio_exists(cursor_change_sfx)) {
2525
audio_play_sound(cursor_change_sfx, 1, false);
2626
}
27+
}
28+
29+
/// @func handle_key_config(item)
30+
/// @param {MenuSpinner} item
31+
function handle_key_config(_item) {
32+
if (_item.discovery_mode) {
33+
_item.keycode = keyboard_key;
34+
_item.discovery_mode = false;
35+
self.active_key_config = noone;
36+
self.enabled = true;
37+
io_clear();
38+
} else {
39+
_item.discovery_mode = true;
40+
self.enabled = false;
41+
self.active_key_config = _item;
42+
io_clear();
43+
}
2744
}

0 commit comments

Comments
 (0)