From 3d4d0cb5749a68436cccd08b7a135f9bb7527038 Mon Sep 17 00:00:00 2001 From: ShadowNinja Date: Fri, 29 Mar 2013 23:28:13 -0400 Subject: Add option to not prepend "Server -!- " to messages sent with minetest.chat_send_player() --- src/server.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/server.h') diff --git a/src/server.h b/src/server.h index 52606b0cb..b668ecae4 100644 --- a/src/server.h +++ b/src/server.h @@ -456,7 +456,7 @@ public: } // Envlock and conlock should be locked when calling this - void notifyPlayer(const char *name, const std::wstring msg); + void notifyPlayer(const char *name, const std::wstring msg, const bool prepend); void notifyPlayers(const std::wstring msg); void spawnParticle(const char *playername, v3f pos, v3f velocity, v3f acceleration, -- cgit v1.2.3 From e703c5b81f87550e636ebb1ebb1eb64027a44687 Mon Sep 17 00:00:00 2001 From: Diego Martínez Date: Wed, 24 Apr 2013 07:52:46 -0300 Subject: Added support to disable built-in HUD elements --- doc/lua_api.txt | 3 +++ src/client.cpp | 14 ++++++++++++++ src/client.h | 7 ++++++- src/clientserver.h | 12 ++++++++++-- src/game.cpp | 15 ++++++++++++--- src/hud.cpp | 8 +++++--- src/hud.h | 17 +++++++++++++++-- src/player.cpp | 6 ++++++ src/player.h | 1 + src/scriptapi_object.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/scriptapi_object.h | 3 +++ src/server.cpp | 24 ++++++++++++++++++++++++ src/server.h | 2 ++ 13 files changed, 138 insertions(+), 11 deletions(-) (limited to 'src/server.h') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 42579fda3..b2106b64c 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1433,6 +1433,9 @@ Player-only: (no-op for other objects) - hud_change(id, stat, value): change a value of a previously added HUD element ^ element stat values: position, name, scale, text, number, item, dir - hud_get(id): gets the HUD element definition structure of the specified ID +- hud_builtin_enable(what, flag): enable or disable built-in HUD items + ^ what: "hotbar", "healthbar", "crosshair", "wielditem" + ^ flag: true/false InvRef: Reference to an inventory methods: diff --git a/src/client.cpp b/src/client.cpp index 12ced17fe..941e9e882 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2114,6 +2114,20 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) event.hudchange.data = intdata; m_client_event_queue.push_back(event); } + else if(command == TOCLIENT_HUD_BUILTIN_ENABLE) + { + std::string datastring((char *)&data[2], datasize - 2); + std::istringstream is(datastring, std::ios_base::binary); + + u32 id = readU8(is); + bool flag = (readU8(is) ? true : false); + + ClientEvent event; + event.type = CE_HUD_BUILTIN_ENABLE; + event.hudbuiltin.id = (HudBuiltinElement)id; + event.hudbuiltin.flag = flag; + m_client_event_queue.push_back(event); + } else { infostream<<"Client: Ignoring unknown command " diff --git a/src/client.h b/src/client.h index 67ba6c565..33872864e 100644 --- a/src/client.h +++ b/src/client.h @@ -163,7 +163,8 @@ enum ClientEventType CE_DELETE_PARTICLESPAWNER, CE_HUDADD, CE_HUDRM, - CE_HUDCHANGE + CE_HUDCHANGE, + CE_HUD_BUILTIN_ENABLE }; struct ClientEvent @@ -243,6 +244,10 @@ struct ClientEvent std::string *sdata; u32 data; } hudchange; + struct{ + u32 id; + u32 flag; + } hudbuiltin; }; }; diff --git a/src/clientserver.h b/src/clientserver.h index 5e981c202..114b04d13 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -94,6 +94,7 @@ SharedBuffer makePacket_TOCLIENT_TIME_OF_DAY(u16 time, float time_speed); TOCLIENT_HUD_ADD TOCLIENT_HUD_RM TOCLIENT_HUD_CHANGE + TOCLIENT_HUD_BUILTIN_ENABLE */ #define LATEST_PROTOCOL_VERSION 20 @@ -456,13 +457,13 @@ enum ToClientCommand v2f1000 offset */ - TOCLIENT_HUDRM = 0x50, + TOCLIENT_HUDRM = 0x4a, /* u16 command u32 id */ - TOCLIENT_HUDCHANGE = 0x51, + TOCLIENT_HUDCHANGE = 0x4b, /* u16 command u32 id @@ -472,6 +473,13 @@ enum ToClientCommand u8[len] data | u32 data] */ + + TOCLIENT_HUD_BUILTIN_ENABLE = 0x4c, + /* + u16 command + u8 id + u8 flag + */ }; enum ToServerCommand diff --git a/src/game.cpp b/src/game.cpp index cbd9eab4d..e3251bf65 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2186,6 +2186,14 @@ void the_game( delete event.hudchange.v2fdata; delete event.hudchange.sdata; } + else if (event.type == CE_HUD_BUILTIN_ENABLE) { + u32 bit = (u32)event.hudbuiltin.id; + u32 mask = 1 << bit; + if (event.hudbuiltin.flag) + player->hud_flags |= mask; + else + player->hud_flags &= ~mask; + } } } @@ -3070,7 +3078,7 @@ void the_game( /* Wielded tool */ - if(show_hud) + if(show_hud && (player->hud_flags & HUD_DRAW_WIELDITEM)) { // Warning: This clears the Z buffer. camera.drawWieldedTool(); @@ -3094,7 +3102,7 @@ void the_game( /* Draw crosshair */ - if (show_hud) + if (show_hud && (player->hud_flags & HUD_DRAW_CROSSHAIR)) hud.drawCrosshair(); } // timer @@ -3109,7 +3117,8 @@ void the_game( if (show_hud) { hud.drawHotbar(v2s32(displaycenter.X, screensize.Y), - client.getHP(), client.getPlayerItem()); + client.getHP(), client.getPlayerItem(), + player->hud_flags); } /* diff --git a/src/hud.cpp b/src/hud.cpp index 9db92db52..8daadad37 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -277,7 +277,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s } -void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { +void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags) { InventoryList *mainlist = inventory->getList("main"); if (mainlist == NULL) { errorstream << "draw_hotbar(): mainlist == NULL" << std::endl; @@ -288,8 +288,10 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { s32 width = hotbar_itemcount * (hotbar_imagesize + padding * 2); v2s32 pos = centerlowerpos - v2s32(width / 2, hotbar_imagesize + padding * 2); - drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); - drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, + if (flags & HUD_DRAW_HOTBAR) + drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); + if (flags & HUD_DRAW_HEALTHBAR) + drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, "heart.png", halfheartcount, v2s32(0, 0)); } diff --git a/src/hud.h b/src/hud.h index 104a2f00d..e0d7ccd6f 100644 --- a/src/hud.h +++ b/src/hud.h @@ -31,6 +31,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define HUD_CORNER_LOWER 1 #define HUD_CORNER_CENTER 2 +#define HUD_DRAW_HOTBAR (1 << 0) +#define HUD_DRAW_HEALTHBAR (1 << 1) +#define HUD_DRAW_CROSSHAIR (1 << 2) +#define HUD_DRAW_WIELDITEM (1 << 3) + class Player; enum HudElementType { @@ -66,6 +71,14 @@ struct HudElement { }; +enum HudBuiltinElement { + HUD_BUILTIN_HOTBAR = 0, + HUD_BUILTIN_HEALTHBAR, + HUD_BUILTIN_CROSSHAIR, + HUD_BUILTIN_WIELDITEM +}; + + inline u32 hud_get_free_id(Player *player) { size_t size = player->hud.size(); for (size_t i = 0; i != size; i++) { @@ -94,7 +107,7 @@ public: IGameDef *gamedef; LocalPlayer *player; Inventory *inventory; - + v2u32 screensize; v2s32 displaycenter; s32 hotbar_imagesize; @@ -112,7 +125,7 @@ public: void drawLuaElements(); void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset); - void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem); + void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags); void resizeHotbar(); void drawCrosshair(); diff --git a/src/player.cpp b/src/player.cpp index 1ca9423b0..e86b64206 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -18,6 +18,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "player.h" +#include "hud.h" #include "constants.h" #include "gamedef.h" #include "connection.h" // PEER_ID_INEXISTENT @@ -76,6 +77,11 @@ Player::Player(IGameDef *gamedef): physics_override_speed = 1; physics_override_jump = 1; physics_override_gravity = 1; + + hud_flags = HUD_DRAW_HOTBAR + | HUD_DRAW_HEALTHBAR + | HUD_DRAW_CROSSHAIR + | HUD_DRAW_WIELDITEM; } Player::~Player() diff --git a/src/player.h b/src/player.h index d0e50d2c3..4e5b3af97 100644 --- a/src/player.h +++ b/src/player.h @@ -245,6 +245,7 @@ public: u32 keyPressed; std::vector hud; + u32 hud_flags; protected: IGameDef *m_gamedef; diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index 6669ad871..e2eec5104 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -52,6 +52,15 @@ struct EnumString es_HudElementStat[] = {0, NULL}, }; +struct EnumString es_HudBuiltinElement[] = +{ + {HUD_BUILTIN_HOTBAR, "hotbar"}, + {HUD_BUILTIN_HEALTHBAR, "healthbar"}, + {HUD_BUILTIN_CROSSHAIR, "crosshair"}, + {HUD_BUILTIN_WIELDITEM, "wielditem"}, + {0, NULL}, +}; + /* ObjectRef @@ -902,6 +911,33 @@ int ObjectRef::l_hud_get(lua_State *L) return 1; } +// hud_builtin_enable(self, id, flag) +int ObjectRef::l_hud_builtin_enable(lua_State *L) +{ + ObjectRef *ref = checkobject(L, 1); + Player *player = getplayer(ref); + if (player == NULL) + return 0; + + HudBuiltinElement id; + int id_i; + + std::string s(lua_tostring(L, 2)); + + // Return nil if component is not in enum + if (!string_to_enum(es_HudBuiltinElement, id_i, s)) + return 0; + + id = (HudBuiltinElement)id_i; + + bool flag = (bool)lua_toboolean(L, 3); + + bool ok = get_server(L)->hudBuiltinEnable(player, id, flag); + + lua_pushboolean(L, (int)ok); + return 1; +} + ObjectRef::ObjectRef(ServerActiveObject *object): m_object(object) { @@ -1012,6 +1048,7 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, hud_remove), luamethod(ObjectRef, hud_change), luamethod(ObjectRef, hud_get), + luamethod(ObjectRef, hud_builtin_enable), //luamethod(ObjectRef, hud_lock_next_bar), //luamethod(ObjectRef, hud_unlock_bar), {0,0} diff --git a/src/scriptapi_object.h b/src/scriptapi_object.h index fd46f2cf6..81e8cda33 100644 --- a/src/scriptapi_object.h +++ b/src/scriptapi_object.h @@ -202,6 +202,9 @@ private: // hud_get(self, id) static int l_hud_get(lua_State *L); + // hud_builtin_enable(self, id, flag) + static int l_hud_builtin_enable(lua_State *L); + public: ObjectRef(ServerActiveObject *object); diff --git a/src/server.cpp b/src/server.cpp index 62c190036..a93d887e2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3675,6 +3675,22 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value m_con.Send(peer_id, 0, data, true); } +void Server::SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag) +{ + std::ostringstream os(std::ios_base::binary); + + // Write command + writeU16(os, TOCLIENT_HUD_BUILTIN_ENABLE); + writeU8(os, id); + writeU8(os, (flag ? 1 : 0)); + + // Make data buffer + std::string s = os.str(); + SharedBuffer data((u8*)s.c_str(), s.size()); + // Send as reliable + m_con.Send(peer_id, 0, data, true); +} + void Server::BroadcastChatMessage(const std::wstring &message) { for(std::map::iterator @@ -4664,6 +4680,14 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data) return true; } +bool Server::hudBuiltinEnable(Player *player, u32 id, bool flag) { + if (!player) + return false; + + SendHUDBuiltinEnable(player->peer_id, id, flag); + return true; +} + void Server::notifyPlayers(const std::wstring msg) { BroadcastChatMessage(msg); diff --git a/src/server.h b/src/server.h index b668ecae4..b951ae53f 100644 --- a/src/server.h +++ b/src/server.h @@ -540,6 +540,7 @@ public: u32 hudAdd(Player *player, HudElement *element); bool hudRemove(Player *player, u32 id); bool hudChange(Player *player, u32 id, HudElementStat stat, void *value); + bool hudBuiltinEnable(Player *player, u32 id, bool flag); private: @@ -583,6 +584,7 @@ private: void SendHUDAdd(u16 peer_id, u32 id, HudElement *form); void SendHUDRemove(u16 peer_id, u32 id); void SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value); + void SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag); /* Send a node removal/addition event to all clients except ignore_id. Additionally, if far_players!=NULL, players further away than -- cgit v1.2.3 From d3f0ce62240b7598eded13153eacb410bf2420a1 Mon Sep 17 00:00:00 2001 From: kwolekr Date: Thu, 25 Apr 2013 19:27:22 -0400 Subject: Generalize hud_builtin_enable into hud_set_flags --- doc/lua_api.txt | 7 ++++--- src/client.cpp | 20 ++++++++++---------- src/client.h | 7 +------ src/clientserver.h | 6 +++--- src/game.cpp | 15 +++------------ src/hud.cpp | 16 +++++++++------- src/hud.h | 21 +++++++-------------- src/player.cpp | 36 +++++++++++++++++------------------- src/scriptapi_object.cpp | 41 +++++++++++++++++++---------------------- src/scriptapi_object.h | 4 ++-- src/server.cpp | 14 +++++++------- src/server.h | 5 +++-- 12 files changed, 85 insertions(+), 107 deletions(-) (limited to 'src/server.h') diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 5b1942aef..07fb1ccd6 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -1434,9 +1434,10 @@ Player-only: (no-op for other objects) - hud_change(id, stat, value): change a value of a previously added HUD element ^ element stat values: position, name, scale, text, number, item, dir - hud_get(id): gets the HUD element definition structure of the specified ID -- hud_builtin_enable(what, flag): enable or disable built-in HUD items - ^ what: "hotbar", "healthbar", "crosshair", "wielditem" - ^ flag: true/false +- hud_set_flags(flags): sets specified HUD flags to true/false + ^ flags: (is visible) hotbar, healthbar, crosshair, wielditem + ^ pass a table containing a true/false value of each flag to be set or unset + ^ if a flag is nil, the flag is not modified InvRef: Reference to an inventory methods: diff --git a/src/client.cpp b/src/client.cpp index 941e9e882..56505c66c 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -2097,8 +2097,8 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) u32 id = readU32(is); u8 stat = (HudElementStat)readU8(is); - if (stat == HUD_STAT_POS || stat == HUD_STAT_SCALE - || stat == HUD_STAT_ALIGN || stat == HUD_STAT_OFFSET) + if (stat == HUD_STAT_POS || stat == HUD_STAT_SCALE || + stat == HUD_STAT_ALIGN || stat == HUD_STAT_OFFSET) v2fdata = readV2F1000(is); else if (stat == HUD_STAT_NAME || stat == HUD_STAT_TEXT) sdata = deSerializeString(is); @@ -2114,19 +2114,19 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id) event.hudchange.data = intdata; m_client_event_queue.push_back(event); } - else if(command == TOCLIENT_HUD_BUILTIN_ENABLE) + else if(command == TOCLIENT_HUD_SET_FLAGS) { std::string datastring((char *)&data[2], datasize - 2); std::istringstream is(datastring, std::ios_base::binary); - u32 id = readU8(is); - bool flag = (readU8(is) ? true : false); + Player *player = m_env.getLocalPlayer(); + assert(player != NULL); - ClientEvent event; - event.type = CE_HUD_BUILTIN_ENABLE; - event.hudbuiltin.id = (HudBuiltinElement)id; - event.hudbuiltin.flag = flag; - m_client_event_queue.push_back(event); + u32 flags = readU32(is); + u32 mask = readU32(is); + + player->hud_flags &= ~mask; + player->hud_flags |= flags; } else { diff --git a/src/client.h b/src/client.h index 33872864e..67ba6c565 100644 --- a/src/client.h +++ b/src/client.h @@ -163,8 +163,7 @@ enum ClientEventType CE_DELETE_PARTICLESPAWNER, CE_HUDADD, CE_HUDRM, - CE_HUDCHANGE, - CE_HUD_BUILTIN_ENABLE + CE_HUDCHANGE }; struct ClientEvent @@ -244,10 +243,6 @@ struct ClientEvent std::string *sdata; u32 data; } hudchange; - struct{ - u32 id; - u32 flag; - } hudbuiltin; }; }; diff --git a/src/clientserver.h b/src/clientserver.h index 114b04d13..cfa87ada7 100644 --- a/src/clientserver.h +++ b/src/clientserver.h @@ -474,11 +474,11 @@ enum ToClientCommand u32 data] */ - TOCLIENT_HUD_BUILTIN_ENABLE = 0x4c, + TOCLIENT_HUD_SET_FLAGS = 0x4c, /* u16 command - u8 id - u8 flag + u32 flags + u32 mask */ }; diff --git a/src/game.cpp b/src/game.cpp index e3251bf65..189003e4c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -2186,14 +2186,6 @@ void the_game( delete event.hudchange.v2fdata; delete event.hudchange.sdata; } - else if (event.type == CE_HUD_BUILTIN_ENABLE) { - u32 bit = (u32)event.hudbuiltin.id; - u32 mask = 1 << bit; - if (event.hudbuiltin.flag) - player->hud_flags |= mask; - else - player->hud_flags &= ~mask; - } } } @@ -3078,7 +3070,7 @@ void the_game( /* Wielded tool */ - if(show_hud && (player->hud_flags & HUD_DRAW_WIELDITEM)) + if(show_hud && (player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE)) { // Warning: This clears the Z buffer. camera.drawWieldedTool(); @@ -3102,7 +3094,7 @@ void the_game( /* Draw crosshair */ - if (show_hud && (player->hud_flags & HUD_DRAW_CROSSHAIR)) + if (show_hud) hud.drawCrosshair(); } // timer @@ -3117,8 +3109,7 @@ void the_game( if (show_hud) { hud.drawHotbar(v2s32(displaycenter.X, screensize.Y), - client.getHP(), client.getPlayerItem(), - player->hud_flags); + client.getHP(), client.getPlayerItem()); } /* diff --git a/src/hud.cpp b/src/hud.cpp index 8daadad37..cf53354b2 100644 --- a/src/hud.cpp +++ b/src/hud.cpp @@ -277,7 +277,7 @@ void Hud::drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s } -void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags) { +void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem) { InventoryList *mainlist = inventory->getList("main"); if (mainlist == NULL) { errorstream << "draw_hotbar(): mainlist == NULL" << std::endl; @@ -288,19 +288,21 @@ void Hud::drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u s32 width = hotbar_itemcount * (hotbar_imagesize + padding * 2); v2s32 pos = centerlowerpos - v2s32(width / 2, hotbar_imagesize + padding * 2); - if (flags & HUD_DRAW_HOTBAR) + if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) drawItem(pos, hotbar_imagesize, hotbar_itemcount, mainlist, playeritem + 1, 0); - if (flags & HUD_DRAW_HEALTHBAR) + if (player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE) drawStatbar(pos - v2s32(0, 4), HUD_CORNER_LOWER, HUD_DIR_LEFT_RIGHT, "heart.png", halfheartcount, v2s32(0, 0)); } void Hud::drawCrosshair() { - driver->draw2DLine(displaycenter - v2s32(10, 0), - displaycenter + v2s32(10, 0), crosshair_argb); - driver->draw2DLine(displaycenter - v2s32(0, 10), - displaycenter + v2s32(0, 10), crosshair_argb); + if (player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) { + driver->draw2DLine(displaycenter - v2s32(10, 0), + displaycenter + v2s32(10, 0), crosshair_argb); + driver->draw2DLine(displaycenter - v2s32(0, 10), + displaycenter + v2s32(0, 10), crosshair_argb); + } } diff --git a/src/hud.h b/src/hud.h index e0d7ccd6f..405e91176 100644 --- a/src/hud.h +++ b/src/hud.h @@ -31,10 +31,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #define HUD_CORNER_LOWER 1 #define HUD_CORNER_CENTER 2 -#define HUD_DRAW_HOTBAR (1 << 0) -#define HUD_DRAW_HEALTHBAR (1 << 1) -#define HUD_DRAW_CROSSHAIR (1 << 2) -#define HUD_DRAW_WIELDITEM (1 << 3) +#define HUD_FLAG_HOTBAR_VISIBLE (1 << 0) +#define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1) +#define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2) +#define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3) class Player; @@ -71,14 +71,6 @@ struct HudElement { }; -enum HudBuiltinElement { - HUD_BUILTIN_HOTBAR = 0, - HUD_BUILTIN_HEALTHBAR, - HUD_BUILTIN_CROSSHAIR, - HUD_BUILTIN_WIELDITEM -}; - - inline u32 hud_get_free_id(Player *player) { size_t size = player->hud.size(); for (size_t i = 0; i != size; i++) { @@ -123,9 +115,10 @@ public: void drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount, InventoryList *mainlist, u16 selectitem, u16 direction); void drawLuaElements(); - void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture, s32 count, v2s32 offset); + void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, + std::string texture, s32 count, v2s32 offset); - void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem, u32 flags); + void drawHotbar(v2s32 centerlowerpos, s32 halfheartcount, u16 playeritem); void resizeHotbar(); void drawCrosshair(); diff --git a/src/player.cpp b/src/player.cpp index d3e16810f..34f0fda08 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -54,35 +54,33 @@ Player::Player(IGameDef *gamedef): inventory.addList("craftresult", 1); // Can be redefined via Lua - inventory_formspec = "size[8,7.5]" + inventory_formspec = "size[8,7.5]" //"image[1,0.6;1,2;player.png]" "list[current_player;main;0,3.5;8,4;]" "list[current_player;craft;3,0;3,3;]" "list[current_player;craftpreview;7,1;1,1;]"; // Initialize movement settings at default values, so movement can work if the server fails to send them - movement_acceleration_default = 3 * BS; - movement_acceleration_air = 2 * BS; - movement_acceleration_fast = 10 * BS; - movement_speed_walk = 4 * BS; - movement_speed_crouch = 1.35 * BS; - movement_speed_fast = 20 * BS; - movement_speed_climb = 2 * BS; - movement_speed_jump = 6.5 * BS; - movement_liquid_fluidity = 1 * BS; - movement_liquid_fluidity_smooth = 0.5 * BS; - movement_liquid_sink = 10 * BS; - movement_gravity = 9.81 * BS; + movement_acceleration_default = 3 * BS; + movement_acceleration_air = 2 * BS; + movement_acceleration_fast = 10 * BS; + movement_speed_walk = 4 * BS; + movement_speed_crouch = 1.35 * BS; + movement_speed_fast = 20 * BS; + movement_speed_climb = 2 * BS; + movement_speed_jump = 6.5 * BS; + movement_liquid_fluidity = 1 * BS; + movement_liquid_fluidity_smooth = 0.5 * BS; + movement_liquid_sink = 10 * BS; + movement_gravity = 9.81 * BS; // Movement overrides are multipliers and must be 1 by default - physics_override_speed = 1; - physics_override_jump = 1; + physics_override_speed = 1; + physics_override_jump = 1; physics_override_gravity = 1; - hud_flags = HUD_DRAW_HOTBAR - | HUD_DRAW_HEALTHBAR - | HUD_DRAW_CROSSHAIR - | HUD_DRAW_WIELDITEM; + hud_flags = HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE | + HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE; } Player::~Player() diff --git a/src/scriptapi_object.cpp b/src/scriptapi_object.cpp index e2eec5104..4dfdeb8c8 100644 --- a/src/scriptapi_object.cpp +++ b/src/scriptapi_object.cpp @@ -54,10 +54,10 @@ struct EnumString es_HudElementStat[] = struct EnumString es_HudBuiltinElement[] = { - {HUD_BUILTIN_HOTBAR, "hotbar"}, - {HUD_BUILTIN_HEALTHBAR, "healthbar"}, - {HUD_BUILTIN_CROSSHAIR, "crosshair"}, - {HUD_BUILTIN_WIELDITEM, "wielditem"}, + {HUD_FLAG_HOTBAR_VISIBLE, "hotbar"}, + {HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"}, + {HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"}, + {HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"}, {0, NULL}, }; @@ -911,30 +911,29 @@ int ObjectRef::l_hud_get(lua_State *L) return 1; } -// hud_builtin_enable(self, id, flag) -int ObjectRef::l_hud_builtin_enable(lua_State *L) +// hud_set_flags(self, flags) +int ObjectRef::l_hud_set_flags(lua_State *L) { ObjectRef *ref = checkobject(L, 1); Player *player = getplayer(ref); if (player == NULL) return 0; - HudBuiltinElement id; - int id_i; + u32 flags = 0; + u32 mask = 0; + bool flag; - std::string s(lua_tostring(L, 2)); - - // Return nil if component is not in enum - if (!string_to_enum(es_HudBuiltinElement, id_i, s)) + const EnumString *esp = es_HudBuiltinElement; + for (int i = 0; esp[i].str; i++) { + if (getboolfield(L, 2, esp[i].str, flag)) { + flags |= esp[i].num * flag; + mask |= esp[i].num; + } + } + if (!get_server(L)->hudSetFlags(player, flags, mask)) return 0; - - id = (HudBuiltinElement)id_i; - bool flag = (bool)lua_toboolean(L, 3); - - bool ok = get_server(L)->hudBuiltinEnable(player, id, flag); - - lua_pushboolean(L, (int)ok); + lua_pushboolean(L, true); return 1; } @@ -1048,9 +1047,7 @@ const luaL_reg ObjectRef::methods[] = { luamethod(ObjectRef, hud_remove), luamethod(ObjectRef, hud_change), luamethod(ObjectRef, hud_get), - luamethod(ObjectRef, hud_builtin_enable), - //luamethod(ObjectRef, hud_lock_next_bar), - //luamethod(ObjectRef, hud_unlock_bar), + luamethod(ObjectRef, hud_set_flags), {0,0} }; diff --git a/src/scriptapi_object.h b/src/scriptapi_object.h index 81e8cda33..82535ee94 100644 --- a/src/scriptapi_object.h +++ b/src/scriptapi_object.h @@ -202,8 +202,8 @@ private: // hud_get(self, id) static int l_hud_get(lua_State *L); - // hud_builtin_enable(self, id, flag) - static int l_hud_builtin_enable(lua_State *L); + // hud_set_flags(self, flags) + static int l_hud_set_flags(lua_State *L); public: ObjectRef(ServerActiveObject *object); diff --git a/src/server.cpp b/src/server.cpp index a93d887e2..d5e505190 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -3675,18 +3675,18 @@ void Server::SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value m_con.Send(peer_id, 0, data, true); } -void Server::SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag) +void Server::SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask) { std::ostringstream os(std::ios_base::binary); // Write command - writeU16(os, TOCLIENT_HUD_BUILTIN_ENABLE); - writeU8(os, id); - writeU8(os, (flag ? 1 : 0)); + writeU16(os, TOCLIENT_HUD_SET_FLAGS); + writeU32(os, flags); + writeU32(os, mask); // Make data buffer std::string s = os.str(); - SharedBuffer data((u8*)s.c_str(), s.size()); + SharedBuffer data((u8 *)s.c_str(), s.size()); // Send as reliable m_con.Send(peer_id, 0, data, true); } @@ -4680,11 +4680,11 @@ bool Server::hudChange(Player *player, u32 id, HudElementStat stat, void *data) return true; } -bool Server::hudBuiltinEnable(Player *player, u32 id, bool flag) { +bool Server::hudSetFlags(Player *player, u32 flags, u32 mask) { if (!player) return false; - SendHUDBuiltinEnable(player->peer_id, id, flag); + SendHUDSetFlags(player->peer_id, flags, mask); return true; } diff --git a/src/server.h b/src/server.h index b951ae53f..dcd007d23 100644 --- a/src/server.h +++ b/src/server.h @@ -540,7 +540,7 @@ public: u32 hudAdd(Player *player, HudElement *element); bool hudRemove(Player *player, u32 id); bool hudChange(Player *player, u32 id, HudElementStat stat, void *value); - bool hudBuiltinEnable(Player *player, u32 id, bool flag); + bool hudSetFlags(Player *player, u32 flags, u32 mask); private: @@ -584,7 +584,8 @@ private: void SendHUDAdd(u16 peer_id, u32 id, HudElement *form); void SendHUDRemove(u16 peer_id, u32 id); void SendHUDChange(u16 peer_id, u32 id, HudElementStat stat, void *value); - void SendHUDBuiltinEnable(u16 peer_id, u32 id, bool flag); + void SendHUDSetFlags(u16 peer_id, u32 flags, u32 mask); + /* Send a node removal/addition event to all clients except ignore_id. Additionally, if far_players!=NULL, players further away than -- cgit v1.2.3