Skip to content

Instantly share code, notes, and snippets.

@flowstate
Created October 7, 2018 19:53
Show Gist options
  • Save flowstate/357702f07d7e8b199e9971b0474bb4c8 to your computer and use it in GitHub Desktop.
Save flowstate/357702f07d7e8b199e9971b0474bb4c8 to your computer and use it in GitHub Desktop.
Sorta fixed...
///@desc draw inventory menu
var _inventoryRows = 5; //***update to dynamically match inventoryCapacity
var _inventoryCols = 4;
var _inventorySlotSprite = spInventorySlot;
var _highlightedInventorySlotSprite = spInventorySlotHighlighted;
var _inventorySlotWidth = sprite_get_width(_inventorySlotSprite);
var _inventorySlotHeight = sprite_get_height(_inventorySlotSprite)
var _itemsInInventory = ds_list_size(oControllerEntity.player.inventory);
var _inventoryItemToShow = 0;
var _currentDrawX = 0;
var _currentDrawY = 0;
var _trueStartX = menuStartX + menuEdgeIndent;
var _trueStartY = menuStartY + menuEdgeIndent;
var _mouseOffsetX = device_mouse_x_to_gui(0) - _trueStartX ;
var _mouseOffsetY = device_mouse_y_to_gui(0) - _trueStartY ;
var _mouseHighlightCol = floor(_mouseOffsetX / _inventorySlotWidth);
var _mouseHighlightRow = floor(_mouseOffsetY / _inventorySlotHeight);
draw_text(50,10,"menuStartX, menuStartY: " + string(menuStartX) + " " + string(menuStartY));
draw_text(50,20,"_trueStartX, _trueStartY: " + string(_trueStartX) + " " + string(_trueStartY));
draw_text(50,30,"mouse_x, mouse_y: " + string(mouse_x) + " " + string(mouse_y));
draw_text(50,40,"offset_x, offset_y: " + string(_mouseOffsetX) + " " + string(_mouseOffsetY));
draw_text(50,50,"mouseCol, mouseRow: " + string(_mouseHighlightCol) + " " + string(_mouseHighlightRow));
//draw inventory grid by creating slots in position
for (var _i = 1; _i <= _inventoryCols; _i++){
for (var _j = 1; _j <= _inventoryRows; _j++){
//determine where to draw
_currentDrawX = _trueStartX + ( _inventorySlotWidth * _j);
_currentDrawY = _trueStartY + (_inventorySlotHeight * _i)
//draw slot
if (_mouseHighlightCol == _i and _mouseHighlightRow == _j)
{
draw_sprite(_highlightedInventorySlotSprite, -1,_currentDrawX , _currentDrawY );
} else {
draw_sprite(_inventorySlotSprite, -1,_currentDrawX , _currentDrawY );
}
//draw_sprite(_inventorySlotSprite, -1,_currentDrawX , _currentDrawY );
//draw items, if any left to show
if _inventoryItemToShow < _itemsInInventory {
var _entityNumber = oControllerEntity.player.inventory[| _inventoryItemToShow];
//ds_list_find_value()
draw_sprite_ext( scGetEntityStat(_entityNumber, actorStat.sprite), scGetEntityStat(_entityNumber, actorStat.subimage), _currentDrawX, _currentDrawY, 1, 1, 0, scGetEntityStat(_entityNumber, actorStat.colour), 1) ;
_inventoryItemToShow++; //increment counter
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment