Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for Game-Specific Menu Music #11241

Merged
merged 10 commits into from Nov 22, 2021
Merged

Conversation

ExeVirus
Copy link
Contributor

@ExeVirus ExeVirus commented May 4, 2021

Goal of the PR

Allow games to provide their own menu music theme , via a file of the same name as the game name in /menu. For example, The game labyrinth would have a music file at "/games/labyrinth/menu/theme.ogg"

Implementation

Old menu music could be provided via a "/sounds/main_menu.ogg" file (or "main_menu.#.ogg") by users if they desired.

That functionality still exists in this implementation, but now in the single-player tab, a game can provide it's own music to be played when the tab is open. If the game does not provide it's own music, no music is played.

To safely stop main menu music when switching to this tab or vice versa, I implemented a function that I thought has been missing from minetest for sometime, and was needed in this case:

#### sound_stop_all()

This function stops all currently playing sounds, without a user needing to provide a handle

How to test

Download an example game with a menu music file: Labyrinth on ContentDB and click on that game in the singleplayer tab. You will hear some music playing. To test the main menu music, feel free to copy that music file to minetest_folder/sounds/ and rename it to "main_menu.ogg". I recommend using a different sound file to see the differences of when music plays or doesn't.

Relevant Issues

#8596

Ready for Review.

src/gui/guiEngine.cpp Outdated Show resolved Hide resolved
src/server.cpp Outdated Show resolved Hide resolved
@ExeVirus
Copy link
Contributor Author

ExeVirus commented May 16, 2021 via email

@ExeVirus
Copy link
Contributor Author

Okay, good to go, much cleaner implementation, thanks for the examples. 👍

@SmallJoker
Copy link
Member

Directory structure:

????/games/minetest_game/menu$ ls
header.png  icon.png  minetest.ogg

Log output:

2021-05-19 14:18:38: [Main]: Playing sound: devtest
2021-05-19 14:18:39: [Main]: Playing sound: minetest

The sound file is not played back (using a renamed carts_cart_moving.1.ogg). Also Playing sound appears even when the selected game did not change. I presume it would restart the sound, which is not ideal.

Also: Menu content uses consistent names. Wouldn't it be possible to name the file theme.ogg and play that in the mainmenu, rather than fetching all possible sound locations?

@ExeVirus
Copy link
Contributor Author

ExeVirus commented May 20, 2021

So a few things:

  1. The name of minetest_game is minetest_game, not minetest. I ask that dev's use the game.id (game name) as the menu theme.

  2. Naming every game's theme to be "theme.ogg" results in name collisions, and my current implementation doesn't make sorting that out easy.

  3. It does restart the sound, not ideal. But again, how many people double click the game they want to play when selecting it? I'll see if I can make it not restart on double click.

  4. As for your last question, yes this can be supported. Looking at the texture code, this can be supported if I change how the lua code is loading it in built-in. Give me a bit to rework.

Edit: My mistake, minetest's id is different from it's directory name, this is why I made the change originally I believe from using game.id. But I will make it work so that theme.ogg is the name not <game_name>.ogg

@ExeVirus
Copy link
Contributor Author

ExeVirus commented May 20, 2021

Not quite as "clean" of a local function as before, but now menu music can simply be called "theme.ogg" / "theme.1.ogg" as you suggested. I have also made it so that re-clicking the game button does not restart the theme from the beginning. Thanks for the push

@ExeVirus ExeVirus changed the title Allow for Game-Specific Menu Music and Add needed sound_stop_all() Allow for Game-Specific Menu Music Jun 9, 2021
@ExeVirus
Copy link
Contributor Author

ExeVirus commented Jun 9, 2021

Okay, sound_stop_all is no more.

Instead added a music_player.lua to the main_menu builtin, it provides a single function that manages the current music handle. When you provide a new file to play, the current is stopped and the new one is played on loop. If you try to play the same theme.ogg again (or main_menu.ogg) nothing occurs and play continues.

@ExeVirus ExeVirus requested a review from SmallJoker June 9, 2021 02:22
Copy link
Member

@ShadowNinja ShadowNinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way that the files are loaded should be cleaned up a bit, also there are some style things.

@@ -0,0 +1,32 @@
--Minetest
--Copyright (C) 2014 sapier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This copyright notice should be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To what, particularly? That was copied from the other main menu lua files. Should we instead leave that for a future PR cleaning up the copyrights for all of them?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just update the author and the date.

builtin/mainmenu/music_player.lua Outdated Show resolved Hide resolved
builtin/mainmenu/tab_local.lua Outdated Show resolved Hide resolved
builtin/mainmenu/tab_local.lua Outdated Show resolved Hide resolved
src/gui/guiEngine.cpp Outdated Show resolved Hide resolved
src/gui/guiEngine.cpp Outdated Show resolved Hide resolved
@ExeVirus
Copy link
Contributor Author

ExeVirus commented Jun 11, 2021

Okay besides the potentially postponed copyright update and possibly more efficient directory search, the requested changes have been committed.

P.S. thanks for the timely review 👍

builtin/mainmenu/music_player.lua Outdated Show resolved Hide resolved
builtin/mainmenu/tab_local.lua Outdated Show resolved Hide resolved
src/gui/guiEngine.cpp Outdated Show resolved Hide resolved
@@ -0,0 +1,32 @@
--Minetest
--Copyright (C) 2014 sapier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just update the author and the date.

Allows Menu music to be provided for indivudal games in games/gamename/menu/gamename.ogg

Add sound_stop_all() lua_api function, no handles required

Conflicts:
	src/gui/guiEngine.cpp
- Use pkgmgr.games[j].id correctly
- clean-up gui/guiEngine.cpp to use local function
- use C++ goodies to clean up src/server.cpp
@ExeVirus
Copy link
Contributor Author

Alrighty, @ShadowNinja @SmallJoker ready for hopefully final review/approval.

Copy link
Member

@ShadowNinja ShadowNinja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good other than some tiny nits that could be fixed when merging.

src/gui/guiEngine.cpp Outdated Show resolved Hide resolved
src/gui/guiEngine.cpp Outdated Show resolved Hide resolved
@rubenwardy
Copy link
Member

When you open a dialog, the game theme still applies (header.png / background.png) but the music stops.

I'd consider changing textures.lua to game_theme.lua, and merging the sound stuff into it - allowing both to be controlled at the same time

@rubenwardy rubenwardy added the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Oct 31, 2021
@ExeVirus
Copy link
Contributor Author

ExeVirus commented Oct 31, 2021 via email

@rubenwardy
Copy link
Member

I'll have to take a look at of that would still work without breaking the
current main menu music system (which plays for the multiplayer tab for
example).

The game theming already shows on the local tab, but not the multiplayer tab. So you'd just play the global mainmenu music when leaving the local tab, when you hide the game theme

- rename the internal textures.lua table to mm_game_theme
- move the music play code to game_theme to fix dialogs stopping music
- Fix Errant \n removal
- Fix guiEngine extraneous \n
@ExeVirus
Copy link
Contributor Author

@rubenwardy

Tested on local machine(working) and updated with your suggested changes, feel free to merge if you are satisfied with it

@rubenwardy rubenwardy removed the Action / change needed Code still needs changes (PR) / more information requested (Issues) label Nov 19, 2021
@rubenwardy rubenwardy self-requested a review November 19, 2021 17:50
@rubenwardy
Copy link
Member

@ShadowNinja: does your approval on this still hold?

@ShadowNinja
Copy link
Member

Yep, looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants