Merge pull request #4 from teppyboy/button
feat(button): add UI image button
This commit is contained in:
@ -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() {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -38,8 +39,22 @@ 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 = 300;
|
||||
int buttonHeight = 80;
|
||||
|
||||
playButton.setSize(buttonWidth, buttonHeight);
|
||||
loadButton.setSize(buttonWidth, buttonHeight);
|
||||
settingsButton.setSize(buttonWidth, buttonHeight);
|
||||
@ -59,6 +74,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());
|
||||
|
||||
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
BIN
app/src/main/resources/textures/ui/IconExitGame.png
Normal file
BIN
app/src/main/resources/textures/ui/IconExitGame.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 480 B |
BIN
app/src/main/resources/textures/ui/ImgReShaSoundOn.png
Normal file
BIN
app/src/main/resources/textures/ui/ImgReShaSoundOn.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
BIN
app/src/main/resources/textures/ui/UI_Gcg_Icon_Close.png
Normal file
BIN
app/src/main/resources/textures/ui/UI_Gcg_Icon_Close.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 869 B |
BIN
app/src/main/resources/textures/ui/UI_Icon_Setting.png
Normal file
BIN
app/src/main/resources/textures/ui/UI_Icon_Setting.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user