G
gibberingmouther
Guest
i'm trying to make it so i can drag object icons from the inventory to a hotkey bar.
i'm not concerned about the hotkey bar here. i'm just trying to get the dragging to work.
relevant draw event code for the inventory
step code for dragging
basically when i click on an inventory slot it's supposed to spawn an instance of obj_genicon but instead it does nothing, no error message, just nothing.
i'm not concerned about the hotkey bar here. i'm just trying to get the dragging to work.
relevant draw event code for the inventory
Code:
//draw list content
//mouseWithin is supposed to be var before but i changed it
for(var A=0;A<itemsShow;A++){
//this is going to show the inventory list
var itemH=listH/itemsShow;
mouseWithin=point_in_rectangle(mouse_x,mouse_y,listX,listY+A*itemH,buttonX[0]-1,listY+(A+1)*itemH-2);
draw_set_valign(fa_center);
//draw list item red if it's hovered
draw_set_colour(cl[mouseWithin]);
draw_text(listX+itemsOffset, listY + A*(listH/itemsShow)+itemH/2, global.item[global.inv[A+itemCurrent, 0], global.DESC] + " x " + string(global.inv[A+itemCurrent, 1]));
}
Code:
if mouseWithin {
if mouse_check_button_pressed(mb_left){
dragging = true;
instance_create(mouse_x, mouse_y, obj_genicon);
xoffset = obj_genicon.x - mouse_x;
yoffset = obj_genicon.y - mouse_y;
}
}
//listX,listY+A*itemH,buttonX[0]-1,listY+(A+1)*itemH-2
if dragging == true{
obj_genicon.x = mouse_x+xoffset;
obj_genicon.y = mouse_y+yoffset;
}
if mouse_check_button_released(mb_left){
if dragging == true{
dragging = false;
with (obj_genicon)
{
instance_destroy();
}
}
}