mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
playable music in game
This commit is contained in:
@@ -65,3 +65,7 @@ mappings = {
|
|||||||
graphics = {
|
graphics = {
|
||||||
resolution = {x = 1920, y = 1080}
|
resolution = {x = 1920, y = 1080}
|
||||||
}
|
}
|
||||||
|
audio = {
|
||||||
|
sfxVolume = 100,
|
||||||
|
musicVolume = 100,
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,28 @@ Size = {x = 70, y = 70}
|
|||||||
sz = 210
|
sz = 210
|
||||||
s = 40
|
s = 40
|
||||||
|
|
||||||
|
function generateFactionMusic(factionId)
|
||||||
|
asianTracks = {'ACS/asian_theme_1.ogg', 'ACS/asian_theme_2.ogg'}
|
||||||
|
americanTracks = {'AInc/american_theme_1.ogg', 'AInc/american_theme_2.ogg'}
|
||||||
|
europeanTracks = {'ER/european_theme_1.ogg', 'ER/european_theme_2.ogg'}
|
||||||
|
|
||||||
|
factionTracks = {}
|
||||||
|
|
||||||
|
if factionId == 0 then
|
||||||
|
factionTracks = americanTracks
|
||||||
|
elseif factionId == 1 then
|
||||||
|
factionTracks = europeanTracks
|
||||||
|
elseif factionId == 2 then
|
||||||
|
factionTracks = asianTracks
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
loop = true,
|
||||||
|
shuffle = false,
|
||||||
|
tracks = factionTracks
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
eyeIcon = 'eye.png'
|
eyeIcon = 'eye.png'
|
||||||
refIcon = 'refineds.png'
|
refIcon = 'refineds.png'
|
||||||
minimapSize = {x = 200, y = 200}
|
minimapSize = {x = 200, y = 200}
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
Size = {x = 150, y = 40}
|
Size = {x = 150, y = 40}
|
||||||
|
|
||||||
numGui = 4
|
numGui = 4
|
||||||
|
music = {
|
||||||
|
loop = true,
|
||||||
|
shuffle = false,
|
||||||
|
tracks = {'intro.ogg'}
|
||||||
|
}
|
||||||
gui = {
|
gui = {
|
||||||
{
|
{
|
||||||
pos = {x = 110, y = 40, z = 0},
|
pos = {x = 110, y = 40, z = 0},
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4
-8
@@ -12,7 +12,7 @@ endif()
|
|||||||
set(CMAKE_CXX_STANDART 17)
|
set(CMAKE_CXX_STANDART 17)
|
||||||
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
|
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
|
||||||
set(CMAKE_BUILD_TYPE Debug)
|
set(CMAKE_BUILD_TYPE Debug)
|
||||||
set(BUILD_TESTS ON)
|
set(BUILD_TESTS OFF)
|
||||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
|
||||||
cmake_policy(SET CMP0015 NEW)
|
cmake_policy(SET CMP0015 NEW)
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ set(UTIL util.cpp binds.h)
|
|||||||
|
|
||||||
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
||||||
|
|
||||||
set(SFML_DIR external/SFML)
|
set(SFML_DIR external/gameBase/external/SFML)
|
||||||
set(VB01_DIR external/vb01)
|
set(VB01_DIR external/vb01)
|
||||||
set(VB01_GUI_DIR external/vb01Gui)
|
set(VB01_GUI_DIR external/vb01Gui)
|
||||||
set(GAME_BASE_DIR external/gameBase)
|
set(GAME_BASE_DIR external/gameBase)
|
||||||
@@ -51,6 +51,7 @@ add_executable(${GAME_NAME} main.cpp ${GAME_SRC})
|
|||||||
include_directories(external/tinydir)
|
include_directories(external/tinydir)
|
||||||
include_directories(external/vb01/external/glm)
|
include_directories(external/vb01/external/glm)
|
||||||
include_directories(external/vb01/external/glm/glm)
|
include_directories(external/vb01/external/glm/glm)
|
||||||
|
include_directories(external/gameBase/external/SFML/include)
|
||||||
|
|
||||||
add_subdirectory(${VB01_DIR})
|
add_subdirectory(${VB01_DIR})
|
||||||
set(VB01_LIB_DIR ${VB01_DIR}/build)
|
set(VB01_LIB_DIR ${VB01_DIR}/build)
|
||||||
@@ -62,12 +63,7 @@ set(GAME_BASE_LIB_DIR build/${GAME_BASE_DIR}/src)
|
|||||||
target_include_directories(${GAME_NAME} PUBLIC ${GAME_BASE_DIR})
|
target_include_directories(${GAME_NAME} PUBLIC ${GAME_BASE_DIR})
|
||||||
target_link_directories(${GAME_NAME} PUBLIC ${GAME_BASE_LIB_DIR})
|
target_link_directories(${GAME_NAME} PUBLIC ${GAME_BASE_LIB_DIR})
|
||||||
|
|
||||||
add_subdirectory(${SFML_DIR})
|
set(DEPS vb01 gameBase)
|
||||||
set(SFML_LIB_DIR build/${SFML_DIR}/src)
|
|
||||||
target_include_directories(${GAME_NAME} PUBLIC ${SFML_DIR}/include)
|
|
||||||
target_link_directories(${GAME_NAME} PUBLIC ${SFML_LIB_DIR})
|
|
||||||
|
|
||||||
set(DEPS vb01 gameBase sfml-system sfml-audio)
|
|
||||||
target_link_libraries(${GAME_NAME} ${DEPS})
|
target_link_libraries(${GAME_NAME} ${DEPS})
|
||||||
|
|
||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
|
|||||||
+11
-1
@@ -120,7 +120,17 @@ namespace battleship{
|
|||||||
|
|
||||||
void ActiveGameState::onAttached() {
|
void ActiveGameState::onAttached() {
|
||||||
AbstractAppState::onAttached();
|
AbstractAppState::onAttached();
|
||||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
|
ConcreteGuiManager::getSingleton()->readLuaScreenScript(
|
||||||
|
"activeGameState.lua",
|
||||||
|
vector<Button*>{},
|
||||||
|
vector<Listbox*>{},
|
||||||
|
vector<Checkbox*>{},
|
||||||
|
vector<Slider*>{},
|
||||||
|
vector<Textbox*>{},
|
||||||
|
vector<Node*>{},
|
||||||
|
vector<Text*>{},
|
||||||
|
"music = generateFactionMusic(" + to_string(mainPlayer->getFaction()) + ")"
|
||||||
|
);
|
||||||
|
|
||||||
if(!cursorNode) initCursor();
|
if(!cursorNode) initCursor();
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-3
@@ -1,4 +1,5 @@
|
|||||||
#include <solUtil.h>
|
#include <solUtil.h>
|
||||||
|
#include <soundManager.h>
|
||||||
|
|
||||||
#include <quad.h>
|
#include <quad.h>
|
||||||
|
|
||||||
@@ -523,6 +524,26 @@ namespace battleship{
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConcreteGuiManager::parseMusic(){
|
||||||
|
sol::state_view SOL_STATE_VIEW = generateView();
|
||||||
|
sol::optional<sol::table> musicTblOpt = SOL_STATE_VIEW["music"];
|
||||||
|
|
||||||
|
if(musicTblOpt == sol::nullopt) return;
|
||||||
|
|
||||||
|
sol::table musicTbl = SOL_STATE_VIEW["music"], tracksTbl = musicTbl["tracks"];
|
||||||
|
bool loop = musicTbl["loop"], shuffle = musicTbl["shuffle"];
|
||||||
|
int numTracks = tracksTbl.size();
|
||||||
|
|
||||||
|
vector<string> trackPaths;
|
||||||
|
|
||||||
|
for(int i = 0; i < numTracks; i++){
|
||||||
|
string track = tracksTbl[i + 1];
|
||||||
|
trackPaths.push_back(GameManager::getSingleton()->getPath() + "Sounds/Music/" + track);
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundManager::getSingleton()->play(trackPaths, 100, loop, shuffle);
|
||||||
|
}
|
||||||
|
|
||||||
void ConcreteGuiManager::readLuaScreenScript(
|
void ConcreteGuiManager::readLuaScreenScript(
|
||||||
string script,
|
string script,
|
||||||
vector<Button*> buttonExceptions,
|
vector<Button*> buttonExceptions,
|
||||||
@@ -531,10 +552,11 @@ namespace battleship{
|
|||||||
vector<Slider*> sliderExceptions,
|
vector<Slider*> sliderExceptions,
|
||||||
vector<Textbox*> textboxExceptions,
|
vector<Textbox*> textboxExceptions,
|
||||||
vector<Node*> guiRectboxExceptions,
|
vector<Node*> guiRectboxExceptions,
|
||||||
vector<Text*> textExceptions
|
vector<Text*> textExceptions,
|
||||||
|
string luaCode
|
||||||
){
|
){
|
||||||
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions);
|
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions);
|
||||||
parseLuaScript(script);
|
parseLuaScript(script, luaCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConcreteGuiManager::readLuaScreenScriptDel(
|
void ConcreteGuiManager::readLuaScreenScriptDel(
|
||||||
@@ -558,13 +580,16 @@ namespace battleship{
|
|||||||
parseLuaScript(script);
|
parseLuaScript(script);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConcreteGuiManager::parseLuaScript(string script){
|
void ConcreteGuiManager::parseLuaScript(string script, string luaCode){
|
||||||
guiElements.clear();
|
guiElements.clear();
|
||||||
|
|
||||||
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
|
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
|
||||||
sol::state_view SOL_LUA_VIEW = generateView();
|
sol::state_view SOL_LUA_VIEW = generateView();
|
||||||
|
SOL_LUA_VIEW.script("music = nil");
|
||||||
SOL_LUA_VIEW.script_file(basePath + script);
|
SOL_LUA_VIEW.script_file(basePath + script);
|
||||||
|
|
||||||
|
if(luaCode != "") SOL_LUA_VIEW.script(luaCode);
|
||||||
|
|
||||||
SOL_LUA_VIEW.script("numGui = #gui");
|
SOL_LUA_VIEW.script("numGui = #gui");
|
||||||
int numGuiElements = SOL_LUA_VIEW["numGui"];
|
int numGuiElements = SOL_LUA_VIEW["numGui"];
|
||||||
|
|
||||||
@@ -595,5 +620,7 @@ namespace battleship{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseMusic();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ namespace vb01{
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX, GUI_RECTANGLE, TEXT};
|
enum GuiElementType {BUTTON, LISTBOX, CHECKBOX, SLIDER, TEXTBOX, GUI_RECTANGLE, TEXT, MUSIC};
|
||||||
enum ButtonType {
|
enum ButtonType {
|
||||||
SINGLE_PLAYER,
|
SINGLE_PLAYER,
|
||||||
EDITOR,
|
EDITOR,
|
||||||
@@ -82,7 +82,8 @@ namespace battleship{
|
|||||||
std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
|
std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
|
||||||
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
|
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
|
||||||
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
||||||
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
std::vector<vb01::Text*> = std::vector<vb01::Text*>{},
|
||||||
|
std::string = ""
|
||||||
);
|
);
|
||||||
void readLuaScreenScriptDel(
|
void readLuaScreenScriptDel(
|
||||||
std::string,
|
std::string,
|
||||||
@@ -94,7 +95,7 @@ namespace battleship{
|
|||||||
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
||||||
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
||||||
);
|
);
|
||||||
void parseLuaScript(std::string);
|
void parseLuaScript(std::string, std::string = "");
|
||||||
private:
|
private:
|
||||||
ConcreteGuiManager();
|
ConcreteGuiManager();
|
||||||
vb01Gui::Button* parseButton(int);
|
vb01Gui::Button* parseButton(int);
|
||||||
@@ -105,6 +106,7 @@ namespace battleship{
|
|||||||
vb01Gui::Textbox* parseTextbox(int);
|
vb01Gui::Textbox* parseTextbox(int);
|
||||||
vb01::Node* parseGuiRectangle(int);
|
vb01::Node* parseGuiRectangle(int);
|
||||||
vb01::Text* parseText(int);
|
vb01::Text* parseText(int);
|
||||||
|
void parseMusic();
|
||||||
|
|
||||||
std::vector<std::pair<int*, void*>> guiElements;
|
std::vector<std::pair<int*, void*>> guiElements;
|
||||||
std::string texBasePath, fontBasePath;
|
std::string texBasePath, fontBasePath;
|
||||||
|
|||||||
+1
-1
@@ -204,7 +204,7 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
sf::Sound *sfx = (sf::Sound*)fx->components[cid].comp;
|
sf::Sound *sfx = (sf::Sound*)fx->components[cid].comp;
|
||||||
const sf::SoundBuffer *buffer = sfx->getBuffer();
|
const sf::SoundBuffer *buffer = &sfx->getBuffer();
|
||||||
sfx->stop();
|
sfx->stop();
|
||||||
|
|
||||||
delete sfx;
|
delete sfx;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stateManager.h>
|
#include <stateManager.h>
|
||||||
#include <inputManager.h>
|
#include <inputManager.h>
|
||||||
|
#include <soundManager.h>
|
||||||
|
|
||||||
#include <assetManager.h>
|
#include <assetManager.h>
|
||||||
#include <root.h>
|
#include <root.h>
|
||||||
@@ -170,6 +171,7 @@ namespace battleship{
|
|||||||
|
|
||||||
void GameManager::update() {
|
void GameManager::update() {
|
||||||
Root::getSingleton()->update();
|
Root::getSingleton()->update();
|
||||||
|
SoundManager::getSingleton()->update();
|
||||||
inputManager->update();
|
inputManager->update();
|
||||||
stateManager->update();
|
stateManager->update();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user