aboutsummaryrefslogtreecommitdiff
path: root/src/keycode.cpp
blob: c5f102b4441a129f616e2e40460a42e259701eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "keycode.h"
#include "main.h" // For g_settings
#include "exceptions.h"
#include "settings.h"
#include "log.h"
#include "hex.h"
#include "debug.h"

class UnknownKeycode : public BaseException
{
public:
	UnknownKeycode(const char *s) :
		BaseException(s) {};
};

#define CHECKKEY(x){if(strcmp(name, #x)==0) return irr::x;}

irr::EKEY_CODE keyname_to_keycode(const char *name)
{
	CHECKKEY(KEY_LBUTTON)
	CHECKKEY(KEY_RBUTTON)
	CHECKKEY(KEY_CANCEL)
	CHECKKEY(KEY_MBUTTON)
	CHECKKEY(KEY_XBUTTON1)
	CHECKKEY(KEY_XBUTTON2)
	CHECKKEY(KEY_BACK)
	CHECKKEY(KEY_TAB)
	CHECKKEY(KEY_CLEAR)
	CHECKKEY(KEY_RETURN)
	CHECKKEY(KEY_SHIFT)
	CHECKKEY(KEY_CONTROL)
	CHECKKEY(KEY_MENU)
	CHECKKEY(KEY_PAUSE)
	CHECKKEY(KEY_CAPITAL)
	CHECKKEY(KEY_KANA)
	CHECKKEY(KEY_HANGUEL)
	CHECKKEY(KEY_HANGUL)
	CHECKKEY(KEY_JUNJA)
	CHECKKEY(KEY_FINAL)
	CHECKKEY(KEY_HANJA)
	CHECKKEY(KEY_KANJI)
	CHECKKEY(KEY_ESCAPE)
	CHECKKEY(KEY_CONVERT)
	CHECKKEY(KEY_NONCONVERT)
	CHECKKEY(KEY_ACCEPT)
	CHECKKEY(KEY_MODECHANGE)
	CHECKKEY(KEY_SPACE)
	CHECKKEY(KEY_PRIOR)
	CHECKKEY(KEY_NEXT)
	CHECKKEY(KEY_END)
	CHECKKEY(KEY_HOME)
	CHECKKEY(KEY_LEFT)
	CHECKKEY(KEY_UP)
	CHECKKEY(KEY_RIGHT)
	CHECKKEY(KEY_DOWN)
	CHECKKEY(KEY_SELECT)
	CHECKKEY(KEY_PRINT)
	CHECKKEY(KEY_EX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(name);
}

static const char *KeyNames[] =
{ "-", "KEY_LBUTTON", "KEY_RBUTTON", "KEY_CANCEL", "KEY_MBUTTON", "KEY_XBUTTON1",
		"KEY_XBUTTON2", "-", "KEY_BACK", "KEY_TAB", "-", "-", "KEY_CLEAR", "KEY_RETURN", "-",
		"-", "KEY_SHIFT", "KEY_CONTROL", "KEY_MENU", "KEY_PAUSE", "KEY_CAPITAL", "KEY_KANA", "-",
		"KEY_JUNJA", "KEY_FINAL", "KEY_KANJI", "-", "KEY_ESCAPE", "KEY_CONVERT", "KEY_NONCONVERT",
		"KEY_ACCEPT", "KEY_MODECHANGE", "KEY_SPACE", "KEY_PRIOR", "KEY_NEXT", "KEY_END",
		"KEY_HOME", "KEY_LEFT", "KEY_UP", "KEY_RIGHT", "KEY_DOWN", "KEY_SELECT", "KEY_PRINT",
		"KEY_EXECUTE", "KEY_SNAPSHOT", "KEY_INSERT", "KEY_DELETE", "KEY_HELP", "KEY_KEY_0",
		"KEY_KEY_1", "KEY_KEY_2", "KEY_KEY_3", "KEY_KEY_4", "KEY_KEY_5",
		"KEY_KEY_6", "KEY_KEY_7", "KEY_KEY_8", "KEY_KEY_9", "-", "-", "-", "-",
		"-", "-", "-", "KEY_KEY_A", "KEY_KEY_B", "KEY_KEY_C", "KEY_KEY_D",
		"KEY_KEY_E", "KEY_KEY_F", "KEY_KEY_G", "KEY_KEY_H", "KEY_KEY_I",
		"KEY_KEY_J", "KEY_KEY_K", "KEY_KEY_L", "KEY_KEY_M", "KEY_KEY_N",
		"KEY_KEY_O", "KEY_KEY_P", "KEY_KEY_Q", "KEY_KEY_R", "KEY_KEY_S",
		"KEY_KEY_T", "KEY_KEY_U", "KEY_KEY_V", "KEY_KEY_W", "KEY_KEY_X",
		"KEY_KEY_Y", "KEY_KEY_Z", "KEY_LWIN", "KEY_RWIN", "KEY_APPS", "-",
		"KEY_SLEEP", "KEY_NUMPAD0", "KEY_NUMPAD1", "KEY_NUMPAD2", "KEY_NUMPAD3",
		"KEY_NUMPAD4", "KEY_NUMPAD5", "KEY_NUMPAD6", "KEY_NUMPAD7",
		"KEY_NUMPAD8", "KEY_NUMPAD9", "KEY_MULTIPLY", "KEY_ADD", "KEY_SEPERATOR",
		"KEY_SUBTRACT", "KEY_DECIMAL", "KEY_DIVIDE", "KEY_F1", "KEY_F2", "KEY_F3",
		"KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", "KEY_F9", "KEY_F10",
		"KEY_F11", "KEY_F12", "KEY_F13", "KEY_F14", "KEY_F15", "KEY_F16",
		"KEY_F17", "KEY_F18", "KEY_F19", "KEY_F20", "KEY_F21", "KEY_F22",
		"KEY_F23", "KEY_F24", "-", "-", "-", "-", "-", "-", "-", "-",
		"KEY_NUMLOCK", "KEY_SCROLL", "-", "-", "-", "-", "-", "-", "-", "-", "-",
		"-", "-", "-", "-", "-", "KEY_LSHIFT", "KEY_RSHIFT", "KEY_LCONTROL",
		"KEY_RCONTROL", "KEY_LMENU", "KEY_RMENU", "-", "-", "-", "-", "-",
		"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
		"-", "-", "KEY_PLUS", "KEY_COMMA", "KEY_MINUS", "KEY_PERIOD", "-", "-", "-", "-", "-",
		"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
		"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
		"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
		"-", "-", "-", "-", "-", "-", "-", "-", "KEY_ATTN", "KEY_CRSEL", "KEY_EXSEL",
		"KEY_EREOF", "KEY_PLAY", "KEY_ZOOM", "KEY_PA1", "KEY_OEM_CLEAR", "-" };

#define N_(text) text

static const char *KeyNamesLang[] =
	{ "-", N_("Left Button"), N_("Right Button"), N_("Cancel"), N_("Middle Button"), N_("X Button 1"),
			N_("X Button 2"), "-", N_("Back"), N_("Tab"), "-", "-", N_("Clear"), N_("Return"), "-",
			"-", N_("Shift"), N_("Control"), N_("Menu"), N_("Pause"), N_("Capital"), N_("Kana"), "-",
			N_("Junja"), N_("Final"), N_("Kanji"), "-", N_("Escape"), N_("Convert"), N_("Nonconvert"),
			N_("Accept"), N_("Mode Change"), N_("Space"), N_("Prior"), N_("Next"), N_("End"), N_("Home"),
			N_("Left"), N_("Up"), N_("Right"), N_("Down"), N_("Select"), N_("Print"), N_("Execute"),
			N_("Snapshot"), N_("Insert"), N_("Delete"), N_("Help"), "0", "1", "2", "3", "4", "5",
			"6", "7", "8", "9", "-", "-", "-", "-", "-", "-", "-", "A", "B", "C",
			"D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
			"R", "S", "T", "U", "V", "W", "X", "Y", "Z", N_("Left Windows"),
			N_("Right Windows"), N_("Apps"), "-", N_("Sleep"), N_("Numpad 0"), N_("Numpad 1"),
			N_("Numpad 2"), N_("Numpad 3"), N_("Numpad 4"), N_("Numpad 5"), N_("Numpad 6"), N_("Numpad 7"),
			N_("Numpad 8"), N_("Numpad 9"), N_("Numpad *"), N_("Numpad +"), N_("Numpad /"), N_("Numpad -"),
			"Numpad .", "Numpad /", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8",
			"F9", "F10", "F11", "F12", "F13", "F14", "F15", "F16", "F17", "F18",
			"F19", "F20", "F21", "F22", "F23", "F24", "-", "-", "-", "-", "-", "-",
			"-", "-", N_("Num Lock"), N_("Scroll Lock"), "-", "-", "-", "-", "-", "-", "-",
			"-", "-", "-", "-", "-", "-", "-", N_("Left Shift"), N_("Right Shift"),
			N_("Left Control"), N_("Right Control"), N_("Left Menu"), N_("Right Menu"), "-", "-",
			"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
			"-", "-", "-", "-", "-", N_("Plus"), N_("Comma"), N_("Minus"), N_("Period"), "-", "-",
			"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
			"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
			"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
			"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", N_("Attn"), N_("CrSel"),
			N_("ExSel"), N_("Erase OEF"), N_("Play"), N_("Zoom"), N_("PA1"), N_("OEM Clear"), "-" };

#undef N_

KeyPress::KeyPress() :
	Key(irr::KEY_KEY_CODES_COUNT),
	Char(L'\0')
{}

KeyPress::KeyPress(const char *name)
{
	if (strlen(name) > 4) {
		try {
			Key = keyname_to_keycode(name);
			m_name = name;
			if (strlen(name) > 8 && strncmp(name, "KEY_KEY_", 8) == 0) {
				int chars_read = mbtowc(&Char, name + 8, 1);
				assert (chars_read == 1 && "unexpected multibyte character");
			} else
				Char = L'\0';
			return;
		} catch (UnknownKeycode &e) {};
	} else {
		// see if we can set it up as a KEY_KEY_something
		m_name = "KEY_KEY_";
		m_name += name;
		try {
			Key = keyname_to_keycode(m_name.c_str());
			int chars_read = mbtowc(&Char, name, 1);
			assert (chars_read == 1 && "unexpected multibyte character");
			return;
		} catch (UnknownKeycode &e) {};
	}

	// it's not a (known) key, just take the first char and use that

	Key = irr::KEY_KEY_CODES_COUNT;

	int mbtowc_ret = mbtowc(&Char, name, 1);
	assert (mbtowc_ret == 1 && "unexpected multibyte character");
	m_name = name[0];
}

KeyPress::KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character)
{
	Key = in.Key;
	Char = in.Char;

	if(prefer_character){
		m_name.resize(MB_CUR_MAX+1, '\0');
		int written = wctomb(&m_name[0], Char);
		if(written > 0){
			infostream<<"KeyPress: Preferring character for "<<m_name<<std::endl;
			Key = irr::KEY_KEY_CODES_COUNT;
			return;
		}
	}

	if (valid_kcode(Key)) {
		m_name = KeyNames[Key];
	} else {
		m_name.resize(MB_CUR_MAX+1, '\0');
		int written = wctomb(&m_name[0], Char);
		if(written < 0){
			std::string hexstr = hex_encode((const char*)&Char, sizeof(Char));
			errorstream<<"KeyPress: Unexpected multibyte character "<<hexstr<<std::endl;
		}
	}
}

const char *KeyPress::sym() const
{
	if (Key && Key < irr::KEY_KEY_CODES_COUNT)
		return KeyNames[Key];
	else {
		return m_name.c_str();
	}
}

const char *KeyPress::name() const
{
	if (Key && Key < irr::KEY_KEY_CODES_COUNT)
		return KeyNamesLang[Key];
	else {
		return m_name.c_str();
	}
}

const KeyPress EscapeKey("KEY_ESCAPE");
const KeyPress CancelKey("KEY_CANCEL");
const KeyPress NumberKey[] = {
	KeyPress("KEY_KEY_0"), KeyPress("KEY_KEY_1"), KeyPress("KEY_KEY_2"),
	KeyPress("KEY_KEY_3"), KeyPress("KEY_KEY_4"), KeyPress("KEY_KEY_5"),
	KeyPress("KEY_KEY_6"), KeyPress("KEY_KEY_7"), KeyPress("KEY_KEY_8"),
	KeyPress("KEY_KEY_9")};

/*
	Key config
*/

// A simple cache for quicker lookup
std::map<std::string, KeyPress> g_key_setting_cache;

KeyPress getKeySetting(const char *settingname)
{
	std::map<std::string, KeyPress>::iterator n;
	n = g_key_setting_cache.find(settingname);
	if(n != g_key_setting_cache.end())
		return n->second;
	g_key_setting_cache[settingname] = g_settings->get(settingname).c_str();
	return g_key_setting_cache.find(settingname)->second;
}

void clearKeyCache()
{
	g_key_setting_cache.clear();
}
is_climbing()` * returns true if player is climbing * `swimming_vertical()` * returns true if player is swimming in vertical * `get_physics_override()` * returns: ```lua { speed = float, jump = float, gravity = float, sneak = boolean, sneak_glitch = boolean } ``` * `get_override_pos()` * returns override position * `get_last_pos()` * returns last player position before the current client step * `get_last_velocity()` * returns last player speed * `get_breath()` * returns the player's breath * `get_movement_acceleration()` * returns acceleration of the player in different environments: ```lua { fast = float, air = float, default = float, } ``` * `get_movement_speed()` * returns player's speed in different environments: ```lua { walk = float, jump = float, crouch = float, fast = float, climb = float, } ``` * `get_movement()` * returns player's movement in different environments: ```lua { liquid_fluidity = float, liquid_sink = float, liquid_fluidity_smooth = float, gravity = float, } ``` * `get_last_look_horizontal()`: * returns last look horizontal angle * `get_last_look_vertical()`: * returns last look vertical angle * `get_key_pressed()`: * returns last key typed by the player * `hud_add(definition)` * add a HUD element described by HUD def, returns ID number on success and `nil` on failure. * See [`HUD definition`](#hud-definition-hud_add-hud_get) * `hud_get(id)` * returns the [`definition`](#hud-definition-hud_add-hud_get) of the HUD with that ID number or `nil`, if non-existent. * `hud_remove(id)` * remove the HUD element of the specified id, returns `true` on success * `hud_change(id, stat, value)` * change a value of a previously added HUD element * element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir` * Returns `true` on success, otherwise returns `nil` ### Settings An interface to read config files in the format of `minetest.conf`. It can be created via `Settings(filename)`. #### Methods * `get(key)`: returns a value * `get_bool(key)`: returns a boolean * `set(key, value)` * `remove(key)`: returns a boolean (`true` for success) * `get_names()`: returns `{key1,...}` * `write()`: returns a boolean (`true` for success) * write changes to file * `to_table()`: returns `{[key1]=value1,...}` ### NodeMetaRef Node metadata: reference extra data and functionality stored in a node. Can be obtained via `minetest.get_meta(pos)`. #### Methods * `get_string(name)` * `get_int(name)` * `get_float(name)` * `to_table()`: returns `nil` or a table with keys: * `fields`: key-value storage * `inventory`: `{list1 = {}, ...}}` ----------------- ### Definitions * `minetest.get_node_def(nodename)` * Returns [node definition](#node-definition) table of `nodename` * `minetest.get_item_def(itemstring)` * Returns item definition table of `itemstring` #### Node Definition ```lua { has_on_construct = bool, -- Whether the node has the on_construct callback defined has_on_destruct = bool, -- Whether the node has the on_destruct callback defined has_after_destruct = bool, -- Whether the node has the after_destruct callback defined name = string, -- The name of the node e.g. "air", "default:dirt" groups = table, -- The groups of the node paramtype = string, -- Paramtype of the node paramtype2 = string, -- ParamType2 of the node drawtype = string, -- Drawtype of the node mesh = <string>, -- Mesh name if existant minimap_color = <Color>, -- Color of node on minimap *May not exist* visual_scale = number, -- Visual scale of node alpha = number, -- Alpha of the node. Only used for liquids color = <Color>, -- Color of node *May not exist* palette_name = <string>, -- Filename of palette *May not exist* palette = <{ -- List of colors Color, Color }>, waving = number, -- 0 of not waving, 1 if waving connect_sides = number, -- Used for connected nodes connects_to = { -- List of nodes to connect to "node1", "node2" }, post_effect_color = Color, -- Color overlayed on the screen when the player is in the node leveled = number, -- Max level for node sunlight_propogates = bool, -- Whether light passes through the block light_source = number, -- Light emitted by the block is_ground_content = bool, -- Whether caves should cut through the node walkable = bool, -- Whether the player collides with the node pointable = bool, -- Whether the player can select the node diggable = bool, -- Whether the player can dig the node climbable = bool, -- Whether the player can climb up the node buildable_to = bool, -- Whether the player can replace the node by placing a node on it rightclickable = bool, -- Whether the player can place nodes pointing at this node damage_per_second = number, -- HP of damage per second when the player is in the node liquid_type = <string>, -- A string containing "none", "flowing", or "source" *May not exist* liquid_alternative_flowing = <string>, -- Alternative node for liquid *May not exist* liquid_alternative_source = <string>, -- Alternative node for liquid *May not exist* liquid_viscosity = <number>, -- How fast the liquid flows *May not exist* liquid_renewable = <boolean>, -- Whether the liquid makes an infinite source *May not exist* liquid_range = <number>, -- How far the liquid flows *May not exist* drowning = bool, -- Whether the player will drown in the node floodable = bool, -- Whether nodes will be replaced by liquids (flooded) node_box = table, -- Nodebox to draw the node with collision_box = table, -- Nodebox to set the collision area selection_box = table, -- Nodebox to set the area selected by the player sounds = { -- Table of sounds that the block makes sound_footstep = SimpleSoundSpec, sound_dig = SimpleSoundSpec, sound_dug = SimpleSoundSpec }, legacy_facedir_simple = bool, -- Whether to use old facedir legacy_wallmounted = bool -- Whether to use old wallmounted } ``` #### Item Definition ```lua { name = string, -- Name of the item e.g. "default:stone" description = string, -- Description of the item e.g. "Stone" type = string, -- Item type: "none", "node", "craftitem", "tool" inventory_image = string, -- Image in the inventory wield_image = string, -- Image in wieldmesh palette_image = string, -- Image for palette color = Color, -- Color for item wield_scale = Vector, -- Wieldmesh scale stack_max = number, -- Number of items stackable together usable = bool, -- Has on_use callback defined liquids_pointable = bool, -- Whether you can point at liquids with the item tool_capabilities = <table>, -- If the item is a tool, tool capabilities of the item groups = table, -- Groups of the item sound_place = SimpleSoundSpec, -- Sound played when placed sound_place_failed = SimpleSoundSpec, -- Sound played when placement failed node_placement_prediction = string -- Node placed in client until server catches up } ``` ----------------- ### Chat command definition (`register_chatcommand`) { params = "<name> <privilege>", -- Short parameter description description = "Remove privilege from player", -- Full description func = function(param), -- Called when command is run. -- Returns boolean success and text output. } ### Server info ```lua { address = "minetest.example.org", -- The domain name/IP address of a remote server or "" for a local server. ip = "203.0.113.156", -- The IP address of the server. port = 30000, -- The port the client is connected to. protocol_version = 30 -- Will not be accurate at start up as the client might not be connected to the server yet, in that case it will be 0. } ``` ### HUD Definition (`hud_add`, `hud_get`) ```lua { hud_elem_type = "image", -- see HUD element types, default "text" -- ^ type of HUD element, can be either of "image", "text", "statbar", or "inventory" position = {x=0.5, y=0.5}, -- ^ Left corner position of element, default `{x=0,y=0}`. name = "<name>", -- default "" scale = {x=2, y=2}, -- default {x=0,y=0} text = "<text>", -- default "" number = 2, -- default 0 item = 3, -- default 0 -- ^ Selected item in inventory. 0 for no item selected. direction = 0, -- default 0 -- ^ Direction: 0: left-right, 1: right-left, 2: top-bottom, 3: bottom-top alignment = {x=0, y=0}, -- default {x=0, y=0} -- ^ See "HUD Element Types" offset = {x=0, y=0}, -- default {x=0, y=0} -- ^ See "HUD Element Types" size = { x=100, y=100 }, -- default {x=0, y=0} -- ^ Size of element in pixels } ``` Escape sequences ---------------- Most text can contain escape sequences, that can for example color the text. There are a few exceptions: tab headers, dropdowns and vertical labels can't. The following functions provide escape sequences: * `minetest.get_color_escape_sequence(color)`: * `color` is a [ColorString](#colorstring) * The escape sequence sets the text color to `color` * `minetest.colorize(color, message)`: * Equivalent to: `minetest.get_color_escape_sequence(color) .. message .. minetest.get_color_escape_sequence("#ffffff")` * `minetest.get_background_escape_sequence(color)` * `color` is a [ColorString](#colorstring) * The escape sequence sets the background of the whole text element to `color`. Only defined for item descriptions and tooltips. * `minetest.strip_foreground_colors(str)` * Removes foreground colors added by `get_color_escape_sequence`. * `minetest.strip_background_colors(str)` * Removes background colors added by `get_background_escape_sequence`. * `minetest.strip_colors(str)` * Removes all color escape sequences. `ColorString` ------------- `#RGB` defines a color in hexadecimal format. `#RGBA` defines a color in hexadecimal format and alpha channel. `#RRGGBB` defines a color in hexadecimal format. `#RRGGBBAA` defines a color in hexadecimal format and alpha channel. Named colors are also supported and are equivalent to [CSS Color Module Level 4](http://dev.w3.org/csswg/css-color/#named-colors). To specify the value of the alpha channel, append `#AA` to the end of the color name (e.g. `colorname#08`). For named colors the hexadecimal string representing the alpha value must (always) be two hexadecimal digits. `Color` ------------- `{a = alpha, r = red, g = green, b = blue}` defines an ARGB8 color. HUD element types ----------------- The position field is used for all element types. To account for differing resolutions, the position coordinates are the percentage of the screen, ranging in value from `0` to `1`. The name field is not yet used, but should contain a description of what the HUD element represents. The direction field is the direction in which something is drawn. `0` draws from left to right, `1` draws from right to left, `2` draws from top to bottom, and `3` draws from bottom to top. The `alignment` field specifies how the item will be aligned. It ranges from `-1` to `1`, with `0` being the center, `-1` is moved to the left/up, and `1` is to the right/down. Fractional values can be used. The `offset` field specifies a pixel offset from the position. Contrary to position, the offset is not scaled to screen size. This allows for some precisely-positioned items in the HUD. **Note**: `offset` _will_ adapt to screen DPI as well as user defined scaling factor! Below are the specific uses for fields in each type; fields not listed for that type are ignored. **Note**: Future revisions to the HUD API may be incompatible; the HUD API is still in the experimental stages. ### `image` Displays an image on the HUD. * `scale`: The scale of the image, with 1 being the original texture size. Only the X coordinate scale is used (positive values). Negative values represent that percentage of the screen it should take; e.g. `x=-100` means 100% (width). * `text`: The name of the texture that is displayed. * `alignment`: The alignment of the image. * `offset`: offset in pixels from position. ### `text` Displays text on the HUD. * `scale`: Defines the bounding rectangle of the text. A value such as `{x=100, y=100}` should work. * `text`: The text to be displayed in the HUD element. * `number`: An integer containing the RGB value of the color used to draw the text. Specify `0xFFFFFF` for white text, `0xFF0000` for red, and so on. * `alignment`: The alignment of the text. * `offset`: offset in pixels from position. ### `statbar` Displays a horizontal bar made up of half-images. * `text`: The name of the texture that is used. * `number`: The number of half-textures that are displayed. If odd, will end with a vertically center-split texture. * `direction` * `offset`: offset in pixels from position. * `size`: If used, will force full-image size to this value (override texture pack image size) ### `inventory` * `text`: The name of the inventory list to be displayed. * `number`: Number of items in the inventory to be displayed. * `item`: Position of item that is selected. * `direction` * `offset`: offset in pixels from position. ### `waypoint` Displays distance to selected world position. * `name`: The name of the waypoint. * `text`: Distance suffix. Can be blank. * `number:` An integer containing the RGB value of the color used to draw the text. * `world_pos`: World position of the waypoint. ### Particle definition (`add_particle`) { pos = {x=0, y=0, z=0}, velocity = {x=0, y=0, z=0}, acceleration = {x=0, y=0, z=0}, -- ^ Spawn particle at pos with velocity and acceleration expirationtime = 1, -- ^ Disappears after expirationtime seconds size = 1, collisiondetection = false, -- ^ collisiondetection: if true collides with physical objects collision_removal = false, -- ^ collision_removal: if true then particle is removed when it collides, -- ^ requires collisiondetection = true to have any effect vertical = false, -- ^ vertical: if true faces player using y axis only texture = "image.png", -- ^ Uses texture (string) animation = {Tile Animation definition}, -- ^ optional, specifies how to animate the particle texture glow = 0 -- ^ optional, specify particle self-luminescence in darkness } ### `ParticleSpawner` definition (`add_particlespawner`) { amount = 1, time = 1, -- ^ If time is 0 has infinite lifespan and spawns the amount on a per-second base minpos = {x=0, y=0, z=0}, maxpos = {x=0, y=0, z=0}, minvel = {x=0, y=0, z=0}, maxvel = {x=0, y=0, z=0}, minacc = {x=0, y=0, z=0}, maxacc = {x=0, y=0, z=0}, minexptime = 1, maxexptime = 1, minsize = 1, maxsize = 1, -- ^ The particle's properties are random values in between the bounds: -- ^ minpos/maxpos, minvel/maxvel (velocity), minacc/maxacc (acceleration), -- ^ minsize/maxsize, minexptime/maxexptime (expirationtime) collisiondetection = false, -- ^ collisiondetection: if true uses collision detection collision_removal = false, -- ^ collision_removal: if true then particle is removed when it collides, -- ^ requires collisiondetection = true to have any effect vertical = false, -- ^ vertical: if true faces player using y axis only texture = "image.png", -- ^ Uses texture (string) }