forked from Meel703/elemental-pixel-dungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
v0.7.5e: implemented a very basic first desktop module and launcher
- Loading branch information
Showing
6 changed files
with
287 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2019 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
apply plugin: "java" | ||
|
||
sourceSets.main.java.srcDirs = [ "src/" ] | ||
|
||
project.ext.mainClassName = "com.shatteredpixel.shatteredpixeldungeon.desktop.DesktopLauncher" | ||
project.ext.assetsDir = new File("../android/src/main/assets") | ||
|
||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8' | ||
|
||
task run(dependsOn: classes, type: JavaExec) { | ||
main = project.mainClassName | ||
classpath = sourceSets.main.runtimeClasspath | ||
workingDir = project.assetsDir | ||
ignoreExitValue = true | ||
} | ||
|
||
//TODO add dist task to generate a .JAR | ||
|
||
dependencies { | ||
implementation project(':core') | ||
|
||
implementation "com.badlogicgames.gdx:gdx-freetype:$gdxVersion" | ||
implementation "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion" | ||
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop" | ||
implementation "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop" | ||
} |
76 changes: 76 additions & 0 deletions
76
desktop/src/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopLauncher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2019 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package com.shatteredpixel.shatteredpixeldungeon.desktop; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.backends.lwjgl.LwjglApplication; | ||
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; | ||
import com.shatteredpixel.shatteredpixeldungeon.ShatteredPixelDungeon; | ||
import com.watabou.noosa.Game; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
||
import javax.swing.JOptionPane; | ||
|
||
public class DesktopLauncher { | ||
public static void main (String[] arg) { | ||
|
||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { | ||
@Override | ||
public void uncaughtException(Thread thread, Throwable throwable) { | ||
StringWriter sw = new StringWriter(); | ||
PrintWriter pw = new PrintWriter(sw); | ||
throwable.printStackTrace(pw); | ||
pw.flush(); | ||
JOptionPane.showMessageDialog(null, "Shattered Pixel Dungeon has crashed! Sorry about that!\n\n" + | ||
"If you could, please email this error message to me and I'll get it fixed (Evan@ShatteredPixel.com):\n\n" + | ||
sw.toString()); | ||
Gdx.app.exit(); | ||
} | ||
}); | ||
|
||
String version = DesktopLauncher.class.getPackage().getSpecificationVersion(); | ||
if (version == null) { | ||
Game.version = "0.7.5d"; | ||
} | ||
|
||
try { | ||
Game.versionCode = Integer.parseInt(DesktopLauncher.class.getPackage().getImplementationVersion()); | ||
} catch (NumberFormatException e) { | ||
Game.versionCode = 372; | ||
} | ||
|
||
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); | ||
|
||
config.width = 1920; | ||
config.height = 1080; | ||
|
||
//uncapped (but vsynced) framerate when focused, paused when not focused | ||
config.foregroundFPS = 0; | ||
config.backgroundFPS = -1; | ||
|
||
config.title = "Shattered Pixel Dungeon"; | ||
|
||
new LwjglApplication(new ShatteredPixelDungeon(new DesktopPlatformSupport()), config); | ||
} | ||
} |
155 changes: 155 additions & 0 deletions
155
desktop/src/com/shatteredpixel/shatteredpixeldungeon/desktop/DesktopPlatformSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Pixel Dungeon | ||
* Copyright (C) 2012-2015 Oleg Dolya | ||
* | ||
* Shattered Pixel Dungeon | ||
* Copyright (C) 2014-2019 Evan Debenham | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
*/ | ||
|
||
package com.shatteredpixel.shatteredpixeldungeon.desktop; | ||
|
||
import com.badlogic.gdx.Gdx; | ||
import com.badlogic.gdx.graphics.Pixmap; | ||
import com.badlogic.gdx.graphics.g2d.BitmapFont; | ||
import com.badlogic.gdx.graphics.g2d.PixmapPacker; | ||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator; | ||
import com.watabou.utils.PlatformSupport; | ||
|
||
import java.util.HashMap; | ||
import java.util.regex.Pattern; | ||
|
||
public class DesktopPlatformSupport extends PlatformSupport { | ||
|
||
@Override | ||
public void updateDisplaySize() { | ||
|
||
} | ||
|
||
@Override | ||
public void updateSystemUI() { | ||
|
||
} | ||
|
||
@Override | ||
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, TextCallback callback) { | ||
|
||
} | ||
|
||
private int pageSize; | ||
private PixmapPacker packer; | ||
private boolean systemfont; | ||
|
||
//droid sans / roboto, or a custom pixel font, for use with Latin and Cyrillic languages | ||
private static FreeTypeFontGenerator basicFontGenerator; | ||
private static HashMap<Integer, BitmapFont> basicFonts = new HashMap<>(); | ||
|
||
@Override | ||
public void setupFontGenerators(int pageSize, boolean systemfont) { | ||
if (basicFontGenerator != null && this.pageSize == pageSize && this.systemfont == systemfont){ | ||
return; | ||
} | ||
this.pageSize = pageSize; | ||
this.systemfont = systemfont; | ||
|
||
if (basicFontGenerator != null){ | ||
for (BitmapFont f : basicFonts.values()){ | ||
f.dispose(); | ||
} | ||
basicFonts.clear(); | ||
basicFontGenerator.dispose(); | ||
if (packer != null){ | ||
for (PixmapPacker.Page p : packer.getPages()){ | ||
p.getTexture().dispose(); | ||
} | ||
packer.dispose(); | ||
} | ||
} | ||
|
||
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("pixel_font.ttf")); | ||
|
||
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false); | ||
} | ||
|
||
@Override | ||
public void resetGenerators() { | ||
if (basicFontGenerator != null) { | ||
for (BitmapFont f : basicFonts.values()) { | ||
f.dispose(); | ||
} | ||
basicFonts.clear(); | ||
basicFontGenerator.dispose(); | ||
|
||
if (packer != null) { | ||
for (PixmapPacker.Page p : packer.getPages()) { | ||
p.getTexture().dispose(); | ||
} | ||
packer.dispose(); | ||
} | ||
} | ||
basicFontGenerator = null; | ||
setupFontGenerators(pageSize, systemfont); | ||
} | ||
|
||
@Override | ||
public BitmapFont getFont(int size, String text) { | ||
FreeTypeFontGenerator generator = basicFontGenerator; | ||
|
||
if (!basicFonts.containsKey(size)) { | ||
FreeTypeFontGenerator.FreeTypeFontParameter parameters = new FreeTypeFontGenerator.FreeTypeFontParameter(); | ||
parameters.size = size; | ||
parameters.flip = true; | ||
parameters.borderWidth = parameters.size / 10f; | ||
parameters.renderCount = 3; | ||
parameters.hinting = FreeTypeFontGenerator.Hinting.None; | ||
parameters.spaceX = -(int) parameters.borderWidth; | ||
parameters.incremental = true; | ||
parameters.characters = ""; | ||
parameters.packer = packer; | ||
|
||
BitmapFont font = generator.generateFont(parameters); | ||
font.getData().missingGlyph = font.getData().getGlyph('�'); | ||
basicFonts.put(size, font); | ||
} | ||
|
||
return basicFonts.get(size); | ||
} | ||
|
||
//splits on newlines, underscores, and chinese/japaneses characters | ||
private Pattern regularsplitter = Pattern.compile( | ||
"(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + | ||
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + | ||
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + | ||
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + | ||
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})"); | ||
|
||
//additionally splits on words, so that each word can be arranged individually | ||
private Pattern regularsplitterMultiline = Pattern.compile( | ||
"(?<= )|(?= )|(?<=\n)|(?=\n)|(?<=_)|(?=_)|" + | ||
"(?<=\\p{InHiragana})|(?=\\p{InHiragana})|" + | ||
"(?<=\\p{InKatakana})|(?=\\p{InKatakana})|" + | ||
"(?<=\\p{InCJK_Unified_Ideographs})|(?=\\p{InCJK_Unified_Ideographs})|" + | ||
"(?<=\\p{InCJK_Symbols_and_Punctuation})|(?=\\p{InCJK_Symbols_and_Punctuation})"); | ||
|
||
@Override | ||
public String[] splitforTextBlock(String text, boolean multiline) { | ||
if (multiline) { | ||
return regularsplitterMultiline.split(text); | ||
} else { | ||
return regularsplitter.split(text); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':core', ':SPD-classes', ':android' | ||
include ':core', ':SPD-classes', ':android', ':desktop' |