ajout dans le menu

This commit is contained in:
heurtet 2021-05-13 19:50:54 +02:00
parent 638235acfa
commit a8e400d22d
2 changed files with 24 additions and 3 deletions

View file

@ -1,8 +1,11 @@
package sagittarius; package sagittarius;
import com.badlogic.gdx.Game; import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.kotcrab.vis.ui.VisUI; import com.kotcrab.vis.ui.VisUI;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.*;
import sagittarius.view.*; import sagittarius.view.*;
public class SagittariusGame extends Game { public class SagittariusGame extends Game {
@ -10,7 +13,7 @@ public class SagittariusGame extends Game {
// Constants // Constants
public static float G = 100; public static float G = 100;
public static boolean debugMode = true; public static boolean debugMode = true;
public static Music music;
private static Game game; private static Game game;
public SagittariusGame() { public SagittariusGame() {
@ -27,6 +30,14 @@ public class SagittariusGame extends Game {
@Override @Override
public void create() { public void create() {
/* A welcome music is played */
music = Gdx.audio.newMusic(Gdx.files.internal("core/assets/sounds/Ghostrifter-Deflector.mp3"));
music.play();
// Default volume
music.setVolume(0.3f);
VisUI.load(); VisUI.load();
game.setScreen(new SettingsScreen()); game.setScreen(new SettingsScreen());
} }

View file

@ -13,13 +13,14 @@ import com.kotcrab.vis.ui.widget.VisTextButton;
import com.kotcrab.vis.ui.widget.spinner.SimpleFloatSpinnerModel; import com.kotcrab.vis.ui.widget.spinner.SimpleFloatSpinnerModel;
import com.kotcrab.vis.ui.widget.spinner.Spinner; import com.kotcrab.vis.ui.widget.spinner.Spinner;
import sagittarius.SagittariusGame; import sagittarius.SagittariusGame;
public class SettingsScreen extends BaseScreen { public class SettingsScreen extends BaseScreen {
@Override @Override
public void initialize() { public void initialize() {
Gdx.input.setInputProcessor(uiStage); Gdx.input.setInputProcessor(uiStage);
// Table creation // Table creation
@ -34,6 +35,12 @@ public class SettingsScreen extends BaseScreen {
VisCheckBox debugModeBox = new VisCheckBox("debug mode"); VisCheckBox debugModeBox = new VisCheckBox("debug mode");
debugModeBox.setChecked(SagittariusGame.debugMode); debugModeBox.setChecked(SagittariusGame.debugMode);
// Change volume of the music
Spinner musicVolume= new Spinner("Music Volume:", new SimpleFloatSpinnerModel(SagittariusGame.music.getVolume(), 0f, 1.0f, 0.01f, 3));
// save button // save button
VisTextButton saveButton = new VisTextButton("Save"); VisTextButton saveButton = new VisTextButton("Save");
saveButton.addListener(new ActorGestureListener() { saveButton.addListener(new ActorGestureListener() {
@ -42,6 +49,7 @@ public class SettingsScreen extends BaseScreen {
super.tap(event, x, y, count, button); super.tap(event, x, y, count, button);
SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText()); SagittariusGame.G = Float.parseFloat(gConstField.getTextField().getText());
SagittariusGame.music.setVolume(Float.parseFloat(musicVolume.getTextField().getText()));
SagittariusGame.debugMode = debugModeBox.isChecked(); SagittariusGame.debugMode = debugModeBox.isChecked();
} }
@ -60,6 +68,8 @@ public class SettingsScreen extends BaseScreen {
// Table structure // Table structure
table.add(gConstField).width(250); table.add(gConstField).width(250);
table.row(); table.row();
table.add(musicVolume).width(250);
table.row();
table.add(debugModeBox).align(Align.left); table.add(debugModeBox).align(Align.left);
table.row(); table.row();
table.add(saveButton).width(250); table.add(saveButton).width(250);