rossenburg Posted July 2, 2022 Share Posted July 2, 2022 Hello guys, so i wanted to add a functionality to my mod , where a sound will be played when a user send a message in the chat field. I noticed when i used the " sound_pressed" function one the send button it worked <object name="chatSubmit" size="100%-72 100%-26 100%-4 100%-4" sound_pressed="audio/interface/ui/Ugggsentmessage.ogg" type="button" style="StoneButton"> <translatableAttribute id="caption">Send</translatableAttribute> </object> when i click on the send button, the sound it triggered as expected but i want to ask how about playing the sound when user press the "ENTER" or "RETURN" button? i tried adding a function called onEnter in style.xml, didn't work too Quote <style name="ChatPanel" buffer_zone="5" font="sans-13" scrollbar="true" scrollbar_style="ModernScrollBar" scroll_bottom="true" textcolor="white" text_align="left" onEnter="Path/to/sound/file" /> i attached a screen record 2137271213_0A.D.2022-07-0218-55-31.mp4 1 Link to comment Share on other sites More sharing options...
Stan` Posted July 2, 2022 Share Posted July 2, 2022 Because it's only implemented for buttons not fields https://github.com/0ad/0ad/blob/master/source/gui/ObjectBases/IGUIButtonBehavior.cpp 1 Link to comment Share on other sites More sharing options...
rossenburg Posted July 2, 2022 Author Share Posted July 2, 2022 @Stan`, how do I achieve this then? When user press Enter the sound should be triggered too, is there any event handler that covers that. Any suggestions or best practice? 1 Link to comment Share on other sites More sharing options...
Stan` Posted July 2, 2022 Share Posted July 2, 2022 32 minutes ago, rossenburg said: @Stan`, how do I achieve this then? When user press Enter the sound should be triggered too, is there any event handler that covers that. Any suggestions or best practice? Look at ChatInput.js and use registerChatSubmitHandler() I suppose. Example in Chat.js, or use the submitchat function in Chat.js To play a sound Engine.PlayUISound("audio/interface/ui/chat_alert.ogg", false); Note to self, one should use soundgroups and not raw sound files. 1 Link to comment Share on other sites More sharing options...
rossenburg Posted July 2, 2022 Author Share Posted July 2, 2022 4 hours ago, Stan` said: Look at ChatInput.js and use registerChatSubmitHandler() I suppose. Example in Chat.js, or use the submitchat function in Chat.js To play a sound Engine.PlayUISound("audio/interface/ui/chat_alert.ogg", false); Note to self, one should use soundgroups and not raw sound files. Worked like magic @Stan`, TY! 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now