From 29bec36ab42a0e87e441ef8a7f3d3f7583171fb1 Mon Sep 17 00:00:00 2001 From: laplamgor Date: Thu, 2 Dec 2021 01:20:55 +0800 Subject: [PATCH 1/2] improve tilting smoothness --- .../java/com/antest1/gotobrowser/Helpers/K3dPatcher.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java b/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java index b39e520..c4b0bf6 100644 --- a/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java +++ b/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java @@ -77,7 +77,7 @@ private void decayTiltAngle() { long newTime = System.currentTimeMillis(); if (oldTime != 0) { // The angle becomes 95% after every 10ms - double decay = Math.pow(0.95f, (newTime - oldTime) / 10.0); + double decay = Math.pow(0.994359f, (newTime - oldTime) / 1.0); gyroX *= decay; gyroY *= decay; } @@ -108,7 +108,7 @@ public void pause() { public void resume() { if (isPatcherEnabled && mSensorManager != null) { - mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_GAME); + mSensorManager.registerListener(this, mGyroscope, SensorManager.SENSOR_DELAY_FASTEST); } } @@ -301,7 +301,6 @@ public static String patchKantai3d(String main_js){ stringsToReplace.put("$", ";\n" + - "setInterval(refreshGyroData, 10)\n" + "\n" + "function refreshGyroData() {\n" + " if (window.displacementFilter && window.displacementFilter.uniforms && window.displacementFilter.uniforms.offset) {\n" + @@ -313,6 +312,7 @@ public static String patchKantai3d(String main_js){ "\n" + "window.displacementFilter.apply = function(filterManager, input, output)\n" + "{\n" + + " refreshGyroData();\n" + " this.uniforms.dimensions = {};\n" + " this.uniforms.dimensions[0] = input.sourceFrame.width;\n" + " this.uniforms.dimensions[1] = input.sourceFrame.height;\n" + From ab9e6d9c739ecbef2deed793e22e20081a460545 Mon Sep 17 00:00:00 2001 From: laplamgor Date: Fri, 3 Dec 2021 15:34:34 +0800 Subject: [PATCH 2/2] add a dialog to show Kantai3D details --- .../gotobrowser/Activity/BrowserActivity.java | 11 +--- .../gotobrowser/Helpers/K3dPatcher.java | 55 ++++++++++++++++++- app/src/main/res/layout/k3d_form.xml | 44 +++++++++++++++ app/src/main/res/values-ja/strings.xml | 6 +- app/src/main/res/values-ko/strings.xml | 6 +- app/src/main/res/values-zh-rCN/strings.xml | 6 +- app/src/main/res/values-zh-rHK/strings.xml | 6 +- app/src/main/res/values-zh-rMO/strings.xml | 6 +- app/src/main/res/values-zh-rSG/strings.xml | 6 +- app/src/main/res/values-zh-rTW/strings.xml | 6 +- app/src/main/res/values/strings.xml | 7 ++- 11 files changed, 140 insertions(+), 19 deletions(-) create mode 100644 app/src/main/res/layout/k3d_form.xml diff --git a/app/src/main/java/com/antest1/gotobrowser/Activity/BrowserActivity.java b/app/src/main/java/com/antest1/gotobrowser/Activity/BrowserActivity.java index f869521..3da3a62 100644 --- a/app/src/main/java/com/antest1/gotobrowser/Activity/BrowserActivity.java +++ b/app/src/main/java/com/antest1/gotobrowser/Activity/BrowserActivity.java @@ -56,7 +56,6 @@ import static com.antest1.gotobrowser.Browser.WebViewManager.OPEN_KANCOLLE; import static com.antest1.gotobrowser.Constants.ACTION_SHOWKEYBOARD; -import static com.antest1.gotobrowser.Constants.ACTION_SHOWPANEL; import static com.antest1.gotobrowser.Constants.APP_UI_HELP_VER; import static com.antest1.gotobrowser.Constants.PREF_ADJUSTMENT; import static com.antest1.gotobrowser.Constants.PREF_CAPTURE; @@ -131,7 +130,7 @@ protected void onCreate(Bundle savedInstanceState) { mContentView = findViewById(R.id.main_browser); - mContentView.addJavascriptInterface(k3dPatcher,"gyroData"); + mContentView.addJavascriptInterface(k3dPatcher,"kantai3dInterface"); manager.setHardwardAcceleratedFlag(); @@ -186,7 +185,6 @@ protected void onCreate(Bundle savedInstanceState) { ImageView menuKantai3d = findViewById(R.id.menu_kantai3d); if (k3dPatcher.isPatcherEnabled()) { - menuKantai3d.setColorFilter(ContextCompat.getColor(getApplicationContext(), k3dPatcher.isEffectEnabled() ? R.color.colorAccent : R.color.lightGray)); menuKantai3d.setOnClickListener(this::setKantai3dMode); } else { menuKantai3d.setVisibility(View.GONE); @@ -556,12 +554,7 @@ public void onAnimationRepeat(Animation animation) { } } private void setKantai3dMode(View v) { - k3dPatcher.setEffectEnabled(!k3dPatcher.isEffectEnabled()); - if (k3dPatcher.isEffectEnabled()) { - ((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.colorAccent)); - } else { - ((ImageView) v).setColorFilter(ContextCompat.getColor(getApplicationContext(), R.color.lightGray)); - } + k3dPatcher.showDialog(); } public void showRefreshDialog() { diff --git a/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java b/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java index c4b0bf6..440f813 100644 --- a/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java +++ b/app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java @@ -7,11 +7,17 @@ import android.hardware.SensorEvent; import android.hardware.SensorEventListener; import android.hardware.SensorManager; +import android.view.View; import android.webkit.JavascriptInterface; +import android.widget.TextView; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.SwitchCompat; import com.antest1.gotobrowser.R; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -72,6 +78,21 @@ public float getY(){ return (float)gotY * sign ; } + private String imageUrl = null; + private boolean depthMapLoaded = false; + + @JavascriptInterface + public void notifyError(String newImageUrl){ + imageUrl = newImageUrl; + depthMapLoaded = false; + } + + @JavascriptInterface + public void notifyLoaded(String newImageUrl){ + imageUrl = newImageUrl; + depthMapLoaded = true; + } + private void decayTiltAngle() { // Slowly rebound the tile angle until it becomes centre long newTime = System.currentTimeMillis(); @@ -147,6 +168,31 @@ public void onSensorChanged(SensorEvent sensorEvent) { public void onAccuracyChanged(Sensor sensor, int accuracy) { } + public void showDialog() { + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + View dialogView = activity.getLayoutInflater().inflate(R.layout.k3d_form, null); + + if (imageUrl != null) { + final TextView textView = dialogView.findViewById(R.id.kantai3d_msg_text); + textView.setText(String.format(Locale.US, activity.getString(depthMapLoaded ? + R.string.msg_kantai3d_loaded : R.string.msg_kantai3d_error), imageUrl)); + } + + final SwitchCompat switchCompat = dialogView.findViewById(R.id.switch_3d); + switchCompat.setChecked(isEffectEnabled()); + + builder.setView(dialogView); + builder.setPositiveButton(R.string.text_save, (dialog, which) -> { + // Make the change effective + setEffectEnabled(switchCompat.isChecked()); + dialog.dismiss(); + }); + + builder.setNegativeButton(R.string.text_cancel, (dialog, which) -> dialog.cancel()); + AlertDialog dialog = builder.create(); + dialog.show(); + } + public static String patchKantai3d(String main_js){ if (!isPatcherEnabled) { return main_js; @@ -187,6 +233,7 @@ public static String patchKantai3d(String main_js){ "window.currentChara = this._chara;\n" + "\n" + "if (window.displacementSprite.width != 1) {\n" + + " window.kantai3dInterface.notifyLoaded(window.displacementPath.replace(/resources\\\\/ship\\\\/full[_dmg]*\\\\/([0-9]*)_([0-9_a-z]*).png(\\\\?version=)?([0-9]*)/g, \"\\$1_\\$2_v\\$4\\.png\"));\n" + " // The depth map is already loaded\n" + " window.displacementFilter.uniforms.displacementMap = window.displacementSprite.texture;\n" + " window.displacementFilter.uniforms.scale = 1.0;\n" + @@ -204,6 +251,7 @@ public static String patchKantai3d(String main_js){ " // Disable the filter first\n" + " window.currentChara.filters = [];\n" + " window.displacementSprite.texture.baseTexture.on('loaded', function(){\n" + + " window.kantai3dInterface.notifyLoaded(window.displacementPath.replace(/resources\\\\/ship\\\\/full[_dmg]*\\\\/([0-9]*)_([0-9_a-z]*).png(\\\\?version=)?([0-9]*)/g, \"\\$1_\\$2_v\\$4\\.png\"));\n" + " // Re-enable the filter when resource loaded\n" + " window.displacementFilter.uniforms.displacementMap = window.displacementSprite.texture;\n" + " window.displacementFilter.uniforms.scale = 1.0;\n" + @@ -217,6 +265,9 @@ public static String patchKantai3d(String main_js){ " prepareJiggle(window.currentChara.texture, window.displacementSprite.texture);\n" + " window.displacementFilter.uniforms.displacementMap = window.jiggledDepthMapRT.texture;\n" + " });\n" + + " window.displacementSprite.texture.baseTexture.on('error', function(){\n" + + " window.kantai3dInterface.notifyError(window.displacementPath.replace(/resources\\\\/ship\\\\/full[_dmg]*\\\\/([0-9]*)_([0-9_a-z]*).png(\\\\?version=)?([0-9]*)/g, \"\\$1_\\$2_v\\$4\\.png\"));\n" + + " })" + "}" + "///////////////////////////////////\n" + @@ -304,8 +355,8 @@ public static String patchKantai3d(String main_js){ "\n" + "function refreshGyroData() {\n" + " if (window.displacementFilter && window.displacementFilter.uniforms && window.displacementFilter.uniforms.offset) {\n" + - " window.displacementFilter.uniforms.offset[0] = window.gyroData.getX();\n" + - " window.displacementFilter.uniforms.offset[1] = window.gyroData.getY();\n" + + " window.displacementFilter.uniforms.offset[0] = window.kantai3dInterface.getX();\n" + + " window.displacementFilter.uniforms.offset[1] = window.kantai3dInterface.getY();\n" + " }" + "}" + "window.displacementFilter = new PIXI.Filter(null, `" + frag + "`);\n" + diff --git a/app/src/main/res/layout/k3d_form.xml b/app/src/main/res/layout/k3d_form.xml new file mode 100644 index 0000000..6a43388 --- /dev/null +++ b/app/src/main/res/layout/k3d_form.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 9513114..830fdd5 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -67,13 +67,17 @@ ログアウト 非公式のMOD(自己責任で使ってください) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 一部の秘書艦に3Dのような視覚効果とおける乳揺れを追加します。作者:@laplamgor About Kantai3D 60FPS制限を削除します 高リフレッシュ・レート対応。ゲームの速度は影響を受けません。 キャッシングに外部ストレージを使用 3D効果 + 秘書艦は発見されなかった + 現在の秘書艦CGの深度マップをダウンロードしました: %s + 現在の秘書艦CGの深度マップが見つからない: %s + 3D対応のCGリストをすべて表示したり、新しい深さマップに貢献したりするには: https://github.com/laplamgor/kantai3d « 外側をクリックしてパネルを開く » \ No newline at end of file diff --git a/app/src/main/res/values-ko/strings.xml b/app/src/main/res/values-ko/strings.xml index 27c7490..40be72a 100644 --- a/app/src/main/res/values-ko/strings.xml +++ b/app/src/main/res/values-ko/strings.xml @@ -68,13 +68,17 @@ 로그아웃 서드파티 모드 (자기 책임하에 사용하세요) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 일부 비서함에 3D 효과 적용. 저자: @laplamgor About Kantai3D 60FPS 제한 제거 더 높은 화면 재생 빈도 장치를 지원합니다. 애니메이션 속도는 영향을 받지 않습니다. 리소스 캐싱 시 외부 저장소 사용 3D 적용 + 비서함에 미정찰 + 현재 비서함 CG의 깊이도를 불러왔습니다: %s + 현재 비서함 CG의 깊이도를 찾을 수 없습니다: %s + 3D를 지원하는 모든 CG 목록을 보거나 새 심도 그래프를 제출하려면 여기로 이동합니다: https://github.com/laplamgor/kantai3d « 게임 화면 외의 공간을 눌러 패널을 여세요 » \ No newline at end of file diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 66a045c..acc964c 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -66,13 +66,17 @@ 注销 第三方MOD(自担风险) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 为部份秘书舰添加仿立体的视觉效果及胸部物理。作者:@laplamgor About Kantai3D 移除60帧限制 支持高刷新率手机。游戏速度不会受影响。 使用外部存储进行缓存 开关立体效果 + 未检测到秘书舰 + 已加载当前秘书舰CG的深度图: %s + 未发现当前秘书舰CG的深度图: %s + 欲查看所有支持 3D 的 CG 列表,或贡献新的深度图,请访问: https://github.com/laplamgor/kantai3d « 点击外侧任意位置以打开面板 » diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index ebf60f0..fedf16f 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -66,13 +66,17 @@ 登出 第三方MOD(風險自負) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 為部份秘書艦添加仿立體的視覺效果及胸部物理。作者:@laplamgor About Kantai3D 移除60幀限制 支持高刷新率手機。遊戲速度不會受影響。 使用外部存儲存放快取 開關立體效果 + 未偵察到秘書艦 + 已載入目前秘書艦CG的深度圖: %s + 找不到目前秘書艦CG的深度圖: %s + 欲查看所有支持 3D 的 CG 列表,或貢獻新的深度圖,請前往: https://github.com/laplamgor/kantai3d « 點擊外側任意位置以打開面板 » diff --git a/app/src/main/res/values-zh-rMO/strings.xml b/app/src/main/res/values-zh-rMO/strings.xml index ebf60f0..fedf16f 100644 --- a/app/src/main/res/values-zh-rMO/strings.xml +++ b/app/src/main/res/values-zh-rMO/strings.xml @@ -66,13 +66,17 @@ 登出 第三方MOD(風險自負) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 為部份秘書艦添加仿立體的視覺效果及胸部物理。作者:@laplamgor About Kantai3D 移除60幀限制 支持高刷新率手機。遊戲速度不會受影響。 使用外部存儲存放快取 開關立體效果 + 未偵察到秘書艦 + 已載入目前秘書艦CG的深度圖: %s + 找不到目前秘書艦CG的深度圖: %s + 欲查看所有支持 3D 的 CG 列表,或貢獻新的深度圖,請前往: https://github.com/laplamgor/kantai3d « 點擊外側任意位置以打開面板 » diff --git a/app/src/main/res/values-zh-rSG/strings.xml b/app/src/main/res/values-zh-rSG/strings.xml index 66a045c..acc964c 100644 --- a/app/src/main/res/values-zh-rSG/strings.xml +++ b/app/src/main/res/values-zh-rSG/strings.xml @@ -66,13 +66,17 @@ 注销 第三方MOD(自担风险) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 为部份秘书舰添加仿立体的视觉效果及胸部物理。作者:@laplamgor About Kantai3D 移除60帧限制 支持高刷新率手机。游戏速度不会受影响。 使用外部存储进行缓存 开关立体效果 + 未检测到秘书舰 + 已加载当前秘书舰CG的深度图: %s + 未发现当前秘书舰CG的深度图: %s + 欲查看所有支持 3D 的 CG 列表,或贡献新的深度图,请访问: https://github.com/laplamgor/kantai3d « 点击外侧任意位置以打开面板 » diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index a549de2..8ae228b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -66,13 +66,17 @@ 登出 第三方MOD(風險自負) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 為部份秘書艦添加仿立體的視覺效果及胸部物理。作者:@laplamgor About Kantai3D 移除60幀限制 支持高刷新率手機。遊戲速度不會受影響。 使用外部存儲存放緩存 開關立體效果 + 未偵察到秘書艦 + 已載入目前秘書艦CG的深度圖: %s + 找不到目前秘書艦CG的深度圖: %s + 欲查看所有支持 3D 的 CG 列表,或貢獻新的深度圖,請前往: https://github.com/laplamgor/kantai3d « 點擊外側任意位置以打開面板 » diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index aa1def5..951034e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -77,13 +77,18 @@ Logout Third Party Mods (use at your own risk) - [Beta] Kantai3D v2.0 + [Beta] Kantai3D v2.1 Add 3D-like visual effects and jiggle physics to some of your secretaries. Author: @laplamgor About Kantai3D Remove 60 FPS limit Support higher refresh rate devices. Animation speed is not affected. Use External Storage for Resource Caching Toggle 3D effects + No secretary detected + The depth map of the current secretary CG is loaded: %s + The depth map of the current secretary CG is unavailable: %s + To see the list of all 3D-supported CG, or contribute new depth maps, please visit: https://github.com/laplamgor/kantai3d + « click any outside area to open the panel »