Skip to content

Commit

Permalink
minimap: Add ability to disable from server
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Aug 13, 2015
1 parent a670ecf commit be9024a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 47 deletions.
6 changes: 4 additions & 2 deletions doc/lua_api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 48 additions & 37 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ class Game {

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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2864,43 +2864,54 @@ 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 (shift_pressed) {
mapper->toggleMinimapShape();
return;
}
MinimapMode mode = mapper->getMinimapMode();
mode = (MinimapMode)((int)(mode) + 1);
*flag = true;
switch (mode) {
case MINIMAP_MODE_SURFACEx1:
statustext = L"Minimap in surface mode, Zoom x1";
break;
case MINIMAP_MODE_SURFACEx2:
statustext = L"Minimap in surface mode, Zoom x2";
break;
case MINIMAP_MODE_SURFACEx4:
statustext = L"Minimap in surface mode, Zoom x4";
break;
case MINIMAP_MODE_RADARx1:
statustext = L"Minimap in radar mode, Zoom x1";
break;
case MINIMAP_MODE_RADARx2:
statustext = L"Minimap in radar mode, Zoom x2";
break;
case MINIMAP_MODE_RADARx4:
statustext = L"Minimap in radar mode, Zoom x4";
break;
default:
mode = MINIMAP_MODE_OFF;
*flag = false;
statustext = L"Minimap hidden";
}
*statustext_time = 0;
mapper->setMinimapMode(mode);
if (!show_hud || !g_settings->getBool("enable_minimap"))
return;

if (shift_pressed) {
mapper->toggleMinimapShape();
return;
}

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:
statustext = L"Minimap in surface mode, Zoom x1";
break;
case MINIMAP_MODE_SURFACEx2:
statustext = L"Minimap in surface mode, Zoom x2";
break;
case MINIMAP_MODE_SURFACEx4:
statustext = L"Minimap in surface mode, Zoom x4";
break;
case MINIMAP_MODE_RADARx1:
statustext = L"Minimap in radar mode, Zoom x1";
break;
case MINIMAP_MODE_RADARx2:
statustext = L"Minimap in radar mode, Zoom x2";
break;
case MINIMAP_MODE_RADARx4:
statustext = L"Minimap in radar mode, Zoom x4";
break;
default:
mode = MINIMAP_MODE_OFF;
*flag = false;
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)
Expand Down
12 changes: 8 additions & 4 deletions src/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -116,11 +120,11 @@ class Hud {
std::string hotbar_selected_image;
bool use_hotbar_selected_image;
v3s16 camera_offset;

Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
Inventory *inventory);

void drawHotbar(u16 playeritem);
void resizeHotbar();
void drawCrosshair();
Expand All @@ -129,12 +133,12 @@ class Hud {
private:
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
s32 count, v2s32 offset, v2s32 size=v2s32());

void drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
InventoryList *mainlist, u16 selectitem, u16 direction);

void drawItem(const ItemStack &item, const core::rect<s32>& rect, bool selected);

v2u32 m_screensize;
v2s32 m_displaycenter;
s32 m_hotbar_imagesize;
Expand Down
10 changes: 6 additions & 4 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
HUD_FLAG_BREATHBAR_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_MINIMAP_VISIBLE;

hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
}
Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit be9024a

Please sign in to comment.