Solarus Forum

Solarus => Development => Topic started by: linq on April 20, 2020, 03:56:36 am

Title: Editing the HUD - Action Button Icon always shows up
Post by: linq on April 20, 2020, 03:56:36 am
EDIT: I have looked at Christopho's tutorial videos and figured out how to get rid of the pause button icon, and that I just need to import the magic meter from another project. The only thing is that I still don't know how to make the action button stay on the HUD at all times - setting its is_enabled to true just doesn't do it and I don't see anywhere else in the code that would affect this.

Hi Everyone,

First time posting, of many, I am sure. I'm starting to learn Solarus and develop a game.

I am trying to customize the HUD to my preferences, and I have two questions. The first is: I want the pause button icon to never show (I don't consider it necessary), and I want the action button to always show up, even if there is no action.

I have tried editing this section of the script hud.lua as follows:
Code: [Select]
    elseif hud.mode == "normal" then
      if attack_icon ~= nil then
        local attack_icon_enabled = false
        local effect = game.get_custom_command_effect ~= nil and game:get_custom_command_effect("attack") or game:get_command_effect("attack")
        if effect then
          attack_icon_enabled = true
          -- Still display the attack icon when the hero does not have a sword, at the beginning of the game.
          local hero_sword = game:get_ability("sword")
          attack_icon_enabled = hero_sword == nil or hero_sword == 0

      if action_icon ~= nil then
        local effect = game.get_custom_command_effect ~= nil and game:get_custom_command_effect("action") or game:get_command_effect("action")
        action_icon:set_enabled(true)   --changed from effect ~= nil

      if pause_icon ~= nil then
        pause_icon:set_enabled(false) --changed from true
        pause_icon:set_active(false)    --changed from true

      for _, item_icon in ipairs(item_icons) do
        if item_icon ~= nil then

What I am getting is that the pause icon still shows up for one frame, before the script kicks in, I suppose. And the action icon still only displays when I am next to a block to grab or a chest to open; i.e., nothing has changed at all with it. What do I need to do to get these buttons to behave the way I want.

The second question is: I want the button icons on the right and the hearts and magic meter on the left, as it is in every official Zelda game other than LTTP. I have managed to move the buttons and hearts by changing the values in hud_config.lua, but I do not see where I define the location of the magic meter. I also don't see where it gets drawn in any of the scripts. What have I missed here?
Title: Re: Editing the HUD - Action Button Icon always shows up
Post by: Dianthus on April 28, 2020, 04:48:50 am
I would love this answered too. I currently playing around with the hud and controls too. I want a similar hud for my game. I am also trying to edit controls to have z and x for two items, c for shield, v for sword and space for pegasus boots.
Title: Re: Editing the HUD - Action Button Icon always shows up
Post by: linq on April 28, 2020, 04:13:11 pm
Editing the control assignments is easy. Just add this script set_controls.lua to your project:
Code: [Select]
--Script to initialize the control scheme
--require() this in features.lua to enable it


local function controls(game)
  local value = game:get_value("controls")
  --Keyboard commands.
  game:set_command_keyboard_binding("attack", "s")
  game:set_command_keyboard_binding("action", "space")
  game:set_command_keyboard_binding("item_1", "d") 
  game:set_command_keyboard_binding("item_2", "a")
  game:set_command_keyboard_binding("pause", "return")
  --Game Controller commands.
  game:set_command_joypad_binding("attack", "button 0")
  game:set_command_joypad_binding("action", "button 1")
  game:set_command_joypad_binding("item_1", "button 2") 
  game:set_command_joypad_binding("item_2", "button 3")
  game:set_command_joypad_binding("pause",  "button 7")

local game_meta = sol.main.get_metatable("game")
game_meta:register_event("on_started", controls)

And then add the line require("scripts/set_controls") to features.lua. Change the arguments to whatever you want the controls to be.

You mention having a shield button - does this mean that you want the shield to work like in Minish Cap or ALBW - where you hold the button to defend and can sidestep while defending? If so, do you have code for this already made and would you be willing to share? Or perhaps it is already available online somewhere? I would also like this system in my project.

PS - do you not find Z, X, and C too close to the spacebar for comfort? Playing that way I feel like I'm using a system made for a child's hand, (and my hands aren't even that big, compared to average). That's why I set my buttons to A, S, and D in my script, to have more space.
Title: Re: Editing the HUD - Action Button Icon always shows up
Post by: Dianthus on April 28, 2020, 07:54:21 pm
wow thx. I have tried editing those for changing controls but never really got it working. Yeah i am trying make a shield like in minish cap and links awakening. Far as I understand someone have already programmed that in a solarus mod before in:

Title: Re: Editing the HUD - Action Button Icon always shows up
Post by: linq on April 28, 2020, 11:35:47 pm
Thanks a lot Dianthus. That shield system Link's Awakening needs some work, but it's a good starting point. Mainly the problem is that Link isn't properly animated while sidestepping. At least it actually is sidestepping though. In the real Link's Awakening you just always turn to walk forwards, which is next to useless if you want to block attacks.

Still interested in a solution to this HUD problem!
Title: Re: Editing the HUD - Action Button Icon always shows up
Post by: ponderitus on April 29, 2020, 08:46:50 pm
an easy solution i can think of to your HUD issue would be to draw the action button sprite that you want to be always there seperate to the words you want to show up, then just make your words pop up with no background.
the pause button never showing, you could just not draw it? you can do that in scripts/hud_config, in that same script you could add your extra "fake action" sprite, in the same location as the action sprite you already have. your magic_bar should be in the same script aswell...if its not then try adding it?

Code: [Select]
  -- Magic bar.
    menu_script = "scripts/hud/magic_bar",
    x = -90,
    y = 27,

that will show the magic bar, delete the bit that says Pause icon and that should never appear