mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 01:53:45 +01:00
Add sound to press event of some formspecs elements (#10402)
This commit is contained in:
parent
43bc3a1245
commit
78273027bf
@ -2843,11 +2843,14 @@ Some types may inherit styles from parent types.
|
|||||||
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
||||||
* padding - rect, adds space between the edges of the button and the content. This value is
|
* padding - rect, adds space between the edges of the button and the content. This value is
|
||||||
relative to bgimg_middle.
|
relative to bgimg_middle.
|
||||||
|
* sound - a sound to be played when clicked.
|
||||||
* textcolor - color, default white.
|
* textcolor - color, default white.
|
||||||
* checkbox
|
* checkbox
|
||||||
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
||||||
|
* sound - a sound to be played when clicked.
|
||||||
* dropdown
|
* dropdown
|
||||||
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
||||||
|
* sound - a sound to be played when clicked.
|
||||||
* field, pwdfield, textarea
|
* field, pwdfield, textarea
|
||||||
* border - set to false to hide the textbox background and border. Default true.
|
* border - set to false to hide the textbox background and border. Default true.
|
||||||
* font - Sets font type. See button `font` property for more information.
|
* font - Sets font type. See button `font` property for more information.
|
||||||
@ -2874,10 +2877,12 @@ Some types may inherit styles from parent types.
|
|||||||
* fgimg_pressed - image when pressed. Defaults to fgimg when not provided.
|
* fgimg_pressed - image when pressed. Defaults to fgimg when not provided.
|
||||||
* This is deprecated, use states instead.
|
* This is deprecated, use states instead.
|
||||||
* NOTE: The parameters of any given image_button will take precedence over fgimg/fgimg_pressed
|
* NOTE: The parameters of any given image_button will take precedence over fgimg/fgimg_pressed
|
||||||
|
* sound - a sound to be played when clicked.
|
||||||
* scrollbar
|
* scrollbar
|
||||||
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
||||||
* tabheader
|
* tabheader
|
||||||
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
* noclip - boolean, set to true to allow the element to exceed formspec bounds.
|
||||||
|
* sound - a sound to be played when clicked.
|
||||||
* textcolor - color. Default white.
|
* textcolor - color. Default white.
|
||||||
* table, textlist
|
* table, textlist
|
||||||
* font - Sets font type. See button `font` property for more information.
|
* font - Sets font type. See button `font` property for more information.
|
||||||
|
@ -2071,7 +2071,7 @@ void Game::openInventory()
|
|||||||
TextDest *txt_dst = new TextDestPlayerInventory(client);
|
TextDest *txt_dst = new TextDestPlayerInventory(client);
|
||||||
auto *&formspec = m_game_ui->updateFormspec("");
|
auto *&formspec = m_game_ui->updateFormspec("");
|
||||||
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
|
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
|
||||||
txt_dst, client->getFormspecPrepend());
|
txt_dst, client->getFormspecPrepend(), sound);
|
||||||
|
|
||||||
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
|
formspec->setFormSpec(fs_src->getForm(), inventoryloc);
|
||||||
}
|
}
|
||||||
@ -2603,7 +2603,7 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation
|
|||||||
|
|
||||||
auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname));
|
auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname));
|
||||||
GUIFormSpecMenu::create(formspec, client, &input->joystick,
|
GUIFormSpecMenu::create(formspec, client, &input->joystick,
|
||||||
fs_src, txt_dst, client->getFormspecPrepend());
|
fs_src, txt_dst, client->getFormspecPrepend(), sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete event->show_formspec.formspec;
|
delete event->show_formspec.formspec;
|
||||||
@ -2616,7 +2616,7 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta
|
|||||||
LocalFormspecHandler *txt_dst =
|
LocalFormspecHandler *txt_dst =
|
||||||
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
new LocalFormspecHandler(*event->show_formspec.formname, client);
|
||||||
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick,
|
GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick,
|
||||||
fs_src, txt_dst, client->getFormspecPrepend());
|
fs_src, txt_dst, client->getFormspecPrepend(), sound);
|
||||||
|
|
||||||
delete event->show_formspec.formspec;
|
delete event->show_formspec.formspec;
|
||||||
delete event->show_formspec.formname;
|
delete event->show_formspec.formname;
|
||||||
@ -3336,7 +3336,7 @@ bool Game::nodePlacement(const ItemDefinition &selected_def,
|
|||||||
|
|
||||||
auto *&formspec = m_game_ui->updateFormspec("");
|
auto *&formspec = m_game_ui->updateFormspec("");
|
||||||
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
|
GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src,
|
||||||
txt_dst, client->getFormspecPrepend());
|
txt_dst, client->getFormspecPrepend(), sound);
|
||||||
|
|
||||||
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
|
formspec->setFormSpec(meta->getString("formspec"), inventoryloc);
|
||||||
return false;
|
return false;
|
||||||
@ -4108,7 +4108,7 @@ void Game::showDeathFormspec()
|
|||||||
|
|
||||||
auto *&formspec = m_game_ui->getFormspecGUI();
|
auto *&formspec = m_game_ui->getFormspecGUI();
|
||||||
GUIFormSpecMenu::create(formspec, client, &input->joystick,
|
GUIFormSpecMenu::create(formspec, client, &input->joystick,
|
||||||
fs_src, txt_dst, client->getFormspecPrepend());
|
fs_src, txt_dst, client->getFormspecPrepend(), sound);
|
||||||
formspec->setFocus("btn_respawn");
|
formspec->setFocus("btn_respawn");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4242,7 +4242,7 @@ void Game::showPauseMenu()
|
|||||||
|
|
||||||
auto *&formspec = m_game_ui->getFormspecGUI();
|
auto *&formspec = m_game_ui->getFormspecGUI();
|
||||||
GUIFormSpecMenu::create(formspec, client, &input->joystick,
|
GUIFormSpecMenu::create(formspec, client, &input->joystick,
|
||||||
fs_src, txt_dst, client->getFormspecPrepend());
|
fs_src, txt_dst, client->getFormspecPrepend(), sound);
|
||||||
formspec->setFocus("btn_continue");
|
formspec->setFocus("btn_continue");
|
||||||
formspec->doPause = true;
|
formspec->doPause = true;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ public:
|
|||||||
COLORS,
|
COLORS,
|
||||||
BORDERCOLORS,
|
BORDERCOLORS,
|
||||||
BORDERWIDTHS,
|
BORDERWIDTHS,
|
||||||
|
SOUND,
|
||||||
NUM_PROPERTIES,
|
NUM_PROPERTIES,
|
||||||
NONE
|
NONE
|
||||||
};
|
};
|
||||||
@ -116,6 +117,8 @@ public:
|
|||||||
return BORDERCOLORS;
|
return BORDERCOLORS;
|
||||||
} else if (name == "borderwidths") {
|
} else if (name == "borderwidths") {
|
||||||
return BORDERWIDTHS;
|
return BORDERWIDTHS;
|
||||||
|
} else if (name == "sound") {
|
||||||
|
return SOUND;
|
||||||
} else {
|
} else {
|
||||||
return NONE;
|
return NONE;
|
||||||
}
|
}
|
||||||
|
@ -170,6 +170,7 @@ GUIEngine::GUIEngine(JoystickController *joystick,
|
|||||||
m_menumanager,
|
m_menumanager,
|
||||||
NULL /* &client */,
|
NULL /* &client */,
|
||||||
m_texture_source,
|
m_texture_source,
|
||||||
|
m_sound_manager,
|
||||||
m_formspecgui,
|
m_formspecgui,
|
||||||
m_buttonhandler,
|
m_buttonhandler,
|
||||||
"",
|
"",
|
||||||
|
@ -48,6 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "client/client.h"
|
#include "client/client.h"
|
||||||
#include "client/fontengine.h"
|
#include "client/fontengine.h"
|
||||||
|
#include "client/sound.h"
|
||||||
#include "util/hex.h"
|
#include "util/hex.h"
|
||||||
#include "util/numeric.h"
|
#include "util/numeric.h"
|
||||||
#include "util/string.h" // for parseColorString()
|
#include "util/string.h" // for parseColorString()
|
||||||
@ -95,11 +96,13 @@ inline u32 clamp_u8(s32 value)
|
|||||||
|
|
||||||
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick,
|
||||||
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
|
gui::IGUIElement *parent, s32 id, IMenuManager *menumgr,
|
||||||
Client *client, ISimpleTextureSource *tsrc, IFormSource *fsrc, TextDest *tdst,
|
Client *client, ISimpleTextureSource *tsrc, ISoundManager *sound_manager,
|
||||||
|
IFormSource *fsrc, TextDest *tdst,
|
||||||
const std::string &formspecPrepend, bool remap_dbl_click):
|
const std::string &formspecPrepend, bool remap_dbl_click):
|
||||||
GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click),
|
GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click),
|
||||||
m_invmgr(client),
|
m_invmgr(client),
|
||||||
m_tsrc(tsrc),
|
m_tsrc(tsrc),
|
||||||
|
m_sound_manager(sound_manager),
|
||||||
m_client(client),
|
m_client(client),
|
||||||
m_formspec_prepend(formspecPrepend),
|
m_formspec_prepend(formspecPrepend),
|
||||||
m_form_src(fsrc),
|
m_form_src(fsrc),
|
||||||
@ -143,11 +146,12 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
|
|||||||
|
|
||||||
void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
||||||
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
|
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
|
||||||
const std::string &formspecPrepend)
|
const std::string &formspecPrepend, ISoundManager *sound_manager)
|
||||||
{
|
{
|
||||||
if (cur_formspec == nullptr) {
|
if (cur_formspec == nullptr) {
|
||||||
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
|
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
|
||||||
client, client->getTextureSource(), fs_src, txt_dest, formspecPrepend);
|
client, client->getTextureSource(), sound_manager, fs_src,
|
||||||
|
txt_dest, formspecPrepend);
|
||||||
cur_formspec->doPause = false;
|
cur_formspec->doPause = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -614,6 +618,9 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element
|
|||||||
data->current_parent, spec.fid, spec.flabel.c_str());
|
data->current_parent, spec.fid, spec.flabel.c_str());
|
||||||
|
|
||||||
auto style = getDefaultStyleForElement("checkbox", name);
|
auto style = getDefaultStyleForElement("checkbox", name);
|
||||||
|
|
||||||
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
||||||
|
|
||||||
if (spec.fname == m_focused_element) {
|
if (spec.fname == m_focused_element) {
|
||||||
@ -1020,6 +1027,9 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
|
|||||||
data->current_parent, spec.fid, spec.flabel.c_str());
|
data->current_parent, spec.fid, spec.flabel.c_str());
|
||||||
|
|
||||||
auto style = getStyleForElement(type, name, (type != "button") ? "button" : "");
|
auto style = getStyleForElement(type, name, (type != "button") ? "button" : "");
|
||||||
|
|
||||||
|
spec.sound = style[StyleSpec::STATE_DEFAULT].get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
e->setStyles(style);
|
e->setStyles(style);
|
||||||
|
|
||||||
if (spec.fname == m_focused_element) {
|
if (spec.fname == m_focused_element) {
|
||||||
@ -1381,6 +1391,9 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element
|
|||||||
e->setSelected(stoi(str_initial_selection)-1);
|
e->setSelected(stoi(str_initial_selection)-1);
|
||||||
|
|
||||||
auto style = getDefaultStyleForElement("dropdown", name);
|
auto style = getDefaultStyleForElement("dropdown", name);
|
||||||
|
|
||||||
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
||||||
|
|
||||||
m_fields.push_back(spec);
|
m_fields.push_back(spec);
|
||||||
@ -1747,6 +1760,10 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen
|
|||||||
);
|
);
|
||||||
|
|
||||||
spec.ftype = f_HyperText;
|
spec.ftype = f_HyperText;
|
||||||
|
|
||||||
|
auto style = getDefaultStyleForElement("hypertext", spec.fname);
|
||||||
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment,
|
GUIHyperText *e = new GUIHyperText(spec.flabel.c_str(), Environment,
|
||||||
data->current_parent, spec.fid, rect, m_client, m_tsrc);
|
data->current_parent, spec.fid, rect, m_client, m_tsrc);
|
||||||
e->drop();
|
e->drop();
|
||||||
@ -1999,6 +2016,8 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem
|
|||||||
|
|
||||||
auto style = getStyleForElement("image_button", spec.fname);
|
auto style = getStyleForElement("image_button", spec.fname);
|
||||||
|
|
||||||
|
spec.sound = style[StyleSpec::STATE_DEFAULT].get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
// Override style properties with values specified directly in the element
|
// Override style properties with values specified directly in the element
|
||||||
if (!image_name.empty())
|
if (!image_name.empty())
|
||||||
style[StyleSpec::STATE_DEFAULT].set(StyleSpec::FGIMG, image_name);
|
style[StyleSpec::STATE_DEFAULT].set(StyleSpec::FGIMG, image_name);
|
||||||
@ -2107,6 +2126,9 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen
|
|||||||
e->setTabHeight(geom.Y);
|
e->setTabHeight(geom.Y);
|
||||||
|
|
||||||
auto style = getDefaultStyleForElement("tabheader", name);
|
auto style = getDefaultStyleForElement("tabheader", name);
|
||||||
|
|
||||||
|
spec.sound = style.get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, true));
|
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, true));
|
||||||
|
|
||||||
for (const std::string &button : buttons) {
|
for (const std::string &button : buttons) {
|
||||||
@ -2195,6 +2217,9 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &
|
|||||||
item_name, m_client);
|
item_name, m_client);
|
||||||
|
|
||||||
auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button");
|
auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button");
|
||||||
|
|
||||||
|
spec_btn.sound = style[StyleSpec::STATE_DEFAULT].get(StyleSpec::Property::SOUND, "");
|
||||||
|
|
||||||
e_btn->setStyles(style);
|
e_btn->setStyles(style);
|
||||||
|
|
||||||
if (spec_btn.fname == m_focused_element) {
|
if (spec_btn.fname == m_focused_element) {
|
||||||
@ -4486,6 +4511,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||||||
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
for (GUIFormSpecMenu::FieldSpec &s : m_fields) {
|
||||||
if ((s.ftype == f_TabHeader) &&
|
if ((s.ftype == f_TabHeader) &&
|
||||||
(s.fid == event.GUIEvent.Caller->getID())) {
|
(s.fid == event.GUIEvent.Caller->getID())) {
|
||||||
|
if (!s.sound.empty() && m_sound_manager)
|
||||||
|
m_sound_manager->playSound(s.sound, false, 1.0f);
|
||||||
s.send = true;
|
s.send = true;
|
||||||
acceptInput();
|
acceptInput();
|
||||||
s.send = false;
|
s.send = false;
|
||||||
@ -4529,6 +4556,9 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (s.ftype == f_Button || s.ftype == f_CheckBox) {
|
if (s.ftype == f_Button || s.ftype == f_CheckBox) {
|
||||||
|
if (!s.sound.empty() && m_sound_manager)
|
||||||
|
m_sound_manager->playSound(s.sound, false, 1.0f);
|
||||||
|
|
||||||
s.send = true;
|
s.send = true;
|
||||||
if (s.is_exit) {
|
if (s.is_exit) {
|
||||||
if (m_allowclose) {
|
if (m_allowclose) {
|
||||||
@ -4551,6 +4581,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||||||
s2.send = false;
|
s2.send = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!s.sound.empty() && m_sound_manager)
|
||||||
|
m_sound_manager->playSound(s.sound, false, 1.0f);
|
||||||
s.send = true;
|
s.send = true;
|
||||||
acceptInput(quit_mode_no);
|
acceptInput(quit_mode_no);
|
||||||
|
|
||||||
@ -4567,6 +4599,8 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
|
|||||||
acceptInput(quit_mode_no);
|
acceptInput(quit_mode_no);
|
||||||
s.fdefault = L"";
|
s.fdefault = L"";
|
||||||
} else if (s.ftype == f_Unknown || s.ftype == f_HyperText) {
|
} else if (s.ftype == f_Unknown || s.ftype == f_HyperText) {
|
||||||
|
if (!s.sound.empty() && m_sound_manager)
|
||||||
|
m_sound_manager->playSound(s.sound, false, 1.0f);
|
||||||
s.send = true;
|
s.send = true;
|
||||||
acceptInput();
|
acceptInput();
|
||||||
s.send = false;
|
s.send = false;
|
||||||
|
@ -39,6 +39,7 @@ class InventoryManager;
|
|||||||
class ISimpleTextureSource;
|
class ISimpleTextureSource;
|
||||||
class Client;
|
class Client;
|
||||||
class GUIScrollContainer;
|
class GUIScrollContainer;
|
||||||
|
class ISoundManager;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
f_Button,
|
f_Button,
|
||||||
@ -127,6 +128,7 @@ class GUIFormSpecMenu : public GUIModalMenu
|
|||||||
int priority;
|
int priority;
|
||||||
core::rect<s32> rect;
|
core::rect<s32> rect;
|
||||||
gui::ECURSOR_ICON fcursor_icon;
|
gui::ECURSOR_ICON fcursor_icon;
|
||||||
|
std::string sound;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TooltipSpec
|
struct TooltipSpec
|
||||||
@ -151,6 +153,7 @@ public:
|
|||||||
IMenuManager *menumgr,
|
IMenuManager *menumgr,
|
||||||
Client *client,
|
Client *client,
|
||||||
ISimpleTextureSource *tsrc,
|
ISimpleTextureSource *tsrc,
|
||||||
|
ISoundManager *sound_manager,
|
||||||
IFormSource* fs_src,
|
IFormSource* fs_src,
|
||||||
TextDest* txt_dst,
|
TextDest* txt_dst,
|
||||||
const std::string &formspecPrepend,
|
const std::string &formspecPrepend,
|
||||||
@ -160,7 +163,7 @@ public:
|
|||||||
|
|
||||||
static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
static void create(GUIFormSpecMenu *&cur_formspec, Client *client,
|
||||||
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
|
JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest,
|
||||||
const std::string &formspecPrepend);
|
const std::string &formspecPrepend, ISoundManager *sound_manager);
|
||||||
|
|
||||||
void setFormSpec(const std::string &formspec_string,
|
void setFormSpec(const std::string &formspec_string,
|
||||||
const InventoryLocation ¤t_inventory_location)
|
const InventoryLocation ¤t_inventory_location)
|
||||||
@ -293,6 +296,7 @@ protected:
|
|||||||
|
|
||||||
InventoryManager *m_invmgr;
|
InventoryManager *m_invmgr;
|
||||||
ISimpleTextureSource *m_tsrc;
|
ISimpleTextureSource *m_tsrc;
|
||||||
|
ISoundManager *m_sound_manager;
|
||||||
Client *m_client;
|
Client *m_client;
|
||||||
|
|
||||||
std::string m_formspec_string;
|
std::string m_formspec_string;
|
||||||
|
Loading…
Reference in New Issue
Block a user