Created
November 12, 2019 18:55
-
-
Save Hornwitser/0bc80085de3893ae5c0c24fc08d5871b to your computer and use it in GitHub Desktop.
Client specific GUI update POC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local mod_gui = require("mod-gui") | |
local current_player_index | |
local name_element | |
local tick_element | |
script.on_init(function() | |
current_player_index = 0 | |
end) | |
script.on_event(defines.events.on_player_joined_game, function(event) | |
local flow = mod_gui.get_frame_flow(game.players[event.player_index]) | |
if flow["info-frame"] then | |
if current_player_index == nil then | |
print("==== player index " .. event.player_index) | |
current_player_index = event.player_index | |
name_element = flow["info-frame"]["info-name"] | |
tick_element = flow["info-frame"]["info-tick"] | |
end | |
else | |
local frame = flow.add{ | |
type = "frame", | |
name = "info-frame", | |
direction = "vertical", | |
} | |
local name = frame.add{type="label", name="info-name", caption="(none)"} | |
local tick = frame.add{type="label", name="info-tick"} | |
if current_player_index == nil then | |
print("==== player index " .. event.player_index) | |
current_player_index = event.player_index | |
name_element = name | |
tick_element = tick | |
end | |
end | |
end) | |
script.on_nth_tick(1, function() | |
if name_element then | |
tick_element.caption = tostring(game.tick) | |
end | |
end) | |
script.on_event(defines.events.on_selected_entity_changed, function(event) | |
if | |
current_player_index ~= event.player_index | |
then | |
return | |
end | |
local player = game.players[event.player_index] | |
local entity = player.selected | |
if entity then | |
name_element.caption = player.selected.name | |
else | |
name_element.caption = "(none)" | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment