Skip to content

Commit be9024a

Browse files
committedAug 13, 2015
minimap: Add ability to disable from server
1 parent a670ecf commit be9024a

File tree

5 files changed

+69
-47
lines changed

5 files changed

+69
-47
lines changed
 

Diff for: ‎doc/lua_api.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -2519,11 +2519,13 @@ This is basically a reference to a C++ `ServerActiveObject`
25192519
* element `stat` values: `position`, `name`, `scale`, `text`, `number`, `item`, `dir`
25202520
* `hud_get(id)`: gets the HUD element definition structure of the specified ID
25212521
* `hud_set_flags(flags)`: sets specified HUD flags to `true`/`false`
2522-
* `flags`: (is visible) `hotbar`, `healthbar`, `crosshair`, `wielditem`
2522+
* `flags`: (is visible) `hotbar`, `healthbar`, `crosshair`, `wielditem`, `minimap`
25232523
* pass a table containing a `true`/`false` value of each flag to be set or unset
25242524
* if a flag equals `nil`, the flag is not modified
2525+
* note that setting `minimap` modifies the client's permission to view the minimap -
2526+
* the client may locally elect to not view the minimap
25252527
* `hud_get_flags()`: returns a table containing status of hud flags
2526-
* returns `{ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true }`
2528+
* returns `{ hotbar=true, healthbar=true, crosshair=true, wielditem=true, breathbar=true, minimap=true }`
25272529
* `hud_set_hotbar_itemcount(count)`: sets number of items in builtin hotbar
25282530
* `count`: number of items, must be between `1` and `23`
25292531
* `hud_get_hotbar_itemcount`: returns number of visible items

Diff for: ‎src/game.cpp

+48-37
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ class Game {
14971497

14981498
void toggleChat(float *statustext_time, bool *flag);
14991499
void toggleHud(float *statustext_time, bool *flag);
1500-
void toggleMinimap(float *statustext_time, bool *flag1, bool *flag2,
1500+
void toggleMinimap(float *statustext_time, bool *flag, bool show_hud,
15011501
bool shift_pressed);
15021502
void toggleFog(float *statustext_time, bool *flag);
15031503
void toggleDebug(float *statustext_time, bool *show_debug,
@@ -2642,7 +2642,7 @@ void Game::processKeyboardInput(VolatileRunFlags *flags,
26422642
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_HUD])) {
26432643
toggleHud(statustext_time, &flags->show_hud);
26442644
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_MINIMAP])) {
2645-
toggleMinimap(statustext_time, &flags->show_minimap, &flags->show_hud,
2645+
toggleMinimap(statustext_time, &flags->show_minimap, flags->show_hud,
26462646
input->isKeyDown(keycache.key[KeyCache::KEYMAP_ID_SNEAK]));
26472647
} else if (input->wasKeyDown(keycache.key[KeyCache::KEYMAP_ID_TOGGLE_CHAT])) {
26482648
toggleChat(statustext_time, &flags->show_chat);
@@ -2864,43 +2864,54 @@ void Game::toggleHud(float *statustext_time, bool *flag)
28642864
client->setHighlighted(client->getHighlighted(), *flag);
28652865
}
28662866

2867-
void Game::toggleMinimap(float *statustext_time, bool *flag, bool *show_hud, bool shift_pressed)
2867+
void Game::toggleMinimap(float *statustext_time, bool *flag,
2868+
bool show_hud, bool shift_pressed)
28682869
{
2869-
if (*show_hud && g_settings->getBool("enable_minimap")) {
2870-
if (shift_pressed) {
2871-
mapper->toggleMinimapShape();
2872-
return;
2873-
}
2874-
MinimapMode mode = mapper->getMinimapMode();
2875-
mode = (MinimapMode)((int)(mode) + 1);
2876-
*flag = true;
2877-
switch (mode) {
2878-
case MINIMAP_MODE_SURFACEx1:
2879-
statustext = L"Minimap in surface mode, Zoom x1";
2880-
break;
2881-
case MINIMAP_MODE_SURFACEx2:
2882-
statustext = L"Minimap in surface mode, Zoom x2";
2883-
break;
2884-
case MINIMAP_MODE_SURFACEx4:
2885-
statustext = L"Minimap in surface mode, Zoom x4";
2886-
break;
2887-
case MINIMAP_MODE_RADARx1:
2888-
statustext = L"Minimap in radar mode, Zoom x1";
2889-
break;
2890-
case MINIMAP_MODE_RADARx2:
2891-
statustext = L"Minimap in radar mode, Zoom x2";
2892-
break;
2893-
case MINIMAP_MODE_RADARx4:
2894-
statustext = L"Minimap in radar mode, Zoom x4";
2895-
break;
2896-
default:
2897-
mode = MINIMAP_MODE_OFF;
2898-
*flag = false;
2899-
statustext = L"Minimap hidden";
2900-
}
2901-
*statustext_time = 0;
2902-
mapper->setMinimapMode(mode);
2870+
if (!show_hud || !g_settings->getBool("enable_minimap"))
2871+
return;
2872+
2873+
if (shift_pressed) {
2874+
mapper->toggleMinimapShape();
2875+
return;
29032876
}
2877+
2878+
u32 hud_flags = client->getEnv().getLocalPlayer()->hud_flags;
2879+
2880+
MinimapMode mode = MINIMAP_MODE_OFF;
2881+
if (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) {
2882+
mode = mapper->getMinimapMode();
2883+
mode = (MinimapMode)((int)mode + 1);
2884+
}
2885+
2886+
*flag = true;
2887+
switch (mode) {
2888+
case MINIMAP_MODE_SURFACEx1:
2889+
statustext = L"Minimap in surface mode, Zoom x1";
2890+
break;
2891+
case MINIMAP_MODE_SURFACEx2:
2892+
statustext = L"Minimap in surface mode, Zoom x2";
2893+
break;
2894+
case MINIMAP_MODE_SURFACEx4:
2895+
statustext = L"Minimap in surface mode, Zoom x4";
2896+
break;
2897+
case MINIMAP_MODE_RADARx1:
2898+
statustext = L"Minimap in radar mode, Zoom x1";
2899+
break;
2900+
case MINIMAP_MODE_RADARx2:
2901+
statustext = L"Minimap in radar mode, Zoom x2";
2902+
break;
2903+
case MINIMAP_MODE_RADARx4:
2904+
statustext = L"Minimap in radar mode, Zoom x4";
2905+
break;
2906+
default:
2907+
mode = MINIMAP_MODE_OFF;
2908+
*flag = false;
2909+
statustext = (hud_flags & HUD_FLAG_MINIMAP_VISIBLE) ?
2910+
L"Minimap hidden" : L"Minimap disabled by server";
2911+
}
2912+
2913+
*statustext_time = 0;
2914+
mapper->setMinimapMode(mode);
29042915
}
29052916

29062917
void Game::toggleFog(float *statustext_time, bool *flag)

Diff for: ‎src/hud.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3232
#define HUD_CORNER_LOWER 1
3333
#define HUD_CORNER_CENTER 2
3434

35+
// Note that these visibility flags do not determine if the hud items are
36+
// actually drawn, but rather, allows the item to be drawn should the rest of
37+
// the game state permit it.
3538
#define HUD_FLAG_HOTBAR_VISIBLE (1 << 0)
3639
#define HUD_FLAG_HEALTHBAR_VISIBLE (1 << 1)
3740
#define HUD_FLAG_CROSSHAIR_VISIBLE (1 << 2)
3841
#define HUD_FLAG_WIELDITEM_VISIBLE (1 << 3)
3942
#define HUD_FLAG_BREATHBAR_VISIBLE (1 << 4)
43+
#define HUD_FLAG_MINIMAP_VISIBLE (1 << 5)
4044

4145
#define HUD_PARAM_HOTBAR_ITEMCOUNT 1
4246
#define HUD_PARAM_HOTBAR_IMAGE 2
@@ -116,11 +120,11 @@ class Hud {
116120
std::string hotbar_selected_image;
117121
bool use_hotbar_selected_image;
118122
v3s16 camera_offset;
119-
123+
120124
Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
121125
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
122126
Inventory *inventory);
123-
127+
124128
void drawHotbar(u16 playeritem);
125129
void resizeHotbar();
126130
void drawCrosshair();
@@ -129,12 +133,12 @@ class Hud {
129133
private:
130134
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
131135
s32 count, v2s32 offset, v2s32 size=v2s32());
132-
136+
133137
void drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
134138
InventoryList *mainlist, u16 selectitem, u16 direction);
135139

136140
void drawItem(const ItemStack &item, const core::rect<s32>& rect, bool selected);
137-
141+
138142
v2u32 m_screensize;
139143
v2s32 m_displaycenter;
140144
s32 m_hotbar_imagesize;

Diff for: ‎src/player.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ Player::Player(IGameDef *gamedef, const char *name):
7575
"listring[]"
7676
"list[current_player;craftpreview;7,1;1,1;]";
7777

78-
// Initialize movement settings at default values, so movement can work if the server fails to send them
78+
// Initialize movement settings at default values, so movement can work
79+
// if the server fails to send them
7980
movement_acceleration_default = 3 * BS;
8081
movement_acceleration_air = 2 * BS;
8182
movement_acceleration_fast = 10 * BS;
@@ -97,9 +98,10 @@ Player::Player(IGameDef *gamedef, const char *name):
9798
physics_override_sneak = true;
9899
physics_override_sneak_glitch = true;
99100

100-
hud_flags = HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
101-
HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
102-
HUD_FLAG_BREATHBAR_VISIBLE;
101+
hud_flags =
102+
HUD_FLAG_HOTBAR_VISIBLE | HUD_FLAG_HEALTHBAR_VISIBLE |
103+
HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
104+
HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE;
103105

104106
hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
105107
}

Diff for: ‎src/script/lua_api/l_object.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct EnumString es_HudBuiltinElement[] =
6868
{HUD_FLAG_CROSSHAIR_VISIBLE, "crosshair"},
6969
{HUD_FLAG_WIELDITEM_VISIBLE, "wielditem"},
7070
{HUD_FLAG_BREATHBAR_VISIBLE, "breathbar"},
71+
{HUD_FLAG_MINIMAP_VISIBLE, "minimap"},
7172
{0, NULL},
7273
};
7374

@@ -1384,6 +1385,8 @@ int ObjectRef::l_hud_get_flags(lua_State *L)
13841385
lua_setfield(L, -2, "wielditem");
13851386
lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
13861387
lua_setfield(L, -2, "breathbar");
1388+
lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
1389+
lua_setfield(L, -2, "minimap");
13871390

13881391
return 1;
13891392
}

0 commit comments

Comments
 (0)
Please sign in to comment.