Regresssion cleanup: Text color as global setting
This commit is contained in:
parent
f31e92572e
commit
8fb08978f8
@ -24,31 +24,30 @@ Some usage examples:
|
|||||||
## Settings
|
## Settings
|
||||||
This mod can be configured via `minetest.conf`.
|
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_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
|
## API
|
||||||
### `cmsg.push_message_player(player, message, color)`
|
### `cmsg.push_message_player(player, message)`
|
||||||
Display a new message to one player only.
|
Display a new message to one player only.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
* `player`: An `ObjectRef` to the player to which to send the message
|
* `player`: An `ObjectRef` to the player to which to send the message
|
||||||
* `message`: A `string` containing the message to be displayed to the player
|
* `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
|
#### Return value
|
||||||
Always `nil`.
|
Always `nil`.
|
||||||
|
|
||||||
|
|
||||||
### `cmsg.push_message_all(message, color)`
|
### `cmsg.push_message_all(message)`
|
||||||
Display a new message to all connected players.
|
Display a new message to all connected players.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
* `player`: An `ObjectRef` to the player to which to send the message
|
* `player`: An `ObjectRef` to the player to which to send the message
|
||||||
* `message`: A `string` containing the message to be displayed to all players
|
* `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
|
#### Return value
|
||||||
Always `nil`.
|
Always `nil`.
|
||||||
|
20
init.lua
20
init.lua
@ -12,7 +12,11 @@ elseif setting == "inf" then
|
|||||||
cmsg.settings.max_messages = nil
|
cmsg.settings.max_messages = nil
|
||||||
end
|
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 function update_display(player, pname)
|
||||||
local messages = {}
|
local messages = {}
|
||||||
@ -35,7 +39,7 @@ local function update_display(player, pname)
|
|||||||
player:hud_change(cmsg.hudids[pname], "text", concat)
|
player:hud_change(cmsg.hudids[pname], "text", concat)
|
||||||
end
|
end
|
||||||
|
|
||||||
cmsg.push_message_player = function(player, text, color)
|
cmsg.push_message_player = function(player, text)
|
||||||
local function push(tbl)
|
local function push(tbl)
|
||||||
-- Horrible Workaround code starts here
|
-- Horrible Workaround code starts here
|
||||||
if not (cmsg.last_push < cmsg.steps) then
|
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 player = tbl.player
|
||||||
local text = tbl.text
|
local text = tbl.text
|
||||||
local color = tbl.color
|
|
||||||
-- Horrible Workaround code ends here
|
-- Horrible Workaround code ends here
|
||||||
|
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
if color == nil then color = cmsg.default_color end
|
|
||||||
if cmsg.hudids[pname] == nil then
|
if cmsg.hudids[pname] == nil then
|
||||||
cmsg.hudids[pname] = player:hud_add({
|
cmsg.hudids[pname] = player:hud_add({
|
||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
text = text,
|
text = text,
|
||||||
number = color,
|
number = cmsg.settings.color,
|
||||||
position = {x=0.5, y=0.5},
|
position = {x=0.5, y=0.5},
|
||||||
offset = {x=-0,y=-256},
|
offset = {x=-0,y=-256},
|
||||||
direction = 3,
|
direction = 3,
|
||||||
@ -86,16 +88,16 @@ cmsg.push_message_player = function(player, text, color)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if cmsg.last_push < cmsg.steps then
|
if cmsg.last_push < cmsg.steps then
|
||||||
push({player=player, text=text, color=color})
|
push({player=player, text=text})
|
||||||
else
|
else
|
||||||
minetest.after(0, push, {player=player, text=text, color=color})
|
minetest.after(0, push, {player=player, text=text})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
cmsg.push_message_all = function(text, color)
|
cmsg.push_message_all = function(text)
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i=1,#players do
|
for i=1,#players do
|
||||||
cmsg.push_message_player(players[i], text, color)
|
cmsg.push_message_player(players[i], text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user