mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-15 15:48:26 -04:00
Refactor: Cache findViewById of game surface
This commit is contained in:
parent
7cc5a24f54
commit
9a403f2926
@ -26,6 +26,8 @@ import net.kdt.pojavlaunch.prefs.*;
|
|||||||
|
|
||||||
public class ControlLayout extends FrameLayout {
|
public class ControlLayout extends FrameLayout {
|
||||||
protected CustomControls mLayout;
|
protected CustomControls mLayout;
|
||||||
|
/* Accessible when inside the game by ControlInterface implementations, cached for perf. */
|
||||||
|
private MinecraftGLSurface mGameSurface = null;
|
||||||
private boolean mModifiable = false;
|
private boolean mModifiable = false;
|
||||||
private CustomControlsActivity mActivity;
|
private CustomControlsActivity mActivity;
|
||||||
private boolean mControlVisible = false;
|
private boolean mControlVisible = false;
|
||||||
@ -386,4 +388,12 @@ public class ControlLayout extends FrameLayout {
|
|||||||
public void notifyAppMenu() {
|
public void notifyAppMenu() {
|
||||||
if(mMenuListener != null) mMenuListener.onClickedMenu();
|
if(mMenuListener != null) mMenuListener.onClickedMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Cached getter for perf purposes */
|
||||||
|
public MinecraftGLSurface getGameSurface(){
|
||||||
|
if(mGameSurface == null){
|
||||||
|
mGameSurface = findViewById(R.id.main_game_render_view);
|
||||||
|
}
|
||||||
|
return mGameSurface;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,8 +109,8 @@ public class ControlButton extends TextView implements ControlInterface {
|
|||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
//Send the event to be taken as a mouse action
|
//Send the event to be taken as a mouse action
|
||||||
if(getProperties().passThruEnabled && CallbackBridge.isGrabbing()){
|
if(getProperties().passThruEnabled && CallbackBridge.isGrabbing()){
|
||||||
MinecraftGLSurface v = getControlLayoutParent().findViewById(R.id.main_game_render_view);
|
View gameSurface = getControlLayoutParent().getGameSurface();
|
||||||
if (v != null) v.dispatchTouchEvent(event);
|
if(gameSurface != null) gameSurface.dispatchTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If out of bounds
|
//If out of bounds
|
||||||
@ -149,8 +149,8 @@ public class ControlButton extends TextView implements ControlInterface {
|
|||||||
case MotionEvent.ACTION_CANCEL: // 3
|
case MotionEvent.ACTION_CANCEL: // 3
|
||||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
case MotionEvent.ACTION_POINTER_UP: // 6
|
||||||
if(getProperties().passThruEnabled){
|
if(getProperties().passThruEnabled){
|
||||||
MinecraftGLSurface v = getControlLayoutParent().findViewById(R.id.main_game_render_view);
|
View gameSurface = getControlLayoutParent().getGameSurface();
|
||||||
if (v != null) v.dispatchTouchEvent(event);
|
if(gameSurface != null) gameSurface.dispatchTouchEvent(event);
|
||||||
}
|
}
|
||||||
if(mIsPointerOutOfBounds) getControlLayoutParent().onTouch(this, event);
|
if(mIsPointerOutOfBounds) getControlLayoutParent().onTouch(this, event);
|
||||||
mIsPointerOutOfBounds = false;
|
mIsPointerOutOfBounds = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user