Skip to content

Commit

Permalink
[app] 1.修复转换键盘模板时因键值不存在导致对应的map元素是null而造成的键值转化时发生的崩溃。2.修复转换旧版键盘模板时,因旧…
Browse files Browse the repository at this point in the history
…版的颜色Hex值中存在透明度导致的按键透明度差异的问题。3.正确的转换旧版按键的透明度到新版按键中。
  • Loading branch information
longjunyu2 committed Jan 3, 2021
1 parent 02c77f3 commit 3cff872
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.aof.mcinabox.gamecontroller.ckb.support;

import android.content.Context;
import android.util.Log;

import com.aof.mcinabox.gamecontroller.ckb.achieve.CkbManager;
import com.aof.mcinabox.gamecontroller.ckb.button.GameButton;
import com.aof.mcinabox.gamecontroller.ckb.button.GameButtonOld;
import com.aof.mcinabox.gamecontroller.definitions.map.MouseMap;
import com.aof.mcinabox.utils.ColorUtils;
import com.google.gson.Gson;

import java.io.File;
Expand All @@ -20,6 +22,7 @@
public class GameButtonConverter {

private final Context mContext;
private final static String TAG = "GameButtonConverter";

public GameButtonConverter(Context context){
this.mContext = context;
Expand Down Expand Up @@ -84,50 +87,47 @@ private GameButtonRecorder getGameButtonRecoderFromOldKeyboardModel(GameButtonOl
gbr.keyChars = "";
gbr.keySize = new float[]{gbo.getKeySizeW(), gbo.getKeySizeH()};
gbr.isChars = false;
gbr.alphaSize = GameButton.DEFAULT_ALPHA_SIZE_PT; //透明度采用默认值
Log.e(TAG, "透明度" + ColorUtils.int2rgba(ColorUtils.hex2Int(gbo.getColorhex()))[3]);
gbr.alphaSize = (int)((ColorUtils.int2rgba(ColorUtils.hex2Int(gbo.getColorhex()))[3]) / 255f * 100); //透明度从颜色值Hex中取出,然后转为不透明度的百分比
gbr.cornerRadius = (gbo.getCornerRadius() / 180) * 100; //圆角值转化为百分比
gbr.designIndex = GameButton.DEFAULT_DESIGN_INDEX; //主题采用默认值
gbr.isHide = gbo.isHide();
gbr.isKeep = gbo.isAutoKeep();
gbr.isViewerFollow = false; //视角跟随默认关闭

String[] keyMap = new String[GameButton.MAX_KEYMAP_SIZE];
Arrays.fill(keyMap, "");

int[] keyTypes = new int[GameButton.MAX_KEYMAP_SIZE];
if (gbo.getKeyMain().equals("空")){
//nothing
}else if (gbo.getKeyMain().equals(OLD_MOUSE_PRI)){
if (gbo.getKeyMain().equals(OLD_MOUSE_PRI)){
keyMap[0] = MouseMap.MOUSEMAP_BUTTON_LEFT;
keyTypes[0] = GameButton.MOUSE_TYPE;
}else if (gbo.getKeyMain().equals(OLD_MOUSE_SEC)){
keyMap[0] = MouseMap.MOUSEMAP_BUTTON_RIGHT;
keyTypes[0] = GameButton.MOUSE_TYPE;
}else{
}else if(!gbo.getKeyMain().equals("空")){
keyMap[0] = gbo.getKeyMain();
keyTypes[0] = GameButton.KEY_TYPE;
}
if(gbo.isMult()){
if (gbo.getSpecialOne().equals("空")){
//nothing
}else if (gbo.getSpecialOne().equals(OLD_MOUSE_PRI)){
if (gbo.isMult()){
if (gbo.getSpecialOne().equals(OLD_MOUSE_PRI)){
keyMap[1] = MouseMap.MOUSEMAP_BUTTON_LEFT;
keyTypes[1] = GameButton.MOUSE_TYPE;
}else if (gbo.getSpecialOne().equals(OLD_MOUSE_SEC)){
keyMap[1] = MouseMap.MOUSEMAP_BUTTON_RIGHT;
keyTypes[1] = GameButton.MOUSE_TYPE;
}else{
}else if (!gbo.getSpecialOne().equals("空")){
keyMap[1] = gbo.getKeyMain();
keyTypes[1] = GameButton.KEY_TYPE;
}

if (gbo.getSpecialTwo().equals("空")){
//nothing
}else if (gbo.getSpecialTwo().equals(OLD_MOUSE_PRI)){
if (gbo.getSpecialTwo().equals(OLD_MOUSE_PRI)){
keyMap[2] = MouseMap.MOUSEMAP_BUTTON_LEFT;
keyTypes[2] = GameButton.MOUSE_TYPE;
}else if (gbo.getSpecialOne().equals(OLD_MOUSE_SEC)){
keyMap[2] = MouseMap.MOUSEMAP_BUTTON_RIGHT;
keyTypes[2] = GameButton.MOUSE_TYPE;
}else{
}else if (!gbo.getSpecialTwo().equals("空")){
keyMap[2] = gbo.getKeyMain();
keyTypes[2] = GameButton.KEY_TYPE;
}
Expand All @@ -139,7 +139,7 @@ private GameButtonRecorder getGameButtonRecoderFromOldKeyboardModel(GameButtonOl
gbr.show = GameButton.SHOW_ALL; //默认全局显示
gbr.textColor = gbo.getTextColorHex();
gbr.themeColors = new String[CkbThemeRecorder.COLOR_INDEX_LENGTH];
gbr.themeColors[0] = gbo.getColorhex(); //默认只给主题的第一个颜色为赋值
gbr.themeColors[0] = new StringBuilder(gbo.getColorhex().substring(3)).insert(0, '#').toString(); //截掉原来的透明度
gbr.textSize = GameButton.DEFAULT_TEXT_SIZE_SP; //文字大小采用默认值

return gbr;
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/aof/mcinabox/utils/ColorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,19 @@ public static int rgb2Int(int[] rgb){
return colorInt;
}

public static int[] int2rgba(int colorInt){
int[] rgba = new int[4];

int red = Color.red(colorInt);
int green = Color.green(colorInt);
int blue = Color.blue(colorInt);
int alpha = Color.alpha(colorInt);
rgba[0] = red;
rgba[1] = green;
rgba[2] = blue;
rgba[3] = alpha;

return rgba;
}

}

0 comments on commit 3cff872

Please sign in to comment.