Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions features/cutscene/cutscene_controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,21 @@ function Public.register_running_cutscene(player_index, identifier, final_transi
local flow = Gui.add_top_element(player, { type = 'flow', name = flow_name })
running_cutscene.btn = flow

local btn = flow.add {type = 'sprite-button', name = skip_btn_name, caption = 'Skip cutscene', style = Styles.default_top_element.name }
local btn = flow.add {type = 'sprite-button', caption = 'Skip cutscene', style = Styles.default_top_element.name, tags = { [Gui.event_tag] = skip_btn_name } }
btn.style.minimal_height = 36
btn.style.maximal_height = 36
btn.style.minimal_width = 150
btn.style.font = 'default-large-bold'
btn.style.font_color = {r = 255, g = 215, b = 0}

local back_btn = flow.add {type = 'sprite-button', name = backward_btn_name, caption = 'Go back', style = Styles.default_top_element.name }
local back_btn = flow.add {type = 'sprite-button', caption = 'Go back', style = Styles.default_top_element.name, tags = { [Gui.event_tag] = backward_btn_name } }
back_btn.style.minimal_height = 36
back_btn.style.maximal_height = 36
back_btn.style.minimal_width = 100
back_btn.style.font = 'default-large-bold'
back_btn.style.font_color = {r = 255, g = 215, b = 0}

local forward_btn = flow.add {type = 'sprite-button', name = forward_btn_name, caption = 'Go forward', style = Styles.default_top_element.name }
local forward_btn = flow.add {type = 'sprite-button', caption = 'Go forward', style = Styles.default_top_element.name, tags = { [Gui.event_tag] = forward_btn_name } }
forward_btn.style.minimal_height = 36
forward_btn.style.maximal_height = 36
forward_btn.style.minimal_width = 100
Expand All @@ -273,9 +273,9 @@ function Public.register_running_cutscene(player_index, identifier, final_transi
local auto_play_cutscene_checkbox = flow.add
{
type = 'checkbox',
name = auto_play_cutscene_checkbox_name,
caption = 'Auto play cutscene',
state = Settings.get(player_index, auto_play_cutscene_setting_name)
state = Settings.get(player_index, auto_play_cutscene_setting_name),
tags = { [Gui.event_tag] = auto_play_cutscene_checkbox_name },
}

auto_play_cutscene_checkbox.style.top_margin = 8
Expand Down
22 changes: 6 additions & 16 deletions features/gui/admin_panel/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function Public.get_main_frame(player)
name = main_frame_name,
direction = 'vertical',
style = 'frame',
tags = { [Gui.event_tag] = main_frame_name },
}
frame.auto_center = true
player.opened = frame
Expand Down Expand Up @@ -82,11 +83,11 @@ function Public.get_main_frame(player)

flow.add {
type = 'sprite-button',
name = close_button_name,
sprite = 'utility/close',
clicked_sprite = 'utility/close_black',
style = 'close_button',
tooltip = {'gui.close-instruction'}
tooltip = {'gui.close-instruction'},
tags = { [Gui.event_tag] = close_button_name },
}
end

Expand Down Expand Up @@ -137,6 +138,7 @@ function Public.update_top_button(player)
name = main_button_name,
sprite = 'item/power-armor-mk2',
tooltip = {'admin_panel.info_tooltip'},
tags = { [Gui.event_tag] = main_button_name },
})
button.visible = player.admin
end
Expand Down Expand Up @@ -183,20 +185,8 @@ Event.add(defines.events.on_player_joined_game, function(event)
end
end)

Event.add(defines.events.on_gui_closed, function(event)
local element = event.element
if not (element and element.valid) then
return
end

local player = game.get_player(event.player_index)
if not (player and player.valid) then
return
end

if element.name == main_frame_name then
Public.toggle_main_button(player)
end
Gui.on_custom_close(main_frame_name, function(event)
Public.toggle_main_button(event.player)
end)

Gui.allow_player_to_toggle_top_element_visibility(main_button_name)
Expand Down
8 changes: 4 additions & 4 deletions features/gui/admin_panel/lua_console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ pages[#pages +1] = {
type = 'sprite-button',
sprite = 'utility/scripting_editor_icon',
tooltip = '[font=default-bold]Lua console[/font]',
name = main_button_name,
auto_toggle = true,
tags = { [Gui.event_tag] = main_button_name },
}

local function draw_gui(player)
Expand Down Expand Up @@ -54,9 +54,9 @@ local function draw_gui(player)

local button_flow = canvas.add { type = 'flow', direction = 'horizontal' }
Gui.add_pusher(button_flow)
button_flow.add { type = 'button', name = clear_button_name, style = 'red_back_button', caption = 'Clear' }
local dry_run = button_flow.add { type = 'button', name = dry_run_button_name, style = 'forward_button', caption = 'Dry run' }
local confirm = button_flow.add { type = 'button', name = confirm_button_name, style = 'confirm_double_arrow_button', caption = 'Confirm', tooltip = 'Run input code' }
button_flow.add { type = 'button', style = 'red_back_button', caption = 'Clear', tags = { [Gui.event_tag] = clear_button_name } }
local dry_run = button_flow.add { type = 'button', tags = { [Gui.event_tag] = dry_run_button_name }, style = 'forward_button', caption = 'Dry run' }
local confirm = button_flow.add { type = 'button', tags = { [Gui.event_tag] = confirm_button_name }, style = 'confirm_double_arrow_button', caption = 'Confirm', tooltip = 'Run input code' }
Gui.set_style(confirm, { left_margin = -9 })

Gui.set_data(dry_run, { input = input, output = output })
Expand Down
47 changes: 18 additions & 29 deletions features/gui/admin_panel/map_manager.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
local AdminPanel = require 'features.gui.admin_panel.core'
local Event = require 'utils.event'
local Gui = require 'utils.gui'
local math = require 'utils.math'
local Surface = require 'features.gui.admin_panel.functions'.surface
Expand Down Expand Up @@ -27,15 +26,15 @@ pages[#pages +1] = {
type = 'sprite-button',
sprite = 'utility/surface_editor_icon',
tooltip = '[font=default-bold]Map manager[/font]',
name = main_button_name,
auto_toggle = true,
tags = { [Gui.event_tag] = main_button_name },
}

local function make_button(parent, params)
local button = parent.add {
type = 'button',
caption = params.caption,
name = params.name,
tags = params.tags,
tooltip = params.tooltip,
}
Gui.set_style(button, {
Expand All @@ -51,7 +50,7 @@ local function make_slider(parent, params)
Gui.set_style(button, { width = 150 })
params.slider.value = math.clamp(params.value, params.slider.minimum_value, params.slider.maximum_value)
local slider = flow.add(params.slider)
slider.tags = { name = slider_tag_name }
slider.tags = { [Gui.event_tag] = slider_tag_name }
slider.tooltip = string.format(params.format, slider.slider_value)
Gui.set_style(slider, { width = 250 })
local label = flow.add { type = 'label', caption = string.format(params.format, params.value), tooltip = params.tooltip or 'Current value' }
Expand Down Expand Up @@ -80,7 +79,7 @@ local function draw_gui(player)
make_slider(row_1, {
button = {
type = 'button',
name = on_performance_speed,
tags = { [Gui.event_tag] = on_performance_speed },
caption = 'Performance speed',
tooltip = {'command_description.performance_scale_set'},
},
Expand All @@ -96,7 +95,7 @@ local function draw_gui(player)
make_slider(row_1, {
button = {
type = 'button',
name = on_slow_down,
tags = { [Gui.event_tag] = on_slow_down },
caption = 'Slow down'
},
slider = {
Expand All @@ -111,7 +110,7 @@ local function draw_gui(player)
make_slider(row_1, {
button = {
type = 'button',
name = on_speed_up,
tags = { [Gui.event_tag] = on_speed_up },
caption = 'Speed up'
},
slider = {
Expand All @@ -128,7 +127,7 @@ local function draw_gui(player)
make_slider(row_2, {
button = {
type = 'button',
name = on_pollution_ageing,
tags = { [Gui.event_tag] = on_pollution_ageing },
caption = 'Ageing'
},
slider = {
Expand All @@ -144,7 +143,7 @@ local function draw_gui(player)
make_slider(row_2, {
button = {
type = 'button',
name = on_pollution_diffusion,
tags = { [Gui.event_tag] = on_pollution_diffusion },
caption = 'Diffusion ratio'
},
slider = {
Expand All @@ -160,7 +159,7 @@ local function draw_gui(player)
make_slider(row_2, {
button = {
type = 'button',
name = on_pollution_attack_modifier,
tags = { [Gui.event_tag] = on_pollution_attack_modifier },
caption = 'Atk. modifier'
},
slider = {
Expand All @@ -178,7 +177,7 @@ local function draw_gui(player)
make_slider(row_3, {
button = {
type = 'button',
name = on_evolution_value,
tags = { [Gui.event_tag] = on_evolution_value },
caption = 'Enemy evolution'
},
slider = {
Expand All @@ -194,7 +193,7 @@ local function draw_gui(player)
make_slider(row_3, {
button = {
type = 'button',
name = on_evolution_destroy_factor,
tags = { [Gui.event_tag] = on_evolution_destroy_factor },
caption = 'Destroy factor'
},
slider = {
Expand All @@ -211,7 +210,7 @@ local function draw_gui(player)
make_slider(row_3, {
button = {
type = 'button',
name = on_evolution_time_factor,
tags = { [Gui.event_tag] = on_evolution_time_factor },
caption = 'Time factor'
},
slider = {
Expand All @@ -229,7 +228,7 @@ local function draw_gui(player)
make_slider(row_4, {
button = {
type = 'button',
name = on_map_chart,
tags = { [Gui.event_tag] = on_map_chart },
caption = 'Chart map'
},
slider = {
Expand All @@ -243,9 +242,9 @@ local function draw_gui(player)
})
local table_4 = row_4.add { type = 'table', column_count = 3 }
for _, button in pairs({
{ name = on_map_hide, caption = 'Hide all' },
{ name = on_map_reveal, caption = 'Reveal all' },
{ name = on_map_rechart, caption = 'Re-chart all' },
{ tags = { [Gui.event_tag] = on_map_hide }, caption = 'Hide all' },
{ tags = { [Gui.event_tag] = on_map_reveal }, caption = 'Reveal all' },
{ tags = { [Gui.event_tag] = on_map_rechart }, caption = 'Re-chart all' },
}) do make_button(table_4, button) end
end

Expand All @@ -261,18 +260,8 @@ Gui.on_click(main_button_name, function(event)
end
end)

Event.add(defines.events.on_gui_value_changed, function(event)
local element = event.element
if not (element and element.valid) then
return
end

local tag = element.tags and element.tags.name
if not tag or tag ~= slider_tag_name then
return
end

local data = Gui.get_data(element)
Gui.on_value_changed(slider_tag_name, function(event)
local data = Gui.get_data(event.element)
data.slider.tooltip = string.format(data.format, data.slider.slider_value)
end)

Expand Down
Loading