diff --git a/app/src/main/java/org/vibecoders/moongazer/scenes/MainMenu.java b/app/src/main/java/org/vibecoders/moongazer/scenes/MainMenu.java index 6f29c41..3239f32 100644 --- a/app/src/main/java/org/vibecoders/moongazer/scenes/MainMenu.java +++ b/app/src/main/java/org/vibecoders/moongazer/scenes/MainMenu.java @@ -6,7 +6,7 @@ import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import org.vibecoders.moongazer.managers.Assets; -import org.vibecoders.moongazer.ui.MenuButton; +import org.vibecoders.moongazer.ui.UITextButton; import org.vibecoders.moongazer.Game; import com.badlogic.gdx.graphics.Texture; @@ -22,10 +22,10 @@ public class MainMenu extends Scene { titleTexture = Assets.getAsset("textures/main_menu/title.png", Texture.class); var font = Assets.getFont("ui", 24); - MenuButton playButton = new MenuButton("Play", font); - MenuButton loadButton = new MenuButton("Load", font); - MenuButton settingsButton = new MenuButton("Settings", font); - MenuButton exitButton = new MenuButton("Exit", font); + UITextButton playButton = new UITextButton("Play", font); + UITextButton loadButton = new UITextButton("Load", font); + UITextButton settingsButton = new UITextButton("Settings", font); + UITextButton exitButton = new UITextButton("Exit", font); int buttonWidth = 220; int buttonHeight = 65; @@ -43,33 +43,10 @@ public class MainMenu extends Scene { settingsButton.setPosition(centerX, startY - buttonSpacing * 2); exitButton.setPosition(centerX, startY - buttonSpacing * 3); - playButton.addEventListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - log.debug("Play clicked"); - } - }); - - loadButton.addEventListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - log.debug("Load clicked"); - } - }); - - settingsButton.addEventListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - log.debug("Settings clicked"); - } - }); - - exitButton.addEventListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - log.debug("Exit clicked"); - } - }); + playButton.onClick(() -> log.debug("Play clicked")); + loadButton.onClick(() -> log.debug("Load clicked")); + settingsButton.onClick(() -> log.debug("Settings clicked")); + exitButton.onClick(() -> log.debug("Exit clicked")); root.addActor(playButton.getActor()); root.addActor(loadButton.getActor()); diff --git a/app/src/main/java/org/vibecoders/moongazer/ui/IngameButton.java b/app/src/main/java/org/vibecoders/moongazer/ui/IngameButton.java deleted file mode 100644 index 5a0b5ac..0000000 --- a/app/src/main/java/org/vibecoders/moongazer/ui/IngameButton.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.vibecoders.moongazer.ui; - -import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; - -public class IngameButton extends BaseButton { - private ImageButton imageButton; - - public IngameButton() { - - } -} diff --git a/app/src/main/java/org/vibecoders/moongazer/ui/MenuButton.java b/app/src/main/java/org/vibecoders/moongazer/ui/MenuButton.java deleted file mode 100644 index 4d460c3..0000000 --- a/app/src/main/java/org/vibecoders/moongazer/ui/MenuButton.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.vibecoders.moongazer.ui; - -import org.vibecoders.moongazer.managers.Assets; - -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; - private Texture buttonTexture; - - public MenuButton(String text, BitmapFont font) { - buttonTexture = Assets.getAsset("textures/ui/menu_button.png", Texture.class); - 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; - } -} \ No newline at end of file diff --git a/app/src/main/java/org/vibecoders/moongazer/ui/BaseButton.java b/app/src/main/java/org/vibecoders/moongazer/ui/UIButton.java similarity index 54% rename from app/src/main/java/org/vibecoders/moongazer/ui/BaseButton.java rename to app/src/main/java/org/vibecoders/moongazer/ui/UIButton.java index f86d020..5e43a97 100644 --- a/app/src/main/java/org/vibecoders/moongazer/ui/BaseButton.java +++ b/app/src/main/java/org/vibecoders/moongazer/ui/UIButton.java @@ -2,9 +2,11 @@ package org.vibecoders.moongazer.ui; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.EventListener; +import com.badlogic.gdx.scenes.scene2d.ui.Button; -public abstract class BaseButton { +public abstract class UIButton { protected Actor actor; + protected Button button; public Actor getActor() { return actor; @@ -21,4 +23,13 @@ public abstract class BaseButton { public void addEventListener(EventListener eventListener) { actor.addListener(eventListener); } + + public void onClick(Runnable action) { + button.addListener(new com.badlogic.gdx.scenes.scene2d.utils.ClickListener() { + @Override + public void clicked(com.badlogic.gdx.scenes.scene2d.InputEvent event, float x, float y) { + action.run(); + } + }); + } } diff --git a/app/src/main/java/org/vibecoders/moongazer/ui/UIImageButton.java b/app/src/main/java/org/vibecoders/moongazer/ui/UIImageButton.java new file mode 100644 index 0000000..3ae9d46 --- /dev/null +++ b/app/src/main/java/org/vibecoders/moongazer/ui/UIImageButton.java @@ -0,0 +1,10 @@ +package org.vibecoders.moongazer.ui; + +import com.badlogic.gdx.scenes.scene2d.ui.ImageButton; + +public class UIImageButton extends UIButton { + public UIImageButton() { + this.button = new ImageButton(new ImageButton.ImageButtonStyle()); + this.actor = button; + } +} diff --git a/app/src/main/java/org/vibecoders/moongazer/ui/UITextButton.java b/app/src/main/java/org/vibecoders/moongazer/ui/UITextButton.java new file mode 100644 index 0000000..0a20354 --- /dev/null +++ b/app/src/main/java/org/vibecoders/moongazer/ui/UITextButton.java @@ -0,0 +1,39 @@ +package org.vibecoders.moongazer.ui; + +import org.vibecoders.moongazer.managers.Assets; + +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 UITextButton extends UIButton { + private Texture buttonTexture; + private Texture buttonDownTexture; + private Texture buttonOverTexture; + + public UITextButton(String text, BitmapFont font) { + buttonTexture = Assets.getAsset("textures/ui/menu_button.png", Texture.class); + buttonDownTexture = Assets.getAsset("textures/ui/menu_button_down.png", Texture.class); + buttonOverTexture = Assets.getAsset("textures/ui/menu_button_over.png", Texture.class); + TextureRegionDrawable buttonDrawable = new TextureRegionDrawable(new TextureRegion(buttonTexture)); + TextureRegionDrawable buttonDownDrawable = new TextureRegionDrawable(new TextureRegion(buttonDownTexture)); + TextureRegionDrawable buttonOverDrawable = new TextureRegionDrawable(new TextureRegion(buttonOverTexture)); + + TextButton.TextButtonStyle style = new TextButton.TextButtonStyle(); + // Text style + style.font = font; + style.fontColor = Color.BLACK; + style.overFontColor = Color.BLACK; + style.downFontColor = Color.BLACK; + // Button style + style.up = buttonDrawable; + style.down = buttonDownDrawable; + style.over = buttonOverDrawable; + + this.button = new TextButton(text, style); + this.actor = button; + } +} \ No newline at end of file diff --git a/app/src/main/resources/textures/ui/menu_button.png b/app/src/main/resources/textures/ui/menu_button.png index 0802ffb..e2d9d4e 100644 Binary files a/app/src/main/resources/textures/ui/menu_button.png and b/app/src/main/resources/textures/ui/menu_button.png differ diff --git a/app/src/main/resources/textures/ui/menu_button_down.png b/app/src/main/resources/textures/ui/menu_button_down.png new file mode 100644 index 0000000..f1b8fa1 Binary files /dev/null and b/app/src/main/resources/textures/ui/menu_button_down.png differ diff --git a/app/src/main/resources/textures/ui/menu_button_over.png b/app/src/main/resources/textures/ui/menu_button_over.png new file mode 100644 index 0000000..f5a208c Binary files /dev/null and b/app/src/main/resources/textures/ui/menu_button_over.png differ