minimap: Add ability to disable from server
This commit is contained in:
parent
a670ecfde4
commit
be9024a397
|
@ -2519,11 +2519,13 @@ This is basically a reference to a C++ `ServerActiveObject`
|
|||
* element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir`
|
||||
* `hud_get(id)`: gets the HUD element definition structure of the specified ID
|
||||
* `hud_set_flags(flags)`: sets specified HUD flags to `true`/`false`
|
||||
* `flags`: (is visible) `hotbar`, `healthbar`, `crosshair`, `wielditem`
|
||||
* `flags`: (is visible) `hotbar`, `healthbar`, `crosshair`, `wielditem`, `minimap`
|
||||
* pass a table containing a `true`/`false` value of each flag to be set or unset
|
||||
* if a flag equals `nil`, the flag is not modified
|
||||
* note that setting `minimap` modifies the client's permission to view the minimap -
|
||||
* the client may locally elect to not view the minimap
|
||||
* `hud_get_flags()`: returns a table containing status of hud flags
|
||||
* returns `{ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true }`
|
||||
* returns `{ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true }`
|
||||
* `hud_set_hotbar_itemcount(count)`: sets number of items in builtin hotbar
|
||||
* `count`: number of items, must be between `1` and `23`
|
||||
* `hud_get_hotbar_itemcount`: returns number of visible items
|
||||
|
|
27
src/game.cpp
27
src/game.cpp
|
@ -1497,7 +1497,7 @@ protected:
|
|||
|
||||
void toggleChat(float *statustext_time, bool *flag);
|
||||
void toggleHud(float *statustext_time, bool *flag);
|
||||
void toggleMinimap(float *statustext_time, bool *flag1, bool *flag2,
|
||||
void toggleMinimap(float *statustext_time, bool *flag, bool show_hud,
|
||||
bool shift_pressed);
|
||||
void toggleFog(float *statustext_time, bool *flag);
|
||||
void toggleDebug(float *statustext_time, bool *show_debug,
|
||||
|
@ -2642,7 +2642,7 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
|
|||
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_HUD])) {
|
||||
toggleHud(statustext_time, &flags->show_hud);
|
||||
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_MINIMAP])) {
|
||||
toggleMinimap(statustext_time, &flags->show_minimap, &flags->show_hud,
|
||||
toggleMinimap(statustext_time, &flags->show_minimap, flags->show_hud,
|
||||
input->isKeyDown(keycache.key[KeyCache::KEYMAP_ID_SNEAK]));
|
||||
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_CHAT])) {
|
||||
toggleChat(statustext_time, &flags->show_chat);
|
||||
|
@ -2864,15 +2864,25 @@ void Game::toggleHud(float *statustext_time, bool *flag)
|
|||
client->setHighlighted(client->getHighlighted(), *flag);
|
||||
}
|
||||
|
||||
void Game::toggleMinimap(float *statustext_time, bool *flag, bool *show_hud, bool shift_pressed)
|
||||
void Game::toggleMinimap(float *statustext_time, bool *flag,
|
||||
bool show_hud, bool shift_pressed)
|
||||
{
|
||||
if (*show_hud && g_settings->getBool("enable_minimap")) {
|
||||
if (!show_hud || !g_settings->getBool("enable_minimap"))
|
||||
return;
|
||||
|
||||
if (shift_pressed) {
|
||||
mapper->toggleMinimapShape();
|
||||
return;
|
||||
}
|
||||
MinimapMode mode = mapper->getMinimapMode();
|
||||
mode = (MinimapMode)((int)(mode) + 1);
|
||||
|
||||
u32 hud_flags = client->getEnv().getLocalPlayer()->hud_flags;
|
||||
|
||||
MinimapMode mode = MINIMAP_MODE_OFF;
|
||||
if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) {
|
||||
mode = mapper->getMinimapMode();
|
||||
mode = (MinimapMode)((int)mode + 1);
|
||||
}
|
||||
|
||||
*flag = true;
|
||||
switch (mode) {
|
||||
case MINIMAP_MODE_SURFACEx1:
|
||||
|
@ -2896,12 +2906,13 @@ void Game::toggleMinimap(float *statustext_time, bool *flag, bool *show_hud, boo
|
|||
default:
|
||||
mode = MINIMAP_MODE_OFF;
|
||||
*flag = false;
|
||||
statustext = L"Minimap hidden";
|
||||
statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ?
|
||||
L"Minimap hidden" : L"Minimap disabled by server";
|
||||
}
|
||||
|
||||
*statustext_time = 0;
|
||||
mapper->setMinimapMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
void Game::toggleFog(float *statustext_time, bool *flag)
|
||||
{
|
||||
|
|
|
@ -32,11 +32,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define HUD_CORNER_LOWER 1
|
||||
#define HUD_CORNER_CENTER 2
|
||||
|
||||
// Note that these visibility flags do not determine if the hud items are
|
||||
// actually drawn, but rather, allows the item to be drawn should the rest of
|
||||
// the game state permit it.
|
||||
#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)
|
||||
#define HUD_FLAG_BREATHBAR_VISIBLE (1 << 4)
|
||||
#define HUD_FLAG_MINIMAP_VISIBLE (1 << 5)
|
||||
|
||||
#define HUD_PARAM_HOTBAR_ITEMCOUNT 1
|
||||
#define HUD_PARAM_HOTBAR_IMAGE 2
|
||||
|
|
|
@ -75,7 +75,8 @@ Player::Player(IGameDef *gamedef, const char *name):
|
|||
"listring[]"
|
||||
"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
|
||||
// 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;
|
||||
|
@ -97,9 +98,10 @@ Player::Player(IGameDef *gamedef, const char *name):
|
|||
physics_override_sneak = true;
|
||||
physics_override_sneak_glitch = true;
|
||||
|
||||
hud_flags = HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
|
||||
hud_flags =
|
||||
HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
|
||||
HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
|
||||
HUD_FLAG_BREATHBAR_VISIBLE;
|
||||
HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE;
|
||||
|
||||
hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ struct EnumString es_HudBuiltinElement[] =
|
|||
{HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"},
|
||||
{HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"},
|
||||
{HUD_FLAG_BREATHBAR_VISIBLE, "breathbar"},
|
||||
{HUD_FLAG_MINIMAP_VISIBLE, "minimap"},
|
||||
{0, NULL},
|
||||
};
|
||||
|
||||
|
@ -1384,6 +1385,8 @@ int ObjectRef::l_hud_get_flags(lua_State *L)
|
|||
lua_setfield(L, -2, "wielditem");
|
||||
lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
|
||||
lua_setfield(L, -2, "breathbar");
|
||||
lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
|
||||
lua_setfield(L, -2, "minimap");
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue