Compare commits

...

5 Commits

Author SHA1 Message Date
Robin Kuck bf49f499d6 gui tooltip picture 2012-01-10 11:08:36 +01:00
Robin Kuck d06224dcb0 GUI Inventory Tooltip 2012-01-10 08:17:53 +01:00
Robin Kuck 4ef0c10ef3 Player died event for the script api 2012-01-10 08:17:53 +01:00
Robin Kuck 4489b205dc Fix it 2012-01-07 00:13:26 +01:00
Robin Kuck 7cdcd146c1 add README 2012-01-06 13:18:54 +01:00
5 changed files with 181 additions and 1 deletions

8
README Normal file
View File

@ -0,0 +1,8 @@
Minetest-c55 Modifications and Patchsets
----------------------------------------
patches/ - Patchsets
mods/ - Mods
mod-patches/ - Patches for Mods

View File

@ -14,7 +14,7 @@ minetest.register_on_dieplayer(function(player)
print(inventorylist[i])
local bnumbeg, bnumend=string.find(inventorylist[i], '" ')
local oldvalue=tonumber(string.sub(inventorylist[i], bnumend))
oldvalue=math.random(0,(oldvalue/3)-1)
oldvalue=math.random(0,(oldvalue/3))
local newstring=string.sub(inventorylist[i], 1, bnumend)
newstring=(newstring..tostring(oldvalue))
if oldvalue == 0 then

84
patches/0000-die.patch Normal file
View File

@ -0,0 +1,84 @@
diff --git a/data/builtin.lua b/data/builtin.lua
index b2ce968..1046e93 100644
--- a/data/builtin.lua
+++ b/data/builtin.lua
@@ -435,6 +435,7 @@ minetest.registered_on_dignodes, minetest.register_on_dignode = make_registratio
minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration()
minetest.registered_on_generateds, minetest.register_on_generated = make_registration()
minetest.registered_on_newplayers, minetest.register_on_newplayer = make_registration()
+minetest.registered_on_dieplayers, minetest.register_on_dieplayer = make_registration()
minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make_registration()
-- END
diff --git a/data/mods/give_initial_stuff/init.lua b/data/mods/give_initial_stuff/init.lua
index e52784d..d374c8b 100644
--- a/data/mods/give_initial_stuff/init.lua
+++ b/data/mods/give_initial_stuff/init.lua
@@ -10,3 +10,6 @@ minetest.register_on_newplayer(function(player)
end
end)
+
+
+
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index 35b5973..546a61e 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -3638,6 +3638,32 @@ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player)
// value removed, keep key for next iteration
}
}
+
+void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player)
+{
+ realitycheck(L);
+ assert(lua_checkstack(L, 20));
+ StackUnroller stack_unroller(L);
+
+ // Get minetest.registered_on_dieplayers
+ lua_getglobal(L, "minetest");
+ lua_getfield(L, -1, "registered_on_dieplayers");
+ luaL_checktype(L, -1, LUA_TTABLE);
+ int table = lua_gettop(L);
+ // Foreach
+ lua_pushnil(L);
+ while(lua_next(L, table) != 0){
+ // key at index -2 and value at index -1
+ luaL_checktype(L, -1, LUA_TFUNCTION);
+ // Call function
+ objectref_get_or_create(L, player);
+ if(lua_pcall(L, 1, 0, 0))
+ script_error(L, "error: %s", lua_tostring(L, -1));
+ // value removed, keep key for next iteration
+ }
+}
+
+
bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player)
{
realitycheck(L);
diff --git a/src/scriptapi.h b/src/scriptapi.h
index d107b15..af8afa3 100644
--- a/src/scriptapi.h
+++ b/src/scriptapi.h
@@ -62,6 +62,7 @@ void scriptapi_environment_on_punchnode(lua_State *L, v3s16 p, MapNode node,
/* misc */
void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player);
+void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player);
bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player);
void scriptapi_get_creative_inventory(lua_State *L, ServerRemotePlayer *player);
diff --git a/src/server.cpp b/src/server.cpp
index 8bf9eee..010a214 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -4522,6 +4522,7 @@ void Server::HandlePlayerHP(Player *player, s16 damage)
player->hp = 0;
//TODO: Throw items around
+ scriptapi_on_dieplayer(m_lua, srp);
// Handle players that are not connected
if(player->peer_id == PEER_ID_INEXISTENT){

View File

@ -0,0 +1,88 @@
diff --git a/src/guiInventoryMenu.cpp b/src/guiInventoryMenu.cpp
index 552e10d..84367b9 100644
--- a/src/guiInventoryMenu.cpp
+++ b/src/guiInventoryMenu.cpp
@@ -106,7 +106,7 @@ void drawInventoryItem(video::IVideoDriver *driver,
GUIInventoryMenu::~GUIInventoryMenu()
{
removeChildren();
-
+ m_tooltip->remove(); // Item Description
if(m_selected_item)
delete m_selected_item;
}
@@ -195,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 = Environment->addStaticText(L"", core::rect<s32>(),true,false,0,-1, true);
}
}
@@ -282,6 +283,24 @@ 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->getItemString();
+ int pos = itemstring.find_first_of(':') + 1;
+ int pos_;
+ itemstring = itemstring.substr(pos, itemstring.find_last_of('"')-pos);
+ pos_ = itemstring.find_first_of('_');
+ while (pos_ != std::string::npos) {
+ itemstring[pos_] = ' ';
+ pos_ = itemstring.find_first_of('_', pos_ +1);
+ }
+ //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 +315,8 @@ void GUIInventoryMenu::drawMenu()
video::SColor bgcolor(140,0,0,0);
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+
+ m_hovered_item_name = L"";
/*
Draw items
@@ -307,6 +328,19 @@ void GUIInventoryMenu::drawMenu()
drawList(s, m_tsrc);
}
+ if (m_hovered_item_name != L"")
+ {
+ m_tooltip->setVisible(true);
+ this->bringToFront(m_tooltip);
+ 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->setRelativePosition(rr);
+ m_tooltip->setText(m_hovered_item_name.c_str());
+ } else {
+ m_tooltip->setVisible(false);
+ }
+
/*
Call base class
*/
diff --git a/src/guiInventoryMenu.h b/src/guiInventoryMenu.h
index 3592686..8fef170 100644
--- a/src/guiInventoryMenu.h
+++ b/src/guiInventoryMenu.h
@@ -162,6 +162,8 @@ class GUIInventoryMenu : public GUIModalMenu
ItemSpec *m_selected_item;
v2s32 m_pointer;
+ gui::IGUIStaticText* m_tooltip;
+ std::wstring m_hovered_item_name;
};
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 KiB