Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mods to force-show the crosshair on touchscreen for bows etc. #15250

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

grorp
Copy link
Member

@grorp grorp commented Oct 7, 2024

On touchscreens, there is no crosshair by default. However, mods might still use the player's look direction for certain items, for example bows or guns. For these items, a crosshair should be shown.

This PR allows mods to force-show the crosshair by setting the HUD flag crosshair_force_show = true.

Alternative to the proposal in https://codeberg.org/mineclonia/mineclonia/pulls/890#issuecomment-2340468, cc @j-r

To do

This PR is a Ready for Review.

Feel free to comment on API design as well

How to test

  1. Set touch_controls = true (also possible on desktop) and touch_use_crosshair = false (the default)
  2. Start a Devtest world with Worldedit
  3. The crosshair is hidden
  4. //lua player:hud_set_flags({crosshair = true, crosshair_force_show = true}) -> The crosshair is shown
  5. //lua player:hud_set_flags({crosshair = false, crosshair_force_show = true}) -> The crosshair is hidden

@grorp
Copy link
Member Author

grorp commented Oct 7, 2024

With this PR, Mineclonia can do:

mcl_player.register_globalstep(function(player)
    local name = player:get_wielded_item():get_name()
    local is_bow = name:sub(1, 12) == "mcl_bows:bow" or name:sub(1, 17) == "mcl_bows:crossbow"
    player:hud_set_flags({crosshair_force_show = is_bow})
end)

@SmallJoker
Copy link
Member

SmallJoker commented Nov 11, 2024

It needs to be true by default, like all other HUD flags

Why? Client::handleCommand_HudSetFlag only modifies the touched flags, and older servers will not touch those (see ObjectRef::l_hud_set_flags -> no lookup possible). Hence crosshair_force_show = false by default should be possible.

@grorp grorp added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Nov 12, 2024
@grorp grorp closed this Nov 16, 2024
@grorp grorp reopened this Dec 8, 2024
@grorp grorp removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Dec 8, 2024
@grorp
Copy link
Member Author

grorp commented Dec 8, 2024

Hence crosshair_force_show = false by default should be possible.

If it's possible, then it's definitely a much cleaner API. Updated, thank you.

@grorp
Copy link
Member Author

grorp commented Dec 8, 2024

Something that should also be considered: What happens to this flag if the crosshair becomes a builtin HUD element? See #14273. The server doesn't have access to the client's settings, so we'd still have to implement this flag in a "hardcoded" manner on the client (or send the setting to the server).

#14273 already needed to do that for the existing client-side conditions though:

But still needs a draw_crosshairs condition since CAMERA_MODE_THIRD_FRONT and HAVE_TOUCHSCREENGUI may disallow crosshairs.

So this is not really a new problem.

@grorp grorp marked this pull request as draft December 17, 2024 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants