fix hudbar in minetest mode and other games

This commit is contained in:
proller 2016-02-06 21:17:19 +03:00
parent c2936af03c
commit 7c004bdaa9
13 changed files with 72 additions and 21 deletions

View File

@ -129,3 +129,9 @@ core.stat_add(key, playername, value=1)
^ If defined, node becomes element of circuit
^ Called when block changes it's input state from non zero to zero
### Functions additions:
core.hud_set_hotbar_image(self, name, items)
added optional param: items=1 mean gui_hotbar.png contains only one cell

View File

@ -81,6 +81,7 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
hotbar_image = "";
hotbar_image_items = 0;
use_hotbar_image = false;
hotbar_selected_image = "";
use_hotbar_selected_image = false;
@ -170,11 +171,22 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
g_touchscreengui->resetHud();
#endif
//only for !hotbar_image_items ===
s32 height = m_hotbar_imagesize + m_padding * 2;
s32 width = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2);
if (direction == HUD_DIR_TOP_BOTTOM || direction == HUD_DIR_BOTTOM_TOP) {
width = m_hotbar_imagesize + m_padding * 2;
height = (itemcount - offset) * (m_hotbar_imagesize + m_padding * 2);
}
//================================
// Position of upper left corner of bar
v2s32 pos = upperleftpos;
if (hotbar_image != player->hotbar_image) {
hotbar_image = player->hotbar_image;
hotbar_image_items = player->hotbar_image_items;
if (hotbar_image != "")
use_hotbar_image = tsrc->isKnownSourceImage(hotbar_image);
else
@ -191,8 +203,20 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
/* draw customized item background */
if (use_hotbar_image) {
if (!hotbar_image_items) {
core::rect<s32> imgrect2(-m_padding/2, -m_padding/2,
width+m_padding/2, height+m_padding/2);
core::rect<s32> rect2 = imgrect2 + pos;
video::ITexture *texture = tsrc->getTexture(hotbar_image);
core::dimension2di imgsize(texture->getOriginalSize());
draw2DImageFilterScaled(driver, texture, rect2,
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
NULL, hbar_colors, true);
} else {
video::ITexture *texture = tsrc->getTexture(hotbar_image);
core::dimension2di imgsize(texture->getOriginalSize());
// todo: maybe deal with hotbar_image_items>1
core::rect<s32> rect(-m_padding, -m_padding,
m_hotbar_imagesize + m_padding, m_hotbar_imagesize + m_padding);
rect += pos;
@ -205,6 +229,8 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
NULL, hbar_colors, true);
rect += step;
}
}
}
for (s32 i = offset; i < itemcount && (size_t)i < mainlist->getSize(); i++)
@ -212,8 +238,11 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
v2s32 steppos;
s32 fullimglen = m_hotbar_imagesize + m_padding * 2;
core::rect<s32> imgrect(-m_padding, -m_padding,
m_hotbar_imagesize - m_padding, m_hotbar_imagesize - m_padding);
core::rect<s32> imgrect;
if (!hotbar_image_items)
imgrect = core::rect<s32>(0, 0, m_hotbar_imagesize, m_hotbar_imagesize);
else
imgrect = core::rect<s32>(-m_padding, -m_padding, m_hotbar_imagesize - m_padding, m_hotbar_imagesize - m_padding);
switch (direction) {
case HUD_DIR_RIGHT_LEFT:
@ -420,7 +449,7 @@ void Hud::drawHotbar(u16 playeritem) {
pos.X += width/4;
v2s32 secondpos = pos;
pos = pos - v2s32(0, m_hotbar_imagesize + m_padding * 2);
pos = pos - v2s32(0, m_hotbar_imagesize + m_padding * (hotbar_image_items ? 2 : 1));
if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) {
drawItems(pos, hotbar_itemcount/2, 0, mainlist, playeritem + 1, 0);

View File

@ -47,6 +47,7 @@ along with Freeminer. If not, see <http://www.gnu.org/licenses/>.
#define HUD_PARAM_HOTBAR_ITEMCOUNT 1
#define HUD_PARAM_HOTBAR_IMAGE 2
static const int HUD_PARAM_HOTBAR_IMAGE_ITEMS = 104;
#define HUD_PARAM_HOTBAR_SELECTED_IMAGE 3
#define HUD_HOTBAR_ITEMCOUNT_DEFAULT 8
@ -119,6 +120,7 @@ public:
video::SColor selectionbox_argb;
bool use_crosshair_image;
std::string hotbar_image;
int hotbar_image_items;
bool use_hotbar_image;
std::string hotbar_selected_image;
bool use_hotbar_selected_image;

View File

@ -49,8 +49,11 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef, const char *name):
last_keyPressed(0),
camera_impact(0.f),
last_animation(NO_ANIM),
/*
hotbar_image(""),
hotbar_image_items(0),
hotbar_selected_image(""),
*/
light_color(255,255,255,255),
m_sneak_node(32767,32767,32767),
m_sneak_node_exists(false),

View File

@ -72,8 +72,11 @@ public:
int last_animation;
float last_animation_speed;
/*
std::string hotbar_image;
int hotbar_image_items;
std::string hotbar_selected_image;
*/
video::SColor light_color;

View File

@ -1131,8 +1131,8 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
*pkt >> param >> value;
Player *player = m_env.getLocalPlayer();
assert(player != NULL);
auto *player = m_env.getLocalPlayer();
//assert(player != NULL);
if (param == HUD_PARAM_HOTBAR_ITEMCOUNT && value.size() == 4) {
s32 hotbar_itemcount = readS32((u8*) value.c_str());
@ -1140,10 +1140,13 @@ void Client::handleCommand_HudSetParam(NetworkPacket* pkt)
player->hud_hotbar_itemcount = hotbar_itemcount;
}
else if (param == HUD_PARAM_HOTBAR_IMAGE) {
((LocalPlayer *) player)->hotbar_image = value;
player->hotbar_image = value;
}
else if (param == HUD_PARAM_HOTBAR_IMAGE_ITEMS) {
player->hotbar_image_items = stoi(value);
}
else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) {
((LocalPlayer *) player)->hotbar_selected_image = value;
player->hotbar_selected_image = value;
}
}

View File

@ -162,7 +162,7 @@ void Client::ProcessData(NetworkPacket *pkt) {
*/
// there's no sane reason why we shouldn't have a player and
// almost everyone needs a player reference
Player *player = m_env.getLocalPlayer();
auto *player = m_env.getLocalPlayer();
if(!player)
return;
@ -756,9 +756,11 @@ void Client::ProcessData(NetworkPacket *pkt) {
if(hotbar_itemcount > 0 && hotbar_itemcount <= HUD_HOTBAR_ITEMCOUNT_MAX)
player->hud_hotbar_itemcount = hotbar_itemcount;
} else if (param == HUD_PARAM_HOTBAR_IMAGE) {
((LocalPlayer *) player)->hotbar_image = value;
player->hotbar_image = value;
} else if (param == HUD_PARAM_HOTBAR_IMAGE_ITEMS) {
player->hotbar_image_items = stoi(value);
} else if (param == HUD_PARAM_HOTBAR_SELECTED_IMAGE) {
((LocalPlayer *) player)->hotbar_selected_image = value;
player->hotbar_selected_image = value;
}
}
/*

View File

@ -65,6 +65,7 @@ Player::Player(IGameDef *gamedef, const std::string & name):
peer_id = PEER_ID_INEXISTENT;
m_name = name;
hotbar_image_items = 0;
inventory.clear();
inventory.addList("main", PLAYER_INVENTORY_SIZE);

View File

@ -240,21 +240,21 @@ public:
void setHotbarImage(const std::string &name)
{
hud_hotbar_image = name;
hotbar_image = name;
}
std::string getHotbarImage()
{
return hud_hotbar_image;
return hotbar_image;
}
void setHotbarSelectedImage(const std::string &name)
{
hud_hotbar_selected_image = name;
hotbar_selected_image = name;
}
std::string getHotbarSelectedImage() {
return hud_hotbar_selected_image;
return hotbar_selected_image;
}
void setSky(const video::SColor &bgcolor, const std::string &type,
@ -402,8 +402,9 @@ public:
u32 hud_flags;
s32 hud_hotbar_itemcount;
std::string hud_hotbar_image;
std::string hud_hotbar_selected_image;
std::string hotbar_image;
int hotbar_image_items;
std::string hotbar_selected_image;
protected:
IGameDef *m_gamedef;

View File

@ -1516,8 +1516,8 @@ int ObjectRef::l_hud_set_hotbar_image(lua_State *L)
return 0;
std::string name = lua_tostring(L, 2);
getServer(L)->hudSetHotbarImage(player, name);
auto items = lua_tonumber(L, 3);
getServer(L)->hudSetHotbarImage(player, name, items);
return 1;
}

View File

@ -3444,13 +3444,14 @@ s32 Server::hudGetHotbarItemcount(Player *player)
return player->getHotbarItemcount();
}
void Server::hudSetHotbarImage(Player *player, std::string name)
void Server::hudSetHotbarImage(Player *player, std::string name, int items)
{
if (!player)
return;
player->setHotbarImage(name);
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE, name);
SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE_ITEMS, std::to_string(items));
}
std::string Server::hudGetHotbarImage(Player *player)

View File

@ -354,7 +354,7 @@ public:
bool hudSetFlags(Player *player, u32 flags, u32 mask);
bool hudSetHotbarItemcount(Player *player, s32 hotbar_itemcount);
s32 hudGetHotbarItemcount(Player *player);
void hudSetHotbarImage(Player *player, std::string name);
void hudSetHotbarImage(Player *player, std::string name, int items = 0);
std::string hudGetHotbarImage(Player *player);
void hudSetHotbarSelectedImage(Player *player, std::string name);
std::string hudGetHotbarSelectedImage(Player *player);

View File

@ -394,7 +394,7 @@ our $tasks = {
}, (
map {
'bot_minetest_' . $_ => [['bot_minetest', $_,]]
} qw(tsan tsannt asan usan)
} qw(tsan tsannt asan usan gdb)
),
#stress => [{ZZbuild_name => 'normal'}, 'prepare', 'cmake', 'make', 'run_server_auto', 'run_clients',],