1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2022 Leszek Koltunski //
|
3
|
// //
|
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
|
import java.util.Random;
|
23
|
|
24
|
import android.app.Activity;
|
25
|
import android.content.SharedPreferences;
|
26
|
import android.os.Bundle;
|
27
|
import android.view.View;
|
28
|
import android.widget.LinearLayout;
|
29
|
|
30
|
import org.distorted.dialogs.RubikDialogBandagedSettings;
|
31
|
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
|
import org.distorted.objectlib.main.TwistyObject;
|
37
|
import org.distorted.objectlib.scrambling.ObjectScrambler;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public class BandagedPlayScreen
|
42
|
{
|
43
|
public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000};
|
44
|
public static final int ANIMATION_ON = 0;
|
45
|
public static final int ANIMATION_OFF = 1;
|
46
|
|
47
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton;
|
48
|
private final LockController mLockController;
|
49
|
private final MovesController mMovesController;
|
50
|
private String mKey;
|
51
|
private int[][] mMoves;
|
52
|
private Random mRnd;
|
53
|
|
54
|
private int mAnimationMode;
|
55
|
private int mScrambleDepth;
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
|
59
|
public BandagedPlayScreen()
|
60
|
{
|
61
|
mLockController = new LockController();
|
62
|
mMovesController= new MovesController();
|
63
|
}
|
64
|
|
65
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
|
67
|
private void setupBackButton(final BandagedPlayActivity act)
|
68
|
{
|
69
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
|
70
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
71
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
72
|
|
73
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
74
|
{
|
75
|
@Override
|
76
|
public void onClick(View v)
|
77
|
{
|
78
|
ObjectControl control = act.getControl();
|
79
|
if( control!=null ) control.unblockEverything();
|
80
|
act.finish();
|
81
|
}
|
82
|
});
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
|
87
|
private void setupSettingsButton(final BandagedPlayActivity act)
|
88
|
{
|
89
|
int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_settings,R.drawable.ui_medium_settings, R.drawable.ui_big_settings, R.drawable.ui_huge_settings);
|
90
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
91
|
mSettingsButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
92
|
|
93
|
mSettingsButton.setOnClickListener( new View.OnClickListener()
|
94
|
{
|
95
|
@Override
|
96
|
public void onClick(View v)
|
97
|
{
|
98
|
Bundle bundle = new Bundle();
|
99
|
bundle.putInt("scraPos", mScrambleDepth );
|
100
|
bundle.putInt("animPos", mAnimationMode );
|
101
|
|
102
|
RubikDialogBandagedSettings setDiag = new RubikDialogBandagedSettings();
|
103
|
setDiag.setArguments(bundle);
|
104
|
setDiag.show(act.getSupportFragmentManager(), null);
|
105
|
}
|
106
|
});
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
private void setupSolveButton(final BandagedPlayActivity act)
|
112
|
{
|
113
|
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);
|
114
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
115
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
116
|
|
117
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
118
|
{
|
119
|
@Override
|
120
|
public void onClick(View v)
|
121
|
{
|
122
|
ObjectControl control = act.getControl();
|
123
|
if( mAnimationMode==ANIMATION_OFF ) control.solveOnly();
|
124
|
if( mAnimationMode==ANIMATION_ON ) control.solveObject();
|
125
|
mMovesController.clearMoves(act);
|
126
|
}
|
127
|
});
|
128
|
}
|
129
|
|
130
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131
|
|
132
|
private void setupScrambleButton(final BandagedPlayActivity act)
|
133
|
{
|
134
|
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);
|
135
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
136
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
137
|
|
138
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
139
|
{
|
140
|
@Override
|
141
|
public void onClick(View v)
|
142
|
{
|
143
|
ObjectControl control = act.getControl();
|
144
|
TwistyObject object = control.getObject();
|
145
|
ObjectScrambler.setSignature(object.getSignature());
|
146
|
|
147
|
int depth = DEPTHS[mScrambleDepth];
|
148
|
|
149
|
if( mAnimationMode==ANIMATION_OFF )
|
150
|
{
|
151
|
if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
|
152
|
if( mRnd==null ) mRnd = new Random();
|
153
|
|
154
|
for(int move=0; move<depth; move++)
|
155
|
{
|
156
|
object.randomizeNewScramble(mMoves, mRnd, move, depth);
|
157
|
}
|
158
|
for(int move=0; move<depth; move++)
|
159
|
{
|
160
|
int row = mMoves[move][1];
|
161
|
mMoves[move][1] = (1<<row);
|
162
|
}
|
163
|
|
164
|
control.initializeObject(mMoves);
|
165
|
}
|
166
|
|
167
|
if( mAnimationMode==ANIMATION_ON )
|
168
|
{
|
169
|
control.scrambleObject(depth);
|
170
|
}
|
171
|
}
|
172
|
});
|
173
|
}
|
174
|
|
175
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
176
|
|
177
|
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
178
|
{
|
179
|
mKey = "moveController_"+objectName;
|
180
|
|
181
|
int width = act.getScreenWidthInPixels();
|
182
|
|
183
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
184
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
185
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
186
|
|
187
|
LinearLayout layoutLeft = new LinearLayout(act);
|
188
|
layoutLeft.setLayoutParams(paramsL);
|
189
|
LinearLayout layoutMid = new LinearLayout(act);
|
190
|
layoutMid.setLayoutParams(paramsM);
|
191
|
LinearLayout layoutRight= new LinearLayout(act);
|
192
|
layoutRight.setLayoutParams(paramsR);
|
193
|
|
194
|
setupBackButton(act);
|
195
|
ObjectControl control = act.getControl();
|
196
|
mMovesController.setupButton(act,control);
|
197
|
layoutLeft.addView(mMovesController.getButton());
|
198
|
mLockController.setupButton(act,control);
|
199
|
layoutMid.addView(mLockController.getButton());
|
200
|
|
201
|
layoutRight.addView(mBackButton);
|
202
|
|
203
|
LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
|
204
|
layoutLower.removeAllViews();
|
205
|
layoutLower.addView(layoutLeft);
|
206
|
layoutLower.addView(layoutMid);
|
207
|
layoutLower.addView(layoutRight);
|
208
|
|
209
|
setupSolveButton(act);
|
210
|
//setupSettingsButton(act);
|
211
|
setupScrambleButton(act);
|
212
|
|
213
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
214
|
|
215
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
216
|
layoutLeftU.setLayoutParams(paramsL);
|
217
|
LinearLayout layoutMidU = new LinearLayout(act);
|
218
|
layoutMidU.setLayoutParams(paramsM);
|
219
|
LinearLayout layoutRightU= new LinearLayout(act);
|
220
|
layoutRightU.setLayoutParams(paramsR);
|
221
|
|
222
|
layoutLeftU.addView(mSolveButton);
|
223
|
//layoutMidU.addView(mSettingsButton);
|
224
|
layoutRightU.addView(mScrambleButton);
|
225
|
|
226
|
layoutUpper.removeAllViews();
|
227
|
layoutUpper.addView(layoutLeftU);
|
228
|
layoutUpper.addView(layoutMidU);
|
229
|
layoutUpper.addView(layoutRightU);
|
230
|
}
|
231
|
|
232
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233
|
|
234
|
public void setLockState(final BandagedPlayActivity act)
|
235
|
{
|
236
|
boolean locked = act.getControl().retLocked();
|
237
|
mLockController.setState(act,locked);
|
238
|
}
|
239
|
|
240
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
241
|
|
242
|
public void reddenLock(final BandagedPlayActivity act)
|
243
|
{
|
244
|
ObjectControl control = act.getControl();
|
245
|
mLockController.reddenLock(act,control);
|
246
|
}
|
247
|
|
248
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
249
|
|
250
|
public void addMove(Activity act, int axis, int row, int angle)
|
251
|
{
|
252
|
mMovesController.addMove(act,axis,row,angle);
|
253
|
}
|
254
|
|
255
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256
|
|
257
|
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
258
|
{
|
259
|
mMovesController.savePreferences(mKey,editor);
|
260
|
ObjectControl control = act.getControl();
|
261
|
control.savePreferences(editor);
|
262
|
|
263
|
editor.putInt("playScreen_scramble" , mScrambleDepth);
|
264
|
editor.putInt("playScreen_animation", mAnimationMode);
|
265
|
}
|
266
|
|
267
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
268
|
|
269
|
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
270
|
{
|
271
|
mMovesController.restorePreferences(act,mKey,preferences);
|
272
|
ObjectControl control = act.getControl();
|
273
|
control.restorePreferences(preferences);
|
274
|
|
275
|
mScrambleDepth = preferences.getInt("playScreen_scramble",1);
|
276
|
mAnimationMode = preferences.getInt("playScreen_animation",ANIMATION_OFF);
|
277
|
}
|
278
|
|
279
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
280
|
|
281
|
public void setAnimationMode(int mode)
|
282
|
{
|
283
|
mAnimationMode = mode;
|
284
|
}
|
285
|
|
286
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287
|
|
288
|
public void setScrambleDepth(int depth)
|
289
|
{
|
290
|
mScrambleDepth = depth;
|
291
|
}
|
292
|
}
|