Best way to do this in GUI?

I know there are a few GUI extensions, but I’m not intimately familiar with them to know which is the best to use. Or just to use the default Defold GUI API.

So in between rounds I want to offer upgrades for purchase. Like this:

Player chooses the type of upgrade they want to get. There will be various costs associated with them.

Then after clicking on it…the Type of upgrades go away and are replaced by a screen offering them random items from that class of upgrade where they can choose 1.

I’ll also want to make fancy shaders for them (think of it like a balatro upgrade system…it’s different but you get the gist).

Any suggestions for doing this that will make the code easy to maintain but also have it be flexible for what I’m trying to do. Yes I can just do it in the default GUI api but was wondering if there are GUI extensions I should use instead.

You mean something with supporting selections or just show/hide scenes? if just show/hide scenes then Monarch is a good one

Something that will make it easy to show the selections and manage them easily.

I’m doing something very similar to this with the default GUI. The player gets to choose a weapon upgrade after leveling up. I store the upgrades in a module and randomly select ones that are available.

For showing/hiding gui nodes, I use scale. Not sure if it’s the best way, but it works for me.

Example

local function hide_weapon_options(self)
	for i = 1, 3 do
		gui.set_scale(self.effect_option[i], vmath.vector3())
	end
end

To show the weapon options

local function show_weapon_options(self)
    -- Make sure table is reset
	self.selection = {}
	-- Prepare copy of weapon index
	local index_copy = {}

	-- Add available weapons to index copy, weapons are stored in a module
	for i = 1, #weapons.index do
		if weapons.index[i].available then
			index_copy[i] = weapons.index[i]
		end
	end

	-- Randomly select 3 weapons
	for i = 1, max_selection do
		local random = math.random(1, #index_copy)
		self.selection[i] = index_copy[random]

		-- Remove weapon from copy to avoid duplicates
		table.remove(index_copy, random)

        -- Store the name when picking it later
		local hash = self.selection[i].hash
        -- Info for the gui nodes
		local id, effect, description = weapons.get_effects(hash)

        -- To use later for input selection
		self.selection[i].id = id

		-- print(effect, description)
		gui.set_text(gui.get_node("effect" .. i), effect)
		gui.set_text(gui.get_node("description" .. i), description)
		gui.set_scale(self.effect_option[i], vmath.vector3(1,1,1))
	end	
end

Selecting an upgrade

local function on_touch_release(self, action)
	for i = 1, #self.effect_option do
		if gui.pick_node(self.effect_option[i], action.x, action.y) then
			add_weapon_effect(self, i)
		end
	end
end

function on_input(self, action_id, action)
	if action_id == TOUCH and action.released then
		on_touch_release(self, action)
	end
end
1 Like

Thanks. I like the module idea.

Modules are very useful. I also have each of the weapons as its own module. This makes it easy to update the weapon - gun.add() and gun.upgrade(effect_id).

Ok, I just looked at monarch. It looks pretty cool to me. I like the popup idea. That may work for what I’m doing. I’ll check it out. Thanks.

1 Like