DirtyLarry - A quick and dirty GUI library

I would recommend that you fork the project on GitHub. That makes it easy for you to submit pull requests for bug fixes, and perhaps also for new components that you create. I don’t know about license. You need to wait for Sven to reply

2 Likes
  1. I will license it under the same license as the rest of the Defold Template contents, see: Tutorial license So you should be free to do whatever you want with it, I think. :slight_smile:
  2. Initially the idea was for it to be as simple as possible, so it might be a good idea to just fork and do your changes. Then depending on what changes you have in mind, we will simply see if they make sense to bring back to my repo (and how that would work with the license).
  3. It’s “finished” for now, but I will update it when I eventually run into a bug or need some new widget! :slight_smile:
3 Likes

Great library, but i cant get it to work. When i click on the input field nothing happens and it prints “Empty” in the field, not the default text thats added.

I have added a input template from dirtylarry in my .gui file and named it “input_field”.

I have mouse_pressed and touch_multi as input_bindings.

local dirtylarry = require "dirtylarry/dirtylarry"

function init(self)
    msg.post(".", "acquire_input_focus")
end

function on_input(self, action_id, action)
    self.input_default = dirtylarry:input("input_field", action_id, action, gui.KEYBOARD_TYPE_DEFAULT, "Default text")
end

How does your game.input_binding look? :slight_smile:

Here is a good base for getting dirtylarry to work:

It looks like this now.

Ok, found it, the action names need to be the same as specified in the dirtylarry.lua file.

1 Like

Dirtylarry only respond to action.release meaning that if you press outside the button A or on button B then hovers button A and release it will register that you clicked button A. This isn’t the expected behavior from buttons, you expect to click and release on the same button.

If you press a button and move the cursor over it the button will swap image between pressed and normal. In other words, it looks like you are releasing and pressing the button repeatedly even though you are not. :slight_smile:

Great job on the library @sven!

1 Like

Just found this extension, seems it’s really good for making UI. But I have a little question about showing/hiding buttons.

I have the following code (show some buttons if button_toggle_turret1 is clicked and hide buttons if user clicks anywhere):

function on_input(self, action_id, action)
dirtylarry:button("button_toggle_turret1", action_id, action, function ()
    	local enabled = not gui.is_enabled(gui.get_node("Turret1"))
    	gui.set_enabled(gui.get_node("Turret1"), enabled)
end)

if gui.is_enabled(gui.get_node("Turret1")) == true and action_id == hash("LMB") then
	gui.set_enabled(gui.get_node("Turret1"), disabled)
end 
end

It works just fine but just in editor’s build. In HTML5 I have the following problem: it executes showing and hiding of buttons just at the same time. When user clicks button to show some buttons - you already clicked, so buttons are hidden instantly. How to fix that? :slight_smile:

Here how it looks like in Defold editor (unfortunately cursor has not been recorded)
In HTML5 build, as I said, no buttons will appear if one clicks.

2 Likes

If i remember correctly dirty larry triggers on action.released. Since you have no filtering of action pressed/released you might see the behaviour you are describing.

Try adding and action.released to the condition for disabling Turret1, like:

if gui.is_enabled(gui.get_node("Turret1")) == true and action_id == hash("LMB") and action.released then
	gui.set_enabled(gui.get_node("Turret1"), disabled)
end

and see if that helps.

2 Likes

Thank you. But this doesn’t work :frowning:

Could you try this instead;

function on_input(self, action_id, action)
	local clicked_button = false
	dirtylarry:button("button_toggle_turret1", action_id, action, function ()
    	local enabled = not gui.is_enabled(gui.get_node("Turret1"))
    	gui.set_enabled(gui.get_node("Turret1"), enabled)
    	clicked_button = true
	end)
	
	if not clicked_button then
		if gui.is_enabled(gui.get_node("Turret1")) and action_id == hash("LMB") and action.released then
			gui.set_enabled(gui.get_node("Turret1"), disabled)
		end 
	end
end

(This works for me, but I might misunderstand what you are trying to achieve. :slight_smile: )

Also, I realise that the dirtylarry API for buttons might need to return a boolean if the button was clicked or not also. Would make this example somewhat easier.

2 Likes

This also doesn’t work with HTML5. Maybe the problem is in something different? But don’t know, I’ve tried to set a timer to if statement (so the if statement starts in few seconds after showing buttons. i.e. 1. Click 2. buttons appear 3. Buttons disappear after few seconds) and everything works, so I think the problem is really in executing both commands at the same time.

GUI:

Defold editor (everything’s fine):

HTML5:

My minimal test seems to work fine on HTML5 as far as I can tell. Would you mind inviting me to your project so I could try to debug? You can add me with this email: sven.andersson@king.com

1 Like

Invitation sent.

1 Like

In your GUI.gui_script, right after you require dirtylarry add this line:

dirtylarry.action_id_touch = hash("LMB")

and in your game.input_binding remove your entry for “touch”.

Otherwise you will be getting multiple clicks each frame, one for each mouse trigger you have set. :slight_smile:

2 Likes

Oh, thank you! Now everything works perfectly! :slight_smile: So using hashes for the same key/mouse triggers is not a good idea. My bad.

1 Like

I guess it depends on what you want to do!
Your code was using both the “LMB” and “touch” triggers for the same logic, so in your case it makes sense to just have one, to not make things unnecessarily complicated. :slight_smile:

2 Likes

Don’t you think that it would be better not to stick tightly to the texture names in the code, for example, the “button_normal, button_pressed”, but to make 2 box-nodes in the template and switch them if necessary. In this case, the designer can arbitrarily change the texture and have several buttons with different textures at the same time, without modifying the code.
And yet - in the hit_test, you check local touch = action_id == dirtylarry.action_id_touch, but when you move the mouse (pressed) over the button, the action_id == nil comes over time after time and the button twitches.

2 Likes

Hey, these are good points! I have been wanting to do a new incarnation of dirtylarry for quite some time, but never gotten around to do it. There are certainly a lot of things that could be looked into and rethought.

The thing is, I personally haven’t run into any huge blockers for what I use it for (which is mainly debug GUI) that has pushed me over the edge to do a rewrite. :slight_smile: There are more mature GUI libraries available, such as gooey, that are aimed at more production level GUI.

That said, I still think dirtylarry still hits a good mixture of ease of use and functionality for “quick and dirty GUIs”. I don’t think I will make any huge changes to dirtylarry in the nearest future, but if someone wants to take a stab and make it easier to make themes/skins for it while keeping the “immediate mode”-ish API, then I’m all for it!

2 Likes

Yes, I like the dirtylarry just for the combination of ease of use and functionality. And use it as GUI-tutorial :slight_smile: Thank you for dirtylarry!

3 Likes