This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9: the 0.3 update.
- Loading branch information
Showing
11 changed files
with
306 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
data:extend({ | ||
{ | ||
type = "font", | ||
name = "evoGUI_small_font", | ||
from = "default", | ||
size = 10, | ||
}, | ||
}) | ||
|
||
local evoGUI_small_button_style = { | ||
type = "button_style", | ||
parent = "button_style", | ||
font = "evoGUI_small_font", | ||
scalable = false, | ||
width = 18, | ||
height = 18, | ||
top_padding = 0, | ||
bottom_padding = 0, | ||
left_padding = 0, | ||
right_padding = 0, | ||
} | ||
|
||
data.raw["gui-style"].default["evoGUI_small_button_style"] = evoGUI_small_button_style |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,145 @@ | ||
require "defines" | ||
require "value_sensors.day_time" | ||
require "value_sensors.evolution_factor" | ||
require "value_sensors.play_time" | ||
require "settingsGUI" | ||
|
||
if not evogui then evogui = {} end | ||
if not evogui.on_click then evogui.on_click = {} end | ||
|
||
evogui.update_delay = 60 -- ticks to wait between each GUI update | ||
local EXPECTED_VERSION = "0.3.0" | ||
|
||
|
||
function evogui.create_player_globals(player) | ||
if not global.evogui then global.evogui = {} end | ||
if not global.evogui[player.name] then global.evogui[player.name] = {} end | ||
local player_settings = global.evogui[player.name] | ||
|
||
if not player_settings.version then player_settings.version = "" end | ||
if not player_settings.always_visible then | ||
player_settings.always_visible = { | ||
["evolution_factor"] = true, | ||
["play_time"] = true, | ||
} | ||
end | ||
if not player_settings.in_popup then | ||
player_settings.in_popup = { | ||
["day_time"] = true, | ||
} | ||
end | ||
if not player_settings.popup_open then player_settings.popup_open = false end | ||
end | ||
|
||
|
||
function evogui.create_sensor_display(player) | ||
local root = player.gui.top.evoGUI | ||
local destroyed = false | ||
if root and global.evogui[player.name].version ~= EXPECTED_VERSION then | ||
player.gui.top.evoGUI.destroy() | ||
destroyed = true | ||
end | ||
|
||
if not root or destroyed then | ||
local root = player.gui.top.add{type="frame", name="evoGUI", direction = "horizontal", style="outer_frame_style"} | ||
|
||
local action_buttons = root.add{type="flow", name="action_buttons", direction = "vertical", style="description_flow_style"} | ||
action_buttons.add{type="button", name="evoGUI_popup", caption="+", style="evoGUI_small_button_style"} | ||
action_buttons.add{type="button", name="evoGUI_settings", caption="s", style="evoGUI_small_button_style"} | ||
|
||
local sensor_flow = root.add{type="flow", name="sensor_flow", direction = "vertical", style="description_flow_style"} | ||
sensor_flow.add{type="flow", name="always_visible", direction = "vertical", style="description_flow_style"} | ||
sensor_flow.add{type="flow", name="in_popup", direction = "vertical", style="description_flow_style"} | ||
|
||
global.evogui[player.name].version = EXPECTED_VERSION | ||
end | ||
end | ||
|
||
|
||
local function update_gui() | ||
function evogui.update_gui() | ||
if (game.tick % evogui.update_delay) == 0 then | ||
for i, player in ipairs(game.players) do | ||
evogui.create_or_update(player) | ||
evogui.create_player_globals(player) | ||
evogui.create_sensor_display(player) | ||
|
||
if player.gui.top.evoGUI then | ||
evogui.update_evolution(player.gui.top.evoGUI) | ||
evogui.update_run_time(player.gui.top.evoGUI) | ||
evogui.update_day_time(player.gui.top.evoGUI) | ||
local player_settings = global.evogui[player.name] | ||
|
||
local sensor_flow = player.gui.top.evoGUI.sensor_flow | ||
evogui.update_av(player, sensor_flow.always_visible) | ||
if player_settings.popup_open then | ||
evogui.update_ip(player, sensor_flow.in_popup) | ||
end | ||
end | ||
end | ||
end | ||
evogui.update_gui = update_gui | ||
|
||
local function create_or_update(player) | ||
if not player.gui.top.evoGUI then | ||
player.gui.top.add{type="frame", name="evoGUI", direction = "vertical"} | ||
player.gui.top.evoGUI.add{type="label", name="day_time"} | ||
player.gui.top.evoGUI.add{type="label", name="evolution_factor"} | ||
player.gui.top.evoGUI.add{type="label", name="run_time"} | ||
end | ||
|
||
if not player.gui.top.evoGUI.day_time or | ||
not player.gui.top.evoGUI.evolution_factor or | ||
not player.gui.top.evoGUI.run_time then | ||
player.gui.top.evoGUI.destroy() | ||
|
||
function evogui.update_av(player, element) | ||
local av_settings = global.evogui[player.name].always_visible | ||
|
||
for _, sensor in ipairs(evogui.value_sensors) do | ||
-- should we show it? | ||
if av_settings[sensor.name] ~= nil then | ||
-- is it not showing yet? | ||
if element[sensor.name] == nil then | ||
element.add{type="label", name=sensor.name} | ||
end | ||
-- and update its display | ||
element[sensor.name].caption = sensor:get_line() | ||
else | ||
-- is it showing? | ||
if element[sensor.name] ~= nil then | ||
element[sensor.name].destroy() | ||
end | ||
end | ||
end | ||
end | ||
evogui.create_or_update = create_or_update | ||
|
||
local function update_evolution(evoGUI) | ||
evoGUI.evolution_factor.caption = {"biter-evolution", string.format("%0.1f%%", game.evolution_factor * 100)} | ||
end | ||
evogui.update_evolution = update_evolution | ||
|
||
local function update_run_time(evoGUI) | ||
local run_time_seconds = math.floor(game.tick/60) | ||
local run_time_minutes = math.floor(run_time_seconds/60) | ||
local run_time_hours = math.floor(run_time_minutes/60) | ||
function evogui.update_ip(player, element) | ||
if not global.evogui[player.name].popup_open then return end | ||
|
||
evoGUI.run_time.caption = {"play-time", string.format("%d:%02d:%02d", | ||
run_time_hours, | ||
run_time_minutes % 60, | ||
run_time_seconds % 60)} | ||
local ip_settings = global.evogui[player.name].in_popup | ||
|
||
for _, sensor in ipairs(evogui.value_sensors) do | ||
-- should we show it? | ||
if ip_settings[sensor.name] ~= nil then | ||
-- is it not showing yet? | ||
if element[sensor.name] == nil then | ||
element.add{type="label", name=sensor.name} | ||
end | ||
-- and update its display | ||
element[sensor.name].caption = sensor:get_line() | ||
else | ||
-- is it showing? | ||
if element[sensor.name] ~= nil then | ||
element[sensor.name].destroy() | ||
end | ||
end | ||
end | ||
end | ||
evogui.update_run_time = update_run_time | ||
|
||
local function update_day_time(evoGUI) | ||
-- 0.5 is midnight; let's make days *start* at midnight instead. | ||
local day_time = math.fmod(game.daytime + 0.5, 1) | ||
|
||
local day_time_minutes = math.floor(day_time * 24 * 60) | ||
local day_time_hours = math.floor(day_time_minutes / 60) | ||
function evogui.on_click.evoGUI_popup(event) | ||
local player = game.get_player(event.player_index) | ||
local player_settings = global.evogui[player.name] | ||
|
||
local rounded_minutes = day_time_minutes - (day_time_minutes % 15) | ||
local root = player.gui.top.evoGUI | ||
|
||
local brightness = math.floor((1 - game.darkness) * 100) | ||
if player_settings.popup_open then | ||
-- close it | ||
player_settings.popup_open = false | ||
|
||
evoGUI.day_time.caption = {"", {"time-of-day", string.format("%d:%02d", day_time_hours, rounded_minutes % 60)}, " ", | ||
{"brightness", string.format("%d%%", brightness)}} | ||
for _, childname in ipairs(root.sensor_flow.in_popup.children_names) do | ||
root.sensor_flow.in_popup[childname].destroy() | ||
end | ||
|
||
root.action_buttons.evoGUI_popup.caption = "+" | ||
else | ||
-- open it | ||
player_settings.popup_open = true | ||
|
||
evogui.update_ip(player, root.sensor_flow.in_popup) | ||
root.action_buttons.evoGUI_popup.caption = "-" | ||
end | ||
end | ||
evogui.update_day_time = update_day_time |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "EvoGUI", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"title": "Evolution Factor Indicator", | ||
"author": "Octav \"narc\" Sandulescu", | ||
"contact": "[email protected]", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
biter-evolution=Biter evolution: __1__. | ||
play-time=Play time: __1__. | ||
time-of-day=It's __1__. | ||
brightness=Brightness: __1__. | ||
sensor.day_time.name=Time of day/sunlight | ||
sensor.day_time.format=It's __1__. Brightness: __2__. | ||
sensor.evolution_factor.name=Evolution factor | ||
sensor.evolution_factor.format=Biter evolution: __1__. | ||
sensor.play_time.name=Time played | ||
sensor.play_time.format=Play time: __1__. | ||
settings_always_visible=Always visible | ||
settings_in_popup=Visible in popup | ||
settings_close=Close |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
require "defines" | ||
|
||
if not evogui then evogui = {} end | ||
if not evogui.on_click then evogui.on_click = {} end | ||
|
||
if not global.evogui then global.evogui = {} end | ||
|
||
|
||
local function toggle_always_visible(event) | ||
local player = game.get_player(event.player_index) | ||
|
||
if event.element.name:sub(1,3) ~= "AV_" then | ||
error(string.format("toggle_always_visible called on the wrong thing: %s", event.element.name)) | ||
return | ||
end | ||
|
||
local always_visible = global.evogui[player.name].always_visible | ||
local sensor_name = event.element.name:sub(4,-1) | ||
if event.element.state then | ||
always_visible[sensor_name] = true | ||
else | ||
always_visible[sensor_name] = nil | ||
end | ||
end | ||
|
||
|
||
local function toggle_in_popup(event) | ||
local player = game.get_player(event.player_index) | ||
|
||
if event.element.name:sub(1,3) ~= "IP_" then | ||
error(string.format("toggle_in_popup called on the wrong thing: %s", event.element.name)) | ||
return | ||
end | ||
|
||
local in_popup = global.evogui[player.name].in_popup | ||
local sensor_name = event.element.name:sub(4,-1) | ||
if event.element.state then | ||
in_popup[sensor_name] = true | ||
else | ||
in_popup[sensor_name] = nil | ||
end | ||
end | ||
|
||
|
||
function evogui.on_click.evoGUI_settings(event) | ||
local player = game.get_player(event.player_index) | ||
if player.gui.center.evoGUI_settingsGUI then return end | ||
|
||
evogui.create_player_globals(player) | ||
local always_visible = global.evogui[player.name].always_visible | ||
local in_popup = global.evogui[player.name].in_popup | ||
|
||
local root = player.gui.center.add{type="frame", direction="vertical", name="evoGUI_settingsGUI"} | ||
local table = root.add{type="table", colspan=3} | ||
|
||
for _, sensor in ipairs(evogui.value_sensors) do | ||
local sensor_always_visible = always_visible[sensor.name] ~= nil | ||
local sensor_in_popup = in_popup[sensor.name] ~= nil | ||
|
||
table.add{type="label", caption=sensor.display_name} | ||
table.add{type="checkbox", name="AV_"..sensor.name, | ||
caption={"settings_always_visible"}, state=sensor_always_visible} | ||
table.add{type="checkbox", name="IP_"..sensor.name, | ||
caption={"settings_in_popup"}, state=sensor_in_popup} | ||
|
||
evogui.on_click["AV_"..sensor.name] = toggle_always_visible | ||
evogui.on_click["IP_"..sensor.name] = toggle_in_popup | ||
end | ||
|
||
local buttons = root.add{type="flow", direction="horizontal"} | ||
buttons.add{type="button", name="evoGUI_settings_close", caption={"settings_close"}} | ||
end | ||
|
||
function evogui.on_click.evoGUI_settings_close(event) | ||
local player = game.get_player(event.player_index) | ||
|
||
if player.gui.center.evoGUI_settingsGUI ~= nil then | ||
player.gui.center.evoGUI_settingsGUI.destroy() | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require "template" | ||
|
||
local sensor = ValueSensor.new("day_time", function(self) | ||
-- 0.5 is midnight; let's make days *start* at midnight instead. | ||
local day_time = math.fmod(game.daytime + 0.5, 1) | ||
|
||
local day_time_minutes = math.floor(day_time * 24 * 60) | ||
local day_time_hours = math.floor(day_time_minutes / 60) | ||
|
||
local rounded_minutes = day_time_minutes - (day_time_minutes % 15) | ||
|
||
local brightness = math.floor((1 - game.darkness) * 100) | ||
|
||
return {self.format_key, | ||
string.format("%d:%02d", day_time_hours, rounded_minutes % 60), | ||
string.format("%d%%", brightness)} | ||
end) | ||
|
||
function evogui.update_day_time(element) | ||
element.caption = sensor:get_line() | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "template" | ||
|
||
local sensor = ValueSensor.new("evolution_factor", function(self) | ||
return {self.format_key, string.format("%0.1f%%", game.evolution_factor * 100)} | ||
end) | ||
|
||
function evogui.update_evolution(element) | ||
element.caption = sensor:get_line() | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "template" | ||
|
||
local sensor = ValueSensor.new("play_time", function(self) | ||
local play_time_seconds = math.floor(game.tick/60) | ||
local play_time_minutes = math.floor(play_time_seconds/60) | ||
local play_time_hours = math.floor(play_time_minutes/60) | ||
|
||
return {self.format_key, | ||
string.format("%d:%02d:%02d", play_time_hours, play_time_minutes % 60, play_time_seconds % 60)} | ||
end) | ||
|
||
function evogui.update_play_time(element) | ||
element.caption = sensor:get_line() | ||
end |
Oops, something went wrong.