Page 1 of 1

Disable sound of selected imagebuttons? [SOLVED]

Posted: Wed Sep 19, 2018 5:22 am
by pastelciel
I customized the preferences screen in my game and used imagebuttons to activate/deactivate functions.
For example, clicking on the "window" button will turn off the fullscreen mode, and so on. When the game is windowed the "window" button stays selected/hovered in regards to colors while the "fullscreen" button is idle. But whenever I hover or activate the window button I can still hear sounds even if it's selected. How can I disable sounds from buttons when they're "switched on"?

Here's my code:

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav"

Re: Disable sound of selected imagebuttons?

Posted: Wed Sep 19, 2018 6:08 am
by Remix
Maybe (untested)
hover_sound ("HOVER.wav" if selected else None)
or maybe
hover_sound ("HOVER.wav" if not _preferences.fullscreen else None)

Re: Disable sound of selected imagebuttons?

Posted: Wed Sep 19, 2018 7:29 am
by IrinaLazareva
pastelciel wrote:
Wed Sep 19, 2018 5:22 am
Here's my code:

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
try

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action Preference('display', 'any window') hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
P.S. It is strange, that this bug is still not corrected...

Re: Disable sound of selected imagebuttons?

Posted: Thu Sep 20, 2018 11:59 am
by pastelciel
Remix wrote:
Wed Sep 19, 2018 6:08 am
Maybe (untested)
hover_sound ("HOVER.wav" if selected else None)
or maybe
hover_sound ("HOVER.wav" if not _preferences.fullscreen else None)
Unfortunately, none of them work : (
IrinaLazareva wrote:
Wed Sep 19, 2018 7:29 am

try

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action Preference('display', 'any window') hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
It's not what I'm looking for, sorry...

Re: Disable sound of selected imagebuttons?

Posted: Thu Sep 20, 2018 2:23 pm
by Remix
I guess _preferences.fullscreen is not evaluating true/false then as the following certainly works:

Code: Select all

screen test_hover_sound():

    default test_val = 0

    vbox:
        textbutton "Test":
            action SetScreenVariable("test_val", test_val+1)
            hover_sound ("audio/auto/default/completion_1_meghan.ogg" if test_val < 5 else None)

        text "[test_val!q]"

label start:

    show screen test_hover_sound

    "..."
So, just amend the conditional and it will work for yours.

Re: Disable sound of selected imagebuttons?

Posted: Fri Sep 21, 2018 6:57 am
by MaydohMaydoh
If you just want to get rid of the sound, shouldn't you just use the selected_ prefix?

Code: Select all

imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav":
    selected_hover_sound None
    selected_activate_sound None

Re: Disable sound of selected imagebuttons? [SOLVED]

Posted: Fri Sep 21, 2018 12:21 pm
by pastelciel
Remix wrote:
Thu Sep 20, 2018 2:23 pm
I guess _preferences.fullscreen is not evaluating true/false then as the following certainly works:

Code: Select all

screen test_hover_sound():

    default test_val = 0

    vbox:
        textbutton "Test":
            action SetScreenVariable("test_val", test_val+1)
            hover_sound ("audio/auto/default/completion_1_meghan.ogg" if test_val < 5 else None)

        text "[test_val!q]"

label start:

    show screen test_hover_sound

    "..."
So, just amend the conditional and it will work for yours.

Thank you very much! That was exactly the code I was looking for!
I couldn't figure out how to make it work with variables though so instead of those I used the very functions of the buttons.
So that's the code that works for me:

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" action Preference('display', 'fullscreen') hover_sound ("HOVER.ogg" if _preferences.fullscreen == False else None) activate_sound ("KETTEI.ogg" if _preferences.fullscreen == False else None) 
imagebutton auto "gui/window_%s.png" action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound ("HOVER.ogg" if _preferences.fullscreen == True else None) activate_sound ("KETTEI.ogg" if _preferences.fullscreen == True else None)
    

Re: Disable sound of selected imagebuttons? [SOLVED]

Posted: Fri Sep 21, 2018 12:27 pm
by pastelciel
MaydohMaydoh wrote:
Fri Sep 21, 2018 6:57 am
If you just want to get rid of the sound, shouldn't you just use the selected_ prefix?

Code: Select all

imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav":
    selected_hover_sound None
    selected_activate_sound None
This works too for my issue, thank you very much!
To think it was this simple...! T__T