v0.9.4: switched from spaces to tabs in new iOS code

This commit is contained in:
Evan Debenham 2021-07-08 14:36:59 -04:00
parent 5ad6594786
commit 603f91d10f
2 changed files with 159 additions and 158 deletions

View File

@ -22,82 +22,83 @@ import org.robovm.apple.glkit.GLKViewDrawableDepthFormat;
import org.robovm.apple.uikit.UIApplication;
public class IOSLauncher extends IOSApplication.Delegate {
@Override
protected IOSApplication createApplication() {
@Override
protected IOSApplication createApplication() {
//ensures the app actually crashes if there's an error in the mobiVM runtime
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
new NSException(ex.getClass().getName(), ex.getMessage(), new NSDictionary()).raise();
}
});
//ensures the app actually crashes if there's an error in the mobiVM runtime
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread thread, Throwable ex) {
new NSException(ex.getClass().getName(), ex.getMessage(), new NSDictionary()).raise();
}
});
try {
Game.version = NSBundle.getMainBundle().getInfoDictionaryObject("CFBundleVersionString").toString();
} catch (Exception e) {
Game.version = "???";
}
try {
Game.versionCode = Integer.parseInt(NSBundle.getMainBundle().getInfoDictionaryObject("CFBundleVersion").toString());
} catch (Exception e) {
Game.versionCode = 0;
}
try {
Game.version = NSBundle.getMainBundle().getInfoDictionaryObject("CFBundleVersionString").toString();
} catch (Exception e) {
Game.version = "???";
}
try {
Game.versionCode = Integer.parseInt(NSBundle.getMainBundle().getInfoDictionaryObject("CFBundleVersion").toString());
} catch (Exception e) {
Game.versionCode = 0;
}
if (UpdateImpl.supportsUpdates()) {
Updates.service = UpdateImpl.getUpdateService();
}
if (NewsImpl.supportsNews()) {
News.service = NewsImpl.getNewsService();
}
FileUtils.setDefaultFileProperties(Files.FileType.Local, "");
if (UpdateImpl.supportsUpdates()) {
Updates.service = UpdateImpl.getUpdateService();
}
if (NewsImpl.supportsNews()) {
News.service = NewsImpl.getNewsService();
}
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
FileUtils.setDefaultFileProperties(Files.FileType.Local, "");
config.colorFormat = GLKViewDrawableColorFormat.RGBA8888;
config.depthFormat = GLKViewDrawableDepthFormat.None;
config.hdpiMode = HdpiMode.Pixels;
IOSApplicationConfiguration config = new IOSApplicationConfiguration();
CGRect statusBarFrame = UIApplication.getSharedApplication().getStatusBarFrame();
double statusBarHeight = Math.min(statusBarFrame.getWidth(), statusBarFrame.getHeight());
config.colorFormat = GLKViewDrawableColorFormat.RGBA8888;
config.depthFormat = GLKViewDrawableDepthFormat.None;
config.hdpiMode = HdpiMode.Pixels;
//if the application has a short status bar (no notch), then hide it
//TODO we do this check elsewhere now, can this be removed?
if (statusBarHeight <= 24) {
UIApplication.getSharedApplication().setStatusBarHidden(true);
}
CGRect statusBarFrame = UIApplication.getSharedApplication().getStatusBarFrame();
double statusBarHeight = Math.min(statusBarFrame.getWidth(), statusBarFrame.getHeight());
config.useAccelerometer = false;
config.useCompass = false;
//devices not currently listed in LibGDX's IOSDevice class
config.addIosDevice("IPHONE_12_MINI", "iPhone13,1", 476);
config.addIosDevice("IPHONE_12", "iPhone13,2", 460);
config.addIosDevice("IPHONE_12_PRO", "iPhone13,3", 460);
config.addIosDevice("IPHONE_12_PRO_MAX", "iPhone13,4", 458);
//if the application has a short status bar (no notch), then hide it
//TODO we do this check elsewhere now, can this be removed?
if (statusBarHeight <= 24) {
UIApplication.getSharedApplication().setStatusBarHidden(true);
}
config.addIosDevice("IPAD_7G_WIFI", "iPad7,11", 264);
config.addIosDevice("IPAD_7G_WIFI_CELLULAR", "iPad7,12", 264);
config.useAccelerometer = false;
config.useCompass = false;
config.addIosDevice("IPAD_8G_WIFI", "iPad11,6", 264);
config.addIosDevice("IPAD_8G_WIFI_CELLULAR", "iPad11,7", 264);
config.addIosDevice("IPAD_AIR_4G_WIFI", "iPad13,1", 264);
config.addIosDevice("IPAD_AIR_4G_WIFI_CELLULAR", "iPad13,2", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,4", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,5", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,6", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,7", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,8", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,9", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,10", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,11", 264);
//devices not currently listed in LibGDX's IOSDevice class
config.addIosDevice("IPHONE_12_MINI", "iPhone13,1", 476);
config.addIosDevice("IPHONE_12", "iPhone13,2", 460);
config.addIosDevice("IPHONE_12_PRO", "iPhone13,3", 460);
config.addIosDevice("IPHONE_12_PRO_MAX", "iPhone13,4", 458);
return new IOSApplication(new ShatteredPixelDungeon(new IOSPlatformSupport()), config);
}
config.addIosDevice("IPAD_7G_WIFI", "iPad7,11", 264);
config.addIosDevice("IPAD_7G_WIFI_CELLULAR", "iPad7,12", 264);
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
config.addIosDevice("IPAD_8G_WIFI", "iPad11,6", 264);
config.addIosDevice("IPAD_8G_WIFI_CELLULAR", "iPad11,7", 264);
config.addIosDevice("IPAD_AIR_4G_WIFI", "iPad13,1", 264);
config.addIosDevice("IPAD_AIR_4G_WIFI_CELLULAR", "iPad13,2", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,4", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,5", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,6", 264);
config.addIosDevice("IPAD_PRO_11_3G", "iPad13,7", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,8", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,9", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,10", 264);
config.addIosDevice("IPAD_PRO_12.8_5G", "iPad13,11", 264);
return new IOSApplication(new ShatteredPixelDungeon(new IOSPlatformSupport()), config);
}
public static void main(String[] argv) {
NSAutoreleasePool pool = new NSAutoreleasePool();
UIApplication.main(argv, null, IOSLauncher.class);
pool.close();
}
}

View File

@ -21,113 +21,113 @@ import java.util.HashMap;
import java.util.regex.Pattern;
public class IOSPlatformSupport extends PlatformSupport {
@Override
public void updateDisplaySize() {
//non-zero safe insets on left/top/right means device has a notch, show status bar
if (Gdx.graphics.getSafeInsetTop() != 0
|| Gdx.graphics.getSafeInsetLeft() != 0
|| Gdx.graphics.getSafeInsetRight() != 0){
UIApplication.getSharedApplication().setStatusBarHidden(false);
} else {
UIApplication.getSharedApplication().setStatusBarHidden(true);
}
@Override
public void updateDisplaySize() {
//non-zero safe insets on left/top/right means device has a notch, show status bar
if (Gdx.graphics.getSafeInsetTop() != 0
|| Gdx.graphics.getSafeInsetLeft() != 0
|| Gdx.graphics.getSafeInsetRight() != 0){
UIApplication.getSharedApplication().setStatusBarHidden(false);
} else {
UIApplication.getSharedApplication().setStatusBarHidden(true);
}
if (!SPDSettings.fullscreen()) {
Game.bottomInset = Gdx.graphics.getSafeInsetBottom();
Game.height -= Game.bottomInset;
Game.dispHeight = Game.height;
} else {
Game.height += Game.bottomInset;
Game.dispHeight = Game.height;
Game.bottomInset = 0;
}
Gdx.gl.glViewport(0, Game.bottomInset, Game.width, Game.height);
}
if (!SPDSettings.fullscreen()) {
Game.bottomInset = Gdx.graphics.getSafeInsetBottom();
Game.height -= Game.bottomInset;
Game.dispHeight = Game.height;
} else {
Game.height += Game.bottomInset;
Game.dispHeight = Game.height;
Game.bottomInset = 0;
}
Gdx.gl.glViewport(0, Game.bottomInset, Game.width, Game.height);
}
@Override
public void updateSystemUI() {
updateDisplaySize();
ShatteredPixelDungeon.seamlessResetScene();
}
@Override
public void updateSystemUI() {
updateDisplaySize();
ShatteredPixelDungeon.seamlessResetScene();
}
@Override
public boolean connectedToUnmeteredNetwork() {
SCNetworkReachability test = new SCNetworkReachability("www.apple.com");
return !test.getFlags().contains(SCNetworkReachabilityFlags.IsWWAN);
}
@Override
public boolean connectedToUnmeteredNetwork() {
SCNetworkReachability test = new SCNetworkReachability("www.apple.com");
return !test.getFlags().contains(SCNetworkReachabilityFlags.IsWWAN);
}
public void vibrate( int millis ){
//gives a short vibrate on iPhone 6+, no vibration otherwise
AudioServices.playSystemSound(1520);
}
public void vibrate( int millis ){
//gives a short vibrate on iPhone 6+, no vibration otherwise
AudioServices.playSystemSound(1520);
}
/* FONT SUPPORT */
/* FONT SUPPORT */
//custom pixel font, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator basicFontGenerator;
//droid sans fallback, for asian fonts
private static FreeTypeFontGenerator asianFontGenerator;
//custom pixel font, for use with Latin and Cyrillic languages
private static FreeTypeFontGenerator basicFontGenerator;
//droid sans fallback, for asian fonts
private static FreeTypeFontGenerator asianFontGenerator;
@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
//don't bother doing anything if nothing has changed
if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont){
return;
}
this.pageSize = pageSize;
this.systemfont = systemfont;
@Override
public void setupFontGenerators(int pageSize, boolean systemfont) {
//don't bother doing anything if nothing has changed
if (fonts != null && this.pageSize == pageSize && this.systemfont == systemfont){
return;
}
this.pageSize = pageSize;
this.systemfont = systemfont;
resetGenerators(false);
fonts = new HashMap<>();
resetGenerators(false);
fonts = new HashMap<>();
if (systemfont) {
basicFontGenerator = asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
} else {
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/pixel_font.ttf"));
asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
}
if (systemfont) {
basicFontGenerator = asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
} else {
basicFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/pixel_font.ttf"));
asianFontGenerator = new FreeTypeFontGenerator(Gdx.files.internal("fonts/droid_sans.ttf"));
}
fonts.put(basicFontGenerator, new HashMap<>());
fonts.put(asianFontGenerator, new HashMap<>());
fonts.put(basicFontGenerator, new HashMap<>());
fonts.put(asianFontGenerator, new HashMap<>());
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
packer = new PixmapPacker(pageSize, pageSize, Pixmap.Format.RGBA8888, 1, false);
}
private static Pattern asianMatcher = Pattern.compile("\\p{InHangul_Syllables}|" +
"\\p{InCJK_Unified_Ideographs}|\\p{InCJK_Symbols_and_Punctuation}|\\p{InHalfwidth_and_Fullwidth_Forms}|" +
"\\p{InHiragana}|\\p{InKatakana}");
private static Pattern asianMatcher = Pattern.compile("\\p{InHangul_Syllables}|" +
"\\p{InCJK_Unified_Ideographs}|\\p{InCJK_Symbols_and_Punctuation}|\\p{InHalfwidth_and_Fullwidth_Forms}|" +
"\\p{InHiragana}|\\p{InKatakana}");
@Override
protected FreeTypeFontGenerator getGeneratorForString( String input ){
if (asianMatcher.matcher(input).find()){
return asianFontGenerator;
} else {
return basicFontGenerator;
}
}
@Override
protected FreeTypeFontGenerator getGeneratorForString( String input ){
if (asianMatcher.matcher(input).find()){
return asianFontGenerator;
} else {
return basicFontGenerator;
}
}
//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})");
//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})");
//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);
}
}
@Override
public String[] splitforTextBlock(String text, boolean multiline) {
if (multiline) {
return regularsplitterMultiline.split(text);
} else {
return regularsplitter.split(text);
}
}
}