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 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.bandaged;
|
21 |
|
|
|
22 |
b72b71a1
|
Leszek Koltunski
|
import java.util.Random;
|
23 |
|
|
|
24 |
88b94310
|
Leszek Koltunski
|
import android.app.Activity;
|
25 |
|
|
import android.content.SharedPreferences;
|
26 |
917d15f5
|
Leszek Koltunski
|
import android.os.Bundle;
|
27 |
9530f6b0
|
Leszek Koltunski
|
import android.view.View;
|
28 |
|
|
import android.widget.LinearLayout;
|
29 |
|
|
|
30 |
1db19441
|
Leszek Koltunski
|
import org.distorted.dialogs.RubikDialogBandagedSettings;
|
31 |
9530f6b0
|
Leszek Koltunski
|
import org.distorted.helpers.LockController;
|
32 |
|
|
import org.distorted.helpers.MovesController;
|
33 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
34 |
|
|
import org.distorted.main.R;
|
35 |
|
|
import org.distorted.objectlib.main.ObjectControl;
|
36 |
4844152a
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
37 |
9530f6b0
|
Leszek Koltunski
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
|
|
public class BandagedPlayScreen
|
41 |
|
|
{
|
42 |
d9a49dde
|
Leszek Koltunski
|
public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000};
|
43 |
b72b71a1
|
Leszek Koltunski
|
public static final int ANIMATION_ON = 0;
|
44 |
|
|
public static final int ANIMATION_OFF = 1;
|
45 |
|
|
|
46 |
1db19441
|
Leszek Koltunski
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton;
|
47 |
9530f6b0
|
Leszek Koltunski
|
private final LockController mLockController;
|
48 |
b72b71a1
|
Leszek Koltunski
|
private final MovesController mMovesController;
|
49 |
972f9eae
|
Leszek Koltunski
|
private String mKey;
|
50 |
b72b71a1
|
Leszek Koltunski
|
private int[][] mMoves;
|
51 |
|
|
private Random mRnd;
|
52 |
|
|
|
53 |
|
|
private int mAnimationMode;
|
54 |
|
|
private int mScrambleDepth;
|
55 |
9530f6b0
|
Leszek Koltunski
|
|
56 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
57 |
|
|
|
58 |
|
|
public BandagedPlayScreen()
|
59 |
|
|
{
|
60 |
|
|
mLockController = new LockController();
|
61 |
|
|
mMovesController= new MovesController();
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
65 |
|
|
|
66 |
|
|
private void setupBackButton(final BandagedPlayActivity act)
|
67 |
|
|
{
|
68 |
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);
|
69 |
9530f6b0
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
70 |
|
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
71 |
|
|
|
72 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
73 |
|
|
{
|
74 |
|
|
@Override
|
75 |
|
|
public void onClick(View v)
|
76 |
|
|
{
|
77 |
|
|
ObjectControl control = act.getControl();
|
78 |
|
|
if( control!=null ) control.unblockEverything();
|
79 |
|
|
act.finish();
|
80 |
|
|
}
|
81 |
|
|
});
|
82 |
|
|
}
|
83 |
|
|
|
84 |
1db19441
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85 |
|
|
|
86 |
|
|
private void setupSettingsButton(final BandagedPlayActivity act)
|
87 |
|
|
{
|
88 |
|
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_settings,R.drawable.ui_medium_settings, R.drawable.ui_big_settings, R.drawable.ui_huge_settings);
|
89 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
90 |
|
|
mSettingsButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
91 |
|
|
|
92 |
|
|
mSettingsButton.setOnClickListener( new View.OnClickListener()
|
93 |
|
|
{
|
94 |
|
|
@Override
|
95 |
|
|
public void onClick(View v)
|
96 |
|
|
{
|
97 |
917d15f5
|
Leszek Koltunski
|
Bundle bundle = new Bundle();
|
98 |
|
|
bundle.putInt("scraPos", mScrambleDepth );
|
99 |
|
|
bundle.putInt("animPos", mAnimationMode );
|
100 |
|
|
|
101 |
1db19441
|
Leszek Koltunski
|
RubikDialogBandagedSettings setDiag = new RubikDialogBandagedSettings();
|
102 |
917d15f5
|
Leszek Koltunski
|
setDiag.setArguments(bundle);
|
103 |
1db19441
|
Leszek Koltunski
|
setDiag.show(act.getSupportFragmentManager(), null);
|
104 |
|
|
}
|
105 |
|
|
});
|
106 |
|
|
}
|
107 |
|
|
|
108 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
f3563327
|
Leszek Koltunski
|
private void setupSolveButton(final BandagedPlayActivity act)
|
111 |
9530f6b0
|
Leszek Koltunski
|
{
|
112 |
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);
|
113 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
114 |
|
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
115 |
|
|
|
116 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
117 |
|
|
{
|
118 |
|
|
@Override
|
119 |
|
|
public void onClick(View v)
|
120 |
|
|
{
|
121 |
b72b71a1
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
122 |
|
|
if( mAnimationMode==ANIMATION_OFF ) control.solveOnly();
|
123 |
|
|
if( mAnimationMode==ANIMATION_ON ) control.solveObject();
|
124 |
f3563327
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
125 |
|
|
}
|
126 |
|
|
});
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
9530f6b0
|
Leszek Koltunski
|
|
131 |
f3563327
|
Leszek Koltunski
|
private void setupScrambleButton(final BandagedPlayActivity act)
|
132 |
|
|
{
|
133 |
|
|
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);
|
134 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
135 |
|
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
136 |
|
|
|
137 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
138 |
|
|
{
|
139 |
|
|
@Override
|
140 |
|
|
public void onClick(View v)
|
141 |
|
|
{
|
142 |
4844152a
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
143 |
|
|
TwistyObject object = control.getObject();
|
144 |
b72b71a1
|
Leszek Koltunski
|
|
145 |
36bf9f0b
|
Leszek Koltunski
|
int depth = DEPTHS[mScrambleDepth];
|
146 |
917d15f5
|
Leszek Koltunski
|
|
147 |
b72b71a1
|
Leszek Koltunski
|
if( mAnimationMode==ANIMATION_OFF )
|
148 |
|
|
{
|
149 |
917d15f5
|
Leszek Koltunski
|
if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
|
150 |
b72b71a1
|
Leszek Koltunski
|
if( mRnd==null ) mRnd = new Random();
|
151 |
|
|
|
152 |
917d15f5
|
Leszek Koltunski
|
for(int move=0; move<depth; move++)
|
153 |
b72b71a1
|
Leszek Koltunski
|
{
|
154 |
917d15f5
|
Leszek Koltunski
|
object.randomizeNewScramble(mMoves, mRnd, move, depth);
|
155 |
b72b71a1
|
Leszek Koltunski
|
}
|
156 |
917d15f5
|
Leszek Koltunski
|
for(int move=0; move<depth; move++)
|
157 |
b72b71a1
|
Leszek Koltunski
|
{
|
158 |
|
|
int row = mMoves[move][1];
|
159 |
|
|
mMoves[move][1] = (1<<row);
|
160 |
|
|
}
|
161 |
|
|
|
162 |
|
|
control.initializeObject(mMoves);
|
163 |
|
|
}
|
164 |
|
|
|
165 |
|
|
if( mAnimationMode==ANIMATION_ON )
|
166 |
|
|
{
|
167 |
917d15f5
|
Leszek Koltunski
|
control.scrambleObject(depth);
|
168 |
b72b71a1
|
Leszek Koltunski
|
}
|
169 |
f3563327
|
Leszek Koltunski
|
}
|
170 |
|
|
});
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
|
|
|
175 |
972f9eae
|
Leszek Koltunski
|
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
176 |
f3563327
|
Leszek Koltunski
|
{
|
177 |
972f9eae
|
Leszek Koltunski
|
mKey = "moveController_"+objectName;
|
178 |
|
|
|
179 |
f3563327
|
Leszek Koltunski
|
int width = act.getScreenWidthInPixels();
|
180 |
9530f6b0
|
Leszek Koltunski
|
|
181 |
|
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
182 |
|
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
183 |
|
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
184 |
|
|
|
185 |
|
|
LinearLayout layoutLeft = new LinearLayout(act);
|
186 |
|
|
layoutLeft.setLayoutParams(paramsL);
|
187 |
|
|
LinearLayout layoutMid = new LinearLayout(act);
|
188 |
|
|
layoutMid.setLayoutParams(paramsM);
|
189 |
|
|
LinearLayout layoutRight= new LinearLayout(act);
|
190 |
|
|
layoutRight.setLayoutParams(paramsR);
|
191 |
|
|
|
192 |
|
|
setupBackButton(act);
|
193 |
|
|
ObjectControl control = act.getControl();
|
194 |
|
|
mMovesController.setupButton(act,control);
|
195 |
|
|
layoutLeft.addView(mMovesController.getButton());
|
196 |
|
|
mLockController.setupButton(act,control);
|
197 |
|
|
layoutMid.addView(mLockController.getButton());
|
198 |
|
|
|
199 |
|
|
layoutRight.addView(mBackButton);
|
200 |
|
|
|
201 |
f3563327
|
Leszek Koltunski
|
LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
|
202 |
|
|
layoutLower.removeAllViews();
|
203 |
|
|
layoutLower.addView(layoutLeft);
|
204 |
|
|
layoutLower.addView(layoutMid);
|
205 |
|
|
layoutLower.addView(layoutRight);
|
206 |
|
|
|
207 |
|
|
setupSolveButton(act);
|
208 |
ecf1aaaa
|
Leszek Koltunski
|
setupSettingsButton(act);
|
209 |
1db19441
|
Leszek Koltunski
|
setupScrambleButton(act);
|
210 |
f3563327
|
Leszek Koltunski
|
|
211 |
|
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
212 |
|
|
|
213 |
|
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
214 |
|
|
layoutLeftU.setLayoutParams(paramsL);
|
215 |
|
|
LinearLayout layoutMidU = new LinearLayout(act);
|
216 |
|
|
layoutMidU.setLayoutParams(paramsM);
|
217 |
|
|
LinearLayout layoutRightU= new LinearLayout(act);
|
218 |
|
|
layoutRightU.setLayoutParams(paramsR);
|
219 |
|
|
|
220 |
|
|
layoutLeftU.addView(mSolveButton);
|
221 |
ecf1aaaa
|
Leszek Koltunski
|
layoutMidU.addView(mSettingsButton);
|
222 |
f3563327
|
Leszek Koltunski
|
layoutRightU.addView(mScrambleButton);
|
223 |
|
|
|
224 |
775d5361
|
Leszek Koltunski
|
layoutUpper.removeAllViews();
|
225 |
f3563327
|
Leszek Koltunski
|
layoutUpper.addView(layoutLeftU);
|
226 |
|
|
layoutUpper.addView(layoutMidU);
|
227 |
|
|
layoutUpper.addView(layoutRightU);
|
228 |
9530f6b0
|
Leszek Koltunski
|
}
|
229 |
|
|
|
230 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
231 |
|
|
|
232 |
88b94310
|
Leszek Koltunski
|
public void setLockState(final BandagedPlayActivity act)
|
233 |
9530f6b0
|
Leszek Koltunski
|
{
|
234 |
|
|
boolean locked = act.getControl().retLocked();
|
235 |
|
|
mLockController.setState(act,locked);
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239 |
|
|
|
240 |
88b94310
|
Leszek Koltunski
|
public void reddenLock(final BandagedPlayActivity act)
|
241 |
9530f6b0
|
Leszek Koltunski
|
{
|
242 |
|
|
ObjectControl control = act.getControl();
|
243 |
|
|
mLockController.reddenLock(act,control);
|
244 |
|
|
}
|
245 |
88b94310
|
Leszek Koltunski
|
|
246 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247 |
|
|
|
248 |
|
|
public void addMove(Activity act, int axis, int row, int angle)
|
249 |
|
|
{
|
250 |
|
|
mMovesController.addMove(act,axis,row,angle);
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254 |
|
|
|
255 |
972f9eae
|
Leszek Koltunski
|
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
256 |
88b94310
|
Leszek Koltunski
|
{
|
257 |
972f9eae
|
Leszek Koltunski
|
mMovesController.savePreferences(mKey,editor);
|
258 |
|
|
ObjectControl control = act.getControl();
|
259 |
|
|
control.savePreferences(editor);
|
260 |
917d15f5
|
Leszek Koltunski
|
|
261 |
|
|
editor.putInt("playScreen_scramble" , mScrambleDepth);
|
262 |
|
|
editor.putInt("playScreen_animation", mAnimationMode);
|
263 |
88b94310
|
Leszek Koltunski
|
}
|
264 |
|
|
|
265 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
266 |
|
|
|
267 |
972f9eae
|
Leszek Koltunski
|
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
268 |
88b94310
|
Leszek Koltunski
|
{
|
269 |
972f9eae
|
Leszek Koltunski
|
mMovesController.restorePreferences(act,mKey,preferences);
|
270 |
|
|
ObjectControl control = act.getControl();
|
271 |
|
|
control.restorePreferences(preferences);
|
272 |
917d15f5
|
Leszek Koltunski
|
|
273 |
e7507e16
|
Leszek Koltunski
|
mScrambleDepth = preferences.getInt("playScreen_scramble" ,3);
|
274 |
917d15f5
|
Leszek Koltunski
|
mAnimationMode = preferences.getInt("playScreen_animation",ANIMATION_OFF);
|
275 |
88b94310
|
Leszek Koltunski
|
}
|
276 |
b72b71a1
|
Leszek Koltunski
|
|
277 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278 |
|
|
|
279 |
|
|
public void setAnimationMode(int mode)
|
280 |
|
|
{
|
281 |
|
|
mAnimationMode = mode;
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
285 |
|
|
|
286 |
|
|
public void setScrambleDepth(int depth)
|
287 |
|
|
{
|
288 |
|
|
mScrambleDepth = depth;
|
289 |
|
|
}
|
290 |
9530f6b0
|
Leszek Koltunski
|
}
|