Skip to content

Commit

Permalink
Allow mods to force-show the crosshair on touchscreen for bows etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Oct 7, 2024
1 parent 1037ee2 commit 8e84ade
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
12 changes: 12 additions & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8372,6 +8372,18 @@ child will follow movement and rotation of that bone.
Does not affect players with the `debug` privilege.
* `chat`: Modifies the client's permission to view chat on the HUD.
The client may locally elect to not view chat. Does not affect the console.
* `touch_hide_crosshair_if_unused`:
* Touchscreen players can use the client-side setting `touch_use_crosshair`
to choose whether they want to play with or without a crosshair.
When `touch_use_crosshair` is false, the entire screen can be used
to interact with nodes and objects.
* If `touch_hide_crosshair_if_unused` is true, this also hides the
crosshair.
* Set `touch_hide_crosshair_if_unused` to false to show the crosshair
regardless. This is useful for items that always work based on the
player's look direction, commonly bows or guns. Only affects clients
with protocol version >= 46.
* All flags default to `true`.
* If a flag equals `nil`, the flag is not modified
* `hud_get_flags()`: returns a table of player HUD flags with boolean values.
* See `hud_set_flags` for a list of flags that can be toggled.
Expand Down
3 changes: 2 additions & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4375,7 +4375,8 @@ void Game::drawScene(ProfilerGraph *graph, RunStats *stats)
(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) &&
(this->camera->getCameraMode() != CAMERA_MODE_THIRD_FRONT));

if (g_touchcontrols && isTouchCrosshairDisabled())
if (g_touchcontrols && isTouchCrosshairDisabled() &&
(player->hud_flags & HUD_FLAG_TOUCH_HIDE_CROSSHAIR_IF_UNUSED))
draw_crosshair = false;

this->m_rendering_engine->draw_scene(sky_color, this->m_game_ui->m_flags.show_hud,
Expand Down
3 changes: 2 additions & 1 deletion src/hud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const struct EnumString es_HudElementStat[] =
{0, NULL},
};

const struct EnumString es_HudBuiltinElement[] =
const struct EnumString es_HudFlag[] =
{
{HUD_FLAG_HOTBAR_VISIBLE, "hotbar"},
{HUD_FLAG_HEALTHBAR_VISIBLE, "healthbar"},
Expand All @@ -66,5 +66,6 @@ const struct EnumString es_HudBuiltinElement[] =
{HUD_FLAG_MINIMAP_RADAR_VISIBLE, "minimap_radar"},
{HUD_FLAG_BASIC_DEBUG, "basic_debug"},
{HUD_FLAG_CHAT_VISIBLE, "chat"},
{HUD_FLAG_TOUCH_HIDE_CROSSHAIR_IF_UNUSED, "touch_hide_crosshair_if_unused"},
{0, NULL},
};
3 changes: 2 additions & 1 deletion src/hud.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define HUD_FLAG_MINIMAP_RADAR_VISIBLE (1 << 6)
#define HUD_FLAG_BASIC_DEBUG (1 << 7)
#define HUD_FLAG_CHAT_VISIBLE (1 << 8)
#define HUD_FLAG_TOUCH_HIDE_CROSSHAIR_IF_UNUSED (1 << 9)

#define HUD_PARAM_HOTBAR_ITEMCOUNT 1
#define HUD_PARAM_HOTBAR_IMAGE 2
Expand Down Expand Up @@ -116,7 +117,7 @@ struct HudElement {

extern const EnumString es_HudElementType[];
extern const EnumString es_HudElementStat[];
extern const EnumString es_HudBuiltinElement[];
extern const EnumString es_HudFlag[];

// Minimap stuff

Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Player::Player(const std::string &name, IItemDefManager *idef):
HUD_FLAG_CROSSHAIR_VISIBLE | HUD_FLAG_WIELDITEM_VISIBLE |
HUD_FLAG_BREATHBAR_VISIBLE | HUD_FLAG_MINIMAP_VISIBLE |
HUD_FLAG_MINIMAP_RADAR_VISIBLE | HUD_FLAG_BASIC_DEBUG |
HUD_FLAG_CHAT_VISIBLE;
HUD_FLAG_CHAT_VISIBLE | HUD_FLAG_TOUCH_HIDE_CROSSHAIR_IF_UNUSED;

hud_hotbar_itemcount = HUD_HOTBAR_ITEMCOUNT_DEFAULT;
}
Expand Down
4 changes: 2 additions & 2 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,7 @@ int ObjectRef::l_hud_set_flags(lua_State *L)
u32 mask = 0;
bool flag;

const EnumString *esp = es_HudBuiltinElement;
const EnumString *esp = es_HudFlag;
for (int i = 0; esp[i].str; i++) {
if (getboolfield(L, 2, esp[i].str, flag)) {
flags |= esp[i].num * flag;
Expand All @@ -1896,7 +1896,7 @@ int ObjectRef::l_hud_get_flags(lua_State *L)
return 0;

lua_newtable(L);
const EnumString *esp = es_HudBuiltinElement;
const EnumString *esp = es_HudFlag;
for (int i = 0; esp[i].str; i++) {
lua_pushboolean(L, (player->hud_flags & esp[i].num) != 0);
lua_setfield(L, -2, esp[i].str);
Expand Down

0 comments on commit 8e84ade

Please sign in to comment.