DirtyLarry - A quick and dirty GUI library

#1

dirtylarry is a tiny Defold GUI library that includes buttons, input fields, checkboxes and radio buttons.

  • Both the implementation and usage is extremely simple. Add one of the supplied GUI template files to your scene, add one* line of Lua code and your done.
  • It’s aimed at debugging purposes; when you need a button but don’t want to rewrite the button code for the 100th time.

(*one line of Lua for each GUI node + one require call :slight_smile: )

More details here: https://github.com/andsve/dirtylarry

26 Likes

How can i create a textbox and a phone keyboard to use in my quiz game using lua?
#2

It’s magnificent!

2 Likes

#3

Hi @sven!
I am thinking of using dirtylarry in my project, buuut~ i have a couple questions first! (would be very happy if you could answer~)
1st - Whats dirtylarry’s licesing terms? o-o cause…you just posted it but idk if i can just copy and paste in my project without a worry, if i can modify it or whatever o-o
2nd - If I do end up using dirtylarry, i will need to write a couple new elements for it (such as dropdown lists, normal lists, lists with scrollbars, progress bars and such), so, am I allowed to write those and create my own variant of dirtylarry, or can i like, send you the modifications and such via Github?
3rd - Are you still working on this or, is it like, a somewhat finished project for you? o-o
XD sorry for the long post and lots of questions!!! and thanks for the work, i like dirty larry very much :smiley:

0 Likes

Any existing gui elements?
#4

@sven is back from vacation on monday, so right now he might be slow to respond… For what it’s worth, I think you can use it however you like. But Sven will need to confirm that as he’s the owner.

0 Likes

#5

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

#6
  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

#7

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
0 Likes

#8

How does your game.input_binding look? :slight_smile:

Here is a good base for getting dirtylarry to work:

0 Likes

#9

It looks like this now.

0 Likes

#10

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

1 Like

#11

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

#12

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

Reactor Defence (a game for CoronaDefold game jam)
#13

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

#14

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

0 Likes

#15

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

#16

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:

0 Likes

#17

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

#18

Invitation sent.

1 Like

#19

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

#20

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