Regresssion cleanup: Text color as global setting

This commit is contained in:
Wuzzy 2015-07-15 06:37:32 +02:00
parent f31e92572e
commit 8fb08978f8
2 changed files with 15 additions and 14 deletions

View File

@ -24,31 +24,30 @@ Some usage examples:
## Settings
This mod can be configured via `minetest.conf`.
Currently, one setting is recognized:
Currently, these settings are recognized:
* `central_message_max`: Limit the number of messages displayed at once, by providing a number. Use `inf` here for no limit. Default: 7
* `central_message_color`: Set the message color of all messages. Value must be `ColorString` (see `lua_api.txt`). Default: `0xFFFFFF` (white)
## API
### `cmsg.push_message_player(player, message, color)`
### `cmsg.push_message_player(player, message)`
Display a new message to one player only.
#### Parameters
* `player`: An `ObjectRef` to the player to which to send the message
* `message`: A `string` containing the message to be displayed to the player
* `color`: Optional. A `ColorString` for the color of the text. Default: `0xFFFFFF` (white)
#### Return value
Always `nil`.
### `cmsg.push_message_all(message, color)`
### `cmsg.push_message_all(message)`
Display a new message to all connected players.
#### Parameters
* `player`: An `ObjectRef` to the player to which to send the message
* `message`: A `string` containing the message to be displayed to all players
* `color`: Optional. A `ColorString` for the color of the text. Default: `0xFFFFFF` (white)
#### Return value
Always `nil`.

View File

@ -12,7 +12,11 @@ elseif setting == "inf" then
cmsg.settings.max_messages = nil
end
cmsg.default_color = 0xFFFFFF
cmsg.settings.color = 0xFFFFFF
setting = minetest.setting_get("central_message_color")
if type(tonumber(setting)) == "number" then
cmsg.settings.color = tonumber(setting)
end
local function update_display(player, pname)
local messages = {}
@ -35,7 +39,7 @@ local function update_display(player, pname)
player:hud_change(cmsg.hudids[pname], "text", concat)
end
cmsg.push_message_player = function(player, text, color)
cmsg.push_message_player = function(player, text)
local function push(tbl)
-- Horrible Workaround code starts here
if not (cmsg.last_push < cmsg.steps) then
@ -45,16 +49,14 @@ cmsg.push_message_player = function(player, text, color)
local player = tbl.player
local text = tbl.text
local color = tbl.color
-- Horrible Workaround code ends here
local pname = player:get_player_name()
if color == nil then color = cmsg.default_color end
if cmsg.hudids[pname] == nil then
cmsg.hudids[pname] = player:hud_add({
hud_elem_type = "text",
text = text,
number = color,
number = cmsg.settings.color,
position = {x=0.5, y=0.5},
offset = {x=-0,y=-256},
direction = 3,
@ -86,16 +88,16 @@ cmsg.push_message_player = function(player, text, color)
end
if cmsg.last_push < cmsg.steps then
push({player=player, text=text, color=color})
push({player=player, text=text})
else
minetest.after(0, push, {player=player, text=text, color=color})
minetest.after(0, push, {player=player, text=text})
end
end
cmsg.push_message_all = function(text, color)
cmsg.push_message_all = function(text)
local players = minetest.get_connected_players()
for i=1,#players do
cmsg.push_message_player(players[i], text, color)
cmsg.push_message_player(players[i], text)
end
end