45 |
45 |
import org.distorted.dialogs.RubikDialogScores;
|
46 |
46 |
import org.distorted.main.R;
|
47 |
47 |
import org.distorted.main.RubikActivity;
|
|
48 |
import org.distorted.main.RubikPreRender;
|
|
49 |
import org.distorted.objects.RubikObject;
|
48 |
50 |
import org.distorted.objects.RubikObjectList;
|
49 |
51 |
|
|
52 |
import java.util.ArrayList;
|
|
53 |
|
50 |
54 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
55 |
|
52 |
|
public class RubikStatePlay extends RubikStateAbstract implements AdapterView.OnItemSelectedListener
|
|
56 |
public class RubikStatePlay extends RubikStateAbstract implements AdapterView.OnItemSelectedListener,
|
|
57 |
RubikPreRender.ActionFinishedListener
|
53 |
58 |
{
|
|
59 |
private static final int DURATION_MILLIS = 750;
|
54 |
60 |
private static final int DEF_LEVEL = 1;
|
55 |
61 |
public static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal();
|
56 |
62 |
public static final int DEF_SIZE = 3;
|
... | ... | |
58 |
64 |
private static int[] BUTTON_LABELS = { R.string.scores, R.string.patterns, R.string.solver, R.string.about };
|
59 |
65 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length;
|
60 |
66 |
|
61 |
|
private ImageButton mObjButton, mMenuButton;
|
62 |
|
private Button mBackButton, mSolveButton, mPlayButton;
|
|
67 |
private ImageButton mObjButton, mMenuButton, mPrevButton, mSolveButton;
|
|
68 |
private Button mPlayButton;
|
63 |
69 |
private PopupWindow mObjectPopup, mMenuPopup;
|
64 |
70 |
private int mObject = DEF_OBJECT;
|
65 |
71 |
private int mSize = DEF_SIZE;
|
... | ... | |
70 |
76 |
private int mLevelValue;
|
71 |
77 |
private float mButtonSize, mTitleSize;
|
72 |
78 |
|
|
79 |
private ArrayList<Move> mMoves;
|
|
80 |
private boolean mCanPrevMove;
|
|
81 |
|
|
82 |
private static class Move
|
|
83 |
{
|
|
84 |
private int mAxis, mRow, mAngle;
|
|
85 |
|
|
86 |
Move(int axis, int row, int angle)
|
|
87 |
{
|
|
88 |
mAxis = axis;
|
|
89 |
mRow = row;
|
|
90 |
mAngle= angle;
|
|
91 |
}
|
|
92 |
}
|
|
93 |
|
73 |
94 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
95 |
|
75 |
96 |
void leaveState(RubikActivity act)
|
... | ... | |
88 |
109 |
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
89 |
110 |
mTitleSize = width*RubikActivity.TITLE_TEXT_SIZE;
|
90 |
111 |
|
|
112 |
mCanPrevMove = true;
|
|
113 |
|
|
114 |
if( mMoves==null ) mMoves = new ArrayList<>();
|
|
115 |
else mMoves.clear();
|
|
116 |
|
91 |
117 |
// TOP ////////////////////////////
|
92 |
118 |
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
93 |
119 |
layoutTop.removeAllViews();
|
... | ... | |
106 |
132 |
LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
|
107 |
133 |
layoutLeft.removeAllViews();
|
108 |
134 |
|
109 |
|
setupMenuButton(act,scale,width);
|
110 |
|
layoutLeft.addView(mMenuButton);
|
111 |
|
setupSolveButton(act,scale);
|
|
135 |
setupPrevButton(act,scale,width);
|
|
136 |
layoutLeft.addView(mPrevButton);
|
|
137 |
setupSolveButton(act,scale,width);
|
112 |
138 |
layoutLeft.addView(mSolveButton);
|
113 |
139 |
|
114 |
140 |
LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
|
115 |
141 |
layoutRight.removeAllViews();
|
116 |
142 |
|
117 |
|
setupBackButton(act,scale);
|
118 |
|
layoutRight.addView(mBackButton);
|
|
143 |
setupMenuButton(act,scale);
|
|
144 |
layoutRight.addView(mMenuButton);
|
119 |
145 |
|
120 |
146 |
setupMenuWindow(act, scale);
|
121 |
147 |
}
|
... | ... | |
161 |
187 |
|
162 |
188 |
private void setupLevelSpinner(final RubikActivity act, final float scale)
|
163 |
189 |
{
|
164 |
|
int spinnerPadding = (int)(scale* 10 + 0.5f);
|
165 |
|
int spinnerMargin = (int)(scale* 3 + 0.5f);
|
|
190 |
int padding = (int)(scale* 10 + 0.5f);
|
|
191 |
int margin = (int)(scale* 3 + 0.5f);
|
166 |
192 |
LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
|
167 |
|
spinnerLayoutParams.topMargin = spinnerMargin;
|
168 |
|
spinnerLayoutParams.bottomMargin = spinnerMargin;
|
169 |
|
spinnerLayoutParams.leftMargin = spinnerMargin;
|
170 |
|
spinnerLayoutParams.rightMargin = 2*spinnerMargin;
|
|
193 |
spinnerLayoutParams.topMargin = margin;
|
|
194 |
spinnerLayoutParams.bottomMargin = margin;
|
|
195 |
spinnerLayoutParams.leftMargin = margin;
|
|
196 |
spinnerLayoutParams.rightMargin = margin;
|
171 |
197 |
|
172 |
198 |
mLevelSpinner = new AppCompatSpinner(act);
|
173 |
199 |
mLevelSpinner.setLayoutParams(spinnerLayoutParams);
|
174 |
|
mLevelSpinner.setPadding(spinnerPadding,0,spinnerPadding,0);
|
|
200 |
mLevelSpinner.setPadding(padding,0,padding,0);
|
175 |
201 |
mLevelSpinner.setBackgroundResource(R.drawable.spinner);
|
176 |
202 |
mLevelSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
|
177 |
203 |
|
... | ... | |
228 |
254 |
|
229 |
255 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
230 |
256 |
|
231 |
|
private void setupMenuButton(final RubikActivity act, final float scale, final float width)
|
|
257 |
private void setupMenuButton(final RubikActivity act, final float scale)
|
232 |
258 |
{
|
233 |
259 |
int padding = (int)(3*scale + 0.5f);
|
234 |
|
int widthBut = (int)(width/6);
|
235 |
|
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(widthBut,LinearLayout.LayoutParams.MATCH_PARENT);
|
|
260 |
LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
|
236 |
261 |
mMenuButton = new ImageButton(act);
|
237 |
262 |
mMenuButton.setLayoutParams(objectParams);
|
238 |
263 |
mMenuButton.setPadding(padding,0,padding,0);
|
... | ... | |
258 |
283 |
|
259 |
284 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
260 |
285 |
|
261 |
|
private void setupSolveButton(final RubikActivity act, final float scale)
|
|
286 |
private void setupSolveButton(final RubikActivity act, final float scale, final float width)
|
262 |
287 |
{
|
263 |
288 |
int padding = (int)(3*scale + 0.5f);
|
264 |
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
265 |
|
mSolveButton = new Button(act);
|
|
289 |
int widthBut = (int)(width/6);
|
|
290 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(widthBut, LinearLayout.LayoutParams.MATCH_PARENT);
|
|
291 |
mSolveButton = new ImageButton(act);
|
266 |
292 |
mSolveButton.setLayoutParams(backParams);
|
267 |
293 |
mSolveButton.setPadding(padding,0,padding,0);
|
268 |
|
mSolveButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
|
269 |
|
|
270 |
|
mSolveButton.setText(R.string.solve);
|
|
294 |
mSolveButton.setImageResource(R.drawable.cube_solve);
|
271 |
295 |
|
272 |
296 |
mSolveButton.setOnClickListener( new View.OnClickListener()
|
273 |
297 |
{
|
... | ... | |
281 |
305 |
|
282 |
306 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283 |
307 |
|
284 |
|
private void setupBackButton(final RubikActivity act, final float scale)
|
|
308 |
private void setupPrevButton(final RubikActivity act, final float scale, final float width)
|
285 |
309 |
{
|
286 |
310 |
int padding = (int)(3*scale + 0.5f);
|
287 |
|
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
288 |
|
mBackButton = new Button(act);
|
289 |
|
mBackButton.setLayoutParams(backParams);
|
290 |
|
mBackButton.setPadding(padding,0,padding,0);
|
291 |
|
mBackButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, mButtonSize);
|
292 |
|
mBackButton.setText(R.string.exit);
|
293 |
|
|
294 |
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
|
311 |
int widthBut = (int)(width/6);
|
|
312 |
LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(widthBut, LinearLayout.LayoutParams.MATCH_PARENT);
|
|
313 |
mPrevButton = new ImageButton(act);
|
|
314 |
mPrevButton.setLayoutParams(backParams);
|
|
315 |
mPrevButton.setPadding(padding,0,padding,0);
|
|
316 |
mPrevButton.setImageResource(R.drawable.cube_back);
|
|
317 |
|
|
318 |
mPrevButton.setOnClickListener( new View.OnClickListener()
|
295 |
319 |
{
|
296 |
320 |
@Override
|
297 |
321 |
public void onClick(View v)
|
298 |
322 |
{
|
299 |
|
if( act.getPreRender().canPlay() ) RubikState.goBack(act);
|
|
323 |
RubikPreRender pre = act.getPreRender();
|
|
324 |
backMove(pre);
|
300 |
325 |
}
|
301 |
326 |
});
|
302 |
327 |
}
|
... | ... | |
398 |
423 |
mMenuLayoutHeight= (int)(margin + NUM_BUTTONS*(mButtonSize+margin));
|
399 |
424 |
}
|
400 |
425 |
|
|
426 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
427 |
|
|
428 |
private void backMove(RubikPreRender pre)
|
|
429 |
{
|
|
430 |
if( mCanPrevMove )
|
|
431 |
{
|
|
432 |
int numMoves = mMoves.size();
|
|
433 |
|
|
434 |
if( numMoves>0 )
|
|
435 |
{
|
|
436 |
Move move = mMoves.remove(numMoves-1);
|
|
437 |
RubikObject object = pre.getObject();
|
|
438 |
|
|
439 |
int axis = move.mAxis;
|
|
440 |
int row = (1<<move.mRow);
|
|
441 |
int angle = move.mAngle;
|
|
442 |
int numRot= Math.abs(angle*object.getBasicAngle()/360);
|
|
443 |
|
|
444 |
if( angle!=0 )
|
|
445 |
{
|
|
446 |
mCanPrevMove = false;
|
|
447 |
pre.addRotation(this, axis, row, -angle, numRot*DURATION_MILLIS);
|
|
448 |
}
|
|
449 |
else
|
|
450 |
{
|
|
451 |
android.util.Log.e("solution", "error: trying to back move of angle 0");
|
|
452 |
}
|
|
453 |
}
|
|
454 |
else
|
|
455 |
{
|
|
456 |
android.util.Log.e("solv", "error: no moves to back!");
|
|
457 |
}
|
|
458 |
}
|
|
459 |
}
|
401 |
460 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
402 |
461 |
|
403 |
462 |
private void Action(RubikActivity act, int button)
|
... | ... | |
522 |
581 |
return mLevelValue;
|
523 |
582 |
}
|
524 |
583 |
|
|
584 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
585 |
|
|
586 |
public void addMove(int axis, int row, int angle)
|
|
587 |
{
|
|
588 |
mMoves.add(new Move(axis,row,angle));
|
|
589 |
}
|
|
590 |
|
525 |
591 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
526 |
592 |
|
527 |
593 |
public int getObject()
|
... | ... | |
546 |
612 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
547 |
613 |
|
548 |
614 |
public void onNothingSelected(AdapterView<?> parent) { }
|
|
615 |
|
|
616 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
617 |
|
|
618 |
public void onActionFinished(final long effectID)
|
|
619 |
{
|
|
620 |
mCanPrevMove = true;
|
|
621 |
}
|
549 |
622 |
}
|
cube_back and cube_solve buttons.