diff --git a/.travis.yml b/.travis.yml index d6e5d91c5..014449154 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,3 @@ language: Java -jdk: - - oraclejdk8 diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c6267f1..6a5b6981e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,39 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +# [1.0.13] + +- Fix bug introduced in latest release. + +# [1.0.12] + +- MusicManager doesn't fail if the music file don't exists. +- Editor supports new gradle compile folder structure to load custom classes. + +# [1.0.11] + +- Exit when back button is pressed on Android. This is a Google Play Pass requeriment. + +# [1.0.10] + +- Nullpointer sanity check. + +# [1.0.9] + +- Fixes for the iphone X screen. + +# [1.0.8] + +- Pick menu screen from v2 + +# [1.0.7] + +- OSX Sandbox + +## [1.0.4 to 1.0.6] + +- Speed Optimization: Don't pre-generate any character when loading fonts. + ## [1.0.3] - FIX: error loading recordings from 'tests' folder. diff --git a/adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorLogger.java b/adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorLogger.java index 5ceb50650..7461e7b99 100644 --- a/adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorLogger.java +++ b/adventure-editor/src/main/java/com/bladecoder/engineeditor/common/EditorLogger.java @@ -188,6 +188,13 @@ public void compareI18N(String lang) { EditorLogger.msg("PROCCESS FINISHED."); } + + @SuppressWarnings("unused") + public void addCutmode() { + ModelTools.addCutMode(); + + EditorLogger.msg("PROCCESS FINISHED."); + } }); } diff --git a/adventure-editor/src/main/java/com/bladecoder/engineeditor/model/Project.java b/adventure-editor/src/main/java/com/bladecoder/engineeditor/model/Project.java index 3a36f30c2..78e040eb9 100644 --- a/adventure-editor/src/main/java/com/bladecoder/engineeditor/model/Project.java +++ b/adventure-editor/src/main/java/com/bladecoder/engineeditor/model/Project.java @@ -255,14 +255,14 @@ private void createLibGdxProject(String projectDir, String name, String pkg, Str DependencyBank bank = new DependencyBank(); ProjectBuilder builder = new ProjectBuilder(bank); - List projects = new ArrayList(); + List projects = new ArrayList<>(); projects.add(ProjectType.CORE); projects.add(ProjectType.DESKTOP); projects.add(ProjectType.ANDROID); projects.add(ProjectType.IOS); // projects.add(ProjectType.HTML); - List dependencies = new ArrayList(); + List dependencies = new ArrayList<>(); dependencies.add(bank.getDependency(ProjectDependency.GDX)); dependencies.add(bank.getDependency(ProjectDependency.FREETYPE)); @@ -287,8 +287,10 @@ public void saveProject() throws IOException { chapter.save(); // 3.- SAVE BladeEngine.properties - projectConfig.store(new FileOutputStream(projectFile.getAbsolutePath() + "/" + ASSETS_PATH + "/" - + Config.PROPERTIES_FILENAME), null); + projectConfig.store( + new FileOutputStream( + projectFile.getAbsolutePath() + "/" + ASSETS_PATH + "/" + Config.PROPERTIES_FILENAME), + null); // 4.- SAVE I18N i18n.save(); @@ -311,8 +313,14 @@ public void loadProject(File projectFile) throws IOException { // Use FolderClassLoader for loading CUSTOM actions. // TODO Add 'core/bin' and '/core/out' folders??? - FolderClassLoader folderClassLoader = new FolderClassLoader(projectFile.getAbsolutePath() - + "/core/build/classes/main"); + + String classFolder = projectFile.getAbsolutePath() + "/core/build/classes/java/main"; + + if (!new File(classFolder).exists()) { + classFolder = projectFile.getAbsolutePath() + "/core/build/classes/main"; + } + + FolderClassLoader folderClassLoader = new FolderClassLoader(classFolder); ActionFactory.setActionClassLoader(folderClassLoader); EngineAssetManager.createEditInstance(Ctx.project.getProjectDir().getAbsolutePath() + Project.ASSETS_PATH); @@ -344,12 +352,12 @@ public void loadProject(File projectFile) throws IOException { editorConfig.setProperty(LAST_PROJECT_PROP, projectFile.getAbsolutePath()); projectConfig = new OrderedProperties(); - projectConfig.load(new FileInputStream(projectFile.getAbsolutePath() + ASSETS_PATH + "/" - + Config.PROPERTIES_FILENAME)); + projectConfig.load(new FileInputStream( + projectFile.getAbsolutePath() + ASSETS_PATH + "/" + Config.PROPERTIES_FILENAME)); modified = false; - - Display.setTitle( "Adventure Editor v" + Versions.getVersion() + " - " + projectFile.getAbsolutePath() ); - + + Display.setTitle("Adventure Editor v" + Versions.getVersion() + " - " + projectFile.getAbsolutePath()); + firePropertyChange(NOTIFY_PROJECT_LOADED); } else { this.projectFile = oldProjectFile; @@ -427,7 +435,7 @@ public BaseActor getActor(String id) { public List getResolutions() { File atlasesPath = new File(projectFile.getAbsolutePath() + ATLASES_PATH); - ArrayList l = new ArrayList(); + ArrayList l = new ArrayList<>(); File[] list = atlasesPath.listFiles(); @@ -462,11 +470,11 @@ public void loadChapter(String selChapter) throws IOException { chapter.load(selChapter); } catch (SerializationException ex) { // check for not compiled custom actions - if (ex.getCause() != null && ex.getCause() instanceof ClassNotFoundException) { + if (ex.getCause() != null && ex.getCause() instanceof ClassNotFoundException) { EditorLogger.debug("Custom action class not found. Trying to compile..."); if (RunProccess.runGradle(Ctx.project.getProjectDir(), "desktop:compileJava")) { - FolderClassLoader folderClassLoader = new FolderClassLoader(projectFile.getAbsolutePath() - + "/core/build/classes/main"); + FolderClassLoader folderClassLoader = new FolderClassLoader( + projectFile.getAbsolutePath() + "/core/build/classes/main"); ActionFactory.setActionClassLoader(folderClassLoader); chapter.load(selChapter); } else { @@ -498,7 +506,8 @@ public Properties getGradleProperties() throws FileNotFoundException, IOExceptio } public void saveGradleProperties(Properties prop) throws IOException { - FileOutputStream os = new FileOutputStream(Ctx.project.getProjectDir().getAbsolutePath() + "/gradle.properties"); + FileOutputStream os = new FileOutputStream( + Ctx.project.getProjectDir().getAbsolutePath() + "/gradle.properties"); prop.store(os, null); } diff --git a/adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ScnEditor.java b/adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ScnEditor.java index 3ebad60c6..26669f750 100644 --- a/adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ScnEditor.java +++ b/adventure-editor/src/main/java/com/bladecoder/engineeditor/scneditor/ScnEditor.java @@ -209,14 +209,15 @@ private void test() { Message.showMsgDialog(getStage(), "Error", msg); return; } + + Stage stage = getStage(); + Message.showMsg(stage, "Running scene...", 5); new Thread(new Runnable() { - Stage stage = getStage(); @Override public void run() { - Message.showMsg(stage, "Running scene...", 5); - + Stage stage = getStage(); try { if (!RunProccess.runBladeEngine(Ctx.project.getProjectDir(), Ctx.project.getChapter().getId(), Ctx.project.getSelectedScene().getId())) diff --git a/adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/PackageDialog.java b/adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/PackageDialog.java index 221021189..ec5fb533b 100644 --- a/adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/PackageDialog.java +++ b/adventure-editor/src/main/java/com/bladecoder/engineeditor/ui/PackageDialog.java @@ -337,7 +337,7 @@ private String packageAdv() throws IOException { p.load(new FileReader(Ctx.project.getProjectDir().getAbsolutePath() + "/ios/robovm.properties")); p.setProperty("app.version", version.getText()); p.setProperty("app.build", versionCode.getText()); - p.setProperty("app.name", projectName); + p.setProperty("app.name", Ctx.project.getProjectConfig().getProperty(Config.TITLE_PROP, getAppName())); p.store(new FileOutputStream( new File(Ctx.project.getProjectDir().getAbsolutePath(), "/ios/robovm.properties")), null); diff --git a/adventure-editor/src/main/resources/versions.properties b/adventure-editor/src/main/resources/versions.properties index d86ef28dd..9e3500d10 100644 --- a/adventure-editor/src/main/resources/versions.properties +++ b/adventure-editor/src/main/resources/versions.properties @@ -1,11 +1,11 @@ #Autogenerated by build.gradle -#Thu Nov 17 12:22:51 CET 2016 +#Tue Nov 17 20:07:15 CET 2020 roboVMVersion=2.2.0 gwtVersion=2.6.0 libgdxVersion=1.9.4 androidAPILevel=20 buildToolsVersion=23.0.1 roboVMGradlePluginVersion=2.2.0 -version=1.0.3 +version=1.0.13 gwtGradlePluginVersion=0.6 androidGradlePluginVersion=1.5.0 diff --git a/blade-engine/src/com/bladecoder/engine/BladeEngine.java b/blade-engine/src/com/bladecoder/engine/BladeEngine.java index 1c1a95ef9..1cf58879f 100644 --- a/blade-engine/src/com/bladecoder/engine/BladeEngine.java +++ b/blade-engine/src/com/bladecoder/engine/BladeEngine.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright 2014 Rafael Garcia Moreno. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -76,18 +76,18 @@ public void forceResolution(String forceRes) { public UI getUI() { return ui; } - + public void loadGame(String baseFolder) { if(ui != null) { ui.dispose(); World.getInstance().dispose(); } - + if(baseFolder != null) { EngineAssetManager.setAssetFolder(baseFolder); Config.load(); } - + try { World.getInstance().loadWorldDesc(); } catch (Exception e) { @@ -95,7 +95,7 @@ public void loadGame(String baseFolder) { EngineLogger.error("EXITING: " + e.getMessage()); Gdx.app.exit(); } - + ui = new UI(); } @@ -152,7 +152,7 @@ public void create() { if (restart) { try { World.getInstance().loadChapter(null); - + ui.setCurrentScreen(UI.Screens.SCENE_SCREEN); } catch (Exception e) { EngineLogger.error("ERROR LOADING GAME", e); @@ -168,7 +168,7 @@ public void create() { ui.getRecorder().setFilename(recordName); ui.getRecorder().load(); ui.getRecorder().setPlaying(true); - + ui.setCurrentScreen(UI.Screens.SCENE_SCREEN); } } @@ -182,7 +182,7 @@ public void create() { EngineLogger.debug("Density: " + Gdx.graphics.getDensity()); EngineLogger.debug("Size Multiplier: " + DPIUtils.getSizeMultiplier()); } - + Gdx.input.setCatchBackKey(true); } @@ -211,7 +211,7 @@ public void render() { @Override public void resize(int width, int height) { EngineLogger.debug(MessageFormat.format("GAME RESIZE {0}x{1}", width, height)); - + if(ui != null) ui.resize(width, height); } @@ -237,6 +237,7 @@ public void pause() { @Override public void resume() { EngineLogger.debug("GAME RESUME"); + resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); ui.resume(); // resets the error when continue diff --git a/blade-engine/src/com/bladecoder/engine/assets/EngineAssetManager.java b/blade-engine/src/com/bladecoder/engine/assets/EngineAssetManager.java index d1a1e41c5..a0f331638 100644 --- a/blade-engine/src/com/bladecoder/engine/assets/EngineAssetManager.java +++ b/blade-engine/src/com/bladecoder/engine/assets/EngineAssetManager.java @@ -48,6 +48,7 @@ import com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader; import com.badlogic.gdx.graphics.g3d.Model; import com.badlogic.gdx.utils.Array; +import com.badlogic.gdx.utils.GdxRuntimeException; import com.bladecoder.engine.util.Config; import com.bladecoder.engine.util.EngineLogger; import com.bladecoder.engine.util.FileUtils; @@ -129,11 +130,10 @@ public static EngineAssetManager getInstance() { /** * Creates a EngineAssetManager instance for edition. That is: * - * - Puts a PathResolver to locate the assets through an absolute path - - * Puts assets scale to "1" + * - Puts a PathResolver to locate the assets through an absolute path - Puts + * assets scale to "1" * - * @param base - * is the project base folder + * @param base is the project base folder */ public static void createEditInstance(String base) { if (instance != null) @@ -147,8 +147,7 @@ public static void createEditInstance(String base) { /** * All assets will be searched in the selected folder. * - * @param base - * The asset base folder + * @param base The asset base folder */ public static void setAssetFolder(String base) { if (instance != null) @@ -228,8 +227,7 @@ public FileHandle getModelFile(String filename) { } /** - * Returns a file in the asset directory SEARCHING in the resolution - * directories + * Returns a file in the asset directory SEARCHING in the resolution directories */ public FileHandle getResAsset(String filename) { return resResolver.resolve(filename); @@ -290,6 +288,7 @@ public Texture getTexture(String filename) { return get(filename, Texture.class); } + @Override public void dispose() { super.dispose(); instance = null; @@ -303,7 +302,7 @@ public String checkIOSSoundName(String filename) { if (FileUtils.exists(EngineAssetManager.getInstance().getAsset(aac))) return aac; - EngineLogger.debug("OGG files not supported in IOS: " + filename); + EngineLogger.error("OGG files not supported in IOS: " + filename); return null; } @@ -318,6 +317,10 @@ public void loadMusic(String filename) { if (n == null) return; + if (!FileUtils.exists(EngineAssetManager.getInstance().getAsset(n))) { + throw new GdxRuntimeException("Cannot load music file: " + n); + } + load(n, Music.class); } @@ -390,7 +393,7 @@ public boolean assetExists(String filename) { } private Resolution[] getResolutions(FileHandleResolver resolver, int worldWidth, int worldHeight) { - ArrayList rl = new ArrayList(); + ArrayList rl = new ArrayList<>(); String list[] = listAssetFiles("ui"); @@ -409,6 +412,7 @@ private Resolution[] getResolutions(FileHandleResolver resolver, int worldWidth, } Collections.sort(rl, new Comparator() { + @Override public int compare(Resolution a, Resolution b) { return a.portraitWidth - b.portraitWidth; } @@ -443,14 +447,14 @@ public String[] listAssetFiles(String base) { n = u.getFile(); FileHandle f = null; - + try { f = Gdx.files.absolute(URLDecoder.decode(n, "UTF-8")); } catch (UnsupportedEncodingException e) { EngineLogger.error("Error decoding URL", e); return new String[0]; } - + FileHandle[] l = f.list(); list = new String[l.length]; @@ -468,8 +472,8 @@ public String[] listAssetFiles(String base) { private String[] getFilesFromJar(String base) { URL dirURL = EngineAssetManager.class.getResource(base); - Set result = new HashSet(); // avoid duplicates in case - // it is a subdirectory + Set result = new HashSet<>(); // avoid duplicates in case + // it is a subdirectory if (dirURL.getProtocol().equals("jar")) { /* A JAR path */ @@ -521,7 +525,15 @@ public FileHandle getUserFile(String filename) { StringBuilder sb = new StringBuilder(); sb.append(".").append(dir).append("/").append(filename); - file = Gdx.files.external(sb.toString()); + + if (System.getProperty("os.name").toLowerCase().contains("mac") + && System.getenv("HOME").contains("Containers")) { + + file = Gdx.files.absolute(System.getenv("HOME") + "/" + sb.toString()); + } else { + + file = Gdx.files.external(sb.toString()); + } } else { file = Gdx.files.local(NOT_DESKTOP_PREFS_DIR + filename); } @@ -537,7 +549,16 @@ public FileHandle getUserFolder() { dir.replace(" ", ""); StringBuilder sb = new StringBuilder("."); - file = Gdx.files.external(sb.append(dir).toString()); + + if (System.getProperty("os.name").toLowerCase().contains("mac") + && System.getenv("HOME").contains("Containers")) { + + file = Gdx.files.absolute(System.getenv("HOME") + "/" + sb.append(dir).toString()); + } else { + + file = Gdx.files.external(sb.append(dir).toString()); + } + } else { file = Gdx.files.local(NOT_DESKTOP_PREFS_DIR); } diff --git a/blade-engine/src/com/bladecoder/engine/model/MusicEngine.java b/blade-engine/src/com/bladecoder/engine/model/MusicEngine.java index 2288e2eca..baea3946b 100644 --- a/blade-engine/src/com/bladecoder/engine/model/MusicEngine.java +++ b/blade-engine/src/com/bladecoder/engine/model/MusicEngine.java @@ -1,6 +1,7 @@ package com.bladecoder.engine.model; import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.utils.GdxRuntimeException; import com.badlogic.gdx.utils.Json; import com.badlogic.gdx.utils.Json.Serializable; import com.badlogic.gdx.utils.JsonValue; @@ -68,20 +69,19 @@ public void setMusic(MusicDesc d) { desc = null; } } - public void setVolume(float volume) { - desc.setVolume(volume); - - if(music != null) + if (desc != null) + desc.setVolume(volume); + + if (music != null) music.setVolume(volume); } - public void leaveScene(MusicDesc newMusicDesc) { - if (desc != null && !desc.isStopWhenLeaving() && - (newMusicDesc == null || newMusicDesc.getFilename().equals(desc.getFilename()))) + if (desc != null && !desc.isStopWhenLeaving() + && (newMusicDesc == null || newMusicDesc.getFilename().equals(desc.getFilename()))) return; if (desc != null) { @@ -112,7 +112,7 @@ public void update(float delta) { playMusic(); } else { if (desc.getRepeatDelay() >= 0 && currentMusicDelay > desc.getRepeatDelay() + desc.getInitialDelay()) { - currentMusicDelay = desc.getInitialDelay(); + currentMusicDelay = desc.getInitialDelay() + delta; playMusic(); } } @@ -133,29 +133,35 @@ public void dispose() { public void loadAssets() { if (music == null && desc != null) { EngineLogger.debug("LOADING MUSIC: " + desc.getFilename()); - EngineAssetManager.getInstance().loadMusic(desc.getFilename()); + try { + EngineAssetManager.getInstance().loadMusic(desc.getFilename()); + } catch (GdxRuntimeException e) { + EngineLogger.error(e.getMessage()); + desc = null; + } } } @Override public void retrieveAssets() { if (music == null && desc != null) { - - if(!EngineAssetManager.getInstance().isLoaded(EngineAssetManager.MUSIC_DIR + desc.getFilename())) { + + if (!EngineAssetManager.getInstance().isLoaded(EngineAssetManager.MUSIC_DIR + desc.getFilename())) { loadAssets(); + EngineAssetManager.getInstance().finishLoading(); } - + EngineLogger.debug("RETRIEVING MUSIC: " + desc.getFilename()); - + music = EngineAssetManager.getInstance().getMusic(desc.getFilename()); - - if(music != null) + + if (music != null) music.setVolume(desc.getVolume()); if (isPlayingSer) { playMusic(); - + if (music != null) { music.setPosition(musicPosSer); musicPosSer = 0f; @@ -170,8 +176,8 @@ public void retrieveAssets() { public void write(Json json) { json.writeValue("desc", desc); json.writeValue("currentMusicDelay", currentMusicDelay); - json.writeValue("isPlaying", music != null && (music.isPlaying()|| isPaused)); - json.writeValue("musicPos", music != null && (music.isPlaying()|| isPaused) ? music.getPosition() : 0f); + json.writeValue("isPlaying", music != null && (music.isPlaying() || isPaused)); + json.writeValue("musicPos", music != null && (music.isPlaying() || isPaused) ? music.getPosition() : 0f); } @Override diff --git a/blade-engine/src/com/bladecoder/engine/model/World.java b/blade-engine/src/com/bladecoder/engine/model/World.java index db94c12bd..ffb179e2d 100644 --- a/blade-engine/src/com/bladecoder/engine/model/World.java +++ b/blade-engine/src/com/bladecoder/engine/model/World.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright 2014 Rafael Garcia Moreno. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -171,7 +171,7 @@ private void init() { /** * Returns a scene from the cache. null if the scene is not cached. - * + * * Note that by now, the cache has only one Scene. In the future, the cache * will be a Hastable. */ @@ -538,13 +538,15 @@ public SceneCamera getSceneCamera() { } public void resize(float viewportWidth, float viewportHeight) { - currentScene.getCamera().viewportWidth = viewportWidth; - currentScene.getCamera().viewportHeight = viewportHeight; + if (currentScene != null) { + currentScene.getCamera().viewportWidth = viewportWidth; + currentScene.getCamera().viewportHeight = viewportHeight; - if (currentScene.getCameraFollowActor() != null) - currentScene.getCamera().updatePos(currentScene.getCameraFollowActor()); + if (currentScene.getCameraFollowActor() != null) + currentScene.getCamera().updatePos(currentScene.getCameraFollowActor()); - currentScene.getCamera().update(); + currentScene.getCamera().update(); + } } public void setChapter(String chapter) { @@ -623,9 +625,9 @@ public void endGame() { /** * Try to load the save game if exists. In other case, load the game from * XML. - * + * * @throws Exception - * + * * @throws IOException * @throws SAXException * @throws ParserConfigurationException @@ -647,7 +649,7 @@ public void load() throws Exception { /** * Load the world description in 'world.json'. - * + * * @throws IOException */ public void loadWorldDesc() throws IOException { diff --git a/blade-engine/src/com/bladecoder/engine/ui/BladeSkin.java b/blade-engine/src/com/bladecoder/engine/ui/BladeSkin.java index 8d872d057..478c11762 100644 --- a/blade-engine/src/com/bladecoder/engine/ui/BladeSkin.java +++ b/blade-engine/src/com/bladecoder/engine/ui/BladeSkin.java @@ -131,6 +131,7 @@ public BitmapFont read(Json json, JsonValue jsonData, @SuppressWarnings("rawtype parameter.shadowOffsetX = json.readValue("shadowOffsetX", int.class, 0, jsonData); parameter.shadowOffsetY = json.readValue("shadowOffsetY", int.class, 0, jsonData); parameter.shadowColor = json.readValue("shadowColor", Color.class, Color.BLACK, jsonData); + parameter.characters = ""; font = generator.generateFont(parameter); diff --git a/blade-engine/src/com/bladecoder/engine/ui/HelpScreen.java b/blade-engine/src/com/bladecoder/engine/ui/HelpScreen.java index e3c49b932..584b70228 100644 --- a/blade-engine/src/com/bladecoder/engine/ui/HelpScreen.java +++ b/blade-engine/src/com/bladecoder/engine/ui/HelpScreen.java @@ -28,7 +28,7 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture.TextureFilter; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.utils.viewport.ScreenViewport; +import com.badlogic.gdx.utils.viewport.FitViewport; import com.badlogic.gdx.utils.viewport.Viewport; import com.bladecoder.engine.assets.EngineAssetManager; import com.bladecoder.engine.i18n.I18N; @@ -50,7 +50,11 @@ public class HelpScreen extends ScreenAdapter implements BladeScreen { private UI ui; private String localeFilename; - private final Viewport viewport = new ScreenViewport(); + private final Viewport viewport; + + public HelpScreen() { + viewport= new FitViewport(Gdx.graphics.getWidth(), Gdx.graphics.getWidth() * 9f/16f); + } private final InputProcessor inputProcessor = new InputAdapter() { @Override @@ -89,6 +93,14 @@ public void render(float delta) { @Override public void resize(int width, int height) { + float aspect = width / height; + float bgAspect = (float)tex.getWidth() / (float)tex.getHeight(); + + if(aspect < bgAspect) + viewport.setWorldSize(width, (int)(width / bgAspect)); + else + viewport.setWorldSize((int)(height * bgAspect), height); + viewport.update(width, height, true); } diff --git a/blade-engine/src/com/bladecoder/engine/ui/MenuScreen.java b/blade-engine/src/com/bladecoder/engine/ui/MenuScreen.java index 30294df2d..9328bfb4c 100644 --- a/blade-engine/src/com/bladecoder/engine/ui/MenuScreen.java +++ b/blade-engine/src/com/bladecoder/engine/ui/MenuScreen.java @@ -19,6 +19,7 @@ import com.badlogic.gdx.Input; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.ScreenAdapter; +import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture.TextureFilter; @@ -28,7 +29,9 @@ import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.ui.Button; +import com.badlogic.gdx.scenes.scene2d.ui.Cell; import com.badlogic.gdx.scenes.scene2d.ui.Dialog; +import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; @@ -48,20 +51,23 @@ import com.bladecoder.engine.util.EngineLogger; public class MenuScreen extends ScreenAdapter implements BladeScreen { - private final static float BUTTON_PADDING = DPIUtils.UI_SPACE; +// private final static float BUTTON_PADDING = DPIUtils.UI_SPACE; private UI ui; private Stage stage; private Texture bgTexFile = null; + private Texture titleTexFile = null; private Pointer pointer; private Button credits; private Button help; private Button debug; - + private final Table menuButtonTable = new Table(); private final Table iconStackTable = new Table(); + private Music music; + public MenuScreen() { } @@ -78,8 +84,8 @@ public void render(float delta) { public void resize(int width, int height) { stage.getViewport().update(width, height, true); pointer.resize(); - - float size = DPIUtils.getPrefButtonSize(); + + float size = DPIUtils.getPrefButtonSize(); credits.setSize(size, size); help.setSize(size, size); debug.setSize(size, size); @@ -87,14 +93,28 @@ public void resize(int width, int height) { @Override public void dispose() { - stage.dispose(); - stage = null; - if (bgTexFile != null) { - bgTexFile.dispose(); - } + if (stage != null) { + + stage.dispose(); + stage = null; + + if (bgTexFile != null) { + bgTexFile.dispose(); + bgTexFile = null; + } + + if (titleTexFile != null) { + titleTexFile.dispose(); + titleTexFile = null; + } - bgTexFile = null; + if (music != null) { + music.stop(); + music.dispose(); + music = null; + } + } } @Override @@ -111,14 +131,16 @@ public void show() { // Image background = new Image(style.background); Drawable bg = style.background; + float scale = 1; + if (bg == null && style.bgFile != null) { bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile)); bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear); - - float scale = (float)bgTexFile.getHeight() / (float) stage.getViewport().getScreenHeight(); - - int width = (int)(stage.getViewport().getScreenWidth() * scale); - int x0 = (int)((bgTexFile.getWidth() - width) / 2); + + scale = (float) bgTexFile.getHeight() / (float) stage.getViewport().getScreenHeight(); + + int width = (int) (stage.getViewport().getScreenWidth() * scale); + int x0 = (bgTexFile.getWidth() - width) / 2; bg = new TextureRegionDrawable(new TextureRegion(bgTexFile, x0, 0, width, bgTexFile.getHeight())); } @@ -130,33 +152,52 @@ public void show() { menuButtonTable.addListener(new InputListener() { @Override public boolean keyUp(InputEvent event, int keycode) { - if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK) + if (keycode == Input.Keys.ESCAPE) { if (world.getCurrentScene() != null) ui.setCurrentScreen(Screens.SCENE_SCREEN); + } else if (keycode == Input.Keys.BACK) { + Gdx.app.exit(); + } return true; } }); - menuButtonTable.defaults().pad(BUTTON_PADDING).width(buttonWidth); + menuButtonTable.align(getAlign()); + menuButtonTable.pad(DPIUtils.getMarginSize() * 2); + menuButtonTable.defaults().pad(DPIUtils.getSpacing()).width(buttonWidth).align(getAlign()); +// menuButtonTable.debug(); stage.setKeyboardFocus(menuButtonTable); - if (style.showTitle) { + if (style.showTitle && style.titleStyle != null) { Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin, style.titleStyle); - - title.setAlignment(Align.center); + + title.setAlignment(getAlign()); menuButtonTable.add(title).padBottom(DPIUtils.getMarginSize() * 2); menuButtonTable.row(); } + if (style.titleFile != null) { + titleTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.titleFile)); + titleTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear); + + Image img = new Image(titleTexFile); + + menuButtonTable.add(img).width(titleTexFile.getWidth() / scale).height(titleTexFile.getHeight() / scale) + .padBottom(DPIUtils.getMarginSize() * 2); + menuButtonTable.row(); + } + if (world.savedGameExists() || world.getCurrentScene() != null) { TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle); + continueGame.getLabel().setAlignment(getAlign()); continueGame.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { if (world.getCurrentScene() == null) try { @@ -174,10 +215,13 @@ public void clicked(InputEvent event, float x, float y) { } TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle); + newGame.getLabel().setAlignment(getAlign()); newGame.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { if (world.savedGameExists()) { Dialog d = new Dialog("", skin) { + @Override protected void result(Object object) { if (((Boolean) object).booleanValue()) { try { @@ -190,31 +234,31 @@ protected void result(Object object) { } } }; - + d.pad(DPIUtils.getMarginSize()); d.getButtonTable().padTop(DPIUtils.getMarginSize()); d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize()).padRight(DPIUtils.getMarginSize()); - - Label l = new Label( I18N.getString("ui.override"), ui.getSkin(), "ui-dialog"); - l.setWrap(true); - l.setAlignment(Align.center); - d.getContentTable().add( l ).prefWidth( Gdx.graphics.getWidth() * .7f); - + Label l = new Label(I18N.getString("ui.override"), ui.getSkin(), "ui-dialog"); + l.setWrap(true); + l.setAlignment(Align.center); + + d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f); + d.button(I18N.getString("ui.yes"), true, ui.getSkin().get("ui-dialog", TextButtonStyle.class)); d.button(I18N.getString("ui.no"), false, ui.getSkin().get("ui-dialog", TextButtonStyle.class)); d.key(Keys.ENTER, true).key(Keys.ESCAPE, false); - + d.show(stage); } else { try { world.newGame(); - ui.setCurrentScreen(Screens.SCENE_SCREEN); + ui.setCurrentScreen(Screens.SCENE_SCREEN); } catch (Exception e) { EngineLogger.error("IN NEW GAME", e); Gdx.app.exit(); - } + } } } }); @@ -223,7 +267,9 @@ protected void result(Object object) { menuButtonTable.row(); TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle); + loadGame.getLabel().setAlignment(getAlign()); loadGame.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN); } @@ -233,7 +279,9 @@ public void clicked(InputEvent event, float x, float y) { menuButtonTable.row(); TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle); + quit.getLabel().setAlignment(getAlign()); quit.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { Gdx.app.exit(); } @@ -249,6 +297,7 @@ public void clicked(InputEvent event, float x, float y) { // BOTTOM-RIGHT BUTTON STACK credits = new Button(skin, "credits"); credits.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.CREDIT_SCREEN); } @@ -256,6 +305,7 @@ public void clicked(InputEvent event, float x, float y) { help = new Button(skin, "help"); help.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { ui.setCurrentScreen(Screens.HELP_SCREEN); } @@ -263,6 +313,7 @@ public void clicked(InputEvent event, float x, float y) { debug = new Button(skin, "debug"); debug.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { DebugScreen debugScr = new DebugScreen(); debugScr.setUI(ui); @@ -287,12 +338,45 @@ public void clicked(InputEvent event, float x, float y) { iconStackTable.setFillParent(true); iconStackTable.pack(); stage.addActor(iconStackTable); - - Label version = new Label("v"+ Config.getProperty(Config.VERSION_PROP, " unspecified"), skin); + + Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin); version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize()); + version.addListener(new ClickListener() { + int count = 0; + long time = System.currentTimeMillis(); + + @Override + public void clicked(InputEvent event, float x, float y) { + if (System.currentTimeMillis() - time < 500) { + count++; + } else { + count = 0; + } + + time = System.currentTimeMillis(); + + if (count == 4) { + EngineLogger.toggle(); + + if (World.getInstance().isDisposed()) + return; + + if (EngineLogger.debugMode()) { + iconStackTable.row(); + iconStackTable.add(debug); + } else { + Cell cell = iconStackTable.getCell(debug); + iconStackTable.removeActor(debug); + cell.reset(); + } + } + } + }); + stage.addActor(version); - + debug.addListener(new ClickListener() { + @Override public void clicked(InputEvent event, float x, float y) { DebugScreen debugScr = new DebugScreen(); debugScr.setUI(ui); @@ -304,24 +388,49 @@ public void clicked(InputEvent event, float x, float y) { stage.addActor(pointer); Gdx.input.setInputProcessor(stage); + + if (style.musicFile != null) { + music = Gdx.audio.newMusic(EngineAssetManager.getInstance().getAsset(style.musicFile)); + music.setLooping(true); + music.play(); + } } - + protected Table getMenuButtonTable() { return menuButtonTable; } - + protected Table getIconStackTable() { return iconStackTable; } - + protected UI getUI() { return ui; } - + protected MenuScreenStyle getStyle() { return ui.getSkin().get(MenuScreenStyle.class); } + private int getAlign() { + if (getStyle().align == null || "center".equals(getStyle().align)) + return Align.center; + + if ("top".equals(getStyle().align)) + return Align.top; + + if ("bottom".equals(getStyle().align)) + return Align.bottom; + + if ("left".equals(getStyle().align)) + return Align.left; + + if ("right".equals(getStyle().align)) + return Align.right; + + return Align.center; + } + @Override public void hide() { dispose(); @@ -330,7 +439,7 @@ public void hide() { @Override public void setUI(UI ui) { this.ui = ui; - + menuButtonTable.setFillParent(true); menuButtonTable.center(); } @@ -341,9 +450,12 @@ public static class MenuScreenStyle { public Drawable background; /** if 'bg' not specified try to load the bgFile */ public String bgFile; + public String titleFile; public String textButtonStyle; public String titleStyle; public boolean showTitle; + public String musicFile; + public String align; public MenuScreenStyle() { } @@ -351,9 +463,12 @@ public MenuScreenStyle() { public MenuScreenStyle(MenuScreenStyle style) { background = style.background; bgFile = style.bgFile; + titleFile = style.titleFile; textButtonStyle = style.textButtonStyle; showTitle = style.showTitle; titleStyle = style.titleStyle; + musicFile = style.musicFile; + align = style.align; } } } diff --git a/gradle.properties b/gradle.properties index 98ed1d84f..81bdb69f2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=1.0.3 +version=1.0.13 libgdxVersion=1.9.4 roboVMVersion=2.2.0 roboVMGradlePluginVersion=2.2.0 @@ -7,4 +7,3 @@ androidAPILevel=20 androidGradlePluginVersion=1.5.0 gwtVersion=2.6.0 gwtGradlePluginVersion=0.6 - diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index b6372cccb..e2f21c0e2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy