Volume setting
This commit is contained in:
@@ -8,5 +8,6 @@ namespace game
|
||||
{
|
||||
public:
|
||||
MeasurementSystem measurementSystem{MeasurementSystem::METRIC};
|
||||
int volume{100};
|
||||
};
|
||||
}
|
||||
@@ -12,6 +12,12 @@ namespace game::resource
|
||||
return mixer;
|
||||
}
|
||||
|
||||
void Audio::set_gain(float gain)
|
||||
{
|
||||
auto mixer = mixer_get();
|
||||
MIX_SetMasterGain(mixer, gain);
|
||||
}
|
||||
|
||||
void Audio::retain()
|
||||
{
|
||||
if (refCount) ++(*refCount);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace game::resource
|
||||
MIX_Audio* internal{nullptr};
|
||||
MIX_Track* track{nullptr};
|
||||
int* refCount{nullptr};
|
||||
MIX_Mixer* mixer_get();
|
||||
static MIX_Mixer* mixer_get();
|
||||
void unload();
|
||||
void retain();
|
||||
void release();
|
||||
@@ -27,5 +27,6 @@ namespace game::resource
|
||||
void play(bool isLoop = false);
|
||||
void stop();
|
||||
bool is_playing() const;
|
||||
static void set_gain(float vol);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -21,4 +21,8 @@ namespace game
|
||||
}
|
||||
|
||||
void Resources::sound_play(audio::Type type) { audio[type].play(); }
|
||||
|
||||
void Resources::set_audio_gain(float vol) {
|
||||
Audio::set_gain(vol);
|
||||
}
|
||||
}
|
||||
@@ -124,5 +124,6 @@ namespace game
|
||||
|
||||
Resources();
|
||||
void sound_play(audio::Type);
|
||||
void set_audio_gain(float vol);
|
||||
};
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace game::window
|
||||
ImVec2 pos)
|
||||
{
|
||||
MeasurementSystem& measurementSystem = gameData.measurementSystem;
|
||||
int& volume = gameData.volume;
|
||||
|
||||
ImGui::SetNextWindowSize(size);
|
||||
ImGui::SetNextWindowPos(pos);
|
||||
@@ -48,6 +49,13 @@ namespace game::window
|
||||
ImGui::RadioButton("Metric", (int*)&measurementSystem, MeasurementSystem::METRIC);
|
||||
ImGui::SameLine();
|
||||
ImGui::RadioButton("Imperial", (int*)&measurementSystem, MeasurementSystem::IMPERIAL);
|
||||
|
||||
ImGui::SeparatorText("Sound");
|
||||
if (ImGui::SliderInt("Volume", (int*)&volume, 0, 100))
|
||||
{
|
||||
resources.set_audio_gain((float)volume / 100);
|
||||
}
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user