diff --git a/VERSION b/VERSION index ef52a64..f905682 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.6 +0.4.7 diff --git a/evoGUI.lua b/evoGUI.lua index 6b6e349..7df027f 100644 --- a/evoGUI.lua +++ b/evoGUI.lua @@ -5,6 +5,7 @@ require "value_sensors.kill_count" require "value_sensors.play_time" require "value_sensors.player_locations" require "value_sensors.pollution_around_player" +require "value_sensors.remote_sensor" require "settingsGUI" require "remote" diff --git a/locale/en/locale.cfg b/locale/en/locale.cfg index 96d4a3f..a0c9a34 100644 --- a/locale/en/locale.cfg +++ b/locale/en/locale.cfg @@ -78,3 +78,8 @@ err_settings_whatsettings=__1__ called for settings-less sensor! err_needplayername=[EvoGUI] Need a player name! err_nosuchplayer=[EvoGUI] No such player: __1__! err_noplayerdata=[EvoGUI] No player data for __1__! + +err_nosensorname=[EvoGUI] Missing a sensor name! +err_nosensortext=[EvoGUI] Missing sensor text for __1__! +err_nosensorcaption=[EvoGUI] Missing caption text for __1__! +err_nosensorfound=[EvoGUI] No sensor was previously created matching the name __1__! Create a sensor first. diff --git a/remote.lua b/remote.lua index fa704b9..c8968e5 100644 --- a/remote.lua +++ b/remote.lua @@ -31,11 +31,76 @@ local function remote_rebuild(player_name) global.evogui[player.name].version = "" end +-- +-- Creates a sensor managed by a remote interface (another mod or script) +-- sensor_name: internal name of the sensor. Should be unique. +-- sensor_text: Text to display in the active gui +-- sensor_caption: Sensor setting name in the EvoGUI settings panel +-- sensor_color: Font color of the text to display in the active gui, optional, may be nil +-- example: remote.call("EvoGUI", "create_remote_sensor", "mymod_my_sensor_name", "Text: Lorem Ipsum", "[My Mod] Lorem Ipsum Text") +local function create_remote_sensor(sensor_name, sensor_text, sensor_caption, sensor_color) + if not sensor_name then + evogui.log({"err_nosensorname"}) + return + end + + if not sensor_text then + evogui.log({"err_nosensortext", sensor_name}) + return + end + + if not sensor_caption then + evogui.log({"err_nosensorcaption", sensor_name}) + return + end + + RemoteSensor.new(sensor_name, sensor_text, sensor_caption, sensor_color) +end + +-- +-- Updates a sensor managed by a remote interface +-- sensor_name: internal name of the sensor. The sensor should have been previously created. +-- sensor_text: Text to display in the active gui +-- sensor_color: Font color of the text to display in the active gui, optional, may be nil +-- example: remote.call("EvoGUI", "update_remote_sensor", "mymod_my_sensor_name", "Text: Lorem Ipsum") +local function update_remote_sensor(sensor_name, sensor_text, sensor_color) + if not sensor_name then + evogui.log({"err_nosensorname"}) + return + end + + if not sensor_text then + evogui.log({"err_nosensortext", sensor_name}) + return + end + + local sensor = RemoteSensor.get_by_name(sensor_name) + if not sensor then + evogui.log({"err_nosensorfound", sensor_name}) + return + end + + sensor["line"] = sensor_text + if sensor_color then + sensor["color"] = sensor_color + end +end + interface = { rebuild = function(player_name) local status, err = pcall(remote_rebuild, player_name) if err then evogui.log({"err_generic", "interface.rebuild", err}) end + end, + + create_remote_sensor = function(sensor_name, sensor_text, sensor_caption, sensor_color) + local status, err = pcall(create_remote_sensor, sensor_name, sensor_text, sensor_caption, sensor_color) + if err then evogui.log({"err_generic", "remote.create_remote_sensor", err}) end + end, + + update_remote_sensor = function(sensor_name, sensor_text, sensor_color) + local status, err = pcall(update_remote_sensor, sensor_name, sensor_text, sensor_color) + if err then evogui.log({"err_generic", "remote.update_remote_sensor", err}) end end } diff --git a/value_sensors/remote_sensor.lua b/value_sensors/remote_sensor.lua new file mode 100644 index 0000000..b23bdb0 --- /dev/null +++ b/value_sensors/remote_sensor.lua @@ -0,0 +1,25 @@ +require "template" + +RemoteSensor = {} +function RemoteSensor.new(name, line, caption, color) + local sensor = ValueSensor.new("remote_sensor_" .. name) + sensor["line"] = line + sensor["display_name"] = caption + sensor["color"] = color + + function sensor:set_line(text) + self.line = text + end + + function sensor:get_line() + return self.line + end + + ValueSensor.register(sensor) +end + +function RemoteSensor.get_by_name(name) + return ValueSensor.get_by_name("remote_sensor_" .. name) +end + +return RemoteSensor diff --git a/value_sensors/template.lua b/value_sensors/template.lua index 47ab6d6..aea25c1 100644 --- a/value_sensors/template.lua +++ b/value_sensors/template.lua @@ -9,6 +9,7 @@ function ValueSensor.new(name) ["name"] = name, ["display_name"] = { "sensor."..name..".name" }, ["format_key"] = "sensor."..name..".format", + ["color"] = { r = 255, g = 255, b = 255 }, } function sensor:get_line() @@ -28,6 +29,7 @@ function ValueSensor.new(name) self.settings = sensor_settings owner[self.name].caption = self:get_line() + owner[self.name].style.font_color = self.color end function sensor:delete_ui(owner)