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 = {
|
||||
resolution = {x = 1920, y = 1080}
|
||||
}
|
||||
audio = {
|
||||
sfxVolume = 100,
|
||||
musicVolume = 100,
|
||||
}
|
||||
|
||||
@@ -3,6 +3,28 @@ Size = {x = 70, y = 70}
|
||||
sz = 210
|
||||
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'
|
||||
refIcon = 'refineds.png'
|
||||
minimapSize = {x = 200, y = 200}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
Size = {x = 150, y = 40}
|
||||
|
||||
numGui = 4
|
||||
music = {
|
||||
loop = true,
|
||||
shuffle = false,
|
||||
tracks = {'intro.ogg'}
|
||||
}
|
||||
gui = {
|
||||
{
|
||||
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_POLICY_VERSION_MINIMUM 3.5)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(BUILD_TESTS ON)
|
||||
set(BUILD_TESTS OFF)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
|
||||
@@ -41,7 +41,7 @@ set(UTIL util.cpp binds.h)
|
||||
|
||||
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_GUI_DIR external/vb01Gui)
|
||||
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/vb01/external/glm)
|
||||
include_directories(external/vb01/external/glm/glm)
|
||||
include_directories(external/gameBase/external/SFML/include)
|
||||
|
||||
add_subdirectory(${VB01_DIR})
|
||||
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_link_directories(${GAME_NAME} PUBLIC ${GAME_BASE_LIB_DIR})
|
||||
|
||||
add_subdirectory(${SFML_DIR})
|
||||
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)
|
||||
set(DEPS vb01 gameBase)
|
||||
target_link_libraries(${GAME_NAME} ${DEPS})
|
||||
|
||||
if(BUILD_TESTS)
|
||||
|
||||
+11
-1
@@ -120,7 +120,17 @@ namespace battleship{
|
||||
|
||||
void ActiveGameState::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();
|
||||
}
|
||||
|
||||
+30
-3
@@ -1,4 +1,5 @@
|
||||
#include <solUtil.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <quad.h>
|
||||
|
||||
@@ -523,6 +524,26 @@ namespace battleship{
|
||||
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(
|
||||
string script,
|
||||
vector<Button*> buttonExceptions,
|
||||
@@ -531,10 +552,11 @@ namespace battleship{
|
||||
vector<Slider*> sliderExceptions,
|
||||
vector<Textbox*> textboxExceptions,
|
||||
vector<Node*> guiRectboxExceptions,
|
||||
vector<Text*> textExceptions
|
||||
vector<Text*> textExceptions,
|
||||
string luaCode
|
||||
){
|
||||
removeAllGuiElements(buttonExceptions, listboxExceptions, checkboxExceptions, sliderExceptions, textboxExceptions, guiRectboxExceptions, textExceptions);
|
||||
parseLuaScript(script);
|
||||
parseLuaScript(script, luaCode);
|
||||
}
|
||||
|
||||
void ConcreteGuiManager::readLuaScreenScriptDel(
|
||||
@@ -558,13 +580,16 @@ namespace battleship{
|
||||
parseLuaScript(script);
|
||||
}
|
||||
|
||||
void ConcreteGuiManager::parseLuaScript(string script){
|
||||
void ConcreteGuiManager::parseLuaScript(string script, string luaCode){
|
||||
guiElements.clear();
|
||||
|
||||
string basePath = GameManager::getSingleton()->getPath() + "Scripts/Gui/";
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
SOL_LUA_VIEW.script("music = nil");
|
||||
SOL_LUA_VIEW.script_file(basePath + script);
|
||||
|
||||
if(luaCode != "") SOL_LUA_VIEW.script(luaCode);
|
||||
|
||||
SOL_LUA_VIEW.script("numGui = #gui");
|
||||
int numGuiElements = SOL_LUA_VIEW["numGui"];
|
||||
|
||||
@@ -595,5 +620,7 @@ namespace battleship{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
parseMusic();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace vb01{
|
||||
}
|
||||
|
||||
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 {
|
||||
SINGLE_PLAYER,
|
||||
EDITOR,
|
||||
@@ -82,7 +82,8 @@ namespace battleship{
|
||||
std::vector<vb01Gui::Slider*> = std::vector<vb01Gui::Slider*>{},
|
||||
std::vector<vb01Gui::Textbox*> = std::vector<vb01Gui::Textbox*>{},
|
||||
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(
|
||||
std::string,
|
||||
@@ -94,7 +95,7 @@ namespace battleship{
|
||||
std::vector<vb01::Node*> = std::vector<vb01::Node*>{},
|
||||
std::vector<vb01::Text*> = std::vector<vb01::Text*>{}
|
||||
);
|
||||
void parseLuaScript(std::string);
|
||||
void parseLuaScript(std::string, std::string = "");
|
||||
private:
|
||||
ConcreteGuiManager();
|
||||
vb01Gui::Button* parseButton(int);
|
||||
@@ -105,6 +106,7 @@ namespace battleship{
|
||||
vb01Gui::Textbox* parseTextbox(int);
|
||||
vb01::Node* parseGuiRectangle(int);
|
||||
vb01::Text* parseText(int);
|
||||
void parseMusic();
|
||||
|
||||
std::vector<std::pair<int*, void*>> guiElements;
|
||||
std::string texBasePath, fontBasePath;
|
||||
|
||||
+1
-1
@@ -204,7 +204,7 @@ namespace battleship{
|
||||
}
|
||||
else{
|
||||
sf::Sound *sfx = (sf::Sound*)fx->components[cid].comp;
|
||||
const sf::SoundBuffer *buffer = sfx->getBuffer();
|
||||
const sf::SoundBuffer *buffer = &sfx->getBuffer();
|
||||
sfx->stop();
|
||||
|
||||
delete sfx;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <inputManager.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
@@ -170,6 +171,7 @@ namespace battleship{
|
||||
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
SoundManager::getSingleton()->update();
|
||||
inputManager->update();
|
||||
stateManager->update();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user