A
Al the Coder
Guest
I am new to programming with GMS in its entirety, and I need a bit of help.
I have a Ds_Grid set up fully with visuals for my inventory system, but the issue is that I have no idea how to grab the array values from the ds_grid relative to the mouse position on the inventory GUI. The inventory is currently situated at the bottom left side of my room when running. So i guess any help or tutorials you can come up with to show me how this can be done would be appreciated.
Code just in case anyone needs to look:
Draw Event:
At the bottom here I have it checking to see if the mouse x and mouse y are pointing inside the inventory gui and give me output and a rectangle visually show me my bounds. My goal here is to be able to click an object within this window and drag the "sprite" or "Object" out to be able to use it elsewhere in room.
If there is a better or easier way to accomplish this let me know. Also feel free to correct my code of any bad coding (if any). Thanks
I have a Ds_Grid set up fully with visuals for my inventory system, but the issue is that I have no idea how to grab the array values from the ds_grid relative to the mouse position on the inventory GUI. The inventory is currently situated at the bottom left side of my room when running. So i guess any help or tutorials you can come up with to show me how this can be done would be appreciated.
Code just in case anyone needs to look:
Draw Event:
Code:
draw_self();
draw_set_color(my_color);
draw_text(bbox_left + 85, bbox_top + text_border, "Name");
item_left_start = bbox_left + 120;
item_top_start = bbox_top + 48;
for (i = 0; i < inventory_end_at; i += 1)
{
for (j = 0; j < inventory_width; j += 1)
{
inventory_on_screen = i;
if (j == 0)
{
draw_text(item_left_start - 43, item_top_start + (i * 32), ds_grid_get(my_items, 0, i + scrolled_amount));
}
if (j == 3)
{
draw_sprite(ds_grid_get(my_items, j, i + scrolled_amount), 0, bbox_left + 45, item_top_start + (i * 32) + 10);
}
}
}
draw_rectangle(bbox_left + text_border, item_top_start + ((item_selected - scrolled_amount) * 32) -7, bbox_right - text_border, item_top_start + ((item_selected - scrolled_amount) * 32) + 25, true);
draw_sprite(s_border_desc_window, 0, bbox_left + sprite_get_xoffset(s_border_desc_window), room_height - sprite_get_yoffset(s_border_desc_window) - 8);
if (is_empty)
{
draw_text_ext(bbox_left + 28, room_height - sprite_get_yoffset(s_border) - 210, empty_message, 32, sprite_get_width(s_border) - text_border);
my_color = c_red;
}
else
{
draw_text_ext(bbox_left + 28, room_height - sprite_get_yoffset(s_border) - 210, ds_grid_get(my_items, 2, item_selected), 32, sprite_get_width(s_border) - text_border);
my_color = c_black;
}
if (ds_grid_height(my_items) > floor((sprite_height - (text_border * 3)) / 32))
{
draw_sprite(s_scrollbar, 0, bbox_right - 16, 25 + bbox_top + item_selected * (sprite_height - text_border) / ds_grid_height(my_items));
}
draw_rectangle(bbox_left, bbox_top + 40, bbox_right, bbox_bottom, true);
if (mouse_x >= bbox_left && mouse_y >= bbox_top + 40 && mouse_x <= bbox_right && mouse_y <= bbox_bottom)
{
show_debug_message("In bounds")
}
If there is a better or easier way to accomplish this let me know. Also feel free to correct my code of any bad coding (if any). Thanks