mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -04:00
Merge pull request #798 from serpentspirale/hotbar_beta_improvement
Hotbar live resizing capability
This commit is contained in:
commit
a721b2d331
@ -10,7 +10,6 @@ import android.view.View.*;
|
||||
import android.view.inputmethod.*;
|
||||
import android.widget.*;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.drawerlayout.widget.*;
|
||||
import com.google.android.material.navigation.*;
|
||||
import java.io.*;
|
||||
@ -661,12 +660,13 @@ public class BaseMainActivity extends LoggableActivity {
|
||||
texture.setDefaultBufferSize((int)(width*scaleFactor),(int)(height*scaleFactor));
|
||||
CallbackBridge.windowWidth = (int)(width*scaleFactor);
|
||||
CallbackBridge.windowHeight = (int)(height*scaleFactor);
|
||||
//CallbackBridge.sendUpdateWindowSize((int)(width*scaleFactor),(int)(height*scaleFactor));
|
||||
|
||||
//Load Minecraft options:
|
||||
MCOptionUtils.load();
|
||||
MCOptionUtils.set("overrideWidth", ""+CallbackBridge.windowWidth);
|
||||
MCOptionUtils.set("overrideHeight", ""+CallbackBridge.windowHeight);
|
||||
MCOptionUtils.save();
|
||||
calculateMcScale();
|
||||
getMcScale();
|
||||
// Should we do that?
|
||||
if (!isCalled) {
|
||||
isCalled = true;
|
||||
@ -698,7 +698,7 @@ public class BaseMainActivity extends LoggableActivity {
|
||||
CallbackBridge.windowWidth = (int)(width*scaleFactor);
|
||||
CallbackBridge.windowHeight = (int)(height*scaleFactor);
|
||||
CallbackBridge.sendUpdateWindowSize((int)(width*scaleFactor),(int)(height*scaleFactor));
|
||||
calculateMcScale();
|
||||
getMcScale();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1025,7 +1025,7 @@ public class BaseMainActivity extends LoggableActivity {
|
||||
}
|
||||
|
||||
public int mcscale(int input) {
|
||||
return this.guiScale * input;
|
||||
return (int)((this.guiScale * input)/scaleFactor);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1171,40 +1171,29 @@ public class BaseMainActivity extends LoggableActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void calculateMcScale() {
|
||||
int scale = 1;
|
||||
while (CallbackBridge.physicalWidth / (scale + 1) >= 320 && CallbackBridge.physicalHeight / (scale + 1) >= 240) {
|
||||
scale++;
|
||||
public void getMcScale() {
|
||||
//Get the scale stored in game files, used auto scale if found or if the stored scaled is bigger than the authorized size.
|
||||
String str = MCOptionUtils.get("guiScale");
|
||||
this.guiScale = (str == null ? 0 :Integer.parseInt(str));
|
||||
|
||||
|
||||
int scale = Math.max(Math.min(CallbackBridge.windowWidth / 320, CallbackBridge.windowHeight / 240), 1);
|
||||
if(scale < this.guiScale || guiScale == 0){
|
||||
this.guiScale = scale;
|
||||
}
|
||||
this.guiScale = scale;
|
||||
}
|
||||
|
||||
public int handleGuiBar(int x, int y) {
|
||||
if (!CallbackBridge.isGrabbing()) return -1;
|
||||
|
||||
int barheight = mcscale(20);
|
||||
int barwidth = mcscale(180);
|
||||
int barx = (CallbackBridge.physicalWidth / 2) - (barwidth / 2);
|
||||
int bary = CallbackBridge.physicalHeight - barheight;
|
||||
if (x < barx || x >= barx + barwidth || y < bary || y >= bary + barheight) {
|
||||
int barHeight = mcscale(20);
|
||||
int barWidth = mcscale(180);
|
||||
int barX = (CallbackBridge.physicalWidth / 2) - (barWidth / 2);
|
||||
int barY = CallbackBridge.physicalHeight - barHeight;
|
||||
if (x < barX || x >= barX + barWidth || y < barY || y >= barY + barHeight) {
|
||||
return -1;
|
||||
}
|
||||
return hotbarKeys[((x - barx) / mcscale(180 / 9)) % 9];
|
||||
return hotbarKeys[((x - barX) / mcscale(180 / 9)) % 9];
|
||||
}
|
||||
/*
|
||||
public int handleGuiBar(int x, int y, MotionEvent e) {
|
||||
if (!CallbackBridge.isGrabbing()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// int screenHeight = CallbackBridge.windowHeight;
|
||||
int barheight = mcscale(20);
|
||||
int barwidth = mcscale(180);
|
||||
int barx = (CallbackBridge.windowWidth / 2) - (barwidth / 2);
|
||||
if (x < barx || x >= barx + barwidth || y < 0 || y >= 0 + barheight) {
|
||||
return -1;
|
||||
}
|
||||
return hotbarKeys[((x - barx) / mcscale(20)) % 9];
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@ -4,8 +4,13 @@ import android.os.*;
|
||||
import android.view.*;
|
||||
import android.view.View.*;
|
||||
import android.widget.*;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.kdt.pojavlaunch.customcontrols.*;
|
||||
import net.kdt.pojavlaunch.prefs.*;
|
||||
import net.kdt.pojavlaunch.utils.MCOptionUtils;
|
||||
|
||||
import org.lwjgl.glfw.*;
|
||||
import java.io.*;
|
||||
import com.google.gson.*;
|
||||
@ -17,6 +22,7 @@ public class MainActivity extends BaseMainActivity {
|
||||
|
||||
private View.OnClickListener mClickListener;
|
||||
private View.OnTouchListener mTouchListener;
|
||||
private FileObserver fileObserver;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@ -99,6 +105,28 @@ public class MainActivity extends BaseMainActivity {
|
||||
}
|
||||
};
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
|
||||
fileObserver = new FileObserver(new File(Tools.DIR_GAME_NEW + "/options.txt"), FileObserver.MODIFY) {
|
||||
@Override
|
||||
public void onEvent(int i, @Nullable String s) {
|
||||
//FIXME Make sure the multithreading nature of this event doesn't cause any problems ?
|
||||
MCOptionUtils.load();
|
||||
getMcScale();
|
||||
}
|
||||
};
|
||||
}else{
|
||||
fileObserver = new FileObserver(Tools.DIR_GAME_NEW + "/options.txt", FileObserver.MODIFY) {
|
||||
@Override
|
||||
public void onEvent(int i, @Nullable String s) {
|
||||
//FIXME Make sure the multithreading nature of this event doesn't cause any problems ?
|
||||
MCOptionUtils.load();
|
||||
getMcScale();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fileObserver.startWatching();
|
||||
|
||||
ControlData[] specialButtons = ControlData.getSpecialButtons();
|
||||
specialButtons[0].specialButtonListener
|
||||
= specialButtons[1].specialButtonListener
|
||||
|
@ -40,6 +40,20 @@ public class MCOptionUtils
|
||||
mLineList.add(key + ":" + value);
|
||||
}
|
||||
|
||||
public static String get(String key){
|
||||
if (mLineList == null){
|
||||
load();
|
||||
}
|
||||
for (int i = 0; i < mLineList.size(); i++) {
|
||||
String line = mLineList.get(i);
|
||||
if (line.startsWith(key + ":")) {
|
||||
String value = mLineList.get(i);
|
||||
return value.substring(value.indexOf(":")+1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < mLineList.size(); i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user