chore: add UI image button

This commit is contained in:
GiaQuang
2025-09-30 23:51:29 +07:00
parent e19c84cad3
commit ac37bb43eb
7 changed files with 63 additions and 0 deletions

View File

@ -89,6 +89,10 @@ public class Assets {
assetManager.load("textures/main_menu/background.png", Texture.class);
assetManager.load("textures/main_menu/title.png", Texture.class);
assetManager.load("textures/ui/text_button.png", Texture.class);
assetManager.load("textures/ui/IconExitGame.png", Texture.class);
assetManager.load("textures/ui/UI_Icon_Setting.png", Texture.class);
assetManager.load("textures/ui/ImgReShaSoundOn.png", Texture.class);
assetManager.load("textures/ui/UI_Gcg_Icon_Close.png", Texture.class);
}
public static boolean isLoadedAll() {

View File

@ -3,6 +3,7 @@ package org.vibecoders.moongazer.scenes;
import static org.vibecoders.moongazer.Constants.*;
import org.vibecoders.moongazer.managers.Assets;
import org.vibecoders.moongazer.ui.UIImageButton;
import org.vibecoders.moongazer.ui.UITextButton;
import org.vibecoders.moongazer.Game;
@ -24,6 +25,19 @@ public class MainMenu extends Scene {
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 = 220;
int buttonHeight = 65;
playButton.setSize(buttonWidth, buttonHeight);
@ -45,6 +59,10 @@ public class MainMenu extends Scene {
settingsButton.onClick(() -> log.debug("Settings clicked"));
exitButton.onClick(() -> log.debug("Exit clicked"));
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());

View File

@ -1,10 +1,51 @@
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) {
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");
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 869 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB