Commit c99935ed authored by kenan's avatar kenan

固定比例开关

parent 2fe782e3
...@@ -35,19 +35,6 @@ bool Game::Initialize() { ...@@ -35,19 +35,6 @@ bool Game::Initialize() {
#endif #endif
srand(time(0)); srand(time(0));
irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters(); irr::SIrrlichtCreationParameters params = irr::SIrrlichtCreationParameters();
int screenH = static_cast<int>(android::getScreenHeight(app));
int screenW = static_cast<int>(android::getScreenWidth(app));
float sH = static_cast<float>(screenH / 1024.0);
float sW = static_cast<float>(screenW / 640.0);
//取最小值
if(sH < sW){
xScale = sH;
yScale = sH;
} else {
xScale = sW;
yScale = sW;
}
#ifdef _IRR_ANDROID_PLATFORM_ #ifdef _IRR_ANDROID_PLATFORM_
android::InitOptions *options = android::getInitOptions(app); android::InitOptions *options = android::getInitOptions(app);
...@@ -61,13 +48,7 @@ bool Game::Initialize() { ...@@ -61,13 +48,7 @@ bool Game::Initialize() {
params.Bits = 24; params.Bits = 24;
params.ZBufferBits = 16; params.ZBufferBits = 16;
params.AntiAlias = 0; params.AntiAlias = 0;
//int w = (int)(1024.0*xScale);
//int h = (int)(640.0*yScale);
params.WindowSize = irr::core::dimension2d<u32>(0, 0); params.WindowSize = irr::core::dimension2d<u32>(0, 0);
//每一个元素得left和top都需要改
//xStart = (float)((screenH - w)/2.0);
//yStart = (float)((screenW - h)/2.0);
//params.WindowPosition = core::position2di((s32)xStart, (s32)yStart);
#else #else
if(gameConf.use_d3d) if(gameConf.use_d3d)
params.DriverType = irr::video::EDT_DIRECT3D9; params.DriverType = irr::video::EDT_DIRECT3D9;
...@@ -92,10 +73,10 @@ bool Game::Initialize() { ...@@ -92,10 +73,10 @@ bool Game::Initialize() {
isPSEnabled = options->isPendulumScaleEnabled(); isPSEnabled = options->isPendulumScaleEnabled();
dataManager.FileSystem = device->getFileSystem(); dataManager.FileSystem = device->getFileSystem();
/* if (xScale < yScale) { xScale = android::getXScale(app);
* xScale = android::getScreenWidth(app) / 1024.0; yScale = android::getYScale(app);
* yScale = android::getScreenHeight(app) / 640.0;
* }//start ygocore when mobile is in landscape mode, or using Android tablets or TV.*/ //start ygocore when mobile is in landscape mode, or using Android tablets or TV.
char log_scale[256] = {0}; char log_scale[256] = {0};
sprintf(log_scale, "xScale = %f, yScale = %f, xStart=%f, yStart=%f", xScale, yScale, xStart, yStart); sprintf(log_scale, "xScale = %f, yScale = %f, xStart=%f, yStart=%f", xScale, yScale, xStart, yStart);
Printer::log(log_scale); Printer::log(log_scale);
......
...@@ -356,7 +356,53 @@ irr::io::path getResourcePath(ANDROID_APP app) { ...@@ -356,7 +356,53 @@ irr::io::path getResourcePath(ANDROID_APP app) {
return ret; return ret;
} }
float getXScale(ANDROID_APP app){
float ret = 1;
if (!app || !app->activity || !app->activity->vm)
return ret;
JNIEnv* jni = 0;
app->activity->vm->AttachCurrentThread(&jni, NULL);
if (!jni)
return ret;
// Retrieves NativeActivity.
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID MethodGetApp = jni->GetMethodID(ClassNativeActivity,
"getApplication", "()Landroid/app/Application;");
jobject application = jni->CallObjectMethod(lNativeActivity, MethodGetApp);
jclass classApp = jni->GetObjectClass(application);
jmethodID glversionMethod = jni->GetMethodID(classApp, "getXScale",
"()F");
ret = jni->CallFloatMethod(application, glversionMethod);
jni->DeleteLocalRef(classApp);
jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread();
return ret;
}
float getYScale(ANDROID_APP app){
float ret = 1;
if (!app || !app->activity || !app->activity->vm)
return ret;
JNIEnv* jni = 0;
app->activity->vm->AttachCurrentThread(&jni, NULL);
if (!jni)
return ret;
// Retrieves NativeActivity.
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID MethodGetApp = jni->GetMethodID(ClassNativeActivity,
"getApplication", "()Landroid/app/Application;");
jobject application = jni->CallObjectMethod(lNativeActivity, MethodGetApp);
jclass classApp = jni->GetObjectClass(application);
jmethodID glversionMethod = jni->GetMethodID(classApp, "getYScale",
"()F");
ret = jni->CallFloatMethod(application, glversionMethod);
jni->DeleteLocalRef(classApp);
jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread();
return ret;
}
//Retrive last deck name. //Retrive last deck name.
irr::io::path getLastDeck(ANDROID_APP app) { irr::io::path getLastDeck(ANDROID_APP app) {
......
...@@ -141,6 +141,10 @@ extern int getCardQuality(ANDROID_APP app); ...@@ -141,6 +141,10 @@ extern int getCardQuality(ANDROID_APP app);
//Retrive local ip address(mostly for wifi only); //Retrive local ip address(mostly for wifi only);
extern int getLocalAddr(ANDROID_APP app); extern int getLocalAddr(ANDROID_APP app);
extern float getXScale(ANDROID_APP app);
extern float getYScale(ANDROID_APP app);
//Retrive font path. //Retrive font path.
extern irr::io::path getFontPath(ANDROID_APP app); extern irr::io::path getFontPath(ANDROID_APP app);
......
...@@ -53,6 +53,12 @@ public abstract class GameApplication extends Application implements IrrlichtBri ...@@ -53,6 +53,12 @@ public abstract class GameApplication extends Application implements IrrlichtBri
isInitSoundEffectPool = initSoundEffectPool; isInitSoundEffectPool = initSoundEffectPool;
} }
public abstract int getGameWidth();
public abstract int getGameHeight();
public abstract boolean isKeepScale();
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void initSoundEffectPool() { public void initSoundEffectPool() {
mSoundEffectPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0); mSoundEffectPool = new SoundPool(2, AudioManager.STREAM_MUSIC, 0);
...@@ -75,10 +81,6 @@ public abstract class GameApplication extends Application implements IrrlichtBri ...@@ -75,10 +81,6 @@ public abstract class GameApplication extends Application implements IrrlichtBri
public abstract float getSmallerSize(); public abstract float getSmallerSize();
public abstract float getXScale();
public abstract float getYScale();
public abstract boolean isLockSreenOrientation(); public abstract boolean isLockSreenOrientation();
public abstract boolean isSensorRefresh(); public abstract boolean isSensorRefresh();
......
...@@ -212,30 +212,20 @@ public class YGOMobileActivity extends NativeActivity implements ...@@ -212,30 +212,20 @@ public class YGOMobileActivity extends NativeActivity implements
if (app().isImmerSiveMode()) { if (app().isImmerSiveMode()) {
mFullScreenUtils.fullscreen(); mFullScreenUtils.fullscreen();
app().attachGame(this); app().attachGame(this);
//游戏大小 //游戏大小
int[] size = getGameSize(); int[] size = getGameSize();
getWindow().setLayout(size[0], size[1]); getWindow().setLayout(size[0], size[1]);
} }
} }
private int[] getGameSize(){ private int[] getGameSize() {
//调整padding //调整padding
float screenW = app().getScreenWidth(); float xScale = app().getXScale();
float screenH = app().getScreenHeight(); float yScale = app().getYScale();
float sH = screenH / 1024.0f; int w = (int) (app().getGameWidth() * xScale);
float sW = screenW / 640.0f; int h = (int) (app().getGameHeight() * yScale);
Log.i("kk", "w=" + w + ",h=" + h + ",xScale=" + xScale + ",yScale=" + yScale);
float xScale,yScale;
//取最小值
if(sH < sW){
xScale = sH;
yScale = sH;
} else {
xScale = sW;
yScale = sW;
}
int w = (int)(1024.0*xScale);
int h = (int)(640.0*yScale);
return new int[]{w, h}; return new int[]{w, h};
} }
......
...@@ -170,6 +170,10 @@ public final class IrrlichtBridge { ...@@ -170,6 +170,10 @@ public final class IrrlichtBridge {
void playSoundEffect(String path); void playSoundEffect(String path);
void runWindbot(String args); void runWindbot(String args);
float getXScale();
float getYScale();
// float getSmallerSize(); // float getSmallerSize();
// float getXScale(); // float getXScale();
......
...@@ -4,7 +4,6 @@ package cn.garymb.ygomobile; ...@@ -4,7 +4,6 @@ package cn.garymb.ygomobile;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.util.Log;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.appcompat.app.AppCompatDelegate; import androidx.appcompat.app.AppCompatDelegate;
...@@ -72,6 +71,20 @@ public class App extends GameApplication { ...@@ -72,6 +71,20 @@ public class App extends GameApplication {
return AppsSettings.get().getFontPath(); return AppsSettings.get().getFontPath();
} }
@Override
public boolean isKeepScale() {
return AppsSettings.get().isKeepScale();
}
@Override
public int getGameHeight() {
return Constants.CORE_GAME_SIZE[1];
}
@Override
public int getGameWidth() {
return Constants.CORE_GAME_SIZE[0];
}
@Override @Override
public void saveSetting(String key, String value) { public void saveSetting(String key, String value) {
......
...@@ -32,6 +32,7 @@ import static cn.garymb.ygomobile.Constants.CORE_EXPANSIONS; ...@@ -32,6 +32,7 @@ import static cn.garymb.ygomobile.Constants.CORE_EXPANSIONS;
import static cn.garymb.ygomobile.Constants.CORE_PACK_PATH; import static cn.garymb.ygomobile.Constants.CORE_PACK_PATH;
import static cn.garymb.ygomobile.Constants.CORE_SYSTEM_PATH; import static cn.garymb.ygomobile.Constants.CORE_SYSTEM_PATH;
import static cn.garymb.ygomobile.Constants.DEF_PREF_FONT_SIZE; import static cn.garymb.ygomobile.Constants.DEF_PREF_FONT_SIZE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT; import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX; import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX;
...@@ -39,6 +40,7 @@ import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE; ...@@ -39,6 +40,7 @@ import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH; import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE; import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE;
import static cn.garymb.ygomobile.Constants.PREF_IMMERSIVE_MODE; import static cn.garymb.ygomobile.Constants.PREF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.PREF_LOCK_SCREEN; import static cn.garymb.ygomobile.Constants.PREF_LOCK_SCREEN;
import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT; import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME;
...@@ -78,13 +80,6 @@ public class AppsSettings { ...@@ -78,13 +80,6 @@ public class AppsSettings {
return new File(getResourcePath(), CORE_SYSTEM_PATH); return new File(getResourcePath(), CORE_SYSTEM_PATH);
} }
private static float getScale(float srcWidth, float srcHeight, float destWidth, float destHeight) {
float sx = srcWidth / destWidth;
float sy = srcHeight == 0 ? (sx + 1.0f) : (srcHeight / destHeight);
return Math.min(sx, sy);
}
public void update(Context context) { public void update(Context context) {
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Point size = new Point(); Point size = new Point();
...@@ -190,12 +185,35 @@ public class AppsSettings { ...@@ -190,12 +185,35 @@ public class AppsSettings {
return false;//mSharedPreferences.getBoolean(PREF_DECK_MANAGER_V2, DEF_PREF_DECK_MANAGER_V2); return false;//mSharedPreferences.getBoolean(PREF_DECK_MANAGER_V2, DEF_PREF_DECK_MANAGER_V2);
} }
public float getGameHeight() {
return (float)Constants.CORE_GAME_SIZE[1];
}
public float getGameWidth() {
return (float)Constants.CORE_GAME_SIZE[0];
}
public float getXScale() { public float getXScale() {
return getScreenHeight() / (float) Constants.CORE_SKIN_BG_SIZE[0]; if(isKeepScale()){
float sx = getScreenHeight() / getGameWidth();
float sy = getScreenWidth() / getGameHeight();
return Math.min(sx, sy);
}
return getScreenHeight() / getGameWidth();
} }
public float getYScale() { public float getYScale() {
return getScreenWidth() / (float) Constants.CORE_SKIN_BG_SIZE[1]; if(isKeepScale()){
//固定比例,取最小值
float sx = getScreenHeight() / getGameWidth();
float sy = getScreenWidth() / getGameHeight();
return Math.min(sx, sy);
}
return getScreenWidth() / getGameHeight();
}
public boolean isKeepScale(){
return mSharedPreferences.getBoolean(PREF_KEEP_SCALE, DEF_PREF_KEEP_SCALE);
} }
public float getScreenHeight() { public float getScreenHeight() {
......
...@@ -90,6 +90,7 @@ public interface Constants { ...@@ -90,6 +90,7 @@ public interface Constants {
String CORE_SKIN_AVATAR_OPPONENT = "opponent.jpg"; String CORE_SKIN_AVATAR_OPPONENT = "opponent.jpg";
String UNKNOWN_IMAGE = "unknown.jpg"; String UNKNOWN_IMAGE = "unknown.jpg";
String YDK_FILE_EX = ".ydk"; String YDK_FILE_EX = ".ydk";
int[] CORE_GAME_SIZE = new int[]{1024, 640};
int[] CORE_SKIN_BG_SIZE = new int[]{1280, 720}; int[] CORE_SKIN_BG_SIZE = new int[]{1280, 720};
int[] CORE_SKIN_CARD_COVER_SIZE = new int[]{177, 254}; int[] CORE_SKIN_CARD_COVER_SIZE = new int[]{177, 254};
int[] CORE_SKIN_AVATAR_SIZE = new int[]{128, 128}; int[] CORE_SKIN_AVATAR_SIZE = new int[]{128, 128};
...@@ -116,6 +117,9 @@ public interface Constants { ...@@ -116,6 +117,9 @@ public interface Constants {
String PREF_DECK_MANAGER_V2 = "pref_settings_deck_manager_v2"; String PREF_DECK_MANAGER_V2 = "pref_settings_deck_manager_v2";
boolean DEF_PREF_DECK_MANAGER_V2 = false; boolean DEF_PREF_DECK_MANAGER_V2 = false;
String PREF_KEEP_SCALE = "pref_settings_keep_scale";
boolean DEF_PREF_KEEP_SCALE = false;
int REQUEST_CUT_IMG = 0x1000 + 0x10; int REQUEST_CUT_IMG = 0x1000 + 0x10;
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20; int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21; int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
......
...@@ -61,6 +61,7 @@ import static cn.garymb.ygomobile.Constants.PREF_GAME_FONT; ...@@ -61,6 +61,7 @@ import static cn.garymb.ygomobile.Constants.PREF_GAME_FONT;
import static cn.garymb.ygomobile.Constants.PREF_GAME_PATH; import static cn.garymb.ygomobile.Constants.PREF_GAME_PATH;
import static cn.garymb.ygomobile.Constants.PREF_IMAGE_QUALITY; import static cn.garymb.ygomobile.Constants.PREF_IMAGE_QUALITY;
import static cn.garymb.ygomobile.Constants.PREF_IMMERSIVE_MODE; import static cn.garymb.ygomobile.Constants.PREF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.PREF_LOCK_SCREEN; import static cn.garymb.ygomobile.Constants.PREF_LOCK_SCREEN;
import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME; import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.PREF_OPENGL_VERSION; import static cn.garymb.ygomobile.Constants.PREF_OPENGL_VERSION;
...@@ -146,6 +147,7 @@ public class SettingFragment extends PreferenceFragmentPlus { ...@@ -146,6 +147,7 @@ public class SettingFragment extends PreferenceFragmentPlus {
bind(SETTINGS_CARD_BG, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath()); bind(SETTINGS_CARD_BG, new File(mSettings.getCoreSkinPath(), Constants.CORE_SKIN_BG).getAbsolutePath());
bind(PREF_FONT_SIZE, mSettings.getFontSize()); bind(PREF_FONT_SIZE, mSettings.getFontSize());
bind(PREF_ONLY_GAME, mSettings.isOnlyGame()); bind(PREF_ONLY_GAME, mSettings.isOnlyGame());
bind(PREF_KEEP_SCALE, mSettings.isKeepScale());
isInit = false; isInit = false;
} }
......
...@@ -270,4 +270,5 @@ ...@@ -270,4 +270,5 @@
<string name="donot_editor_bot_Deck">덱을 변경하지 말아 주세요. 그러면 프로그램이 제대로 작동하지 않을 수 있습니다.</string> <string name="donot_editor_bot_Deck">덱을 변경하지 말아 주세요. 그러면 프로그램이 제대로 작동하지 않을 수 있습니다.</string>
<string name="unable_to_edit_empty_deck">사용할 수 없는 빈 구역</string> <string name="unable_to_edit_empty_deck">사용할 수 없는 빈 구역</string>
<string name="create_new_failed">생성실패</string> <string name="create_new_failed">생성실패</string>
<string name="about_pref_settings_keep_scale">Keep Display Scale</string>
</resources> </resources>
...@@ -269,4 +269,5 @@ ...@@ -269,4 +269,5 @@
<string name="donot_editor_bot_Deck">请不要更改/删除AI卡组否则会导致人机模式无法正常使用</string> <string name="donot_editor_bot_Deck">请不要更改/删除AI卡组否则会导致人机模式无法正常使用</string>
<string name="unable_to_edit_empty_deck">不可操作空卡组</string> <string name="unable_to_edit_empty_deck">不可操作空卡组</string>
<string name="create_new_failed">创建失败</string> <string name="create_new_failed">创建失败</string>
<string name="about_pref_settings_keep_scale">游戏画面比例固定</string>
</resources> </resources>
...@@ -272,4 +272,5 @@ ...@@ -272,4 +272,5 @@
<string name="screenshoot">Screenshoot</string> <string name="screenshoot">Screenshoot</string>
<string name="unable_to_edit_empty_deck">unable to edit empty deck</string> <string name="unable_to_edit_empty_deck">unable to edit empty deck</string>
<string name="create_new_failed">Create Failed</string> <string name="create_new_failed">Create Failed</string>
<string name="about_pref_settings_keep_scale">Keep Display Scale</string>
</resources> </resources>
...@@ -13,6 +13,12 @@ ...@@ -13,6 +13,12 @@
<Preference <Preference
android:key="pref_key_change_log" android:key="pref_key_change_log"
android:title="@string/settings_about_change_log" /> android:title="@string/settings_about_change_log" />
<CheckBoxPreference
android:key="pref_settings_keep_scale"
android:persistent="false"
android:title="@string/about_pref_settings_keep_scale"/>
<ListPreference <ListPreference
android:entries="@array/opengl_version" android:entries="@array/opengl_version"
android:entryValues="@array/opengl_version_value" android:entryValues="@array/opengl_version_value"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment