Created
December 7, 2011 06:31
-
-
Save anonymous/1441721 to your computer and use it in GitHub Desktop.
attempt at tool tips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua | |
index 4acf8d8..697a4d2 100644 | |
--- a/data/mods/default/init.lua | |
+++ b/data/mods/default/init.lua | |
@@ -346,6 +346,7 @@ minetest.register_tool(":", { | |
}) | |
minetest.register_tool("default:pick_wood", { | |
+ description = "Wooden Pickaxe", | |
image = "default_tool_woodpick.png", | |
basetime = 2.0, | |
dt_weight = 0, | |
@@ -359,6 +360,7 @@ minetest.register_tool("default:pick_wood", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:pick_stone", { | |
+ description = "Stone Pickaxe", | |
image = "default_tool_stonepick.png", | |
basetime = 1.5, | |
dt_weight = 0, | |
@@ -372,6 +374,7 @@ minetest.register_tool("default:pick_stone", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:pick_steel", { | |
+ description = "Steel Pickaxe", | |
image = "default_tool_steelpick.png", | |
basetime = 1.0, | |
dt_weight = 0, | |
@@ -385,6 +388,7 @@ minetest.register_tool("default:pick_steel", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:pick_mese", { | |
+ description = "Mese Pickaxe", | |
image = "default_tool_mesepick.png", | |
basetime = 0, | |
dt_weight = 0, | |
@@ -398,6 +402,7 @@ minetest.register_tool("default:pick_mese", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:shovel_wood", { | |
+ description = "Wooden Shovel", | |
image = "default_tool_woodshovel.png", | |
basetime = 2.0, | |
dt_weight = 0.5, | |
@@ -411,6 +416,7 @@ minetest.register_tool("default:shovel_wood", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:shovel_stone", { | |
+ description = "Stone Shovel", | |
image = "default_tool_stoneshovel.png", | |
basetime = 1.5, | |
dt_weight = 0.5, | |
@@ -424,6 +430,7 @@ minetest.register_tool("default:shovel_stone", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:shovel_steel", { | |
+ description = "Steel Shovel", | |
image = "default_tool_steelshovel.png", | |
basetime = 1.0, | |
dt_weight = 0.5, | |
@@ -437,6 +444,7 @@ minetest.register_tool("default:shovel_steel", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:axe_wood", { | |
+ description = "Wooden Axe", | |
image = "default_tool_woodaxe.png", | |
basetime = 2.0, | |
dt_weight = 0.5, | |
@@ -450,6 +458,7 @@ minetest.register_tool("default:axe_wood", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:axe_stone", { | |
+ description = "Stone Axe", | |
image = "default_tool_stoneaxe.png", | |
basetime = 1.5, | |
dt_weight = 0.5, | |
@@ -463,6 +472,7 @@ minetest.register_tool("default:axe_stone", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:axe_steel", { | |
+ description = "Steel Axe", | |
image = "default_tool_steelaxe.png", | |
basetime = 1.0, | |
dt_weight = 0.5, | |
@@ -476,6 +486,7 @@ minetest.register_tool("default:axe_steel", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:sword_wood", { | |
+ description = "Wooden Sword", | |
image = "default_tool_woodsword.png", | |
basetime = 3.0, | |
dt_weight = 3, | |
@@ -489,6 +500,7 @@ minetest.register_tool("default:sword_wood", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:sword_stone", { | |
+ description = "Stone Sword", | |
image = "default_tool_stonesword.png", | |
basetime = 2.5, | |
dt_weight = 3, | |
@@ -502,6 +514,7 @@ minetest.register_tool("default:sword_stone", { | |
dd_cuttability = 0, | |
}) | |
minetest.register_tool("default:sword_steel", { | |
+ description = "Steel Sword", | |
image = "default_tool_steelsword.png", | |
basetime = 2.0, | |
dt_weight = 3, | |
@@ -783,6 +796,7 @@ minetest.register_craft({ | |
-- | |
minetest.register_node("default:stone", { | |
+ description = "Stone", | |
tile_images = {"default_stone.png"}, | |
inventory_image = minetest.inventorycube("default_stone.png"), | |
paramtype = "mineral", | |
@@ -793,6 +807,7 @@ minetest.register_node("default:stone", { | |
}) | |
minetest.register_node("default:dirt_with_grass", { | |
+ description = "Grass", | |
tile_images = {"default_grass.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"}, | |
inventory_image = minetest.inventorycube("default_dirt.png^default_grass_side.png"), | |
is_ground_content = true, | |
@@ -801,6 +816,7 @@ minetest.register_node("default:dirt_with_grass", { | |
}) | |
minetest.register_node("default:dirt_with_grass_footsteps", { | |
+ description = "Grass 2", | |
tile_images = {"default_grass_footsteps.png", "default_dirt.png", "default_dirt.png^default_grass_side.png"}, | |
inventory_image = "default_grass_footsteps.png", | |
is_ground_content = true, | |
@@ -809,6 +825,7 @@ minetest.register_node("default:dirt_with_grass_footsteps", { | |
}) | |
minetest.register_node("default:dirt", { | |
+ description = "Dirt", | |
tile_images = {"default_dirt.png"}, | |
inventory_image = minetest.inventorycube("default_dirt.png"), | |
is_ground_content = true, | |
@@ -816,6 +833,7 @@ minetest.register_node("default:dirt", { | |
}) | |
minetest.register_node("default:sand", { | |
+ description = "Sand", | |
tile_images = {"default_sand.png"}, | |
inventory_image = minetest.inventorycube("default_sand.png"), | |
is_ground_content = true, | |
@@ -824,6 +842,7 @@ minetest.register_node("default:sand", { | |
}) | |
minetest.register_node("default:gravel", { | |
+ description = "Gravel", | |
tile_images = {"default_gravel.png"}, | |
inventory_image = minetest.inventorycube("default_gravel.png"), | |
is_ground_content = true, | |
@@ -831,6 +850,7 @@ minetest.register_node("default:gravel", { | |
}) | |
minetest.register_node("default:sandstone", { | |
+ description = "Sandstone", | |
tile_images = {"default_sandstone.png"}, | |
inventory_image = minetest.inventorycube("default_sandstone.png"), | |
is_ground_content = true, | |
@@ -839,6 +859,7 @@ minetest.register_node("default:sandstone", { | |
}) | |
minetest.register_node("default:clay", { | |
+ description = "Clay", | |
tile_images = {"default_clay.png"}, | |
inventory_image = minetest.inventorycube("default_clay.png"), | |
is_ground_content = true, | |
@@ -847,6 +868,7 @@ minetest.register_node("default:clay", { | |
}) | |
minetest.register_node("default:brick", { | |
+ description = "Brick", | |
tile_images = {"default_brick.png"}, | |
inventory_image = minetest.inventorycube("default_brick.png"), | |
is_ground_content = true, | |
@@ -855,6 +877,7 @@ minetest.register_node("default:brick", { | |
}) | |
minetest.register_node("default:tree", { | |
+ description = "Log", | |
tile_images = {"default_tree_top.png", "default_tree_top.png", "default_tree.png"}, | |
inventory_image = minetest.inventorycube("default_tree_top.png", "default_tree.png", "default_tree.png"), | |
is_ground_content = true, | |
@@ -864,6 +887,7 @@ minetest.register_node("default:tree", { | |
}) | |
minetest.register_node("default:jungletree", { | |
+ description = "Log", | |
tile_images = {"default_jungletree_top.png", "default_jungletree_top.png", "default_jungletree.png"}, | |
inventory_image = minetest.inventorycube("default_jungletree_top.png", "default_jungletree.png", "default_jungletree.png"), | |
is_ground_content = true, | |
@@ -873,6 +897,7 @@ minetest.register_node("default:jungletree", { | |
}) | |
minetest.register_node("default:junglegrass", { | |
+ description = "Jungle Grass", | |
drawtype = "plantlike", | |
visual_scale = 1.3, | |
tile_images = {"default_junglegrass.png"}, | |
@@ -885,6 +910,7 @@ minetest.register_node("default:junglegrass", { | |
}) | |
minetest.register_node("default:leaves", { | |
+ description = "Leaves", | |
drawtype = "allfaces_optional", | |
visual_scale = 1.3, | |
tile_images = {"default_leaves.png"}, | |
@@ -898,6 +924,7 @@ minetest.register_node("default:leaves", { | |
}) | |
minetest.register_node("default:cactus", { | |
+ description = "Cactus", | |
tile_images = {"default_cactus_top.png", "default_cactus_top.png", "default_cactus_side.png"}, | |
inventory_image = minetest.inventorycube("default_cactus_top.png", "default_cactus_side.png", "default_cactus_side.png"), | |
is_ground_content = true, | |
@@ -906,6 +933,7 @@ minetest.register_node("default:cactus", { | |
}) | |
minetest.register_node("default:papyrus", { | |
+ description = "Papyrus", | |
drawtype = "plantlike", | |
tile_images = {"default_papyrus.png"}, | |
inventory_image = "default_papyrus.png", | |
@@ -918,6 +946,7 @@ minetest.register_node("default:papyrus", { | |
}) | |
minetest.register_node("default:bookshelf", { | |
+ description = "Bookshelf", | |
tile_images = {"default_wood.png", "default_wood.png", "default_bookshelf.png"}, | |
inventory_image = minetest.inventorycube("default_wood.png", "default_bookshelf.png", "default_bookshelf.png"), | |
is_ground_content = true, | |
@@ -926,6 +955,7 @@ minetest.register_node("default:bookshelf", { | |
}) | |
minetest.register_node("default:glass", { | |
+ description = "Glass", | |
drawtype = "glasslike", | |
tile_images = {"default_glass.png"}, | |
inventory_image = minetest.inventorycube("default_glass.png"), | |
@@ -937,6 +967,7 @@ minetest.register_node("default:glass", { | |
}) | |
minetest.register_node("default:fence_wooden", { | |
+ description = "Wooden Fence", | |
drawtype = "fencelike", | |
tile_images = {"default_wood.png"}, | |
inventory_image = "default_fence.png", | |
@@ -952,6 +983,7 @@ minetest.register_node("default:fence_wooden", { | |
}) | |
minetest.register_node("default:rail", { | |
+ description = "Rail", | |
drawtype = "raillike", | |
tile_images = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"}, | |
inventory_image = "default_rail.png", | |
@@ -967,6 +999,7 @@ minetest.register_node("default:rail", { | |
}) | |
minetest.register_node("default:ladder", { | |
+ description = "Ladder", | |
drawtype = "signlike", | |
tile_images = {"default_ladder.png"}, | |
inventory_image = "default_ladder.png", | |
@@ -987,6 +1020,7 @@ minetest.register_node("default:ladder", { | |
}) | |
minetest.register_node("default:wood", { | |
+ description = "Wood Plank", | |
tile_images = {"default_wood.png"}, | |
inventory_image = minetest.inventorycube("default_wood.png"), | |
is_ground_content = true, | |
@@ -995,6 +1029,7 @@ minetest.register_node("default:wood", { | |
}) | |
minetest.register_node("default:mese", { | |
+ description = "Mese", | |
tile_images = {"default_mese.png"}, | |
inventory_image = minetest.inventorycube("default_mese.png"), | |
is_ground_content = true, | |
@@ -1003,12 +1038,14 @@ minetest.register_node("default:mese", { | |
}) | |
minetest.register_node("default:cloud", { | |
+ description = "Cloud", | |
tile_images = {"default_cloud.png"}, | |
inventory_image = minetest.inventorycube("default_cloud.png"), | |
is_ground_content = true, | |
}) | |
minetest.register_node("default:water_flowing", { | |
+ description = "Water", | |
drawtype = "flowingliquid", | |
tile_images = {"default_water.png"}, | |
alpha = WATER_ALPHA, | |
@@ -1031,6 +1068,7 @@ minetest.register_node("default:water_flowing", { | |
}) | |
minetest.register_node("default:water_source", { | |
+ description = "Water Source", | |
drawtype = "liquid", | |
tile_images = {"default_water.png"}, | |
alpha = WATER_ALPHA, | |
@@ -1053,6 +1091,7 @@ minetest.register_node("default:water_source", { | |
}) | |
minetest.register_node("default:lava_flowing", { | |
+ description = "Lava", | |
drawtype = "flowingliquid", | |
tile_images = {"default_lava.png"}, | |
inventory_image = minetest.inventorycube("default_lava.png"), | |
@@ -1076,6 +1115,7 @@ minetest.register_node("default:lava_flowing", { | |
}) | |
minetest.register_node("default:lava_source", { | |
+ description = "Lava Source", | |
drawtype = "liquid", | |
tile_images = {"default_lava.png"}, | |
inventory_image = minetest.inventorycube("default_lava.png"), | |
@@ -1100,6 +1140,7 @@ minetest.register_node("default:lava_source", { | |
}) | |
minetest.register_node("default:torch", { | |
+ description = "Torch", | |
drawtype = "torchlike", | |
tile_images = {"default_torch_on_floor.png", "default_torch_on_ceiling.png", "default_torch.png"}, | |
inventory_image = "default_torch_on_floor.png", | |
@@ -1120,6 +1161,7 @@ minetest.register_node("default:torch", { | |
}) | |
minetest.register_node("default:sign_wall", { | |
+ description = "Sign", | |
drawtype = "signlike", | |
tile_images = {"default_sign_wall.png"}, | |
inventory_image = "default_sign_wall.png", | |
@@ -1140,6 +1182,7 @@ minetest.register_node("default:sign_wall", { | |
}) | |
minetest.register_node("default:chest", { | |
+ description = "Chest", | |
tile_images = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", | |
"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"}, | |
inventory_image = minetest.inventorycube("default_chest_top.png", "default_chest_front.png", "default_chest_side.png"), | |
@@ -1150,6 +1193,7 @@ minetest.register_node("default:chest", { | |
}) | |
minetest.register_node("default:chest_locked", { | |
+ description = "Locked Chest", | |
tile_images = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png", | |
"default_chest_side.png", "default_chest_side.png", "default_chest_lock.png"}, | |
inventory_image = minetest.inventorycube("default_chest_top.png", "default_chest_lock.png", "default_chest_side.png"), | |
@@ -1160,6 +1204,7 @@ minetest.register_node("default:chest_locked", { | |
}) | |
minetest.register_node("default:furnace", { | |
+ description = "Furnace", | |
tile_images = {"default_furnace_side.png", "default_furnace_side.png", "default_furnace_side.png", | |
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"}, | |
inventory_image = minetest.inventorycube("default_furnace_side.png", "default_furnace_front.png", "default_furnace_side.png"), | |
@@ -1169,6 +1214,7 @@ minetest.register_node("default:furnace", { | |
}) | |
minetest.register_node("default:cobble", { | |
+ description = "Cobblestone", | |
tile_images = {"default_cobble.png"}, | |
inventory_image = minetest.inventorycube("default_cobble.png"), | |
is_ground_content = true, | |
@@ -1177,6 +1223,7 @@ minetest.register_node("default:cobble", { | |
}) | |
minetest.register_node("default:mossycobble", { | |
+ description = "Mossy Cobblestone", | |
tile_images = {"default_mossycobble.png"}, | |
inventory_image = minetest.inventorycube("default_mossycobble.png"), | |
is_ground_content = true, | |
@@ -1184,6 +1231,7 @@ minetest.register_node("default:mossycobble", { | |
}) | |
minetest.register_node("default:steelblock", { | |
+ description = "Steel Block", | |
tile_images = {"default_steel_block.png"}, | |
inventory_image = minetest.inventorycube("default_steel_block.png"), | |
is_ground_content = true, | |
@@ -1191,6 +1239,7 @@ minetest.register_node("default:steelblock", { | |
}) | |
minetest.register_node("default:nyancat", { | |
+ description = "Nyancat", | |
tile_images = {"default_nc_side.png", "default_nc_side.png", "default_nc_side.png", | |
"default_nc_side.png", "default_nc_back.png", "default_nc_front.png"}, | |
inventory_image = "default_nc_front.png", | |
@@ -1200,6 +1249,7 @@ minetest.register_node("default:nyancat", { | |
}) | |
minetest.register_node("default:nyancat_rainbow", { | |
+ description = "Rainbow Nyancat", | |
tile_images = {"default_nc_rb.png"}, | |
inventory_image = "default_nc_rb.png", | |
material = minetest.digprop_stonelike(3.0), | |
@@ -1207,6 +1257,7 @@ minetest.register_node("default:nyancat_rainbow", { | |
}) | |
minetest.register_node("default:sapling", { | |
+ description = "Sapling", | |
drawtype = "plantlike", | |
visual_scale = 1.0, | |
tile_images = {"default_sapling.png"}, | |
@@ -1219,6 +1270,7 @@ minetest.register_node("default:sapling", { | |
}) | |
minetest.register_node("default:apple", { | |
+ description = "Apple", | |
drawtype = "plantlike", | |
visual_scale = 1.0, | |
tile_images = {"default_apple.png"}, | |
@@ -1237,55 +1289,65 @@ minetest.register_node("default:apple", { | |
-- | |
minetest.register_craftitem("default:stick", { | |
+ description = "Stick", | |
image = "default_stick.png", | |
--furnace_burntime = ..., | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:paper", { | |
+ description = "Paper", | |
image = "default_paper.png", | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:book", { | |
+ description = "Book", | |
image = "default_book.png", | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:coal_lump", { | |
+ description = "Lump of Coal", | |
image = "default_coal_lump.png", | |
furnace_burntime = 40; | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:iron_lump", { | |
+ description = "Lump of Iron", | |
image = "default_iron_lump.png", | |
cookresult_itemstring = 'craft "default:steel_ingot" 1', | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:clay_lump", { | |
+ description = "Lump of Clay", | |
image = "default_clay_lump.png", | |
cookresult_itemstring = 'craft "default:clay_brick" 1', | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:steel_ingot", { | |
+ description = "Steel Ingot", | |
image = "default_steel_ingot.png", | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:clay_brick", { | |
+ description = "Clay Brick", | |
image = "default_clay_brick.png", | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:scorched_stuff", { | |
+ description = "Scorched Stuff", | |
image = "default_scorched_stuff.png", | |
on_place_on_ground = minetest.craftitem_place_item, | |
}) | |
minetest.register_craftitem("default:apple", { | |
+ description = "Apple", | |
image = "default_apple.png", | |
on_place_on_ground = minetest.craftitem_place_item, | |
on_use = minetest.craftitem_eat(4), | |
diff --git a/src/craftitemdef.cpp b/src/craftitemdef.cpp | |
index b8f9d1d..96c9cb0 100644 | |
--- a/src/craftitemdef.cpp | |
+++ b/src/craftitemdef.cpp | |
@@ -32,7 +32,8 @@ | |
usable(false), | |
liquids_pointable(false), | |
dropcount(-1), | |
- stack_max(99) | |
+ stack_max(99), | |
+ description("") | |
{} | |
std::string CraftItemDefinition::dump() | |
@@ -46,6 +47,7 @@ | |
os<<", liquids_pointable="<<liquids_pointable; | |
os<<", dropcount="<<dropcount; | |
os<<", stack_max="<<stack_max; | |
+ os<<", description="<<description; | |
return os.str(); | |
} | |
@@ -60,6 +62,7 @@ void CraftItemDefinition::serialize(std::ostream &os) | |
writeU8(os, liquids_pointable); | |
writeS16(os, dropcount); | |
writeS16(os, stack_max); | |
+ os<<serializeString(description); | |
} | |
void CraftItemDefinition::deSerialize(std::istream &is) | |
@@ -75,6 +78,7 @@ void CraftItemDefinition::deSerialize(std::istream &is) | |
liquids_pointable = readU8(is); | |
dropcount = readS16(is); | |
stack_max = readS16(is); | |
+ description = deSerializeString(is); | |
} | |
class CCraftItemDefManager: public IWritableCraftItemDefManager | |
@@ -99,6 +103,14 @@ class CCraftItemDefManager: public IWritableCraftItemDefManager | |
return ""; | |
return def->imagename; | |
} | |
+ virtual std::string getDescription(const std::string &itemname) const | |
+ { | |
+ const CraftItemDefinition *def = getCraftItemDefinition(itemname); | |
+ if(def == NULL) | |
+ return ""; | |
+ return def->description; | |
+ } | |
+ | |
virtual bool registerCraftItem(std::string itemname, const CraftItemDefinition &def) | |
{ | |
infostream<<"registerCraftItem: registering CraftItem \""<<itemname<<"\""<<std::endl; | |
diff --git a/src/craftitemdef.h b/src/craftitemdef.h | |
index 2f1a5bf..de09f17 100644 | |
--- a/src/craftitemdef.h | |
+++ b/src/craftitemdef.h | |
@@ -29,6 +29,7 @@ struct CraftItemDefinition | |
{ | |
std::string imagename; | |
std::string cookresult_item; | |
+ std::string description; | |
float furnace_cooktime; | |
float furnace_burntime; | |
bool usable; | |
@@ -49,6 +50,7 @@ class ICraftItemDefManager | |
virtual ~ICraftItemDefManager(){} | |
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname) const=0; | |
virtual std::string getImagename(const std::string &itemname) const =0; | |
+ virtual std::string getDescription(const std::string &itemname) const =0; | |
virtual void serialize(std::ostream &os)=0; | |
}; | |
@@ -60,7 +62,7 @@ class IWritableCraftItemDefManager : public ICraftItemDefManager | |
virtual ~IWritableCraftItemDefManager(){} | |
virtual const CraftItemDefinition* getCraftItemDefinition(const std::string &itemname) const=0; | |
virtual std::string getImagename(const std::string &itemname) const =0; | |
- | |
+ virtual std::string getDescription(const std::string &itemname) const =0; | |
virtual bool registerCraftItem(std::string itemname, const CraftItemDefinition &def)=0; | |
virtual void clear()=0; | |
diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp | |
index d9a98b5..767eec6 100644 | |
--- a/src/guiInventoryMenu.cpp | |
+++ b/src/guiInventoryMenu.cpp | |
@@ -105,7 +105,7 @@ void drawInventoryItem(video::IVideoDriver *driver, | |
GUIInventoryMenu::~GUIInventoryMenu() | |
{ | |
removeChildren(); | |
- | |
+ m_tooltip_button->remove(); | |
if(m_selected_item) | |
delete m_selected_item; | |
} | |
@@ -130,6 +130,7 @@ void GUIInventoryMenu::removeChildren() | |
if(e != NULL) | |
e->remove(); | |
}*/ | |
+ | |
} | |
void GUIInventoryMenu::regenerateGui(v2u32 screensize) | |
@@ -194,6 +195,7 @@ void GUIInventoryMenu::regenerateGui(v2u32 screensize) | |
const wchar_t *text = | |
L"Left click: Move all items, Right click: Move single item"; | |
Environment->addStaticText(text, rect, false, true, this, 256); | |
+ m_tooltip_button = Environment->addButton(core::rect<s32>(0,0,110,18),0,-1,L"",L""); | |
} | |
} | |
@@ -281,6 +283,15 @@ void GUIInventoryMenu::drawList(const ListDrawSpec &s, ITextureSource *tsrc) | |
{ | |
drawInventoryItem(driver, font, item, | |
rect, &AbsoluteClippingRect, tsrc); | |
+ if (rect.isPointInside(m_pointer)) { | |
+ //get hovered item string name for tooltip | |
+ std::string itemstring; | |
+ itemstring = item->getDescription(); | |
+ //need to convert the string into a wstring for a irrlicht button | |
+ std::wstring temp(itemstring.length(),L' '); | |
+ std::copy(itemstring.begin(), itemstring.end(), temp.begin()); | |
+ m_hovered_item_name = temp; | |
+ } | |
} | |
} | |
@@ -296,6 +307,7 @@ void GUIInventoryMenu::drawMenu() | |
video::SColor bgcolor(140,0,0,0); | |
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect); | |
+ m_hovered_item_name = L""; | |
/* | |
Draw items | |
*/ | |
@@ -305,6 +317,23 @@ void GUIInventoryMenu::drawMenu() | |
ListDrawSpec &s = m_draw_spec[i]; | |
drawList(s, m_tsrc); | |
} | |
+ | |
+ if (m_hovered_item_name != L"") | |
+ { | |
+ m_tooltip_button->setVisible(true); | |
+ this->bringToFront(m_tooltip_button); | |
+ int size = m_hovered_item_name.size(); | |
+ if (size < 5) size = 5; | |
+ core::rect<s32> rr(m_pointer.X + 10,m_pointer.Y + 10,m_pointer.X + (size * 10) + 10,m_pointer.Y + 50); | |
+ m_tooltip_button->setRelativePosition(rr); | |
+ m_tooltip_button->setText(m_hovered_item_name.c_str()); | |
+ } else { | |
+ m_tooltip_button->setVisible(false); | |
+ } | |
+ | |
+ | |
+ | |
+ | |
/* | |
Call base class | |
@@ -331,7 +360,7 @@ bool GUIInventoryMenu::OnEvent(const SEvent& event) | |
v2s32 p(event.MouseInput.X, event.MouseInput.Y); | |
ItemSpec s = getItemAtPos(p); | |
- if(event.MouseInput.Event==EMIE_MOUSE_MOVED) | |
+ if(event.MouseInput.Event==EMIE_MOUSE_MOVED) | |
m_pointer = v2s32(event.MouseInput.X, event.MouseInput.Y); | |
else if(event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN) | |
amount = 0; | |
diff --git a/src/guiInventoryMenu.h b/src/guiInventoryMenu.h | |
index c8fe0d0..e6b345d 100644 | |
--- a/src/guiInventoryMenu.h | |
+++ b/src/guiInventoryMenu.h | |
@@ -160,6 +160,8 @@ class GUIInventoryMenu : public GUIModalMenu | |
ItemSpec *m_selected_item; | |
v2s32 m_pointer; | |
+ gui::IGUIButton* m_tooltip_button; | |
+ std::wstring m_hovered_item_name; | |
}; | |
#endif | |
diff --git a/src/inventory.cpp b/src/inventory.cpp | |
index a913430..f3e25a7 100644 | |
--- a/src/inventory.cpp | |
+++ b/src/inventory.cpp | |
@@ -297,6 +297,13 @@ float MaterialItem::getBurnTime() const | |
return f.furnace_burntime; | |
} | |
+std::string MaterialItem::getDescription() | |
+{ | |
+ INodeDefManager *ndef = m_gamedef->ndef(); | |
+ const ContentFeatures &f = ndef->get(m_nodename); | |
+ return "MATL:" + f.description; | |
+} | |
+ | |
content_t MaterialItem::getMaterial() const | |
{ | |
INodeDefManager *ndef = m_gamedef->ndef(); | |
@@ -314,6 +321,11 @@ content_t MaterialItem::getMaterial() const | |
return m_gamedef->getToolDefManager()->getImagename(m_toolname); | |
} | |
+std::string ToolItem::getDescription() const | |
+{ | |
+ return "TOOL:" + m_gamedef->getToolDefManager()->getDescription(m_toolname); | |
+} | |
+ | |
#ifndef SERVER | |
video::ITexture * ToolItem::getImage() const | |
{ | |
@@ -364,6 +376,12 @@ bool ToolItem::isKnown() const | |
} | |
#endif | |
+std::string CraftItem::getDescription() const | |
+{ | |
+ ICraftItemDefManager *cidef = m_gamedef->cidef(); | |
+ return "CI:" + cidef->getDescription(m_subname); | |
+} | |
+ | |
bool CraftItem::isKnown() const | |
{ | |
ICraftItemDefManager *cidef = m_gamedef->cidef(); | |
diff --git a/src/inventory.h b/src/inventory.h | |
index 3f3c543..63321b7 100644 | |
--- a/src/inventory.h | |
+++ b/src/inventory.h | |
@@ -64,6 +64,10 @@ class InventoryItem | |
virtual std::string getText() { return ""; } | |
// Returns the string used for inventory | |
virtual std::string getItemString(); | |
+ | |
+ // returns the tooltip to show in the GUI | |
+ // getText() can't be used - it's parsed to show quantity overlays | |
+ virtual std::string getDescription() { return "Unknown"; } | |
// Shall return false if item is not known and cannot be used | |
virtual bool isKnown() const { return true; } | |
@@ -174,12 +178,13 @@ class MaterialItem : public InventoryItem | |
#ifndef SERVER | |
video::ITexture * getImage() const; | |
#endif | |
- std::string getText() | |
+ virtual std::string getText() | |
{ | |
std::ostringstream os; | |
os<<m_count; | |
return os.str(); | |
} | |
+ virtual std::string getDescription(); | |
virtual bool addableTo(const InventoryItem *other) const | |
{ | |
@@ -265,6 +270,7 @@ class CraftItem : public InventoryItem | |
#ifndef SERVER | |
video::ITexture * getImage() const; | |
#endif | |
+ std::string getDescription() const; | |
std::string getText() | |
{ | |
std::ostringstream os; | |
@@ -362,6 +368,7 @@ class ToolItem : public InventoryItem | |
} | |
std::string getImageBasename() const; | |
+ std::string getDescription() const; | |
#ifndef SERVER | |
video::ITexture * getImage() const; | |
video::ITexture * getImageRaw() const; | |
diff --git a/src/nodedef.cpp b/src/nodedef.cpp | |
index 9f2d4f0..c08cb9c 100644 | |
--- a/src/nodedef.cpp | |
+++ b/src/nodedef.cpp | |
@@ -156,6 +156,7 @@ void ContentFeatures::reset() | |
cookresult_item = ""; // Cannot be cooked | |
furnace_cooktime = 3.0; | |
furnace_burntime = -1.0; // Cannot be burned | |
+ description = ""; | |
} | |
void ContentFeatures::serialize(std::ostream &os) | |
@@ -203,6 +204,7 @@ void ContentFeatures::serialize(std::ostream &os) | |
os<<serializeString(cookresult_item); | |
writeF1000(os, furnace_cooktime); | |
writeF1000(os, furnace_burntime); | |
+ os<<serializeString(description); | |
} | |
void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef) | |
@@ -255,6 +257,7 @@ void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef) | |
cookresult_item = deSerializeString(is); | |
furnace_cooktime = readF1000(is); | |
furnace_burntime = readF1000(is); | |
+ description = deSerializeString(is); | |
} | |
void ContentFeatures::setTexture(u16 i, std::string name) | |
diff --git a/src/nodedef.h b/src/nodedef.h | |
index e0b5c86..678bad6 100644 | |
--- a/src/nodedef.h | |
+++ b/src/nodedef.h | |
@@ -205,6 +205,7 @@ struct ContentFeatures | |
std::string cookresult_item; | |
float furnace_cooktime; | |
float furnace_burntime; | |
+ std::string description; | |
/* | |
Methods | |
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp | |
index 624ca5d..4146f6e 100644 | |
--- a/src/scriptapi.cpp | |
+++ b/src/scriptapi.cpp | |
@@ -587,6 +587,7 @@ static ToolDefinition read_tool_definition(lua_State *L, int table) | |
{ | |
ToolDefinition def; | |
getstringfield(L, table, "image", def.imagename); | |
+ getstringfield(L, table, "description", def.description); | |
def.properties = read_tool_digging_properties(L, table); | |
return def; | |
} | |
@@ -861,6 +862,7 @@ static int l_register_craftitem(lua_State *L) | |
getstringfield(L, table, "image", def.imagename); | |
getstringfield(L, table, "cookresult_itemstring", def.cookresult_item); | |
+ getstringfield(L, table, "description", def.description); | |
getfloatfield(L, table, "furnace_cooktime", def.furnace_cooktime); | |
getfloatfield(L, table, "furnace_burntime", def.furnace_burntime); | |
def.usable = getboolfield_default(L, table, "usable", got_on_use); | |
@@ -1112,7 +1114,7 @@ static int l_register_node(lua_State *L) | |
getstringfield(L, nodedef_table, "cookresult_itemstring", f.cookresult_item); | |
getfloatfield(L, nodedef_table, "furnace_cooktime", f.furnace_cooktime); | |
getfloatfield(L, nodedef_table, "furnace_burntime", f.furnace_burntime); | |
- | |
+ getstringfield(L, nodedef_table, "description", f.description); | |
/* | |
Register it | |
*/ | |
diff --git a/src/tooldef.cpp b/src/tooldef.cpp | |
index 45193f4..341fa3b 100644 | |
--- a/src/tooldef.cpp | |
+++ b/src/tooldef.cpp | |
@@ -62,6 +62,7 @@ void ToolDefinition::serialize(std::ostream &os) | |
writeF1000(os, properties.dd_crumbliness); | |
writeF1000(os, properties.dd_cuttability); | |
writeF1000(os, properties.full_punch_interval); | |
+ os<<serializeString(description); | |
} | |
void ToolDefinition::deSerialize(std::istream &is) | |
@@ -83,6 +84,7 @@ void ToolDefinition::deSerialize(std::istream &is) | |
try{ | |
properties.full_punch_interval = readF1000(is); | |
}catch(SerializationError &e){} // Temporary for 0.4.dev | |
+ description = deSerializeString(is); | |
} | |
class CToolDefManager: public IWritableToolDefManager | |
@@ -107,6 +109,14 @@ class CToolDefManager: public IWritableToolDefManager | |
return ""; | |
return def->imagename; | |
} | |
+ virtual std::string getDescription(const std::string &toolname) const | |
+ { | |
+ const ToolDefinition *def = getToolDefinition(toolname); | |
+ if(def == NULL) | |
+ return ""; | |
+ return def->description; | |
+ } | |
+ | |
virtual ToolDiggingProperties getDiggingProperties( | |
const std::string &toolname) const | |
{ | |
diff --git a/src/tooldef.h b/src/tooldef.h | |
index aa4cb69..cdaf2c5 100644 | |
--- a/src/tooldef.h | |
+++ b/src/tooldef.h | |
@@ -46,6 +46,7 @@ struct ToolDiggingProperties | |
struct ToolDefinition | |
{ | |
std::string imagename; | |
+ std::string description; | |
ToolDiggingProperties properties; | |
ToolDefinition(){} | |
@@ -67,6 +68,7 @@ class IToolDefManager | |
virtual ~IToolDefManager(){} | |
virtual const ToolDefinition* getToolDefinition(const std::string &toolname) const=0; | |
virtual std::string getImagename(const std::string &toolname) const =0; | |
+ virtual std::string getDescription(const std::string &toolname) const =0; | |
virtual ToolDiggingProperties getDiggingProperties( | |
const std::string &toolname) const =0; | |
@@ -80,6 +82,7 @@ class IWritableToolDefManager : public IToolDefManager | |
virtual ~IWritableToolDefManager(){} | |
virtual const ToolDefinition* getToolDefinition(const std::string &toolname) const=0; | |
virtual std::string getImagename(const std::string &toolname) const =0; | |
+ virtual std::string getDescription(const std::string &toolname) const =0; | |
virtual ToolDiggingProperties getDiggingProperties( | |
const std::string &toolname) const =0; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment