diff options
| author | ilotterytea <iltsu@alright.party> | 2024-05-29 19:08:37 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-05-29 19:08:37 +0500 |
| commit | ab2e0e35b3f6619cc8c5fa6e7b30d34e396cb1a9 (patch) | |
| tree | f9c07fced27ffeaab396c185c8bde8f61b870f8e /core | |
| parent | 421d0f0a8472b3330b5ec4042d0511c423f7f8de (diff) | |
upd: menu layout
Diffstat (limited to 'core')
4 files changed, 302 insertions, 574 deletions
diff --git a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java index 3c9245e..ec152cb 100644 --- a/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java +++ b/core/src/com/ilotterytea/maxoning/screens/MenuScreen.java @@ -5,79 +5,45 @@ import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.graphics.*; import com.badlogic.gdx.graphics.g2d.TextureAtlas; -import com.badlogic.gdx.graphics.g2d.TextureRegion; import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction; import com.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Image; -import com.badlogic.gdx.scenes.scene2d.ui.Label; -import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; -import com.badlogic.gdx.utils.viewport.FillViewport; +import com.badlogic.gdx.utils.viewport.ScreenViewport; import com.ilotterytea.maxoning.MaxonConstants; import com.ilotterytea.maxoning.MaxonGame; -import com.ilotterytea.maxoning.anim.SpriteUtils; import com.ilotterytea.maxoning.player.MaxonSavegame; -import com.ilotterytea.maxoning.player.utils.PetUtils; import com.ilotterytea.maxoning.ui.*; import com.ilotterytea.maxoning.utils.I18N; import com.ilotterytea.maxoning.utils.serialization.GameDataSystem; -import java.awt.*; import java.util.ArrayList; -import java.util.Locale; public class MenuScreen implements Screen { + private final MaxonGame game; - final MaxonGame game; - - final Stage stage; - final Skin skin; - TextureAtlas brandAtlas, mainAtlas; - - Image brandLogo; - - final Music menuMusic; - - Table menuTable; - - TextButton startBtn; - ImageButton rArrowBtn, lArrowBtn; - Label savLabel; - final DebugInfo debugInfo; - + private final Stage stage; + private final Music menuMusic; MaxonSavegame sav; - ArrayList<SavegameInfo> savInfos; - ArrayList<Image> savImgs; - - int curSav; - SavegameInfo curSavInfo; - Image curSavImg; - - boolean inOptions = false; - - private final MovingChessBackground bg; - public MenuScreen(final MaxonGame game) { this.game = game; - savInfos = new ArrayList<>(); - savImgs = new ArrayList<>(); - curSav = -1; - // Stage and skin: - this.stage = new Stage(new FillViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight())); + this.stage = new Stage(new ScreenViewport()); this.stage.addAction(Actions.sequence(Actions.alpha(0.0f), Actions.alpha(1.0f, 1f))); - this.skin = game.assetManager.get("MainSpritesheet.skin", Skin.class); - brandAtlas = game.assetManager.get("sprites/gui/brand.atlas", TextureAtlas.class); - mainAtlas = game.assetManager.get("MainSpritesheet.atlas", TextureAtlas.class); + Skin skin = game.assetManager.get("MainSpritesheet.skin", Skin.class); + Skin widgetSkin = game.assetManager.get("sprites/gui/widgets.skin", Skin.class); + TextureAtlas brandAtlas = game.assetManager.get("sprites/gui/brand.atlas", TextureAtlas.class); + TextureAtlas widgetAtlas = game.assetManager.get("sprites/gui/widgets.atlas", TextureAtlas.class); sav = GameDataSystem.load("00.maxon"); @@ -85,53 +51,21 @@ public class MenuScreen implements Screen { this.menuMusic = game.assetManager.get("mus/menu/mus_menu_loop.ogg", Music.class); menuMusic.setLooping(true); - // // Menu table: - float iconSize = 64f, iconPad = 6f; - menuTable = new Table(); - menuTable.setSize(stage.getWidth() / 2f, iconSize); - menuTable.setPosition(0, 0); - menuTable.pad(iconPad); - menuTable.align(Align.bottomLeft); - - // Quit button: - ImageButton quitBtn = new ImageButton(skin, "quit"); + // - - - - - - U I - - - - - - + Table menuTable = new Table(); + menuTable.setFillParent(true); - quitBtn.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - Gdx.app.exit(); - } - }); - - menuTable.add(quitBtn).size(iconSize).pad(iconPad); - - // Options button: - ImageButton optBtn = new ImageButton(skin, "options"); - - optBtn.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - showOptions(); - } - }); + // - - - Brand - - - + Table brandTable = new Table(); - menuTable.add(optBtn).size(iconSize).pad(iconPad); + Image logo = new Image(brandAtlas.findRegion("brand")); - stage.addActor(menuTable); - - // // Logo: - brandLogo = new Image(brandAtlas.findRegion("brand")); - brandLogo.setPosition( - (stage.getWidth() / 2f) - (brandLogo.getWidth() / 2f), - stage.getHeight() - brandLogo.getHeight() * 1.2f - ); - - brandLogo.setOrigin( - brandLogo.getWidth() / 2f, - brandLogo.getHeight() / 2f + logo.setOrigin( + logo.getWidth() / 2f, + logo.getHeight() / 2f ); - brandLogo.addAction( + logo.addAction( Actions.repeat( RepeatAction.FOREVER, Actions.sequence( @@ -147,277 +81,43 @@ public class MenuScreen implements Screen { ) ); - stage.addActor(brandLogo); - - // Debug info: - debugInfo = new DebugInfo(skin, game.locale); - debugInfo.setPosition(4, (stage.getHeight() / 2f) + 128f); - if (game.prefs.getBoolean("debug")) stage.addActor(debugInfo); - - Gdx.input.setInputProcessor(new InputMultiplexer(stage)); - - // Generate background tiles: - this.bg = new MovingChessBackground( - 1, - 1, - stage.getWidth(), - stage.getHeight(), - skin.getDrawable("tile_01"), - skin.getDrawable("tile_02") - ); - - generateSaves(); - - updateCurrentVisualSavegame(false); - - // Save control buttons: - rArrowBtn = new ImageButton(skin, "right_arrow"); - rArrowBtn.setPosition( - stage.getWidth() - (rArrowBtn.getWidth() * 2), - (stage.getHeight() / 2f) - (rArrowBtn.getHeight() / 2f) - ); - rArrowBtn.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - if (!inOptions) updateCurrentVisualSavegame(false); - } - }); - - stage.addActor(rArrowBtn); - - - // Save control buttons: - lArrowBtn = new ImageButton(skin, "left_arrow"); - lArrowBtn.setPosition( - lArrowBtn.getWidth(), - (stage.getHeight() / 2f) - (lArrowBtn.getHeight() / 2f) - ); - lArrowBtn.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - if (!inOptions) updateCurrentVisualSavegame(true); - } - }); - - stage.addActor(lArrowBtn); - } - - @Override public void show() { - if (game.prefs.getBoolean("music", true)) menuMusic.play(); - - // Start to render: - render(Gdx.graphics.getDeltaTime()); - } - - @Override - public void render(float delta) { - Gdx.gl.glClearColor(1, 1, 1, 1f); - Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - - game.batch.begin(); - - bg.draw(game.batch); - - game.batch.end(); - - stage.act(delta); - stage.draw(); - } - - @Override - public void resize(int width, int height) { - bg.update(width, height); - - stage.getViewport().update(width, height, true); - } - - private void showOptions() { - inOptions = !inOptions; - - lArrowBtn.addAction(Actions.moveTo(-lArrowBtn.getWidth(), lArrowBtn.getY(), 1f, Interpolation.smoother)); - rArrowBtn.addAction(Actions.moveTo(stage.getWidth(), rArrowBtn.getY(), 1f, Interpolation.smoother)); - curSavInfo.addAction(Actions.moveTo(curSavInfo.getX(), -curSavInfo.getHeight(), 1f, Interpolation.smoother)); - curSavImg.addAction(Actions.moveTo(curSavImg.getX(), -curSavImg.getHeight(), 2f, Interpolation.smoother)); - menuTable.addAction(Actions.moveTo(menuTable.getX(), -menuTable.getY() - menuTable.getHeight() - 48f, 1f, Interpolation.smoother)); - - brandLogo.clearActions(); - brandLogo.addAction(Actions.moveTo(brandLogo.getX(), stage.getHeight() + brandLogo.getHeight(), 1f, Interpolation.smoother)); - - // Main options window: - final Table optionsTable = new Table(skin); - optionsTable.setBackground("bg"); - optionsTable.align(Align.top | Align.center); - optionsTable.setSize(768f, 640f); - optionsTable.setX((stage.getWidth() / 2f) - (optionsTable.getWidth() / 2f)); - stage.addActor(optionsTable); - - float paddingBottom = 10f; - - // Options title: - Label optTitle = new Label(game.locale.TranslatableText("options.title"), skin, "header_with_bg"); - optTitle.setAlignment(Align.center); - optionsTable.add(optTitle).width(optionsTable.getWidth()).row(); - - Table contentTable = new Table(); - contentTable.align(Align.top | Align.center); - contentTable.setWidth(optionsTable.getWidth()); - - // Scroll panel for options: - ScrollPane optScroll = new ScrollPane(contentTable); - optScroll.setScrollingDisabled(true, false); - optionsTable.add(optScroll).width(optionsTable.getWidth()).height(512f).padBottom(paddingBottom).row(); - - // - - - General category - - -: - Label genLabel = new Label(game.locale.TranslatableText("options.general"), skin, "subheader_with_bg"); - contentTable.add(genLabel).fillX().padBottom(paddingBottom).row(); - - Table genCategory = new Table(); - contentTable.add(genCategory).fillX().padBottom(paddingBottom).row(); - - // Show debug: - Label debLabel = new Label(game.locale.TranslatableText("options.debug"), skin); - debLabel.setAlignment(Align.left); - genCategory.add(debLabel).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom); - - final TextButton debButton = new TextButton((game.prefs.getBoolean("debug", false)) ? "ON" : "OFF", skin); - - debButton.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - boolean value = game.prefs.getBoolean("debug", false); - - game.prefs.putBoolean("debug", !value); - - value = !value; - - if (value) stage.addActor(debugInfo); - else debugInfo.remove(); - - debButton.getLabel().setText((value) ? "ON" : "OFF"); - } - }); - - genCategory.add(debButton).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom).row(); - - // - - - Audio category - - -: - Label audioLabel = new Label(game.locale.TranslatableText("options.audio"), skin, "subheader_with_bg"); - contentTable.add(audioLabel).fillX().padBottom(paddingBottom).row(); - - Table audioCategory = new Table(); - contentTable.add(audioCategory).fillX().padBottom(paddingBottom).row(); - - // Music: - Label musLabel = new Label(game.locale.TranslatableText("options.music"), skin); - musLabel.setAlignment(Align.left); - audioCategory.add(musLabel).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom); - - final TextButton musButton = new TextButton((game.prefs.getBoolean("music", true)) ? "ON" : "OFF", skin); - - musButton.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - boolean value = game.prefs.getBoolean("music", true); - - game.prefs.putBoolean("music", !value); - - value = !value; + brandTable.add(logo); - if (value) menuMusic.play(); - else menuMusic.pause(); + // - - - Menu control (quit, options, etc.) - - - + Table controlTable = new Table(skin); + controlTable.align(Align.top | Align.center); + controlTable.pad(6f); - musButton.getLabel().setText((value) ? "ON" : "OFF"); - } - }); - - audioCategory.add(musButton).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom).row(); + // Left part of menu control + Table leftGameControlTable = new Table(); + leftGameControlTable.align(Align.left); - // Sound: - Label sndLabel = new Label(game.locale.TranslatableText("options.sound"), skin); - sndLabel.setAlignment(Align.left); - audioCategory.add(sndLabel).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom); + ImageButton quitButton = new ImageButton(widgetSkin, "quit"); - final TextButton sndButton = new TextButton((game.prefs.getBoolean("sfx", true)) ? "ON" : "OFF", skin); - - sndButton.addListener(new ClickListener() { + quitButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - boolean value = game.prefs.getBoolean("sfx", true); - - game.prefs.putBoolean("sfx", !value); - - value = !value; - - sndButton.getLabel().setText((value) ? "ON" : "OFF"); - } - }); - - audioCategory.add(sndButton).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom).row(); - - // - - - Video category - - -: - Label videoLabel = new Label(game.locale.TranslatableText("options.video"), skin, "subheader_with_bg"); - contentTable.add(videoLabel).fillX().padBottom(paddingBottom).row(); - - Table videoCategory = new Table(); - contentTable.add(videoCategory).fillX().padBottom(paddingBottom).row(); - - // Vertical sync: - Label vscLabel = new Label(game.locale.TranslatableText("options.vsync"), skin); - vscLabel.setAlignment(Align.left); - videoCategory.add(vscLabel).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom); - - final TextButton vscButton = new TextButton((game.prefs.getBoolean("vsync", true)) ? "ON" : "OFF", skin); - - vscButton.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - boolean value = game.prefs.getBoolean("vsync", true); - - game.prefs.putBoolean("vsync", !value); - - value = !value; - - Gdx.graphics.setVSync(value); - - vscButton.getLabel().setText((value) ? "ON" : "OFF"); + super.clicked(event, x, y); + Gdx.app.exit(); } }); - videoCategory.add(vscButton).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom).row(); - - // Full screen: - Label fscLabel = new Label(game.locale.TranslatableText("options.fullscreen"), skin); - fscLabel.setAlignment(Align.left); - //videoCategory.add(fscLabel).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom); + leftGameControlTable.add(quitButton).padRight(12f); - final TextButton fscButton = new TextButton((game.prefs.getBoolean("fullscreen", true)) ? "ON" : "OFF", skin); + // Right part of menu control + Table rightGameControlTable = new Table(); + rightGameControlTable.align(Align.right); - fscButton.addListener(new ClickListener() { - @Override - public void clicked(InputEvent event, float x, float y) { - boolean value = game.prefs.getBoolean("fullscreen", true); - - game.prefs.putBoolean("fullscreen", !value); - - value = !value; - Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); - - if (value) Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); - else Gdx.graphics.setWindowedMode(dim.width, dim.height); - - fscButton.getLabel().setText((value) ? "ON" : "OFF"); - } - }); - - //videoCategory.add(fscButton).width(optionsTable.getWidth() / 2f).padBottom(paddingBottom).row(); - - // - - - Switch the language - - -: + // Localization String[] fh4Locale = game.locale.getFileHandle().nameWithoutExtension().split("_"); - Locale locale = new Locale(fh4Locale[0], fh4Locale[1]); - final TextButton langButton = new TextButton(game.locale.FormattedText("options.language", locale.getDisplayLanguage(), locale.getDisplayCountry()), skin); + String localeButtonStyleName = "locale_" + fh4Locale[0]; + ImageButton localeButton = new ImageButton(widgetSkin, localeButtonStyleName); - langButton.addListener(new ClickListener() { + localeButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + int index = 0; ArrayList<FileHandle> fhArray = new ArrayList<>(); fhArray.add(MaxonConstants.FILE_RU_RU); @@ -431,156 +131,121 @@ public class MenuScreen implements Screen { game.locale = new I18N(fhNext); game.prefs.putString("lang", fhNext.nameWithoutExtension()); + game.prefs.flush(); - String[] fh4Locale = fhNext.nameWithoutExtension().split("_"); - Locale locale = new Locale(fh4Locale[0], fh4Locale[1]); - - langButton.setText(game.locale.FormattedText("options.language", locale.getDisplayLanguage(), locale.getDisplayCountry())); game.setScreen(new SplashScreen(game)); menuMusic.stop(); } }); - contentTable.add(langButton).width(optionsTable.getWidth()).padBottom(paddingBottom).row(); - // Game info: - Label infLabel = new Label(String.format("%s-%s - %s", System.getProperty("os.name"), System.getProperty("os.arch"), MaxonConstants.GAME_VERSION), skin, "small-pixeled"); - infLabel.setAlignment(Align.center); - optionsTable.add(infLabel).maxWidth(optionsTable.getWidth() / 2f).row(); + rightGameControlTable.add(localeButton).padRight(16f); - // // Action buttons: - Table actTable = new Table(skin); - actTable.setBackground("fg"); - actTable.setWidth(optionsTable.getWidth()); - actTable.align(Align.right); - optionsTable.add(actTable).width(optionsTable.getWidth()).maxWidth(optionsTable.getWidth()).pad(5f); + // Music button + String musicButtonStyleName; - TextButton closeBtn = new TextButton("Back to main menu", skin); + if (game.prefs.getBoolean("music")) { + musicButtonStyleName = "music_on"; + menuMusic.play(); + } else { + musicButtonStyleName = "music_off"; + } - closeBtn.addListener(new ClickListener() { + ImageButton musicButton = new ImageButton(widgetSkin, musicButtonStyleName); + musicButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - inOptions = !inOptions; - optionsTable.addAction(Actions.moveTo(optionsTable.getX(), -stage.getHeight(), 2f, Interpolation.smoother)); + super.clicked(event, x, y); - brandLogo.clearActions(); - brandLogo.addAction( - Actions.sequence( - Actions.parallel( - Actions.rotateTo(0f, 1f), - Actions.moveTo( - (stage.getWidth() / 2f) - (brandLogo.getWidth() / 2f), - stage.getHeight() - brandLogo.getHeight() * 1.2f, - 1f, - Interpolation.fade - ) - ), - Actions.repeat( - RepeatAction.FOREVER, - Actions.sequence( - Actions.parallel( - Actions.rotateTo(-5f, 5f, Interpolation.smoother), - Actions.scaleTo(0.9f, 0.9f, 5f, Interpolation.smoother) - ), - Actions.parallel( - Actions.rotateTo(5f, 5f, Interpolation.smoother), - Actions.scaleTo(1.1f, 1.1f, 5f, Interpolation.smoother) - ) - ) - ) - ) - ); + Button.ButtonStyle style; + + if (game.prefs.getBoolean("music")) { + style = widgetSkin.get("music_off", ImageButton.ImageButtonStyle.class); + menuMusic.pause(); + } else { + style = widgetSkin.get("music_on", ImageButton.ImageButtonStyle.class); + menuMusic.play(); + } - lArrowBtn.addAction(Actions.moveTo(lArrowBtn.getWidth(), lArrowBtn.getY(), 1f, Interpolation.smoother)); - rArrowBtn.addAction(Actions.moveTo(stage.getWidth() - rArrowBtn.getWidth() * 2, rArrowBtn.getY(), 1f, Interpolation.smoother)); - curSavInfo.addAction(Actions.moveTo(curSavInfo.getX(), 6f, 1f, Interpolation.smoother)); - curSavImg.addAction(Actions.moveTo(curSavImg.getX(), (stage.getHeight() / 2f) - (curSavImg.getHeight() / 2f), 2f, Interpolation.smoother)); - menuTable.addAction(Actions.moveTo(menuTable.getX(), 0, 1f, Interpolation.smoother)); + game.prefs.putBoolean("music", !game.prefs.getBoolean("music")); + game.prefs.flush(); + + musicButton.setStyle(style); } }); + rightGameControlTable.add(musicButton).padRight(16f); - actTable.add(closeBtn).pad(5f); + // Resolution button + String resolutionButtonStyleName; - TextButton saveBtn = new TextButton("Apply", skin); + if (game.prefs.getBoolean("fullscreen")) { + resolutionButtonStyleName = "windowed"; + } else { + resolutionButtonStyleName = "fullscreen"; + } - saveBtn.addListener(new ClickListener() { + ImageButton resolutionButton = new ImageButton(widgetSkin, resolutionButtonStyleName); + resolutionButton.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { - game.prefs.flush(); - } - }); - - actTable.add(saveBtn).pad(5f); - - optionsTable.setY(-optionsTable.getHeight()); - optionsTable.addAction(Actions.moveTo(optionsTable.getX(), (stage.getHeight() / 2f) - (optionsTable.getHeight() / 2f), 2f, Interpolation.smoother)); - } + super.clicked(event, x, y); - private void generateSaves() { - ArrayList<MaxonSavegame> saves = GameDataSystem.getSavegames(); - int i = -1; + Button.ButtonStyle style; - for (MaxonSavegame sav : saves) { - i++; + if (game.prefs.getBoolean("fullscreen")) { + style = widgetSkin.get("fullscreen", ImageButton.ImageButtonStyle.class); + Gdx.graphics.setWindowedMode(game.prefs.getInteger("width", 800), game.prefs.getInteger("height", 600)); + } else { + style = widgetSkin.get("windowed", ImageButton.ImageButtonStyle.class); + Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); + } - savInfos.add(new SavegameInfo(game, game.locale, skin, sav, i)); - savImgs.add(new Image( - PetUtils.animatedImageById(game.assetManager, sav.petId).getDrawable() - ) - ); - } + game.prefs.putBoolean("fullscreen", !game.prefs.getBoolean("fullscreen")); + game.prefs.flush(); - savInfos.add(new SavegameInfo(game, game.locale, skin, null, i + 1)); - savImgs.add(new Image( - mainAtlas.findRegion("unknown") - )); - } + resolutionButton.setStyle(style); + } + }); + rightGameControlTable.add(resolutionButton); - private void updateCurrentVisualSavegame(boolean indexNegative) { - if (indexNegative) curSav--; - else curSav++; + controlTable.add(leftGameControlTable).grow(); + controlTable.add(rightGameControlTable).grow(); - if (curSav < 0) { - curSav = savInfos.size() - 1; - } + // - - - Savegame - - - + Table savegameTable = new Table(); + SavegameWidget info = new SavegameWidget(this.game, skin, sav); - if (savInfos.size() - 1 < curSav || savImgs.size() - 1 < curSav) { - curSav = 0; - } + savegameTable.add(info).minSize(640f, 240f); - // Set the image: - if (curSavImg != null) { - curSavImg.remove(); - curSavImg.setSize( - curSavImg.getWidth() / 2f, - curSavImg.getHeight() / 2f - ); - } - curSavImg = savImgs.get(curSav); + // Adding tables into the main UI table + menuTable.add(brandTable).grow().row(); + menuTable.add(savegameTable).grow().row(); + menuTable.add(controlTable).growX(); - curSavImg.setSize( - curSavImg.getWidth() * 2f, - curSavImg.getHeight() * 2f - ); + this.stage.addActor(menuTable); - curSavImg.setPosition( - (stage.getWidth() / 2f) - (curSavImg.getWidth() / 2f), - (stage.getHeight() / 2f) - (curSavImg.getHeight() / 2f) - ); + Gdx.input.setInputProcessor(stage); + } - stage.addActor(curSavImg); + @Override public void show() { + if (game.prefs.getBoolean("music", true)) menuMusic.play(); - // Set the info: - if (curSavInfo != null) curSavInfo.remove(); + // Start to render: + render(Gdx.graphics.getDeltaTime()); + } - curSavInfo = savInfos.get(curSav); + @Override + public void render(float delta) { + Gdx.gl.glClearColor(1, 1, 1, 1f); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); - curSavInfo.setPosition( - (stage.getWidth() / 2f) - (curSavInfo.getWidth() / 2f), - 6f - ); + stage.act(delta); + stage.draw(); + } - stage.addActor(curSavInfo); + @Override + public void resize(int width, int height) { + stage.getViewport().update(width, height, true); } @Override public void pause() {} diff --git a/core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt b/core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt deleted file mode 100644 index 0b7e3ad..0000000 --- a/core/src/com/ilotterytea/maxoning/ui/SavegameInfo.kt +++ /dev/null @@ -1,118 +0,0 @@ -package com.ilotterytea.maxoning.ui - -import com.badlogic.gdx.scenes.scene2d.InputEvent -import com.badlogic.gdx.scenes.scene2d.ui.* -import com.badlogic.gdx.scenes.scene2d.utils.ClickListener -import com.badlogic.gdx.utils.Align -import com.ilotterytea.maxoning.MaxonGame -import com.ilotterytea.maxoning.player.MaxonSavegame -import com.ilotterytea.maxoning.screens.GameScreen -import com.ilotterytea.maxoning.utils.I18N -import com.ilotterytea.maxoning.utils.formatters.NumberFormatter - -/** - * Savegame information widget. - * @since 1.3 - * @author ilotterytea - */ -class SavegameInfo( - game: MaxonGame, - i18n: I18N, - skin: Skin, - sav: MaxonSavegame?, - savId: Int -) : Table(skin) { - init { - this.setBackground("bg") - this.width = 512f - this.height = 324f - this.align(Align.top) - - val title = Label(if (sav != null) i18n.FormattedText("savegame.title", (savId + 1).toString(), sav.name) else i18n.TranslatableText("savegame.new"), skin, "header_with_bg") - this.add(title).width(506f).pad(6f).row() - - val content = Table() - content.align(Align.top) - this.add(content).width(506f).maxWidth(506f).pad(6f).expandY().row() - - // - - - A C T I O N S - - - : - val actions = Table() - this.add(actions).width(508f).row() - - if (sav != null) { - // - - - P O I N T S - - - : - // Label for points: - val pointsLabel = Label(i18n.TranslatableText("savegame.points"), skin) - content.add(pointsLabel).width(246f).pad(4f) - // Label for points count: - val pointsCLabel = Label(NumberFormatter.format(sav.points.toLong()), skin, "value") - pointsCLabel.setAlignment(Align.right) - content.add(pointsCLabel).width(246f).pad(4f).row() - - // - - - M U L T I P L I E R - - - : - // Label for multiplier: - val mpLabel = Label(i18n.TranslatableText("savegame.multiplier"), skin) - content.add(mpLabel).width(246f).pad(4f) - // Label for multiplier count: - val mpCLabel = Label(i18n.FormattedText("savegame.multiplier.count", NumberFormatter.format(sav.multiplier.toLong())), skin, "value") - mpCLabel.setAlignment(Align.right) - content.add(mpCLabel).width(246f).pad(4f).row() - - // - - - P U R C H A S E D I T E M S - - - : - // Label for purchased items: - val piLabel = Label(i18n.TranslatableText("savegame.purchased"), skin) - content.add(piLabel).width(246f).pad(4f) - // Label for purchased items count: - val piCLabel = Label(sav.inv.size.toString(), skin, "value") - piCLabel.setAlignment(Align.right) - content.add(piCLabel).width(246f).pad(4f).row() - - // Deletion button: - val delButton = ImageButton(skin, "delete") - - delButton.addListener(object : ClickListener() { - override fun clicked(event: InputEvent?, x: Float, y: Float) { - super.clicked(event, x, y) - } - }) - - //actions.add(delButton).pad(4f) - - // Play button: - val playButton = TextButton(i18n.TranslatableText("menu.continue"), skin) - - playButton.addListener(object : ClickListener() { - override fun clicked(event: InputEvent, x: Float, y: Float) { - game.screen = GameScreen(game, sav, savId) - } - }) - - actions.add(playButton).width(508f) - } else { - // - - - N A M E - - - : - // Label for points: - val nameLabel = Label(i18n.TranslatableText("savegame.your_name"), skin) - content.add(nameLabel).width(246f).pad(4f) - // Label for points count: - val nameField = TextField(System.getProperty("user.name"), skin) - content.add(nameField).width(246f).pad(4f).row() - - - // Play button: - val playButton = TextButton(i18n.TranslatableText("menu.playGame"), skin) - - playButton.addListener(object : ClickListener() { - override fun clicked(event: InputEvent, x: Float, y: Float) { - val _sav = MaxonSavegame() - _sav.name = nameField.text - - game.screen = GameScreen(game, _sav, savId) - } - }) - - actions.add(playButton).width(502f) - } - - - } -}
\ No newline at end of file diff --git a/core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java b/core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java new file mode 100644 index 0000000..a710418 --- /dev/null +++ b/core/src/com/ilotterytea/maxoning/ui/SavegameWidget.java @@ -0,0 +1,179 @@ +package com.ilotterytea.maxoning.ui; + +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.ui.*; +import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.badlogic.gdx.utils.Align; +import com.badlogic.gdx.utils.Disposable; +import com.ilotterytea.maxoning.MaxonGame; +import com.ilotterytea.maxoning.player.MaxonSavegame; +import com.ilotterytea.maxoning.screens.GameScreen; +import com.ilotterytea.maxoning.utils.formatters.NumberFormatter; + +import java.io.IOException; + +public class SavegameWidget extends Table implements Disposable { + private final Skin skin; + private final MaxonSavegame savegame; + private final Table dataTable, controlTable; + private final TextureAtlas atlas; + private final MaxonGame game; + + public SavegameWidget(final MaxonGame game, Skin skin, final MaxonSavegame savegame) { + super(); + this.game = game; + this.atlas = game.assetManager.get("MainSpritesheet.atlas", TextureAtlas.class); + + this.skin = skin; + this.savegame = savegame; + + this.dataTable = new Table(this.skin); + this.dataTable.pad(16f); + this.dataTable.setBackground("bg"); + + super.add(this.dataTable).grow().padBottom(16f).row(); + + this.controlTable = new Table(); + this.controlTable.align(Align.left); + super.add(this.controlTable).growX(); + + if (savegame == null) { + createEmpty(); + } else { + createWithSavegame(); + } + } + + private void createEmpty() { + final boolean[] gameCreation = {false}; + + // Body + Table body = new Table(); + + Label name = new Label("New Game", skin); + name.setAlignment(Align.center); + body.add(name).grow().row(); + + this.dataTable.add(body).grow().row(); + + // - - - C O N T R O L - - - + TextButton playButton = new TextButton("play", skin); + TextField field = new TextField(System.getProperty("user.name", "Maxon"), skin); + + body.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + if (!gameCreation[0]) { + name.setText("What is your name?"); + + body.add(field).growX(); + + controlTable.add(playButton).growX(); + gameCreation[0] = true; + } + } + }); + + playButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + MaxonSavegame sav = new MaxonSavegame(); + sav.name = field.getText(); + + try { + game.setScreen(new GameScreen(game, sav, 0)); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + }); + } + + private void createWithSavegame() { + // - - - S A V E G A M E D A T A - - - + // Header + Table header = new Table(); + + Label name = new Label(savegame.name, skin); + header.add(name).grow(); + + long minutes = savegame.elapsedTime / 1000 / 60; + long seconds = savegame.elapsedTime / 1000 % 60; + + Label time = new Label(String.format("%s:%s", NumberFormatter.pad(minutes), NumberFormatter.pad(seconds)), skin); + time.setAlignment(Align.right); + header.add(time).grow().row(); + + this.dataTable.add(header).grow().row(); + + // Data + Table data = new Table(); + data.align(Align.left); + + // Points + Image pointsIcon = new Image(atlas.findRegion("points")); + data.add(pointsIcon).size(32f, 32f).padRight(8f); + + Label points = new Label(NumberFormatter.format(savegame.points), skin); + data.add(points).padRight(32f); + + // Unit + long amount = savegame.inv.size(); + + Image unitIcon = new Image(atlas.findRegion("points")); + data.add(unitIcon).size(32f, 32f).padRight(8f); + + Label unit = new Label(NumberFormatter.format(amount), skin); + data.add(unit).padRight(32f); + + // Multiplier + Image multiplierIcon = new Image(atlas.findRegion("multiplier")); + data.add(multiplierIcon).size(32f, 32f).padRight(8f); + + Label multiplier = new Label(NumberFormatter.format(savegame.multiplier), skin); + data.add(multiplier); + + this.dataTable.add(data).grow(); + + // - - - C O N T R O L - - - + TextButton playButton = new TextButton(game.locale.TranslatableText("menu.continue"), skin); + controlTable.add(playButton).padRight(16f).growX(); + + playButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + try { + game.setScreen(new GameScreen(game, savegame, 0)); + } catch (IOException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + }); + + TextButton resetButton = new TextButton(game.locale.TranslatableText("menu.reset"), skin); + controlTable.add(resetButton); + + resetButton.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + + controlTable.clear(); + dataTable.clear(); + createEmpty(); + } + }); + } + + @Override + public void dispose() { + atlas.dispose(); + } +} diff --git a/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java b/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java index 250fbab..c0605f3 100644 --- a/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java +++ b/core/src/com/ilotterytea/maxoning/utils/AssetLoading.java @@ -25,6 +25,8 @@ public class AssetLoading { am.load("sprites/gui/icons.atlas", TextureAtlas.class); am.load("sprites/gui/ilotterytea.atlas", TextureAtlas.class); am.load("sprites/gui/widgets.atlas", TextureAtlas.class); + am.load("sprites/gui/widgets.skin", Skin.class, new SkinLoader.SkinParameter("sprites/gui/widgets.atlas")); + am.load("sprites/gui/widgeticons.atlas", TextureAtlas.class); am.load("MainSpritesheet.atlas", TextureAtlas.class); |
