Skip to content

Commit

Permalink
Fix crash when opening the universe explorer via keybind or shortcut …
Browse files Browse the repository at this point in the history
…and then clicking on a zone
  • Loading branch information
Quezler committed Dec 20, 2023
1 parent 1df76ec commit ef68e53
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 35 deletions.
84 changes: 50 additions & 34 deletions mods/se-core-miner-output-helper/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,44 +45,12 @@ function get_mining_time(fragment_name)
return game.entity_prototypes[fragment_name].mineable_properties.mining_time
end

script.on_event(defines.events.on_gui_click, function(event)
if not event.element.valid then return end

local player = game.get_player(event.player_index)

local root = Zonelist.get(player)
if not root then return end

local parent = Util.get_gui_element(root, Zonelist.path_zone_data_flow)
if not parent then return end

local container = parent[Zonelist.name_zone_data_container_frame]
local content = container[Zonelist.name_zone_data_content_scroll_pane]

-- `Zonelist.make_zone_data_section` regenerates when the universe explorer initially opens,
-- so here we will inject our core miner flow for the liftime of the gui once and then update.
if event.element.name == Zonelist.name_button_overhead_explorer then
content.add{
type = "checkbox",
name = "coremining-header",
caption = {"space-exploration.zonelist-coremining-header"},
state = false,
tags = {action=Zonelist.action_zone_data_content_header, name="coremining"},
style = "se_zonelist_zone_data_header_checkbox"
}
content.add{
type = "flow",
name = "coremining",
direction = "vertical",
style = "se_zonelist_zone_data_content_sub_flow"
}
end

function update_content_for_player(content, player)
local coremining_header = content["coremining-header"]
local coremining = content.coremining

-- grab the zone_index from the "View Surface" button
local button_flow = parent[Zonelist.name_zone_data_bottom_button_flow]
local button_flow = content.parent.parent[Zonelist.name_zone_data_bottom_button_flow]
local view_button = button_flow[Zonelist.name_zone_data_view_surface_button]
local zone_index = view_button.tags.zone_index

Expand Down Expand Up @@ -135,4 +103,52 @@ script.on_event(defines.events.on_gui_click, function(event)
if zone.core_seam_positions then
assert(table_size(zone.core_seam_positions) == math.floor(Zone_get_core_seam_count(zone)))
end
end

script.on_event(defines.events.on_gui_opened, function(event)
if not event.element then return end
if event.element.name ~= Zonelist.name_root then return end

local root = event.element

local parent = Util.get_gui_element(root, Zonelist.path_zone_data_flow)
if not parent then return end

local container = parent[Zonelist.name_zone_data_container_frame]
local content = container[Zonelist.name_zone_data_content_scroll_pane]

content.add{
type = "checkbox",
name = "coremining-header",
caption = {"space-exploration.zonelist-coremining-header"},
state = false,
tags = {action=Zonelist.action_zone_data_content_header, name="coremining"},
style = "se_zonelist_zone_data_header_checkbox"
}
content.add{
type = "flow",
name = "coremining",
direction = "vertical",
style = "se_zonelist_zone_data_content_sub_flow"
}

local player = game.get_player(event.player_index)
update_content_for_player(content, player)
end)

script.on_event(defines.events.on_gui_click, function(event)
if not event.element.valid then return end

local player = game.get_player(event.player_index)

local root = Zonelist.get(player)
if not root then return end

local parent = Util.get_gui_element(root, Zonelist.path_zone_data_flow)
if not parent then return end

local container = parent[Zonelist.name_zone_data_container_frame]
local content = container[Zonelist.name_zone_data_content_scroll_pane]

update_content_for_player(content, player)
end)
2 changes: 1 addition & 1 deletion mods/se-core-miner-output-helper/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "se-core-miner-output-helper",
"title": "Space Exploration - core miner output helper",
"description": "Hover over any core miner (or look in the universe explorer) to get the fragments per second for that surface.",
"version": "1.0.5",
"version": "1.0.6",
"author": "Quezler",
"factorio_version": "1.1",
"dependencies": [
Expand Down

0 comments on commit ef68e53

Please sign in to comment.