Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
up
Browse files Browse the repository at this point in the history
鼠标指针设置
  • Loading branch information
Coloryr committed Oct 19, 2023
1 parent a2cf1a6 commit 2aff136
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 160 deletions.
2 changes: 1 addition & 1 deletion app_pojavlauncher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ dependencies {
implementation 'com.github.PojavLauncherTeam:portrait-sdp:ed33e89cbc'
implementation 'com.github.PojavLauncherTeam:portrait-ssp:6c02fd739b'
implementation 'com.github.Mathias-Boulay:ExtendedView:1.0.0'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:eb92e3a5bb'
implementation 'com.github.Mathias-Boulay:android_gamepad_remapper:67b4fd4448'
implementation 'com.github.Mathias-Boulay:virtual-joystick-android:2e7aa25e50'

// https://mavenlibs.com/maven/dependency/io.netty/netty-all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.DEFAULT_PREF;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.util.AttributeSet;
import android.view.GestureDetector;
Expand All @@ -22,6 +24,10 @@

import org.lwjgl.glfw.CallbackBridge;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
* Class dealing with the virtual mouse
*/
Expand Down Expand Up @@ -157,8 +163,22 @@ public void placeMouseAt(float x, float y) {
}

private void init(){
File file = new File(Tools.DIR_GAME_HOME, "mouse");
// Setup mouse pointer
mMousePointerImageView.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_mouse_pointer, getContext().getTheme()));
if(file.exists()) {
try {
InputStream stream1 = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(stream1);
mMousePointerImageView.setImageBitmap(bitmap);
stream1.close();
} catch (Exception e) {

}
}
else {
mMousePointerImageView.setImageDrawable(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_mouse_pointer, getContext().getTheme()));
}

mMousePointerImageView.post(() -> {
ViewGroup.LayoutParams params = mMousePointerImageView.getLayoutParams();
params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_SOUTH_WEST;
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.DIRECTION_WEST;
import static net.kdt.pojavlaunch.customcontrols.gamepad.GamepadJoystick.isJoystickEvent;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_DEADZONE_SCALE;
import static net.kdt.pojavlaunch.utils.MCOptionUtils.getMcScale;
import static org.lwjgl.glfw.CallbackBridge.sendKeyPress;
import static org.lwjgl.glfw.CallbackBridge.sendMouseButton;

import fr.spse.gamepad_remapper.GamepadHandler;
import fr.spse.gamepad_remapper.Settings;

public class Gamepad implements GrabListener, GamepadHandler {

Expand Down Expand Up @@ -88,6 +90,7 @@ public class Gamepad implements GrabListener, GamepadHandler {
private final MCOptionUtils.MCOptionListener mGuiScaleListener = () -> notifyGUISizeChange(getMcScale());

public Gamepad(View contextView, InputDevice inputDevice){
Settings.setDeadzoneScale(PREF_DEADZONE_SCALE);
mScreenChoreographer = Choreographer.getInstance();
Choreographer.FrameCallback frameCallback = new Choreographer.FrameCallback() {
@Override
Expand Down Expand Up @@ -184,10 +187,8 @@ private void tick(long frameTimeNanos){
//update mouse position
long newFrameTime = System.nanoTime();
if(mLastHorizontalValue != 0 || mLastVerticalValue != 0){
GamepadJoystick currentJoystick = isGrabbing ? mLeftJoystick : mRightJoystick;
double acceleration = Math.pow(mMouseMagnitude, MOUSE_MAX_ACCELERATION);

double acceleration = (mMouseMagnitude - currentJoystick.getDeadzone()) / (1 - currentJoystick.getDeadzone());
acceleration = Math.pow(acceleration, MOUSE_MAX_ACCELERATION);
if(acceleration > 1) acceleration = 1;

// Compute delta since last tick time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public double getMagnitude(){
}

public float getVerticalAxis(){
return applyDeadzone(mVerticalAxisValue);
return mVerticalAxisValue;
}

public float getHorizontalAxis(){
return applyDeadzone(mHorizontalAxisValue);
return mHorizontalAxisValue;
}

public static boolean isJoystickEvent(MotionEvent event){
Expand All @@ -73,36 +73,10 @@ public static boolean isJoystickEvent(MotionEvent event){


public int getHeightDirection(){
if(getMagnitude() <= getDeadzone()) return DIRECTION_NONE;
if(getMagnitude() == 0) return DIRECTION_NONE;
return ((int) ((getAngleDegree()+22.5)/45)) % 8;
}

/**
* Get the deadzone from the Input device linked to this joystick
* Some controller aren't supported, fallback to 0.2 if that the case.
* @return the deadzone of the joystick
*/
public float getDeadzone() {
try{
return mInputDevice.getMotionRange(mHorizontalAxis).getFlat() * PREF_DEADZONE_SCALE;
}catch (Exception e){
Log.e(GamepadJoystick.class.toString(), "Dynamic Deadzone is not supported ");
return 0.2f;
}
}

private float applyDeadzone(float value){
//This piece of code also modifies the value
//to make it seem like there was no deadzone in the first place

double magnitude = getMagnitude();
float deadzone = getDeadzone();
if (magnitude < deadzone) return 0;

return (float) ( (value / magnitude) * ((magnitude - deadzone) / (1 - deadzone)) );
}


/* Setters */
public void setXAxisValue(float value){
this.mHorizontalAxisValue = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package net.kdt.pojavlaunch.prefs.screens;


import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;

import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;

import com.kdt.pickafile.FileListView;
import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
* Preference for the main screen, any sub-screen should inherit this class for consistent behavior,
Expand All @@ -29,6 +45,50 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
@Override
public void onCreatePreferences(Bundle b, String str) {
addPreferencesFromResource(R.xml.pref_main);
findPreference("control_mouse_setting").setOnPreferenceClickListener((preference) -> {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, 1);
return true;
});

findPreference("control_mouse_setting1").setOnPreferenceClickListener((preference) -> {
File file = new File(Tools.DIR_GAME_HOME, "mouse");
if (file.exists()) {
file.delete();
}
Toast.makeText(getContext(), R.string.notif_mouse1, Toast.LENGTH_SHORT).show();
return true;
});
}

@Override
public void onActivityResult(
int requestCode, int resultCode, final Intent data) {
if (resultCode != Activity.RESULT_OK) {
// Handle error
return;
}

if (requestCode == 1) {// Get photo picker response for single select.
Uri currentUri = data.getData();
try {
File file = new File(Tools.DIR_GAME_HOME, "mouse");
if (file.exists()) {
file.delete();
}

InputStream stream1 = getContext().getContentResolver().openInputStream(currentUri);
FileOutputStream stream = new FileOutputStream(file);

IOUtils.copy(stream1, stream);
stream.close();
stream1.close();
Toast.makeText(getContext(), R.string.notif_mouse, Toast.LENGTH_SHORT).show();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@Override
Expand Down
50 changes: 13 additions & 37 deletions app_pojavlauncher/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -1,64 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- App name part -->
<string name="app_name">PojavView(适用于 Android 的《Minecraft:Java版》)</string>
<string name="app_short_name">PojavView</string>
<string name="app_motd">在您的设备上启动《Minecraft:Java版》!</string>
<!-- Action bar part -->
<!-- Languages list part -->
<!-- Login strings -->
<string name="login_online_username_hint">电子邮箱或用户名</string>
<string name="login_online_password_hint">密码</string>
<string name="login_online_check_keeplogin">保持登录状态</string>
<string name="login_online_login_label">登录</string>
<string name="login_error_invalid_username">用户名无效。用户名必须在 3-16 个字符的范围内,且只能包含 A-Z、a-z、0-9 和下划线。</string>
<string name="login_error_exist_username">用户名已存在</string>
<string name="login_microsoft">微软账号登录</string>
<string name="login_select_account">选择账户</string>
<string name="login_title_no_saved_account">该账户不存在!</string>
<string name="login_dialog_no_saved_account">尚未保存任何账户。\n使用<b>“保持登录状态”</b>选项以在首次登录后保存账户。</string>
<!-- Hint -->
<string name="hint_control_mapping">"点击顶部中央齿轮图标打开背景菜单⚙\n点击一个按钮进行自定义:编辑、缩放、删除或自定义其键绑定。"</string>
<!-- Warnings -->
<string name="warning_remove_account">此账户将被移除!</string>
<!-- AlertDialog title -->
<string name="alerttitle_install_jre">安装 Java 运行时 %1$s (.tar.xz)</string>
<string name="alerttitle_installmod">选择模组安装器</string>
<!-- Error messages -->
<string name="error_fatal">意外崩溃</string>
<string name="error_no_version">无版本!</string>
<string name="error_show_more">显示细节</string>
<string name="error_show_less">隐藏细节</string>
<!-- Toast messages -->
<string name="toast_permission_denied">需要存储读写权限!</string>
<string name="toast_optifine_success">安装成功</string>
<string name="toast_uninstalljre_done">Java 运行时卸载成功</string>
<!--
<string name="toast_3">Exit</string>
-->
<!-- MCLauncherActivity: Tabs -->
<string name="mcl_tab_wiki">百科</string>
<string name="mcl_tab_console">开发控制台</string>
<string name="mcl_tab_crash">崩溃日志</string>
<!-- MCLauncherActivity: Account status -->
<string name="mcl_account_connected">已连接</string>
<string name="mcl_account_local">本地模式</string>
<!-- MCLauncherActivity: Strings -->
<string name="mcl_version_msg">Minecraft %1$s 就绪</string>
<string name="mcl_launch_cleancache">正在清理缓存</string>
<string name="mcl_launch_downloading">正在下载 %1$s</string>
<string name="mcl_launch_downloading_progress">"正在下载 %1$s (%2$.2f MB / %3$.2f MB)"</string>
<string name="mcl_launch_download_assets">正在准备下载资源</string>
<string name="mcl_launch_error_localmode">Minecraft 无法在本地账户中进行安装,请切换到正版账户以继续。</string>
<string name="mcl_options">选项</string>
<string name="mcl_option_modinstall">启动模组安装器(例如 Forge、LabyMod、Fabric...)</string>
<string name="mcl_option_modinstallwitharg">以自定义参数启动模组安装器</string>
<string name="mcl_option_customcontrol">自定义控制按键</string>
<string name="mcl_option_settings">设置</string>
<string name="mcl_option_about">关于</string>
<string name="mcl_setting_title_use_surface_view">使用备用表面渲染(Surface Rendering)</string>
<string name="mcl_setting_subtitle_use_surface_view">可能有助于提升受 GPU 机能限制的性能</string>
<string name="mcl_setting_title_uninstalljre">卸载 Java 运行时</string>
<string name="mcl_setting_subtitle_uninstalljre">【需要重启启动器】这会让你重新安装 Java 运行时。</string>
<string name="mcl_setting_title_freeform">以自由窗口模式启动 Minecraft</string>
<string name="mcl_setting_subtitle_freeform">在浮动窗口中启动 Minecraft。需要 Android 7.0+</string>
Expand Down Expand Up @@ -177,6 +140,7 @@
<string name="customctrl_keycombine_shift">Shift</string>
<string name="customctrl_addbutton">添加按键</string>
<string name="customctrl_addbutton_drawer">添加组合键</string>
<string name="customctrl_addbutton_joystick">添加摇杆</string>
<string name="customctrl_addsubbutton">添加子按钮</string>
<string name="customctrl_add_subbutton_message">子按钮 n°%1$d 已添加!</string>
<string name="customctrl_selectdefault">选择默认 .json 控制键位</string>
Expand Down Expand Up @@ -319,4 +283,16 @@

<string name="preference_vulkan_driver_system_title">使用系统 Vulkan 驱动</string>
<string name="preference_vulkan_driver_system_description">强制启动器在 Adreno GPU 上使用系统 Vulkan 驱动而非 Turnip。仅影响使用 Vulkan 的 Zink 和模组。</string>
<string name="preference_category_gestures">手势</string>
<string name="preference_category_buttons">按钮</string>
<string name="preference_category_experimental_settings">实验性内容</string>
<string name="preference_category_java_tweaks">Jvm调整</string>
<string name="preference_category_main_categories">分组</string>
<string name="preference_category_miscellaneous">其他设置</string>
<string name="preference_category_video">视频选项</string>
<string name="preference_mouse_description">设置游戏内鼠标图标</string>
<string name="preference_mouse_title">鼠标图标自定义</string>
<string name="notif_mouse">设置完成</string>
<string name="preference_mouse_title1">删除设置的鼠标图标</string>
<string name="notif_mouse1">删除成功</string>
</resources>
Loading

0 comments on commit 2aff136

Please sign in to comment.