@ -0,0 +1,24 @@
|
|||||||
|
package org.vibecoders.moongazer.buttons;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.EventListener;
|
||||||
|
|
||||||
|
public abstract class BaseButton {
|
||||||
|
protected Actor actor;
|
||||||
|
|
||||||
|
public Actor getActor() {
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(int x, int y) {
|
||||||
|
actor.setPosition(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(int width, int height) {
|
||||||
|
actor.setSize(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void eventListener(EventListener eventListener) {
|
||||||
|
actor.addListener(eventListener);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package org.vibecoders.moongazer.buttons;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
|
||||||
|
|
||||||
|
public class IngameButton extends BaseButton {
|
||||||
|
private ImageButton imageButton;
|
||||||
|
|
||||||
|
public IngameButton() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,31 @@
|
|||||||
|
package org.vibecoders.moongazer.buttons;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
|
||||||
|
|
||||||
|
public class MenuButton extends BaseButton {
|
||||||
|
private TextButton textButton;
|
||||||
|
|
||||||
|
public MenuButton(String text, BitmapFont font) {
|
||||||
|
Texture buttonTexture = new Texture(Gdx.files.internal("icons/MenuIcon.png"));
|
||||||
|
TextureRegionDrawable buttonDrawable = new TextureRegionDrawable(new TextureRegion(buttonTexture));
|
||||||
|
|
||||||
|
TextButton.TextButtonStyle style = new TextButton.TextButtonStyle();
|
||||||
|
style.font = font;
|
||||||
|
style.fontColor = Color.BLACK;
|
||||||
|
style.overFontColor = Color.BLUE;
|
||||||
|
style.downFontColor = Color.BLUE;
|
||||||
|
|
||||||
|
style.up = buttonDrawable;
|
||||||
|
style.down = buttonDrawable;
|
||||||
|
style.over = buttonDrawable;
|
||||||
|
|
||||||
|
textButton = new TextButton(text, style);
|
||||||
|
this.actor = textButton;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,11 @@ package org.vibecoders.moongazer.scenes;
|
|||||||
|
|
||||||
import static org.vibecoders.moongazer.Constants.*;
|
import static org.vibecoders.moongazer.Constants.*;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.InputEvent;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.Stage;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;
|
||||||
|
import org.vibecoders.moongazer.buttons.MenuButton;
|
||||||
import org.vibecoders.moongazer.managers.Assets;
|
import org.vibecoders.moongazer.managers.Assets;
|
||||||
import org.vibecoders.moongazer.Game;
|
import org.vibecoders.moongazer.Game;
|
||||||
|
|
||||||
@ -22,32 +27,64 @@ public class MainMenu extends Scene {
|
|||||||
|
|
||||||
public MainMenu(Game game) {
|
public MainMenu(Game game) {
|
||||||
super(game);
|
super(game);
|
||||||
backgroundTexture = Assets.getAsset("textures/main_menu/background.png", Texture.class);
|
var font = Assets.getFont("ui", 24);
|
||||||
titleTexture = Assets.getAsset("textures/main_menu/title.png", Texture.class);
|
textLabel = new Label("Moongazer", new LabelStyle(font, Color.BLACK));
|
||||||
initializeLabels();
|
textLabel.setPosition(WINDOW_WIDTH / 2f - textLabel.getWidth() / 2f, WINDOW_HEIGHT / 2f - textLabel.getHeight() / 2f);
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeLabels() {
|
MenuButton playButton = new MenuButton("Play", font);
|
||||||
var menuFont = Assets.getFont("ui", 24);
|
MenuButton loadButton = new MenuButton("Load", font);
|
||||||
|
MenuButton settingsButton = new MenuButton("Settings", font);
|
||||||
|
MenuButton exitButton = new MenuButton("Exit", font);
|
||||||
|
|
||||||
newGameLabel = new Label("New Game", new LabelStyle(menuFont, Color.BLACK));
|
int buttonWidth = 220;
|
||||||
loadGameLabel = new Label("Load Game", new LabelStyle(menuFont, Color.BLACK));
|
int buttonHeight = 65;
|
||||||
settingsLabel = new Label("Settings", new LabelStyle(menuFont, Color.BLACK));
|
playButton.setSize(buttonWidth, buttonHeight);
|
||||||
quitGameLabel = new Label("Quit Game", new LabelStyle(menuFont, Color.BLACK));
|
loadButton.setSize(buttonWidth, buttonHeight);
|
||||||
|
settingsButton.setSize(buttonWidth, buttonHeight);
|
||||||
|
exitButton.setSize(buttonWidth, buttonHeight);
|
||||||
|
|
||||||
float centerX = WINDOW_WIDTH / 2f;
|
int centerX = WINDOW_WIDTH / 2 - buttonWidth / 2;
|
||||||
float startY = WINDOW_HEIGHT * 0.6f;
|
int startY = WINDOW_HEIGHT / 2 - buttonHeight / 2;
|
||||||
float menuSpacing = 60f;
|
int buttonSpacing = 50;
|
||||||
|
|
||||||
newGameLabel.setPosition(centerX - newGameLabel.getWidth() / 2f, startY);
|
playButton.setPosition(centerX, startY);
|
||||||
loadGameLabel.setPosition(centerX - loadGameLabel.getWidth() / 2f, startY - menuSpacing);
|
loadButton.setPosition(centerX, startY - buttonSpacing);
|
||||||
settingsLabel.setPosition(centerX - settingsLabel.getWidth() / 2f, startY - menuSpacing * 2);
|
settingsButton.setPosition(centerX, startY - buttonSpacing * 2);
|
||||||
quitGameLabel.setPosition(centerX - quitGameLabel.getWidth() / 2f, startY - menuSpacing * 3);
|
exitButton.setPosition(centerX, startY - buttonSpacing * 3);
|
||||||
|
|
||||||
root.addActor(newGameLabel);
|
playButton.getActor().addListener(new ClickListener() {
|
||||||
root.addActor(loadGameLabel);
|
@Override
|
||||||
root.addActor(settingsLabel);
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
root.addActor(quitGameLabel);
|
System.out.println("Play clicked");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loadButton.getActor().addListener(new ClickListener() {
|
||||||
|
@Override
|
||||||
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
|
System.out.println("Load clicked");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
settingsButton.getActor().addListener(new ClickListener() {
|
||||||
|
@Override
|
||||||
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
|
System.out.println("Settings clicked");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
exitButton.getActor().addListener(new ClickListener() {
|
||||||
|
@Override
|
||||||
|
public void clicked(InputEvent event, float x, float y) {
|
||||||
|
System.out.println("Exit clicked");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
game.root.addActor(textLabel);
|
||||||
|
game.root.addActor(playButton.getActor());
|
||||||
|
game.root.addActor(loadButton.getActor());
|
||||||
|
game.root.addActor(settingsButton.getActor());
|
||||||
|
game.root.addActor(exitButton.getActor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
BIN
app/src/main/resources/icons/MenuIcon.png
Normal file
BIN
app/src/main/resources/icons/MenuIcon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
Reference in New Issue
Block a user