| 1 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
da56b12f
|
Leszek Koltunski
|
// Copyright 2022 Leszek Koltunski //
|
| 3 |
9530f6b0
|
Leszek Koltunski
|
// //
|
| 4 |
|
|
// This file is part of Magic Cube. //
|
| 5 |
|
|
// //
|
| 6 |
44fec653
|
Leszek Koltunski
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
| 7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
| 8 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 9 |
|
|
|
| 10 |
|
|
package org.distorted.bandaged;
|
| 11 |
|
|
|
| 12 |
88b94310
|
Leszek Koltunski
|
import android.app.Activity;
|
| 13 |
|
|
import android.content.SharedPreferences;
|
| 14 |
9530f6b0
|
Leszek Koltunski
|
import android.view.View;
|
| 15 |
|
|
import android.widget.LinearLayout;
|
| 16 |
|
|
|
| 17 |
|
|
import org.distorted.helpers.LockController;
|
| 18 |
|
|
import org.distorted.helpers.MovesController;
|
| 19 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
| 20 |
|
|
import org.distorted.main.R;
|
| 21 |
b1629e16
|
Leszek Koltunski
|
import org.distorted.objectlib.effects.BaseEffect;
|
| 22 |
9530f6b0
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
| 23 |
|
|
|
| 24 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 25 |
|
|
|
| 26 |
|
|
public class BandagedPlayScreen
|
| 27 |
|
|
{
|
| 28 |
bb3bc6a9
|
Leszek Koltunski
|
private static final int NUM_SCRAMBLES = 300;
|
| 29 |
b72b71a1
|
Leszek Koltunski
|
|
| 30 |
ca280c3f
|
Leszek Koltunski
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
|
| 31 |
9530f6b0
|
Leszek Koltunski
|
private final LockController mLockController;
|
| 32 |
b72b71a1
|
Leszek Koltunski
|
private final MovesController mMovesController;
|
| 33 |
972f9eae
|
Leszek Koltunski
|
private String mKey;
|
| 34 |
9530f6b0
|
Leszek Koltunski
|
|
| 35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 36 |
|
|
|
| 37 |
|
|
public BandagedPlayScreen()
|
| 38 |
|
|
{
|
| 39 |
|
|
mLockController = new LockController();
|
| 40 |
|
|
mMovesController= new MovesController();
|
| 41 |
|
|
}
|
| 42 |
|
|
|
| 43 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 44 |
|
|
|
| 45 |
|
|
private void setupBackButton(final BandagedPlayActivity act)
|
| 46 |
|
|
{
|
| 47 |
88b94310
|
Leszek Koltunski
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
|
| 48 |
9530f6b0
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
| 49 |
|
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
| 50 |
|
|
|
| 51 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
| 52 |
|
|
{
|
| 53 |
|
|
@Override
|
| 54 |
|
|
public void onClick(View v)
|
| 55 |
|
|
{
|
| 56 |
|
|
ObjectControl control = act.getControl();
|
| 57 |
|
|
if( control!=null ) control.unblockEverything();
|
| 58 |
|
|
act.finish();
|
| 59 |
|
|
}
|
| 60 |
|
|
});
|
| 61 |
|
|
}
|
| 62 |
|
|
|
| 63 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 64 |
|
|
|
| 65 |
f3563327
|
Leszek Koltunski
|
private void setupSolveButton(final BandagedPlayActivity act)
|
| 66 |
9530f6b0
|
Leszek Koltunski
|
{
|
| 67 |
f3563327
|
Leszek Koltunski
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
|
| 68 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
| 69 |
|
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
| 70 |
|
|
|
| 71 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
| 72 |
|
|
{
|
| 73 |
|
|
@Override
|
| 74 |
|
|
public void onClick(View v)
|
| 75 |
|
|
{
|
| 76 |
b72b71a1
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
| 77 |
ca280c3f
|
Leszek Koltunski
|
control.solveObject();
|
| 78 |
f3563327
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
| 79 |
|
|
}
|
| 80 |
|
|
});
|
| 81 |
|
|
}
|
| 82 |
|
|
|
| 83 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 84 |
9530f6b0
|
Leszek Koltunski
|
|
| 85 |
f3563327
|
Leszek Koltunski
|
private void setupScrambleButton(final BandagedPlayActivity act)
|
| 86 |
|
|
{
|
| 87 |
|
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
|
| 88 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
| 89 |
|
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
| 90 |
|
|
|
| 91 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
| 92 |
|
|
{
|
| 93 |
|
|
@Override
|
| 94 |
|
|
public void onClick(View v)
|
| 95 |
|
|
{
|
| 96 |
4844152a
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
| 97 |
b1629e16
|
Leszek Koltunski
|
int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
|
| 98 |
|
|
control.fastScrambleObject(duration,NUM_SCRAMBLES);
|
| 99 |
ca280c3f
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
| 100 |
f3563327
|
Leszek Koltunski
|
}
|
| 101 |
|
|
});
|
| 102 |
|
|
}
|
| 103 |
|
|
|
| 104 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 105 |
|
|
|
| 106 |
972f9eae
|
Leszek Koltunski
|
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
| 107 |
f3563327
|
Leszek Koltunski
|
{
|
| 108 |
972f9eae
|
Leszek Koltunski
|
mKey = "moveController_"+objectName;
|
| 109 |
|
|
|
| 110 |
f3563327
|
Leszek Koltunski
|
int width = act.getScreenWidthInPixels();
|
| 111 |
9530f6b0
|
Leszek Koltunski
|
|
| 112 |
|
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
| 113 |
|
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
| 114 |
|
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
| 115 |
|
|
|
| 116 |
|
|
LinearLayout layoutLeft = new LinearLayout(act);
|
| 117 |
|
|
layoutLeft.setLayoutParams(paramsL);
|
| 118 |
|
|
LinearLayout layoutMid = new LinearLayout(act);
|
| 119 |
|
|
layoutMid.setLayoutParams(paramsM);
|
| 120 |
|
|
LinearLayout layoutRight= new LinearLayout(act);
|
| 121 |
|
|
layoutRight.setLayoutParams(paramsR);
|
| 122 |
|
|
|
| 123 |
|
|
setupBackButton(act);
|
| 124 |
|
|
ObjectControl control = act.getControl();
|
| 125 |
|
|
mMovesController.setupButton(act,control);
|
| 126 |
|
|
layoutLeft.addView(mMovesController.getButton());
|
| 127 |
|
|
mLockController.setupButton(act,control);
|
| 128 |
|
|
layoutMid.addView(mLockController.getButton());
|
| 129 |
|
|
|
| 130 |
|
|
layoutRight.addView(mBackButton);
|
| 131 |
|
|
|
| 132 |
f3563327
|
Leszek Koltunski
|
LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
|
| 133 |
|
|
layoutLower.removeAllViews();
|
| 134 |
|
|
layoutLower.addView(layoutLeft);
|
| 135 |
|
|
layoutLower.addView(layoutMid);
|
| 136 |
|
|
layoutLower.addView(layoutRight);
|
| 137 |
|
|
|
| 138 |
|
|
setupSolveButton(act);
|
| 139 |
1db19441
|
Leszek Koltunski
|
setupScrambleButton(act);
|
| 140 |
f3563327
|
Leszek Koltunski
|
|
| 141 |
|
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
| 142 |
|
|
|
| 143 |
|
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
| 144 |
|
|
layoutLeftU.setLayoutParams(paramsL);
|
| 145 |
|
|
LinearLayout layoutMidU = new LinearLayout(act);
|
| 146 |
|
|
layoutMidU.setLayoutParams(paramsM);
|
| 147 |
|
|
LinearLayout layoutRightU= new LinearLayout(act);
|
| 148 |
|
|
layoutRightU.setLayoutParams(paramsR);
|
| 149 |
|
|
|
| 150 |
|
|
layoutLeftU.addView(mSolveButton);
|
| 151 |
|
|
layoutRightU.addView(mScrambleButton);
|
| 152 |
|
|
|
| 153 |
775d5361
|
Leszek Koltunski
|
layoutUpper.removeAllViews();
|
| 154 |
f3563327
|
Leszek Koltunski
|
layoutUpper.addView(layoutLeftU);
|
| 155 |
|
|
layoutUpper.addView(layoutMidU);
|
| 156 |
|
|
layoutUpper.addView(layoutRightU);
|
| 157 |
9530f6b0
|
Leszek Koltunski
|
}
|
| 158 |
|
|
|
| 159 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 160 |
|
|
|
| 161 |
88b94310
|
Leszek Koltunski
|
public void setLockState(final BandagedPlayActivity act)
|
| 162 |
9530f6b0
|
Leszek Koltunski
|
{
|
| 163 |
|
|
boolean locked = act.getControl().retLocked();
|
| 164 |
|
|
mLockController.setState(act,locked);
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 168 |
|
|
|
| 169 |
88b94310
|
Leszek Koltunski
|
public void reddenLock(final BandagedPlayActivity act)
|
| 170 |
9530f6b0
|
Leszek Koltunski
|
{
|
| 171 |
|
|
ObjectControl control = act.getControl();
|
| 172 |
|
|
mLockController.reddenLock(act,control);
|
| 173 |
|
|
}
|
| 174 |
88b94310
|
Leszek Koltunski
|
|
| 175 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 176 |
|
|
|
| 177 |
|
|
public void addMove(Activity act, int axis, int row, int angle)
|
| 178 |
|
|
{
|
| 179 |
|
|
mMovesController.addMove(act,axis,row,angle);
|
| 180 |
|
|
}
|
| 181 |
|
|
|
| 182 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 183 |
|
|
|
| 184 |
972f9eae
|
Leszek Koltunski
|
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
| 185 |
88b94310
|
Leszek Koltunski
|
{
|
| 186 |
972f9eae
|
Leszek Koltunski
|
mMovesController.savePreferences(mKey,editor);
|
| 187 |
|
|
ObjectControl control = act.getControl();
|
| 188 |
|
|
control.savePreferences(editor);
|
| 189 |
88b94310
|
Leszek Koltunski
|
}
|
| 190 |
|
|
|
| 191 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 192 |
|
|
|
| 193 |
972f9eae
|
Leszek Koltunski
|
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
| 194 |
88b94310
|
Leszek Koltunski
|
{
|
| 195 |
972f9eae
|
Leszek Koltunski
|
mMovesController.restorePreferences(act,mKey,preferences);
|
| 196 |
|
|
ObjectControl control = act.getControl();
|
| 197 |
|
|
control.restorePreferences(preferences);
|
| 198 |
b72b71a1
|
Leszek Koltunski
|
}
|
| 199 |
9530f6b0
|
Leszek Koltunski
|
}
|