Ticket #948: 948_ButtonSoundAttribute.patch

File 948_ButtonSoundAttribute.patch, 2.8 KB (added by Matt Lott, 12 years ago)

This adds a button_sound attribute to buttons.

  • binaries/data/mods/public/gui/common/styles.xml

     
    2121        multiline="false"
    2222    />
    2323
    24     <!--
     24  <!--
    2525    ==========================================
     26    - DEFAULT BUTTON STYLE: The style with the name 'default_button' is special, it will
     27    - be called by every button object before any other style is loaded, except 'default'.
     28    ==========================================
     29    -->
     30
     31  <style name="default_button"
     32    button_sound="audio/interface/ui/ui_button_click.ogg"
     33    />
     34
     35  <!--
     36    ==========================================
    2637    - STYLE - GLOBAL - PANES - WHEAT SKIN
    2738    ==========================================
    2839    -->
  • source/gui/CButton.cpp

     
    3232CButton::CButton()
    3333{
    3434    AddSetting(GUIST_float,                 "buffer_zone");
     35    AddSetting(GUIST_CStr,                  "button_sound");
    3536    AddSetting(GUIST_CGUIString,            "caption");
    3637    AddSetting(GUIST_int,                   "cell_id");
    3738    AddSetting(GUIST_CStrW,                 "font");
  • source/gui/CGUI.cpp

     
    11691169    if (m_Styles.count("default") == 1)
    11701170        object->LoadStyle(*this, "default");
    11711171
     1172    if (type.Find("button") != -1 && m_Styles.count("default_button") == 1)
     1173        object->LoadStyle(*this, "default_button");
     1174
    11721175    if (! argStyle.empty())
    11731176    {
    11741177        // additional check
  • source/gui/IGUIButtonBehavior.cpp

     
    2121
    2222#include "precompiled.h"
    2323#include "GUI.h"
     24#include "lib/res/sound/snd_mgr.h"
     25#include "ps/Filesystem.h"
     26#include "ps/CLogger.h"
    2427
    25 
    2628//-------------------------------------------------------------------
    2729//  Constructor / Destructor
    2830//-------------------------------------------------------------------
     
    7880            }
    7981        }
    8082    }   break;
     83   
     84    case GUIM_PRESSED:
     85    {
     86        // Play button sound if available
     87        CStr button_sound;
     88        if (PSRETURN_OK == GUI<CStr>::GetSetting(this, "button_sound", button_sound))
     89        {
     90            Handle hvs = snd_open(g_VFS, button_sound.c_str());
     91            if (hvs > 0)
     92            {
     93                snd_set_pos(hvs, 0,0,0, true);
     94                snd_play(hvs);
     95            }
     96            else
     97            {
     98                LOGWARNING(L"Unable to snd_open button_sound %hs in IGUIButtonBehavior", button_sound.c_str());
     99            }
     100        }       
     101        // else no button_sound to play
    81102
     103    }   break;
     104
    82105    default:
    83106        break;
    84107    }