Skip to content

Commit

Permalink
Merge pull request #68 from antest1/feature/kantai3d_2.1
Browse files Browse the repository at this point in the history
Kantai3D v2.1
  • Loading branch information
antest1 authored Dec 3, 2021
2 parents 3e18b60 + ab9e6d9 commit 5502f9a
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected void onCreate(Bundle savedInstanceState) {

mContentView = findViewById(R.id.main_browser);

mContentView.addJavascriptInterface(k3dPatcher,"gyroData");
mContentView.addJavascriptInterface(k3dPatcher,"kantai3dInterface");


manager.setHardwareAcceleratedFlag();
Expand Down Expand Up @@ -185,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);
Expand Down Expand Up @@ -555,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() {
Expand Down
61 changes: 56 additions & 5 deletions app/src/main/java/com/antest1/gotobrowser/Helpers/K3dPatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -73,12 +79,27 @@ 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();
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;
}
Expand Down Expand Up @@ -112,7 +133,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);
}
}

Expand Down Expand Up @@ -151,6 +172,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;
Expand Down Expand Up @@ -191,6 +237,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" +
Expand All @@ -208,6 +255,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" +
Expand All @@ -221,6 +269,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" +
Expand Down Expand Up @@ -305,18 +356,18 @@ 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" +
" 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" +
"\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" +
Expand Down
44 changes: 44 additions & 0 deletions app/src/main/res/layout/k3d_form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="12dp">

<TextView
android:id="@+id/kantai3d_msg_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="email"
android:linksClickable="true"
android:text="@string/msg_kantai3d_init"
android:textAlignment="center"
android:padding="12dp"/>

<androidx.appcompat.widget.SwitchCompat
android:id="@+id/switch_3d"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/menu_tooltip_kantai3d" />

<TextView
android:id="@+id/kantai3d_redirect_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:text="@string/msg_kantai3d_redirect"
android:padding="12dp"/>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>

</LinearLayout>
6 changes: 5 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@
<string name="settings_legacy_renderer_enable">レガシーレンダラを使用する</string>

<string name="settings_mod_label">非公式のMOD(自己責任で使ってください)</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.0</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.1</string>
<string name="settings_mod_kantai3d_summary">一部の秘書艦に3Dのような視覚効果とおける乳揺れを追加します。作者:@laplamgor</string>
<string name="settings_mod_kantai3d_about">About Kantai3D</string>
<string name="settings_mod_fps_enable">60FPS制限を削除します</string>
<string name="settings_mod_fps_summary">高リフレッシュ・レート対応。ゲームの速度は影響を受けません。</string>
<string name="settings_use_external_dir">キャッシングに外部ストレージを使用</string>
<string name="menu_tooltip_kantai3d">3D効果</string>
<string name="msg_kantai3d_init">秘書艦は発見されなかった</string>
<string name="msg_kantai3d_loaded">現在の秘書艦CGの深度マップをダウンロードしました: %s</string>
<string name="msg_kantai3d_error">現在の秘書艦CGの深度マップが見つからない: %s</string>
<string name="msg_kantai3d_redirect">3D対応のCGリストをすべて表示したり、新しい深さマップに貢献したりするには: https://github.com/laplamgor/kantai3d</string>

<string name="browser_ui_hint_text">« 外側をクリックしてパネルを開く »</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@
<string name="settings_legacy_renderer_enable">레거시 렌더러 사용</string>

<string name="settings_mod_label">서드파티 모드 (자기 책임하에 사용하세요)</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.0</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.1</string>
<string name="settings_mod_kantai3d_summary">일부 비서함에 3D 효과 적용. 저자: @laplamgor</string>
<string name="settings_mod_kantai3d_about">About Kantai3D</string>
<string name="settings_mod_fps_enable">60FPS 제한 제거</string>
<string name="settings_mod_fps_summary">더 높은 화면 재생 빈도 장치를 지원합니다. 애니메이션 속도는 영향을 받지 않습니다.</string>
<string name="settings_use_external_dir">리소스 캐싱 시 외부 저장소 사용</string>
<string name="menu_tooltip_kantai3d">3D 적용</string>
<string name="msg_kantai3d_init">비서함에 미정찰</string>
<string name="msg_kantai3d_loaded">현재 비서함 CG의 깊이도를 불러왔습니다: %s</string>
<string name="msg_kantai3d_error">현재 비서함 CG의 깊이도를 찾을 수 없습니다: %s</string>
<string name="msg_kantai3d_redirect">3D를 지원하는 모든 CG 목록을 보거나 새 심도 그래프를 제출하려면 여기로 이동합니다: https://github.com/laplamgor/kantai3d</string>

<string name="browser_ui_hint_text">« 게임 화면 외의 공간을 눌러 패널을 여세요 »</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@
<string name="settings_legacy_renderer_summary">强制PixiJS引擎使用Canvas渲染器而非WebGL渲染器。可解决大部份图形奇怪错误但会降低效能。</string>

<string name="settings_mod_label">第三方MOD(自担风险)</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.0</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.1</string>
<string name="settings_mod_kantai3d_summary">为部份秘书舰添加仿立体的视觉效果及胸部物理。作者:@laplamgor</string>
<string name="settings_mod_kantai3d_about">About Kantai3D</string>
<string name="settings_mod_fps_enable">移除60帧限制</string>
<string name="settings_mod_fps_summary">支持高刷新率手机。游戏速度不会受影响。</string>
<string name="settings_use_external_dir">使用外部存储进行缓存</string>
<string name="menu_tooltip_kantai3d">开关立体效果</string>
<string name="msg_kantai3d_init">未检测到秘书舰</string>
<string name="msg_kantai3d_loaded">已加载当前秘书舰CG的深度图: %s</string>
<string name="msg_kantai3d_error">未发现当前秘书舰CG的深度图: %s</string>
<string name="msg_kantai3d_redirect">欲查看所有支持 3D 的 CG 列表,或贡献新的深度图,请访问: https://github.com/laplamgor/kantai3d</string>

<string name="browser_ui_hint_text">« 点击外侧任意位置以打开面板 »</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@
<string name="settings_legacy_renderer_summary">強制PixiJS引擎使用Canvas渲染器而非WebGL渲染器。可解決大部份圖形奇怪錯誤但會降低效能。</string>

<string name="settings_mod_label">第三方MOD(風險自負)</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.0</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.1</string>
<string name="settings_mod_kantai3d_summary">為部份秘書艦添加仿立體的視覺效果及胸部物理。作者:@laplamgor</string>
<string name="settings_mod_kantai3d_about">About Kantai3D</string>
<string name="settings_mod_fps_enable">移除60幀限制</string>
<string name="settings_mod_fps_summary">支持高刷新率手機。遊戲速度不會受影響。</string>
<string name="settings_use_external_dir">使用外部存儲存放快取</string>
<string name="menu_tooltip_kantai3d">開關立體效果</string>
<string name="msg_kantai3d_init">未偵察到秘書艦</string>
<string name="msg_kantai3d_loaded">已載入目前秘書艦CG的深度圖: %s</string>
<string name="msg_kantai3d_error">找不到目前秘書艦CG的深度圖: %s</string>
<string name="msg_kantai3d_redirect">欲查看所有支持 3D 的 CG 列表,或貢獻新的深度圖,請前往: https://github.com/laplamgor/kantai3d</string>

<string name="browser_ui_hint_text">« 點擊外側任意位置以打開面板 »</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rMO/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@
<string name="settings_legacy_renderer_summary">強制PixiJS引擎使用Canvas渲染器而非WebGL渲染器。可解決大部份圖形奇怪錯誤但會降低效能。</string>

<string name="settings_mod_label">第三方MOD(風險自負)</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.0</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.1</string>
<string name="settings_mod_kantai3d_summary">為部份秘書艦添加仿立體的視覺效果及胸部物理。作者:@laplamgor</string>
<string name="settings_mod_kantai3d_about">About Kantai3D</string>
<string name="settings_mod_fps_enable">移除60幀限制</string>
<string name="settings_mod_fps_summary">支持高刷新率手機。遊戲速度不會受影響。</string>
<string name="settings_use_external_dir">使用外部存儲存放快取</string>
<string name="menu_tooltip_kantai3d">開關立體效果</string>
<string name="msg_kantai3d_init">未偵察到秘書艦</string>
<string name="msg_kantai3d_loaded">已載入目前秘書艦CG的深度圖: %s</string>
<string name="msg_kantai3d_error">找不到目前秘書艦CG的深度圖: %s</string>
<string name="msg_kantai3d_redirect">欲查看所有支持 3D 的 CG 列表,或貢獻新的深度圖,請前往: https://github.com/laplamgor/kantai3d</string>

<string name="browser_ui_hint_text">« 點擊外側任意位置以打開面板 »</string>
</resources>
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rSG/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@
<string name="settings_legacy_renderer_summary">强制PixiJS引擎使用Canvas渲染器而非WebGL渲染器。可解决大部份图形奇怪错误但会降低效能。</string>

<string name="settings_mod_label">第三方MOD(自担风险)</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.0</string>
<string name="settings_mod_kantai3d_enable">[Beta] Kantai3D v2.1</string>
<string name="settings_mod_kantai3d_summary">为部份秘书舰添加仿立体的视觉效果及胸部物理。作者:@laplamgor</string>
<string name="settings_mod_kantai3d_about">About Kantai3D</string>
<string name="settings_mod_fps_enable">移除60帧限制</string>
<string name="settings_mod_fps_summary">支持高刷新率手机。游戏速度不会受影响。</string>
<string name="settings_use_external_dir">使用外部存储进行缓存</string>
<string name="menu_tooltip_kantai3d">开关立体效果</string>
<string name="msg_kantai3d_init">未检测到秘书舰</string>
<string name="msg_kantai3d_loaded">已加载当前秘书舰CG的深度图: %s</string>
<string name="msg_kantai3d_error">未发现当前秘书舰CG的深度图: %s</string>
<string name="msg_kantai3d_redirect">欲查看所有支持 3D 的 CG 列表,或贡献新的深度图,请访问: https://github.com/laplamgor/kantai3d</string>

<string name="browser_ui_hint_text">« 点击外侧任意位置以打开面板 »</string>
</resources>
Loading

0 comments on commit 5502f9a

Please sign in to comment.