Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

luttje

4
Posts
A member registered Apr 09, 2021

Recent community posts

(2 edits)

Heya again,

Thanks for explaining that the UIPanels weren't meant for that. I used them to create panels with a background sprite, but now that you said that I was doing something unintended- I double-checked the docs and found that a UIGroup can have a background sprite as well.

I guess the term 'panel' gave me the illusion that they would be similar to WinForms Panels, but they're more akin to Forms there I guess. I've switched to UIGroups for my purposes, but will leave the code snippet up since it may be useful to someone else for other reasons.

Thanks again for your quick support!

Heya :)

No the UIGrid did not contain any UIPanels, however the structure was somewhat complex:

  • UIPanel
    • UIGrid (2 rows, 1 column)
      • UIGrid in 1st row (1 row, 3 columns - column definitions [1, 1, 1])
        • UIButton (column 1)
        • UIButton (column 2)
        • UIButton (column 3)

Sadly I can't share a minimal, reproducible example atm since a lot of the code is intertwined with custom functions and little time to extract it.

Sharing another snippet of something I had to kinda of workaround.

I have a couple UIPanel widgets that I add as children to a grid. Upon closing the room I call a function to remove all widgets that are 'bound' to the room. Sadly panels that are parented to a Grid don't fully delete themselves. I had to use this workaround to get them to completely delete:

if (_widget.getType() == UI_TYPE.PANEL) {
    _widget.__parent.remove(_widget.getID());
    UI.__destroy_widget(_widget);
}
_widget.destroy()


Full snippet for the logic to register and later remove widgets when the room ends:

global.widgets_to_remove = []
// Registers a widget that will be removed when the room ends
function widget_bound_to_room(_widget)
{
    array_push(global.widgets_to_remove, _widget)    
    return _widget
}
// Called on room end to remove bound widgets
function widgets_remove_room_bound()
{
    for (var _i = array_length(global.widgets_to_remove) - 1; _i >= 0; _i--) {
        var _widget = array_pop(global.widgets_to_remove)
        
        custom_event_call("widget_removing_room_bound", {
            widget_to_remove: _widget    
        });
        
        // Workaround for panels not removing correctly
        if (_widget.getType() == UI_TYPE.PANEL) {
            _widget.__parent.remove(_widget.getID());
            UI.__destroy_widget(_widget);
        }
        
        _widget.destroy()
    }
}


To use it:

1. When creating widgets call widget_bound_to_room on it, e.g:

var _crafting_group = widget_bound_to_room(new UIGroup("CraftingGroup", 0, 0, 250, 0, spr_back, UI_RELATIVE_TO.MIDDLE_CENTER))
_crafting_group.setInheritHeight(true)
_crafting_group.add(widget_bound_to_room(new UIPanel("ParentedPanel", _x, _y, _width, _height, spr_frame_simple)))


2. When the room ends call:

widgets_remove_room_bound();

Thanks so much for sharing this awesome UI framework for free. Saves me a ton of work and it functions intuitively and is quite stable.

One thing I want to share is that it seems UIGrid.scroll doesn't move the children in cells. The cell groups themselves move (I can see that with setShowGridOverlay), but the children stay where they are initially placed.


For others struggling with this: I've made this (temporary) workaround that hotfixes the problem. Call it on the grid you want to scroll with the same parameters you would give to the .scroll method:

function ui_grid_scroll(_ui_grid, _orientation = UI_ORIENTATION.HORIZONTAL, _sign = 1, _amount = UI_SCROLL_SPEED)
{
    // Just this scrolls the cell groups, but their children aren't updated. BUG?
    _ui_grid.scroll(_orientation, _sign, _amount)
    
    // HOTFIX that triggers the children to update to their correct position
    var _children = _ui_grid.getChildren()
    
    for (var _i = 0; _i < array_length(_children); _i++) {
        var _child = _children[_i]
        
        _child.scroll(_orientation, _sign, 0)
    }    
}