Skip to content

Commit 87291ea

Browse files
RealBadAngelparamat
authored andcommittedJan 18, 2016
Show infotext with description for item entities
1 parent eb6e2c1 commit 87291ea

File tree

7 files changed

+21
-2
lines changed

7 files changed

+21
-2
lines changed
 

‎builtin/game/item_entity.lua

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ core.register_entity(":__builtin:item", {
3131
spritediv = {x = 1, y = 1},
3232
initial_sprite_basepos = {x = 0, y = 0},
3333
is_visible = false,
34+
infotext = "",
3435
},
3536

3637
itemstring = '',
@@ -50,6 +51,7 @@ core.register_entity(":__builtin:item", {
5051
local c = s
5152
local itemtable = stack:to_table()
5253
local itemname = nil
54+
local description = ""
5355
if itemtable then
5456
itemname = stack:to_table().name
5557
end
@@ -58,6 +60,7 @@ core.register_entity(":__builtin:item", {
5860
if core.registered_items[itemname] then
5961
item_texture = core.registered_items[itemname].inventory_image
6062
item_type = core.registered_items[itemname].type
63+
description = core.registered_items[itemname].description
6164
end
6265
local prop = {
6366
is_visible = true,
@@ -66,6 +69,7 @@ core.register_entity(":__builtin:item", {
6669
visual_size = {x = s, y = s},
6770
collisionbox = {-c, -c, -c, c, c, c},
6871
automatic_rotate = math.pi * 0.5,
72+
infotext = description,
6973
}
7074
self.object:set_properties(prop)
7175
end,

‎doc/lua_api.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,7 @@ Definition tables
32413241
backface_culling = true, -- false to disable backface_culling for model
32423242
nametag = "", -- by default empty, for players their name is shown if empty
32433243
nametag_color = <color>, -- sets color of nametag as ColorSpec
3244+
infotext = "", -- by default empty, text to be shown when pointed at object
32443245
}
32453246

32463247
### Entity definition (`register_entity`)

‎src/content_cao.h

+5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ class GenericCAO : public ClientActiveObject
201201
float time_from_last_punch=1000000);
202202

203203
std::string debugInfoText();
204+
205+
std::string infoText()
206+
{
207+
return m_prop.infotext;
208+
}
204209
};
205210

206211

‎src/game.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -3732,8 +3732,11 @@ void Game::handlePointingAtObject(GameRunData *runData,
37323732
{
37333733
infotext = utf8_to_wide(runData->selected_object->infoText());
37343734

3735-
if (infotext == L"" && show_debug) {
3736-
infotext = utf8_to_wide(runData->selected_object->debugInfoText());
3735+
if (show_debug) {
3736+
if (infotext != L"") {
3737+
infotext += L"\n";
3738+
}
3739+
infotext += utf8_to_wide(runData->selected_object->debugInfoText());
37373740
}
37383741

37393742
if (input->getLeftState()) {

‎src/object_properties.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ void ObjectProperties::serialize(std::ostream &os) const
118118
os << serializeString(nametag);
119119
writeARGB8(os, nametag_color);
120120
writeF1000(os, automatic_face_movement_max_rotation_per_sec);
121+
os << serializeString(infotext);
121122

122123
// Add stuff only at the bottom.
123124
// Never remove anything, because we don't want new versions of this
@@ -159,6 +160,7 @@ void ObjectProperties::deSerialize(std::istream &is)
159160
nametag = deSerializeString(is);
160161
nametag_color = readARGB8(is);
161162
automatic_face_movement_max_rotation_per_sec = readF1000(is);
163+
infotext = deSerializeString(is);
162164
}catch(SerializationError &e){}
163165
}
164166
else

‎src/object_properties.h

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct ObjectProperties
5151
std::string nametag;
5252
video::SColor nametag_color;
5353
f32 automatic_face_movement_max_rotation_per_sec;
54+
std::string infotext;
5455

5556
ObjectProperties();
5657
std::string dump();

‎src/script/common/c_content.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ void read_object_properties(lua_State *L, int index,
216216
prop->automatic_face_movement_max_rotation_per_sec = luaL_checknumber(L, -1);
217217
}
218218
lua_pop(L, 1);
219+
getstringfield(L, -1, "infotext", prop->infotext);
219220
}
220221

221222
/******************************************************************************/
@@ -282,6 +283,8 @@ void push_object_properties(lua_State *L, ObjectProperties *prop)
282283
lua_setfield(L, -2, "nametag_color");
283284
lua_pushnumber(L, prop->automatic_face_movement_max_rotation_per_sec);
284285
lua_setfield(L, -2, "automatic_face_movement_max_rotation_per_sec");
286+
lua_pushlstring(L, prop->infotext.c_str(), prop->infotext.size());
287+
lua_setfield(L, -2, "infotext");
285288
}
286289

287290
/******************************************************************************/

0 commit comments

Comments
 (0)
Please sign in to comment.