feat(scene): implement settings scene
Also move testing bits to settings so yeah :P
This commit is contained in:
@ -26,6 +26,7 @@ public class Game extends ApplicationAdapter {
|
||||
Scene currentScene;
|
||||
Scene introScene;
|
||||
public Scene mainMenuScene;
|
||||
public Scene settingsScene;
|
||||
public ArrayList<Scene> gameScenes;
|
||||
|
||||
@Override
|
||||
@ -44,7 +45,7 @@ public class Game extends ApplicationAdapter {
|
||||
gameScenes = new ArrayList<>();
|
||||
currentScene = introScene = new Intro(this);
|
||||
gameScenes.add(introScene);
|
||||
// By the end of the intro, the main menu scene will be created and assigned to Game.mainMenuScene
|
||||
// By the end of the intro, other secenes will be created and assigned to Game.mainMenuScene
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,6 +66,9 @@ public class Game extends ApplicationAdapter {
|
||||
case MAIN_MENU:
|
||||
currentScene = mainMenuScene;
|
||||
break;
|
||||
case SETTINGS:
|
||||
currentScene = settingsScene;
|
||||
break;
|
||||
case IN_GAME:
|
||||
// Render in-game scene
|
||||
break;
|
||||
|
||||
@ -3,5 +3,6 @@ package org.vibecoders.moongazer;
|
||||
public enum State {
|
||||
INTRO,
|
||||
MAIN_MENU,
|
||||
SETTINGS,
|
||||
IN_GAME
|
||||
}
|
||||
|
||||
@ -29,8 +29,11 @@ public class Intro extends Scene {
|
||||
startTime = System.currentTimeMillis() + 500;
|
||||
log.info("Starting to load all remaining assets...");
|
||||
Assets.loadAll();
|
||||
// Create scenes
|
||||
game.mainMenuScene = new MainMenu(game);
|
||||
game.settingsScene = new Settings(game);
|
||||
game.gameScenes.add(game.mainMenuScene);
|
||||
game.gameScenes.add(game.settingsScene);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -6,7 +6,9 @@ import org.vibecoders.moongazer.managers.Assets;
|
||||
import org.vibecoders.moongazer.ui.UIImageButton;
|
||||
import org.vibecoders.moongazer.ui.UITextButton;
|
||||
import org.vibecoders.moongazer.Game;
|
||||
import org.vibecoders.moongazer.State;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
@ -38,19 +40,6 @@ public class MainMenu extends Scene {
|
||||
UITextButton loadButton = new UITextButton("Load", font);
|
||||
UITextButton settingsButton = new UITextButton("Settings", font);
|
||||
UITextButton exitButton = new UITextButton("Exit", font);
|
||||
|
||||
UIImageButton settingButton = UIImageButton.settingButton();
|
||||
UIImageButton exitImgButton = UIImageButton.exitButton();
|
||||
UIImageButton soundButton = UIImageButton.soundButton();
|
||||
UIImageButton closeButton = UIImageButton.closeButton();
|
||||
settingButton.setSize(50, 50);
|
||||
exitImgButton.setSize(50, 50);
|
||||
soundButton.setSize(50, 50);
|
||||
closeButton.setSize(50, 50);
|
||||
settingButton.setPosition(20, WINDOW_HEIGHT - 70);
|
||||
exitImgButton.setPosition(WINDOW_WIDTH - 70, WINDOW_HEIGHT - 70);
|
||||
soundButton.setPosition(20, 20);
|
||||
closeButton.setPosition(WINDOW_WIDTH - 70, 20);
|
||||
|
||||
int buttonWidth = 300;
|
||||
int buttonHeight = 80;
|
||||
@ -71,17 +60,22 @@ public class MainMenu extends Scene {
|
||||
|
||||
playButton.onClick(() -> log.debug("Play clicked"));
|
||||
loadButton.onClick(() -> log.debug("Load clicked"));
|
||||
settingsButton.onClick(() -> log.debug("Settings clicked"));
|
||||
exitButton.onClick(() -> log.debug("Exit clicked"));
|
||||
settingsButton.onClick(() -> {
|
||||
log.debug("Settings clicked");
|
||||
if (game.transition == null) {
|
||||
game.transition = new Transition(game, this, game.settingsScene, State.SETTINGS, 350);
|
||||
}
|
||||
});
|
||||
exitButton.onClick(() -> {
|
||||
log.debug("Exit clicked");
|
||||
Gdx.app.exit();
|
||||
});
|
||||
|
||||
root.addActor(settingButton.getActor());
|
||||
root.addActor(exitImgButton.getActor());
|
||||
root.addActor(soundButton.getActor());
|
||||
root.addActor(closeButton.getActor());
|
||||
root.addActor(playButton.getActor());
|
||||
root.addActor(loadButton.getActor());
|
||||
root.addActor(settingsButton.getActor());
|
||||
root.addActor(exitButton.getActor());
|
||||
|
||||
game.stage.addActor(root);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,50 @@
|
||||
package org.vibecoders.moongazer.scenes;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
import static org.vibecoders.moongazer.Constants.*;
|
||||
|
||||
import org.vibecoders.moongazer.Game;
|
||||
import org.vibecoders.moongazer.State;
|
||||
import org.vibecoders.moongazer.managers.Assets;
|
||||
import org.vibecoders.moongazer.ui.UIImageButton;
|
||||
|
||||
public class Settings extends Scene {
|
||||
public Settings(Game game) {
|
||||
super(game);
|
||||
// WIP
|
||||
UIImageButton settingButton = new UIImageButton("textures/ui/UI_Icon_Setting.png");
|
||||
UIImageButton exitImgButton = new UIImageButton("textures/ui/IconExitGame.png");
|
||||
UIImageButton soundButton = new UIImageButton("textures/ui/ImgReShaSoundOn.png");
|
||||
UIImageButton closeButton = new UIImageButton("textures/ui/UI_Gcg_Icon_Close.png");
|
||||
settingButton.setSize(50, 50);
|
||||
exitImgButton.setSize(50, 50);
|
||||
soundButton.setSize(50, 50);
|
||||
closeButton.setSize(50, 50);
|
||||
settingButton.setPosition(20, WINDOW_HEIGHT - 70);
|
||||
exitImgButton.setPosition(WINDOW_WIDTH - 70, WINDOW_HEIGHT - 70);
|
||||
soundButton.setPosition(20, 20);
|
||||
closeButton.setPosition(WINDOW_WIDTH - 70, 20);
|
||||
|
||||
root.addActor(settingButton.getActor());
|
||||
root.addActor(exitImgButton.getActor());
|
||||
root.addActor(soundButton.getActor());
|
||||
root.addActor(closeButton.getActor());
|
||||
settingButton.onClick(() -> log.debug("Settings clicked"));
|
||||
exitImgButton.onClick(() -> {
|
||||
log.debug("Exit clicked");
|
||||
if (game.transition == null) {
|
||||
game.transition = new Transition(game, this, game.mainMenuScene, State.MAIN_MENU, 350);
|
||||
}
|
||||
});
|
||||
soundButton.onClick(() -> log.debug("Sound clicked"));
|
||||
closeButton.onClick(() -> log.debug("Close clicked"));
|
||||
|
||||
game.stage.addActor(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(SpriteBatch batch) {
|
||||
batch.draw(Assets.getWhiteTexture(), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
}
|
||||
}
|
||||
@ -3,49 +3,18 @@ package org.vibecoders.moongazer.ui;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||
import org.vibecoders.moongazer.managers.Assets;
|
||||
|
||||
public class UIImageButton extends UIButton {
|
||||
|
||||
public UIImageButton() {
|
||||
this.button = new ImageButton(new ImageButton.ImageButtonStyle());
|
||||
this.actor = button;
|
||||
}
|
||||
|
||||
public UIImageButton(UIImageButton other) {
|
||||
this.button = new ImageButton((ImageButton.ImageButtonStyle) other.button.getStyle());
|
||||
this.actor = button;
|
||||
}
|
||||
|
||||
private static UIImageButton createButton(String texturePath) {
|
||||
public UIImageButton(String texturePath) {
|
||||
Texture texture = Assets.getAsset(texturePath, Texture.class);
|
||||
TextureRegionDrawable drawable = new TextureRegionDrawable(new TextureRegion(texture));
|
||||
|
||||
ImageButton.ImageButtonStyle style = new ImageButton.ImageButtonStyle();
|
||||
style.imageUp = drawable;
|
||||
style.imageDown = drawable;
|
||||
style.imageOver = drawable;
|
||||
|
||||
UIImageButton button = new UIImageButton();
|
||||
button.button.setStyle(style);
|
||||
return button;
|
||||
}
|
||||
|
||||
public static UIImageButton settingButton() {
|
||||
return createButton("textures/ui/UI_Icon_Setting.png");
|
||||
}
|
||||
|
||||
public static UIImageButton exitButton() {
|
||||
return createButton("textures/ui/IconExitGame.png");
|
||||
}
|
||||
|
||||
public static UIImageButton soundButton() {
|
||||
return createButton("textures/ui/ImgReShaSoundOn.png");
|
||||
}
|
||||
|
||||
public static UIImageButton closeButton() {
|
||||
return createButton("textures/ui/UI_Gcg_Icon_Close.png");
|
||||
this.button = new ImageButton(style);
|
||||
this.actor = button;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user