I want to make simple gui window, just sprite, which changes from a global variable
This gui must be opened when I click on some entity
I try to find how to do it, but I don't know where to start to learn how to make gui
How to start creating a gui
Re: How to start creating a gui
I've made something like that for minime -- a very basic GUI with one button that will open or close the actual menu, which is just a number of buttons arranged vertically.SLywnow wrote: Wed Aug 19, 2020 1:19 am I want to make simple gui window, just sprite, which changes from a global variable
This gui must be opened when I click on some entity
For each player, the GUI needs to be defined first:
Code: Select all
local gui = player.gui.top
------------------------------------------------------------------------------------
-- Define GUI
gui.add{
type = "flow",
name = "minime_gui",
enabled = true,
direction = "vertical"
}
Code: Select all
gui = gui["minime_gui"]
------------------------------------------------------------------------------------
-- Toggle button
gui.add{
type = "sprite-button",
name = "minime_toggle_list",
caption = {"minime-GUI.gui-name"},
tooltip = {"minime-GUI.gui-name-tooltip"},
enabled = true,
style = "minime_toggle_button"
}
Code: Select all
------------------------------------------------------------------------------------
-- Frame
gui.add{
type = "frame",
name = "minime_character_list",
caption = {"minime-GUI.gui-name-tooltip"},
direction = "vertical",
visible = global.player_data[player.index].show_character_list,
}
Code: Select all
local buttons = gui["minime_character_list"]
------------------------------------------------------------------------------------
-- If the player's character is not on our list, let's just assume it's a valid cha-
-- racter and create a button with a warning as tooltip.
if some_condition == true then
buttons.add{
type = "button",
name = "minime_characters_" .. last_character,
caption = minime.loc_name(player.character),
enabled = true,
style = "minime_button_on",
}
end
Code: Select all
-- Create normal buttons for known characters from our list
for char, loc_name in pairs(global.minime_characters) do
buttons.add{
type = "button",
name = "minime_characters_" .. char,
caption = loc_name,
enabled = true,
style = "minime_button_on",
}
end
Code: Select all
-- Turn other buttons red if button for current character should be removed
if some_condition == true then
for _, button in ipairs(buttons.children) do
button.style = "minime_button_warning"
button.tooltip = {"minime-GUI.remove-character-button-warning",
minime.loc_name(player.character)}
end
-- Turn button for current character off
else
for _, button in ipairs(buttons.children) do
if other_condition == true then
button.style = "minime_button_off"
button.tooltip = table_size(global.minime_characters) == 2 and
{"minime-GUI.disabled-button-tooltip"} or
{"minime-GUI.disabled-button-tooltip-plural"}
button.enabled = false
break
end
end
end
Code: Select all
local buttons = gui["minime_gui"]["minime_character_list"]
for _, button in pairs(buttons) do
…
end
Finally an example of button-style definitions I use in data.lua:
Code: Select all
data.raw['gui-style'].default.minime_button_off = {
type = "button_style",
parent = "button",
padding = 4,
}
data.raw['gui-style'].default.minime_button_on = {
type = "button_style",
parent = "green_button",
padding = 4,
I'm not aware of a "How to make a GUI" tutorial, but you should definitely have a look at the documentation of LuaGui and LuaGuiElement!I try to find how to do it, but I don't know where to start to learn how to make gui
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!
Re: How to start creating a gui
Thank you very much!