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 {
|
||||
protected CustomControls mLayout;
|
||||
/* Accessible when inside the game by ControlInterface implementations, cached for perf. */
|
||||
private MinecraftGLSurface mGameSurface = null;
|
||||
private boolean mModifiable = false;
|
||||
private CustomControlsActivity mActivity;
|
||||
private boolean mControlVisible = false;
|
||||
@ -386,4 +388,12 @@ public class ControlLayout extends FrameLayout {
|
||||
public void notifyAppMenu() {
|
||||
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:
|
||||
//Send the event to be taken as a mouse action
|
||||
if(getProperties().passThruEnabled && CallbackBridge.isGrabbing()){
|
||||
MinecraftGLSurface v = getControlLayoutParent().findViewById(R.id.main_game_render_view);
|
||||
if (v != null) v.dispatchTouchEvent(event);
|
||||
View gameSurface = getControlLayoutParent().getGameSurface();
|
||||
if(gameSurface != null) gameSurface.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
//If out of bounds
|
||||
@ -149,8 +149,8 @@ public class ControlButton extends TextView implements ControlInterface {
|
||||
case MotionEvent.ACTION_CANCEL: // 3
|
||||
case MotionEvent.ACTION_POINTER_UP: // 6
|
||||
if(getProperties().passThruEnabled){
|
||||
MinecraftGLSurface v = getControlLayoutParent().findViewById(R.id.main_game_render_view);
|
||||
if (v != null) v.dispatchTouchEvent(event);
|
||||
View gameSurface = getControlLayoutParent().getGameSurface();
|
||||
if(gameSurface != null) gameSurface.dispatchTouchEvent(event);
|
||||
}
|
||||
if(mIsPointerOutOfBounds) getControlLayoutParent().onTouch(this, event);
|
||||
mIsPointerOutOfBounds = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user