From 78bddd9956765f28b587c68c3e61178b6fc66cb8 Mon Sep 17 00:00:00 2001 From: TheCodeBoat Date: Fri, 21 Jun 2013 12:37:29 +0200 Subject: [PATCH] Refactor GUI --- .../wyrez/shootingstars/ShootingStars.java | 2 + .../shootingstars/gui/FileMetaInfoGUI.java | 44 +++-- .../org/wyrez/shootingstars/gui/GameGUI.java | 46 +++--- .../wyrez/shootingstars/gui/HighscoreGUI.java | 46 ++++-- .../wyrez/shootingstars/gui/LoadingGui.java | 15 +- .../org/wyrez/shootingstars/gui/MenuGUI.java | 40 +++-- .../wyrez/shootingstars/gui/OptionsGUI.java | 150 +++++++++++------- .../shootingstars/gui/SelectTrackGUI.java | 36 +++-- .../shootingstars/gui/YTDownloadGUI.java | 48 ++++-- .../gui/listener/YTDownloadListener.java | 2 + .../shootingstars/helper/ScreenHelper.java | 27 ++++ .../states/FileMetaInfoState.java | 5 +- .../wyrez/shootingstars/states/GameState.java | 5 +- .../shootingstars/states/HighscoreState.java | 5 +- .../shootingstars/states/LoadingState.java | 5 +- .../wyrez/shootingstars/states/MenuState.java | 5 +- .../shootingstars/states/OptionsState.java | 5 +- .../states/SelectTrackState.java | 5 +- .../shootingstars/states/YTDownloadState.java | 9 +- 19 files changed, 331 insertions(+), 169 deletions(-) create mode 100644 ShootingStars/src/org/wyrez/shootingstars/helper/ScreenHelper.java diff --git a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java index 3e9661d..c122676 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java +++ b/ShootingStars/src/org/wyrez/shootingstars/ShootingStars.java @@ -35,6 +35,7 @@ import org.wyrez.shootingstars.factories.Materials; import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.manager.HighscoreManager; import org.wyrez.shootingstars.gui.manager.ScoreComparator; +import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.io.SQLiteConnector; import org.wyrez.shootingstars.states.State; import org.wyrez.shootingstars.states.StateManager; @@ -90,6 +91,7 @@ public class ShootingStars extends SimpleApplication { container.registerType(ScoreComparator.class, true); container.registerType(HighscoreManager.class, true); container.registerType(Screen.class, true); + container.registerType(ScreenHelper.class, true); container.registerType(AudioDataManager.class, true); container.registerType(YTDownloader.class); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/FileMetaInfoGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/FileMetaInfoGUI.java index 8bd3c01..5803727 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/FileMetaInfoGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/FileMetaInfoGUI.java @@ -27,6 +27,7 @@ import org.jaudiotagger.tag.Tag; import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.listener.FileMetaInfoListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.windows.Panel; @@ -40,25 +41,28 @@ public class FileMetaInfoGUI extends Panel implements Gui { private FileMetaInfoListener listener; private GameSettings settings; + private ScreenHelper screenHelper; private String fileName = ""; private String duration = ""; private String title = ""; private String artist = ""; - public FileMetaInfoGUI(Screen screen, FileMetaInfoListener listener, GameSettings settings) { + public FileMetaInfoGUI(Screen screen, FileMetaInfoListener listener, GameSettings settings, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); this.listener = listener; this.settings = settings; + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); } private void create() { - float startPointx = 256f; - float startPointy = 202f; - float marginLeft = 110f; - float buttonWidth = 153.6f; + float startPointx = screenHelper.calcX(256f); + float startPointy = screenHelper.calcY(202f); + float marginLeft = screenHelper.calcX(110f); + float buttonWidth = screenHelper.calcX(153.6f); + float labelFontSize = screenHelper.calcX(20f); File file = null; if(settings.useVideo()) { @@ -69,45 +73,55 @@ public class FileMetaInfoGUI extends Panel implements Gui { readMetaData(file); - Label lblFileNameHead = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(100f, 40f)); + Label lblFileNameHead = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); lblFileNameHead.setText("Track Name"); + lblFileNameHead.setFontSize(labelFontSize); - Label lblFileName = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy), new Vector2f(400f, 40f)); + Label lblFileName = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblFileName.setText(fileName); + lblFileName.setFontSize(labelFontSize); - Label lblArtistHead = new Label(screen, new Vector2f(startPointx, startPointy + 50f), new Vector2f(100f, 40f)); + Label lblArtistHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); lblArtistHead.setText("Artist"); + lblArtistHead.setFontSize(labelFontSize); - Label lblArtist = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + 50f), new Vector2f(400f, 40f)); + Label lblArtist = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(50f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblArtist.setText(artist); + lblArtist.setFontSize(labelFontSize); - Label lblTitelHead = new Label(screen, new Vector2f(startPointx, startPointy + 100f), new Vector2f(100f, 40f)); + Label lblTitelHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); lblTitelHead.setText("Titel"); + lblTitelHead.setFontSize(labelFontSize); - Label lblTitel = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + 100f), new Vector2f(400f, 40f)); + Label lblTitel = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(100f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblTitel.setText(title); + lblTitel.setFontSize(labelFontSize); - Label lblDurationHead = new Label(screen, new Vector2f(startPointx, startPointy + 150f), new Vector2f(100f, 40f)); + Label lblDurationHead = new Label(screen, new Vector2f(startPointx, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(100f), screenHelper.calcY(40f))); lblDurationHead.setText("Duration"); + lblDurationHead.setFontSize(labelFontSize); - Label lblDuration = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + 150f), new Vector2f(400f, 40f)); + Label lblDuration = new Label(screen, new Vector2f(startPointx + marginLeft, startPointy + screenHelper.calcY(150f)), new Vector2f(screenHelper.calcX(400f), screenHelper.calcY(40f))); lblDuration.setText(duration); + lblDuration.setFontSize(labelFontSize); - Button btnStartLoading = new ButtonBase(screen, new Vector2f(startPointx + 653f, startPointy + 438.8f), new Vector2f(buttonWidth, 40)) { + Button btnStartLoading = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(653f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.startLoading(); } }; btnStartLoading.setText("Play"); + btnStartLoading.setFontSize(labelFontSize); - Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + 836f, startPointy + 438.8f), new Vector2f(buttonWidth, 40)) { + Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(836f), startPointy + screenHelper.calcY(438.8f)), new Vector2f(buttonWidth, screenHelper.calcY(40))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.cancel(); } }; btnCancel.setText("Cancel"); + btnCancel.setFontSize(labelFontSize); this.addChild(lblFileNameHead); this.addChild(lblFileName); diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java index f1308e8..38c40fb 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/GameGUI.java @@ -28,6 +28,7 @@ import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.controls.GuiPlayerPointsControl; import org.wyrez.shootingstars.gui.controls.IndicatorBase; import org.wyrez.shootingstars.gui.listener.GameListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.extras.Indicator; import tonegod.gui.controls.text.Label; @@ -50,11 +51,13 @@ public class GameGUI extends Panel { private AssetManager assetManager; private Spatial player; private Label lblPoints; + private ScreenHelper screenHelper; - public GameGUI(Screen screen, GameListener listener, AssetManager assetManager) { + public GameGUI(Screen screen, GameListener listener, AssetManager assetManager, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; this.assetManager = assetManager; + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); @@ -62,22 +65,24 @@ public class GameGUI extends Panel { private void create() { - float startPointx = 537f; - float startPointy = 576f; + float startPointx = screenHelper.calcX(537f); + float startPointy = screenHelper.calcY(576f); - float startPointCrosshairx = 441f; - float startPointCrosshairy = 560f; + float startPointCrosshairx = screenHelper.calcX(441f); + float startPointCrosshairy = screenHelper.calcY(560f); - float startPointOverheatx = 505f; - float startPointOverheaty = 270f; + float startPointOverheatx = screenHelper.calcX(505f); + float startPointOverheaty = screenHelper.calcY(270f); - float startPointPointsx = 1100f; - float startPointPointsy = 25f; + float startPointPointsx = screenHelper.calcX(1100f); + float startPointPointsy = screenHelper.calcY(25f); - float startPointYMenu = 200f; + float startPointYMenu = screenHelper.calcY(200f); + + float labelFontSize = screenHelper.calcX(20f); btnStart = new ButtonBase(screen, new Vector2f(startPointx, startPointy), - new Vector2f(200f, 30f)) { + new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.start(); @@ -85,9 +90,10 @@ public class GameGUI extends Panel { }; btnStart.setText("Launch"); btnStart.setTextAlign(BitmapFont.Align.Center); + btnStart.setFontSize(labelFontSize); btnResume = new ButtonBase(screen, new Vector2f(startPointx, startPointYMenu), - new Vector2f(200f, 30f)) { + new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.resume(); @@ -95,9 +101,10 @@ public class GameGUI extends Panel { }; btnResume.setText("Resume"); btnResume.setTextAlign(BitmapFont.Align.Center); + btnResume.setFontSize(labelFontSize); - btnMenu = new ButtonBase(screen, new Vector2f(startPointx, startPointYMenu + 40f), - new Vector2f(200f, 30f)) { + btnMenu = new ButtonBase(screen, new Vector2f(startPointx, startPointYMenu + screenHelper.calcY(40f)), + new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.cancelTrack(); @@ -105,10 +112,11 @@ public class GameGUI extends Panel { }; btnMenu.setText("Menu"); btnMenu.setTextAlign(BitmapFont.Align.Center); + btnMenu.setFontSize(labelFontSize); picCrosshair = new Picture("Crosshair"); - picCrosshair.setWidth(400f); - picCrosshair.setHeight(400f); + picCrosshair.setWidth(screenHelper.calcX(400f)); + picCrosshair.setHeight(screenHelper.calcY(400f)); picCrosshair.setImage(assetManager, "Textures/Crosshair.png", true); Panel plnCrosshair = new Panel(screen, new Vector2f(startPointCrosshairx, startPointCrosshairy), new Vector2f(0f, 0f)); @@ -117,15 +125,15 @@ public class GameGUI extends Panel { plnCrosshair.attachChild(picCrosshair); indOverheat = new IndicatorBase(screen, new Vector2f(startPointOverheatx, startPointOverheaty), - new Vector2f(275f, 180f), Indicator.Orientation.VERTICAL); + new Vector2f(screenHelper.calcX(275f), screenHelper.calcY(180f)), Indicator.Orientation.VERTICAL); //indOverheat.setIndicatorColor(new ColorRGBA(0f, 0f, 1f, 0.5f)); indOverheat.setAlphaMap("Textures/Crosshair_AlphaMap.png"); indOverheat.setOverlayImage("Textures/Crosshair_OverlayImage.png"); indOverheat.setIndicatorImage("Textures/Crosshair_Overheat_Fog.png"); - lblPoints = new Label(screen, new Vector2f(startPointPointsx, startPointPointsy), new Vector2f(275f, 180f)); + lblPoints = new Label(screen, new Vector2f(startPointPointsx, startPointPointsy), new Vector2f(screenHelper.calcX(275f), screenHelper.calcY(180f))); lblPoints.setFontColor(new ColorRGBA(1f, 0f, 0f, 1f)); - lblPoints.setFontSize(50f); + lblPoints.setFontSize(screenHelper.calcX(50f)); this.addChild(btnStart); this.addChild(btnResume); diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java index 5360a5f..17692cc 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/HighscoreGUI.java @@ -23,6 +23,7 @@ import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.listener.HighscoreListener; import org.wyrez.shootingstars.gui.manager.HighscoreManager; import org.wyrez.shootingstars.gui.model.Score; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.windows.Panel; @@ -36,13 +37,15 @@ public class HighscoreGUI extends Panel implements Gui { private HighscoreListener listener; private HighscoreManager highscoreManager; + private ScreenHelper screenHelper; - public HighscoreGUI(Screen screen, HighscoreListener listener, HighscoreManager highscoreManager) { + public HighscoreGUI(Screen screen, HighscoreListener listener, HighscoreManager highscoreManager, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); this.listener = listener; - this.setIgnoreMouse(true); - this.setIsVisible(false); this.highscoreManager = highscoreManager; + this.screenHelper = screenHelper; + this.setIgnoreMouse(true); + this.setIsVisible(false); create(); } @@ -55,25 +58,30 @@ public class HighscoreGUI extends Panel implements Gui { } private void create() { - float startPointx = 32f; - float startPointy = 18f; + float startPointx = screenHelper.calcX(32f); + float startPointy = screenHelper.calcY(18f); - float marginScoreNameLeft = 14f; - float marginScorePointsLeft = 300f; - float marginScoreSongNameLeft = 600f; + float marginScoreNameLeft = screenHelper.calcX(14f); + float marginScorePointsLeft = screenHelper.calcX(300f); + float marginScoreSongNameLeft = screenHelper.calcX(600f); - float marginScoreTop = 50f; + float marginScoreTop = screenHelper.calcY(50f); + + float labelFontSize = screenHelper.calcX(20f); List highscores = highscoreManager.getScores(); - Label lblScoreNameHead = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy), new Vector2f(250f, 40f)); + Label lblScoreNameHead = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f))); lblScoreNameHead.setText("Name"); + lblScoreNameHead.setFontSize(labelFontSize); - Label lblScorePointsHead = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy), new Vector2f(250f, 40f)); + Label lblScorePointsHead = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f))); lblScorePointsHead.setText("Points"); + lblScorePointsHead.setFontSize(labelFontSize); - Label lblScoreSongNameHead = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy), new Vector2f(600f, 40f)); + Label lblScoreSongNameHead = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f))); lblScoreSongNameHead.setText("Song Name"); + lblScoreSongNameHead.setFontSize(labelFontSize); int maxScores = 0; if(highscores.size() > 10) { @@ -84,28 +92,32 @@ public class HighscoreGUI extends Panel implements Gui { for (int i = 0; i < maxScores; i++) { Score score = highscores.get(i); - Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f)); + Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f))); lblScoreName.setText(score.getPlayerName()); + lblScoreName.setFontSize(labelFontSize); - Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f)); + Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(250f), screenHelper.calcY(40f))); lblScorePoints.setText(String.valueOf(score.getScore())); + lblScorePoints.setFontSize(labelFontSize); - Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(600f, 40f)); + Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(screenHelper.calcX(600f), screenHelper.calcY(40f))); lblScoreSongName.setText(score.getSongName()); + lblScoreSongName.setFontSize(labelFontSize); this.addChild(lblScoreName); this.addChild(lblScorePoints); this.addChild(lblScoreSongName); - marginScoreTop += 50f; + marginScoreTop += screenHelper.calcY(50f); } - Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + 1060f, startPointy + 622.8f), new Vector2f(153f, 40)) { + Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + screenHelper.calcX(1060f), startPointy + screenHelper.calcY(622.8f)), new Vector2f(screenHelper.calcX(153f), screenHelper.calcY(40f))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.back(); } }; btnBack.setText("Back"); + btnBack.setFontSize(labelFontSize); this.addChild(lblScoreNameHead); this.addChild(lblScorePointsHead); diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java b/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java index 63e03e6..dce6724 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/LoadingGui.java @@ -20,6 +20,7 @@ import com.jme3.font.BitmapFont; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector2f; import org.wyrez.shootingstars.gui.controls.IndicatorBase; +import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.states.util.LoadingProgress; import tonegod.gui.controls.extras.Indicator; import tonegod.gui.controls.text.Label; @@ -34,9 +35,11 @@ public class LoadingGui extends Panel { private Label lblStatus; private Indicator indProgress; + private ScreenHelper screenHelper; - public LoadingGui(Screen screen) { + public LoadingGui(Screen screen, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); @@ -44,17 +47,17 @@ public class LoadingGui extends Panel { private void create() { - float startPointx = 537f;//screen.getWidth() * 0.42f; - float startPointy = 576f;//screen.getHeight() * 0.80f; - float distancePogressbarLabely = 36f; + float startPointx = screenHelper.calcX(537f); + float startPointy = screenHelper.calcY(576f); + float distancePogressbarLabely = screenHelper.calcY(36f); indProgress = new IndicatorBase(screen, new Vector2f(startPointx, startPointy), - new Vector2f(200f, 30f), Indicator.Orientation.HORIZONTAL); + new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f)), Indicator.Orientation.HORIZONTAL); indProgress.setDisplayValues(); indProgress.setMaxValue(LoadingProgress.getProgressCount()); indProgress.setIndicatorColor(ColorRGBA.Black); - lblStatus = new Label(screen, new Vector2f(startPointx, startPointy + distancePogressbarLabely), new Vector2f(200f, 30f)); + lblStatus = new Label(screen, new Vector2f(startPointx, startPointy + distancePogressbarLabely), new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f))); lblStatus.setTextAlign(BitmapFont.Align.Center); this.addChild(indProgress); diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/MenuGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/MenuGUI.java index 127e67a..18cbc84 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/MenuGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/MenuGUI.java @@ -20,6 +20,7 @@ import com.jme3.input.event.MouseButtonEvent; import com.jme3.math.Vector2f; import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.listener.MenuListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.windows.Panel; @@ -32,10 +33,12 @@ import tonegod.gui.core.Screen; public class MenuGUI extends Panel implements Gui { private MenuListener listener; + private ScreenHelper screenHelper; - public MenuGUI(Screen screen, MenuListener listener) { + public MenuGUI(Screen screen, MenuListener listener, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); @@ -43,55 +46,60 @@ public class MenuGUI extends Panel implements Gui { private void create() { - float startPointx = 256f; - float startPointy = 252f; - float labelFontSize = 89f; - float buttonLabelDistancex = 512f; - float buttonButtonDistancex = buttonLabelDistancex + 192f; - float buttonButtonDistancey = 90f; - float buttonWidth = 153f; - float marginButtonTop = 25f; - float distanceLabelLabely = 60f; + float startPointx = screenHelper.calcX(256f); + float startPointy = screenHelper.calcY(252f); + float labelFontSize = screenHelper.calcX(89f); + float buttonLabelDistancex = screenHelper.calcX(512f); + float buttonButtonDistancex = buttonLabelDistancex + screenHelper.calcX(192f); + float buttonButtonDistancey = screenHelper.calcY(90f); + float buttonWidth = screenHelper.calcX(153f); + float marginButtonTop = screenHelper.calcY(25f); + float distanceLabelLabely = screenHelper.calcY(60f); + float buttonFontSize = screenHelper.calcX(20f); - Label lblWyrez = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(300, 40)); + Label lblWyrez = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(300), screenHelper.calcY(40))); lblWyrez.setFontSize(labelFontSize); lblWyrez.setText("Wyrez"); - Label lblShootingStars = new Label(screen, new Vector2f(startPointx, startPointy + distanceLabelLabely), new Vector2f(500, 40)); + Label lblShootingStars = new Label(screen, new Vector2f(startPointx, startPointy + distanceLabelLabely), new Vector2f(screenHelper.calcX(500), screenHelper.calcY(40))); lblShootingStars.setFontSize(labelFontSize); lblShootingStars.setText("Shooting Stars"); - Button btnStart = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, 40)) { + Button btnStart = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, screenHelper.calcY(40))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.selectFile(); } }; btnStart.setText("Start Game"); + btnStart.setFontSize(buttonFontSize); - Button btnHighscore = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, 40)) { + Button btnHighscore = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, screenHelper.calcY(40))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.openhighscore(); } }; btnHighscore.setText("Highscore"); + btnHighscore.setFontSize(buttonFontSize); - Button btnOptions = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, 40)) { + Button btnOptions = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.openOptions(); } }; btnOptions.setText("Options"); + btnOptions.setFontSize(buttonFontSize); - Button btnExit = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, 40)) { + Button btnExit = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, screenHelper.calcY(40))) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.exitGame(); } }; btnExit.setText("Exit Game"); + btnExit.setFontSize(buttonFontSize); this.addChild(btnStart); this.addChild(btnHighscore); diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java index 614c45e..aa8efbe 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/OptionsGUI.java @@ -21,6 +21,7 @@ import com.jme3.math.Vector2f; import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.listener.OptionsListener; import org.wyrez.shootingstars.helper.DisplayHelper; +import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.states.util.OptionSettings; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.buttons.CheckBox; @@ -40,6 +41,8 @@ public class OptionsGUI extends Panel implements Gui { private OptionsListener listener; private OptionSettings settings; + private ScreenHelper screenHelper; + //General Controls private TextField txtPlayerName; @@ -56,10 +59,11 @@ public class OptionsGUI extends Panel implements Gui { private Slider sldFXVolume; private Slider sldSoundVolume; - public OptionsGUI(Screen screen, OptionsListener listener, OptionSettings settings) { + public OptionsGUI(Screen screen, OptionsListener listener, OptionSettings settings, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; this.settings = settings; + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); @@ -75,12 +79,15 @@ public class OptionsGUI extends Panel implements Gui { } private void create() { - float tabControlStartPointx = 32f; - float tabControlStartPointy = 18f; - float witdhTabControl = 1216f; - float heightTabControl = 612f; + float tabControlStartPointx = screenHelper.calcX(32f); + float tabControlStartPointy = screenHelper.calcY(18f); + float witdhTabControl = screenHelper.calcX(1216f); + float heightTabControl = screenHelper.calcY(612f); - float buttonWidth = 153.6f; + float buttonWidth = screenHelper.calcX(153.6f); + float buttonHeight = screenHelper.calcY(40f); + + float labelFontSize = screenHelper.calcX(20f); TabControl tcOptions = new TabControl(screen, "tcOptions", new Vector2f(tabControlStartPointx, tabControlStartPointy), new Vector2f(witdhTabControl, heightTabControl)); tcOptions.setUseSlideEffect(true); @@ -88,13 +95,13 @@ public class OptionsGUI extends Panel implements Gui { tcOptions.addTab("Video"); tcOptions.addTab("Audio"); - createGeneralTab(tcOptions); - createVideoTab(tcOptions); - createAudioTab(tcOptions); + createGeneralTab(tcOptions,labelFontSize); + createVideoTab(tcOptions,labelFontSize); + createAudioTab(tcOptions,labelFontSize); - float differnceTabControlButtons = 622.8f; + float differnceTabControlButtons = screenHelper.calcY(622.8f); - Button btnSave = new ButtonBase(screen, new Vector2f(tabControlStartPointx + 877f, tabControlStartPointy + differnceTabControlButtons), new Vector2f(buttonWidth, 40)) { + Button btnSave = new ButtonBase(screen, new Vector2f(tabControlStartPointx + screenHelper.calcX(877f), tabControlStartPointy + differnceTabControlButtons), new Vector2f(buttonWidth, buttonHeight)) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { saveControlValues(); @@ -102,146 +109,181 @@ public class OptionsGUI extends Panel implements Gui { } }; btnSave.setText("Save"); + btnSave.setFontSize(labelFontSize); - Button btnCancel = new ButtonBase(screen, new Vector2f(tabControlStartPointx + 1060f, tabControlStartPointy + differnceTabControlButtons), new Vector2f(buttonWidth, 40)) { + Button btnCancel = new ButtonBase(screen, new Vector2f(tabControlStartPointx + screenHelper.calcX(1060f), tabControlStartPointy + differnceTabControlButtons), new Vector2f(buttonWidth, buttonHeight)) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.cancel(); } }; btnCancel.setText("Cancel"); + btnCancel.setFontSize(labelFontSize); this.addChild(tcOptions); this.addChild(btnSave); this.addChild(btnCancel); } - private void createGeneralTab(TabControl tcOptions) { - float startPointx = 64f; - float startPointy = 36f; - float marginLeftControls = 115.8f; + private void createGeneralTab(TabControl tcOptions, float labelFontSize) { + float startPointx = screenHelper.calcX(64f); + float startPointy = screenHelper.calcY(36f); + float marginLeftControls = screenHelper.calcX(115.8f); - Label lblPlayerName = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(120f, 40f)); + Label lblPlayerName = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(screenHelper.calcX(120f), screenHelper.calcY(40f))); lblPlayerName.setText("PlayerName"); + lblPlayerName.setFontSize(labelFontSize); - txtPlayerName = new TextField(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 7f), new Vector2f(200f, 30f)); + txtPlayerName = new TextField(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(7f)), new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f))); + txtPlayerName.setFontSize(labelFontSize); tcOptions.addTabChild(0, lblPlayerName); tcOptions.addTabChild(0, txtPlayerName); } - private void createVideoTab(TabControl tcOptions) { + private void createVideoTab(TabControl tcOptions, float labelFontSize) { - float startPointx = 64f; - float startPointy = 36f; - float marginLeftControls = 115.8f; + float startPointx = screenHelper.calcX(64f); + float startPointy = screenHelper.calcY(36f); + float marginLeftControls = screenHelper.calcX(115.8f); + float labelWitdh = screenHelper.calcX(120f); + float labelHeight = screenHelper.calcY(40f); + + float comboBoxWidth = screenHelper.calcX(200f); + float comboBoxHeight = screenHelper.calcY(30f); + + float checkBoxWitdh = screenHelper.calcX(20f); + float checkBoxHeight = screenHelper.calcX(20f); + + float sliderWitdh = screenHelper.calcX(200f); + float sliderHeight = screenHelper.calcY(30f); - Label lblResolution = new Label(screen, "lblResolution", new Vector2f(startPointx, startPointy), new Vector2f(100f, 40f)); + Label lblResolution = new Label(screen, "lblResolution", new Vector2f(startPointx, startPointy), new Vector2f(labelWitdh, labelHeight)); lblResolution.setText("Resolution"); + lblResolution.setFontSize(labelFontSize); - cboResolution = new ComboBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 7f), new Vector2f(200f, 30f)) { + cboResolution = new ComboBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(7f)), new Vector2f(comboBoxWidth, comboBoxHeight)) { @Override public void onChange(int selectedIndex, Object value) { } }; + cboResolution.setFontSize(labelFontSize); for (String s : DisplayHelper.getResolutions()) { cboResolution.addListItem(s, s); } - Label lblFrequency = new Label(screen, "lblFrequency", new Vector2f(startPointx, startPointy + 40f), new Vector2f(100f, 40f)); + Label lblFrequency = new Label(screen, "lblFrequency", new Vector2f(startPointx, startPointy + screenHelper.calcY(40f)), new Vector2f(labelWitdh, labelHeight)); lblFrequency.setText("Frequency"); + lblFrequency.setFontSize(labelFontSize); - cboFrequency = new ComboBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 47f), new Vector2f(200f, 30f)) { + cboFrequency = new ComboBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(47f)), new Vector2f(comboBoxWidth, comboBoxHeight)) { @Override public void onChange(int selectedIndex, Object value) { } }; + cboFrequency.setFontSize(labelFontSize); for (String s : DisplayHelper.getFrequencys()) { cboFrequency.addListItem(s, s); } - Label lblDepthBits = new Label(screen, "lblDepthBits", new Vector2f(startPointx, startPointy + 80f), new Vector2f(100f, 40f)); + Label lblDepthBits = new Label(screen, "lblDepthBits", new Vector2f(startPointx, startPointy + screenHelper.calcY(80f)), new Vector2f(labelWitdh, labelHeight)); lblDepthBits.setText("DepthBits"); + lblDepthBits.setFontSize(labelFontSize); - cboDepthBits = new ComboBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 87f), new Vector2f(200f, 30f)) { + cboDepthBits = new ComboBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(87f)), new Vector2f(comboBoxWidth, comboBoxHeight)) { @Override public void onChange(int selectedIndex, Object value) { } }; + cboDepthBits.setFontSize(labelFontSize); for (String s : DisplayHelper.getDepthBits()) { cboDepthBits.addListItem(s, s); } - Label lblFullscreen = new Label(screen, "lblFullscreen", new Vector2f(startPointx, startPointy + 120f), new Vector2f(100f, 40f)); + Label lblFullscreen = new Label(screen, "lblFullscreen", new Vector2f(startPointx, startPointy + screenHelper.calcY(120f)), new Vector2f(labelWitdh, labelHeight)); lblFullscreen.setText("Fullscreen"); + lblFullscreen.setFontSize(labelFontSize); - chkFullscreen = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 132f), new Vector2f(20f, 20f)); + chkFullscreen = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(132f)), new Vector2f(checkBoxWitdh, checkBoxHeight)); - Label lblVSync = new Label(screen, "lblVSync", new Vector2f(startPointx, startPointy + 160f), new Vector2f(100f, 40f)); + Label lblVSync = new Label(screen, "lblVSync", new Vector2f(startPointx, startPointy + screenHelper.calcY(160f)), new Vector2f(labelWitdh, labelHeight)); lblVSync.setText("VSync"); + lblVSync.setFontSize(labelFontSize); - chkVSync = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 172f), new Vector2f(20f, 20f)); + chkVSync = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(172f)), new Vector2f(checkBoxWitdh, checkBoxHeight)); - Label lblPostProcessing = new Label(screen, "lblPostProcessing", new Vector2f(startPointx, startPointy + 200f), new Vector2f(120f, 40f)); + Label lblPostProcessing = new Label(screen, "lblPostProcessing", new Vector2f(startPointx, startPointy + screenHelper.calcY(200f)), new Vector2f(labelWitdh, labelHeight)); lblPostProcessing.setText("PostProcessing"); + lblPostProcessing.setFontSize(labelFontSize); - chkPostProcessing = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 212f), new Vector2f(20f, 20f)); + chkPostProcessing = new CheckBox(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(212f)), new Vector2f(checkBoxWitdh, checkBoxHeight)); - Label lblParticleDensity = new Label(screen, "lblParticleDensity", new Vector2f(startPointx, startPointy + 240f), new Vector2f(120f, 40f)); + Label lblParticleDensity = new Label(screen, "lblParticleDensity", new Vector2f(startPointx, startPointy +screenHelper.calcY(240f)), new Vector2f(labelWitdh, labelHeight)); lblParticleDensity.setText("ParticleDensity"); + lblParticleDensity.setFontSize(labelFontSize); - sldParticleDensity = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 247f), new Vector2f(200f, 30f), Slider.Orientation.HORIZONTAL, false) { + sldParticleDensity = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(247f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) { @Override public void onChange(int selectedIndex, Object value) { } }; sldParticleDensity.setStepIntegerRange(0, 3, 1); - tcOptions.addTabChild(1, lblResolution); - tcOptions.addTabChild(1, cboResolution); - tcOptions.addTabChild(1, lblFrequency); - tcOptions.addTabChild(1, cboFrequency); - tcOptions.addTabChild(1, lblDepthBits); - tcOptions.addTabChild(1, cboDepthBits); - tcOptions.addTabChild(1, lblFullscreen); - tcOptions.addTabChild(1, chkFullscreen); + tcOptions.addTabChild(1, lblVSync); tcOptions.addTabChild(1, chkVSync); + tcOptions.addTabChild(1, lblFullscreen); + tcOptions.addTabChild(1, chkFullscreen); + tcOptions.addTabChild(1, lblDepthBits); + tcOptions.addTabChild(1, cboDepthBits); + tcOptions.addTabChild(1, lblFrequency); + tcOptions.addTabChild(1, cboFrequency); + tcOptions.addTabChild(1, lblResolution); + tcOptions.addTabChild(1, cboResolution); tcOptions.addTabChild(1, lblPostProcessing); tcOptions.addTabChild(1, chkPostProcessing); tcOptions.addTabChild(1, lblParticleDensity); tcOptions.addTabChild(1, sldParticleDensity); } - private void createAudioTab(TabControl tcOptions) { - float startPointx = 64f; - float startPointy = 36f; - float marginLeftControls = 115.8f; + private void createAudioTab(TabControl tcOptions, float labelFontSize) { + float startPointx = screenHelper.calcX(64f); + float startPointy = screenHelper.calcY(36f); + float marginLeftControls = screenHelper.calcX(115.8f); + + float labelWitdh = screenHelper.calcX(120f); + float labelHeight = screenHelper.calcY(40f); + + float sliderWitdh = screenHelper.calcX(200f); + float sliderHeight = screenHelper.calcY(30f); - Label lblMasterVolume = new Label(screen, "lblMasterVolume", new Vector2f(startPointx, startPointy), new Vector2f(120f, 40f)); + Label lblMasterVolume = new Label(screen, "lblMasterVolume", new Vector2f(startPointx, startPointy), new Vector2f(labelWitdh, labelHeight)); lblMasterVolume.setText("MasterVolume"); + lblMasterVolume.setFontSize(labelFontSize); - sldMasterVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 7f), new Vector2f(200f, 30f), Slider.Orientation.HORIZONTAL, false) { + sldMasterVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(7f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) { @Override public void onChange(int selectedIndex, Object value) { } }; sldMasterVolume.setStepIntegerRange(0, 100, 1); - Label lblFXVolume = new Label(screen, "lblFXVolume", new Vector2f(startPointx, startPointy + 40f), new Vector2f(100f, 40f)); + Label lblFXVolume = new Label(screen, "lblFXVolume", new Vector2f(startPointx, startPointy + screenHelper.calcY(40f)), new Vector2f(labelWitdh, labelHeight)); lblFXVolume.setText("FXVolume"); + lblFXVolume.setFontSize(labelFontSize); - sldFXVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 47f), new Vector2f(200f, 30f), Slider.Orientation.HORIZONTAL, false) { + sldFXVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(47f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) { @Override public void onChange(int selectedIndex, Object value) { } }; sldFXVolume.setStepIntegerRange(0, 100, 1); - Label lblSoundVolume = new Label(screen, "lblSoundVolume", new Vector2f(startPointx, startPointy + 80f), new Vector2f(120f, 40f)); + Label lblSoundVolume = new Label(screen, "lblSoundVolume", new Vector2f(startPointx, startPointy + screenHelper.calcY(80f)), new Vector2f(labelWitdh, labelHeight)); lblSoundVolume.setText("SoundVolume"); + lblSoundVolume.setFontSize(labelFontSize); - sldSoundVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + 87f), new Vector2f(200f, 30f), Slider.Orientation.HORIZONTAL, false) { + sldSoundVolume = new Slider(screen, new Vector2f(startPointx + marginLeftControls, startPointy + screenHelper.calcY(87f)), new Vector2f(sliderWitdh, sliderHeight), Slider.Orientation.HORIZONTAL, false) { @Override public void onChange(int selectedIndex, Object value) { } diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/SelectTrackGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/SelectTrackGUI.java index 12c2ee3..7b0aead 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/SelectTrackGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/SelectTrackGUI.java @@ -20,6 +20,7 @@ import com.jme3.input.event.MouseButtonEvent; import com.jme3.math.Vector2f; import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.listener.SelectFileListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.windows.Panel; @@ -31,52 +32,61 @@ import tonegod.gui.core.Screen; */ public class SelectTrackGUI extends Panel implements Gui{ - SelectFileListener listener; + private SelectFileListener listener; + private ScreenHelper screenHelper; - public SelectTrackGUI(Screen screen, SelectFileListener listener) { + public SelectTrackGUI(Screen screen, SelectFileListener listener, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); } private void create() { - float startPointx = 576f; - float startPointy = 260f; - float labelFontSize = 76f; - float buttonWidth = 153f; - float marginLabelOrLeft = 45f; - float marginLabelOrTop = 43f; - float marginButtonYTDownloadTop = 129f; + float startPointx = screenHelper.calcX(576f); + float startPointy = screenHelper.calcY(260f); + float labelFontSize = screenHelper.calcX(76f); + float buttonWidth = screenHelper.calcX(153f); + float marginLabelOrLeft = screenHelper.calcX(45f); + float marginLabelOrTop = screenHelper.calcY(43f); + float marginButtonYTDownloadTop = screenHelper.calcY(129f); + float buttonHeight = screenHelper.calcY(40f); + float labelWitdh = screenHelper.calcX(100f); + float labelHeight = screenHelper.calcY(40f); + float buttonFontSize = screenHelper.calcX(20f); - Button btnSelectFile = new ButtonBase(screen, new Vector2f(startPointx, startPointy), new Vector2f(buttonWidth, 40)) { + Button btnSelectFile = new ButtonBase(screen, new Vector2f(startPointx, startPointy), new Vector2f(buttonWidth, buttonHeight)) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.selectFile(); } }; btnSelectFile.setText("Select File"); + btnSelectFile.setFontSize(buttonFontSize); - Label lblOr = new Label(screen, new Vector2f(startPointx + marginLabelOrLeft, startPointy + marginLabelOrTop), new Vector2f(100, 40)); + Label lblOr = new Label(screen, new Vector2f(startPointx + marginLabelOrLeft, startPointy + marginLabelOrTop), new Vector2f(labelWitdh, labelHeight)); lblOr.setFontSize(labelFontSize); lblOr.setText("Or"); - Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop), new Vector2f(buttonWidth, 40)) { + Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop), new Vector2f(buttonWidth, buttonHeight)) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.downloadYT(); } }; btnYTDownload.setText("YT Download"); + btnYTDownload.setFontSize(buttonFontSize); - Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop + 114f), new Vector2f(buttonWidth, 40)) { + Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx, startPointy + marginButtonYTDownloadTop + screenHelper.calcY(114f)), new Vector2f(buttonWidth, buttonHeight)) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.cancel(); } }; btnCancel.setText("Cancel"); + btnCancel.setFontSize(buttonFontSize); this.addChild(btnSelectFile); this.addChild(lblOr); diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/YTDownloadGUI.java b/ShootingStars/src/org/wyrez/shootingstars/gui/YTDownloadGUI.java index a47ff40..5af5340 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/YTDownloadGUI.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/YTDownloadGUI.java @@ -20,6 +20,7 @@ import com.jme3.input.event.MouseButtonEvent; import com.jme3.math.Vector2f; import org.wyrez.shootingstars.gui.controls.ButtonBase; import org.wyrez.shootingstars.gui.listener.YTDownloadListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.controls.buttons.Button; import tonegod.gui.controls.text.Label; import tonegod.gui.controls.text.TextField; @@ -33,45 +34,66 @@ import tonegod.gui.core.Screen; public class YTDownloadGUI extends Panel implements Gui{ private YTDownloadListener listener; + private ScreenHelper screenHelper; - public YTDownloadGUI(Screen screen, YTDownloadListener listener) { + public YTDownloadGUI(Screen screen, YTDownloadListener listener, ScreenHelper screenHelper) { super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd this.listener = listener; + this.screenHelper = screenHelper; this.setIgnoreMouse(true); this.setIsVisible(false); create(); } private void create() { - float startPointx = 384f;//screen.getWidth() * 0.3f; - float startPointy = 324f;//screen.getHeight() * 0.45f; - float labelFontSize = 51.2f;//screen.getWidth() * 0.04f; - float buttonWidth = 153f;//screen.getWidth() * 0.12f; - float textFieldWitdh = 409f;//screen.getWidth() * 0.32f; - float marginTextFieldLeft = 153f; - float marginTextFieldTop = 8.64f; - float marginYTButtonLeft = 409f; - float marginYTButtonTop = 72f; + float startPointx = screenHelper.calcX(384f); + float startPointy = screenHelper.calcY(324f); + float labelFontSize = screenHelper.calcX(51.2f); + float buttonWidth = screenHelper.calcX(153f); + float textFieldWitdh = screenHelper.calcX(409f); + float marginTextFieldLeft = screenHelper.calcX(153f); + float marginTextFieldTop = screenHelper.calcY(8.64f); + float marginYTButtonLeft = screenHelper.calcX(250f); + float marginCancelButtonLeft = screenHelper.calcX(409f); + float marginYTButtonTop = screenHelper.calcY(72f); + float labelWitdh = screenHelper.calcX(160f); + float labelHeight = screenHelper.calcY(40f); + + float buttonFontSize = screenHelper.calcX(20f); + float buttonHeight = screenHelper.calcY(40f); + float textFieldHeight = screenHelper.calcY(40f); - Label lblYTLink = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(160, 40)); + Label lblYTLink = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(labelWitdh, labelHeight)); lblYTLink.setFontSize(labelFontSize); lblYTLink.setText("YT Link"); - final TextField txtYTLink = new TextField(screen,"txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, 40)); + final TextField txtYTLink = new TextField(screen,"txtYTLink", new Vector2f(startPointx + marginTextFieldLeft, startPointy + marginTextFieldTop), new Vector2f(textFieldWitdh, textFieldHeight)); txtYTLink.setType(TextField.Type.DEFAULT); + txtYTLink.setFontSize(buttonFontSize); - Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx + marginYTButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, 40)) { + Button btnYTDownload = new ButtonBase(screen, new Vector2f(startPointx + marginYTButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) { @Override public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { listener.downloadYTVideo(txtYTLink.getText()); } }; btnYTDownload.setText("Download"); + btnYTDownload.setFontSize(buttonFontSize); + + Button btnCancel = new ButtonBase(screen, new Vector2f(startPointx + marginCancelButtonLeft, startPointy + marginYTButtonTop), new Vector2f(buttonWidth, buttonHeight)) { + @Override + public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) { + listener.cancel(); + } + }; + btnCancel.setText("Cancel"); + btnCancel.setFontSize(buttonFontSize); this.addChild(lblYTLink); this.addChild(txtYTLink); this.addChild(btnYTDownload); + this.addChild(btnCancel); } public void attach() { diff --git a/ShootingStars/src/org/wyrez/shootingstars/gui/listener/YTDownloadListener.java b/ShootingStars/src/org/wyrez/shootingstars/gui/listener/YTDownloadListener.java index a50ceb9..d2c3dbb 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/gui/listener/YTDownloadListener.java +++ b/ShootingStars/src/org/wyrez/shootingstars/gui/listener/YTDownloadListener.java @@ -23,4 +23,6 @@ package org.wyrez.shootingstars.gui.listener; public interface YTDownloadListener { public void downloadYTVideo(String url); + + public void cancel(); } diff --git a/ShootingStars/src/org/wyrez/shootingstars/helper/ScreenHelper.java b/ShootingStars/src/org/wyrez/shootingstars/helper/ScreenHelper.java new file mode 100644 index 0000000..d63f7eb --- /dev/null +++ b/ShootingStars/src/org/wyrez/shootingstars/helper/ScreenHelper.java @@ -0,0 +1,27 @@ +package org.wyrez.shootingstars.helper; + +import tonegod.gui.core.Screen; + +/** + * + * @author Snowsun + */ +public class ScreenHelper { + + private static final float X = 1280; + private static final float Y = 720; + private Screen screen; + + + public ScreenHelper(Screen screen) { + this.screen = screen; + } + + public float calcX(float value) { + return screen.getWidth() * ((100/X) * value) / 100; + } + + public float calcY(float value) { + return screen.getHeight() * ((100/Y) * value) / 100; + } +} diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/FileMetaInfoState.java b/ShootingStars/src/org/wyrez/shootingstars/states/FileMetaInfoState.java index 1c866d1..a122e37 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/FileMetaInfoState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/FileMetaInfoState.java @@ -22,6 +22,7 @@ import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.FileMetaInfoGUI; import org.wyrez.shootingstars.gui.Gui; import org.wyrez.shootingstars.gui.listener.FileMetaInfoListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.core.Screen; /** @@ -34,10 +35,10 @@ public class FileMetaInfoState extends AbstractAppState implements FileMetaInfoL private GameSettings settings; private Gui gui; - public FileMetaInfoState(Screen screen, StateManager stateManager, GameSettings settings) { + public FileMetaInfoState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) { this.stateManager = stateManager; this.settings = settings; - this.gui = new FileMetaInfoGUI(screen, this, settings); + this.gui = new FileMetaInfoGUI(screen, this, settings, screenHelper); } public void startLoading() { diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java index 98c6fec..55efb68 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/GameState.java @@ -42,6 +42,7 @@ import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.game.Ground; import org.wyrez.shootingstars.gui.GameGUI; import org.wyrez.shootingstars.gui.listener.GameListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.helper.UserDataKeys; import tonegod.gui.core.Screen; import uk.co.caprica.vlcj.player.MediaPlayerFactory; @@ -71,10 +72,10 @@ public class GameState extends AbstractAppState implements GameListener, ActionL public GameState(Node rootNode, Screen screen, StateManager stateManager, AssetManager assetManager, ViewPort viewPort, - InputManager inputManager, Camera camera, AudioDataManager audioDataManager, GameSettings settings) { + InputManager inputManager, Camera camera, AudioDataManager audioDataManager, GameSettings settings, ScreenHelper screenHelper) { this.rootNode = rootNode; - this.gui = new GameGUI(screen, this, assetManager); + this.gui = new GameGUI(screen, this, assetManager,screenHelper); this.stateManager = stateManager; inputManager.addListener(this, new String[]{"ESC"}); diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/HighscoreState.java b/ShootingStars/src/org/wyrez/shootingstars/states/HighscoreState.java index 6fd48fe..c83e969 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/HighscoreState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/HighscoreState.java @@ -22,6 +22,7 @@ import org.wyrez.shootingstars.gui.Gui; import org.wyrez.shootingstars.gui.HighscoreGUI; import org.wyrez.shootingstars.gui.listener.HighscoreListener; import org.wyrez.shootingstars.gui.manager.HighscoreManager; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.core.Screen; /** @@ -34,10 +35,10 @@ public class HighscoreState extends AbstractAppState implements HighscoreListene private HighscoreManager highscoreManager; private Gui gui; - public HighscoreState(Screen screen, StateManager stateManager, HighscoreManager highscoreManager) { + public HighscoreState(Screen screen, StateManager stateManager, HighscoreManager highscoreManager, ScreenHelper screenHelper) { this.stateManager = stateManager; this.highscoreManager = highscoreManager; - this.gui = new HighscoreGUI(screen, this, highscoreManager); + this.gui = new HighscoreGUI(screen, this, highscoreManager,screenHelper); } public void back() { diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java index 4d79c4d..703fcec 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/LoadingState.java @@ -25,6 +25,7 @@ import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.LoadingGui; import org.wyrez.shootingstars.helper.ChecksumHelper; import org.wyrez.shootingstars.helper.PathHelper; +import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.states.util.LoadingProgress; import tonegod.gui.core.Screen; @@ -41,9 +42,9 @@ public class LoadingState extends AbstractAppState { private GameSettings settings; public LoadingState(Screen screen, StateManager stateManager, - AudioDataManager audioDataManager, GameSettings settings) { + AudioDataManager audioDataManager, GameSettings settings, ScreenHelper screenHelper) { this.stateManager = stateManager; - this.gui = new LoadingGui(screen); + this.gui = new LoadingGui(screen,screenHelper); this.audioDataManager = audioDataManager; this.settings = settings; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java b/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java index 60d9f6c..7c1a7b9 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/MenuState.java @@ -23,6 +23,7 @@ import org.wyrez.shootingstars.ShootingStars; import org.wyrez.shootingstars.gui.Gui; import org.wyrez.shootingstars.gui.MenuGUI; import org.wyrez.shootingstars.gui.listener.MenuListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.core.Screen; /** @@ -35,9 +36,9 @@ public class MenuState extends AbstractAppState implements MenuListener { private Gui gui; private ShootingStars shootingStars; - public MenuState(Screen screen, StateManager stateManager, ShootingStars shootingStars) { + public MenuState(Screen screen, StateManager stateManager, ShootingStars shootingStars, ScreenHelper screenHelper) { this.stateManager = stateManager; - this.gui = new MenuGUI(screen, this); + this.gui = new MenuGUI(screen, this, screenHelper); this.shootingStars = shootingStars; } diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/OptionsState.java b/ShootingStars/src/org/wyrez/shootingstars/states/OptionsState.java index d5d0b36..219e0ac 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/OptionsState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/OptionsState.java @@ -20,6 +20,7 @@ import com.jme3.app.state.AbstractAppState; import com.jme3.app.state.AppStateManager; import org.wyrez.shootingstars.gui.OptionsGUI; import org.wyrez.shootingstars.gui.listener.OptionsListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import org.wyrez.shootingstars.states.util.OptionSettings; import tonegod.gui.core.Screen; @@ -33,10 +34,10 @@ public class OptionsState extends AbstractAppState implements OptionsListener { private OptionsGUI gui; private OptionSettings settings; - public OptionsState(Screen screen, StateManager stateManager, OptionSettings settings) { + public OptionsState(Screen screen, StateManager stateManager, OptionSettings settings, ScreenHelper screenHelper) { this.stateManager = stateManager; this.settings = settings; - this.gui = new OptionsGUI(screen, this,settings); + this.gui = new OptionsGUI(screen, this,settings, screenHelper); } @Override diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java b/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java index 5869b04..1849dda 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/SelectTrackState.java @@ -23,6 +23,7 @@ import javax.swing.JFileChooser; import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.SelectTrackGUI; import org.wyrez.shootingstars.gui.listener.SelectFileListener; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.core.Screen; /** @@ -35,10 +36,10 @@ public class SelectTrackState extends AbstractAppState implements SelectFileList private GameSettings settings; private SelectTrackGUI gui; - public SelectTrackState(Screen screen, StateManager stateManager, GameSettings settings) { + public SelectTrackState(Screen screen, StateManager stateManager, GameSettings settings, ScreenHelper screenHelper) { this.stateManager = stateManager; this.settings = settings; - this.gui = new SelectTrackGUI(screen, this); + this.gui = new SelectTrackGUI(screen, this,screenHelper); } @Override diff --git a/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java b/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java index a609dc1..9a38f3d 100644 --- a/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java +++ b/ShootingStars/src/org/wyrez/shootingstars/states/YTDownloadState.java @@ -26,6 +26,7 @@ import org.wyrez.shootingstars.game.GameSettings; import org.wyrez.shootingstars.gui.YTDownloadGUI; import org.wyrez.shootingstars.gui.listener.YTDownloadListener; import org.wyrez.shootingstars.helper.PathHelper; +import org.wyrez.shootingstars.helper.ScreenHelper; import tonegod.gui.core.Screen; /** @@ -42,10 +43,10 @@ public class YTDownloadState extends AbstractAppState implements YTDownloadListe private YTDownloader downloader; public YTDownloadState(Screen screen, StateManager stateManager, - GameSettings settings, YTDownloader downloader) { + GameSettings settings, YTDownloader downloader, ScreenHelper screenHelper) { this.stateManager = stateManager; this.settings = settings; - this.gui = new YTDownloadGUI(screen, this); + this.gui = new YTDownloadGUI(screen, this,screenHelper); this.downloader = downloader; } @@ -94,4 +95,8 @@ public class YTDownloadState extends AbstractAppState implements YTDownloadListe } return null; } + + public void cancel() { + stateManager.setState(State.MENU); + } }