1 |
adbd16d9
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.screens;
|
21 |
|
|
|
22 |
|
|
import java.util.Random;
|
23 |
|
|
|
24 |
|
|
import android.content.SharedPreferences;
|
25 |
|
|
import android.os.Bundle;
|
26 |
|
|
import android.view.View;
|
27 |
|
|
import android.widget.LinearLayout;
|
28 |
|
|
|
29 |
|
|
import org.distorted.dialogs.RubikDialogFreePlaySettings;
|
30 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
31 |
|
|
import org.distorted.main.R;
|
32 |
|
|
import org.distorted.main.RubikActivity;
|
33 |
|
|
import org.distorted.objectlib.main.ObjectControl;
|
34 |
|
|
import org.distorted.objectlib.main.TwistyObject;
|
35 |
|
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
public class RubikScreenFreePlay extends RubikScreenBase
|
39 |
|
|
{
|
40 |
|
|
public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000};
|
41 |
|
|
public static final int ANIMATION_ON = 0;
|
42 |
|
|
public static final int ANIMATION_OFF = 1;
|
43 |
|
|
|
44 |
|
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton;
|
45 |
|
|
private int[][] mMoves;
|
46 |
|
|
private Random mRnd;
|
47 |
|
|
private int mAnimationMode;
|
48 |
|
|
private int mScrambleDepth;
|
49 |
|
|
|
50 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51 |
|
|
|
52 |
|
|
void leaveScreen(final RubikActivity act)
|
53 |
|
|
{
|
54 |
|
|
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
|
59 |
|
|
void enterScreen(final RubikActivity act)
|
60 |
|
|
{
|
61 |
|
|
int width = act.getScreenWidthInPixels();
|
62 |
|
|
|
63 |
|
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
64 |
|
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
65 |
|
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
66 |
|
|
|
67 |
|
|
// UPPER PANE /////////////
|
68 |
|
|
|
69 |
|
|
setupSolveButton(act);
|
70 |
|
|
setupSettingsButton(act);
|
71 |
|
|
setupScrambleButton(act);
|
72 |
|
|
|
73 |
|
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
74 |
|
|
|
75 |
|
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
76 |
|
|
layoutLeftU.setLayoutParams(paramsL);
|
77 |
|
|
LinearLayout layoutMidU = new LinearLayout(act);
|
78 |
|
|
layoutMidU.setLayoutParams(paramsM);
|
79 |
|
|
LinearLayout layoutRightU= new LinearLayout(act);
|
80 |
|
|
layoutRightU.setLayoutParams(paramsR);
|
81 |
|
|
|
82 |
|
|
layoutLeftU.addView(mSolveButton);
|
83 |
|
|
layoutMidU.addView(mSettingsButton);
|
84 |
|
|
layoutRightU.addView(mScrambleButton);
|
85 |
|
|
|
86 |
|
|
layoutUpper.removeAllViews();
|
87 |
|
|
layoutUpper.addView(layoutLeftU);
|
88 |
|
|
layoutUpper.addView(layoutMidU);
|
89 |
|
|
layoutUpper.addView(layoutRightU);
|
90 |
|
|
|
91 |
|
|
// LOWER PANE /////////////
|
92 |
|
|
|
93 |
|
|
setupBackButton(act);
|
94 |
|
|
createBottomPane(act,mBackButton,null);
|
95 |
|
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
private void setupBackButton(final RubikActivity act)
|
100 |
|
|
{
|
101 |
|
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
|
102 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
103 |
|
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
104 |
|
|
|
105 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
106 |
|
|
{
|
107 |
|
|
@Override
|
108 |
|
|
public void onClick(View v)
|
109 |
|
|
{
|
110 |
|
|
ScreenList.goBack(act);
|
111 |
|
|
}
|
112 |
|
|
});
|
113 |
|
|
}
|
114 |
|
|
|
115 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
|
117 |
|
|
private void setupSettingsButton(final RubikActivity act)
|
118 |
|
|
{
|
119 |
|
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_settings,R.drawable.ui_medium_settings, R.drawable.ui_big_settings, R.drawable.ui_huge_settings);
|
120 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
121 |
|
|
mSettingsButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
122 |
|
|
|
123 |
|
|
mSettingsButton.setOnClickListener( new View.OnClickListener()
|
124 |
|
|
{
|
125 |
|
|
@Override
|
126 |
|
|
public void onClick(View v)
|
127 |
|
|
{
|
128 |
|
|
Bundle bundle = new Bundle();
|
129 |
|
|
bundle.putInt("scraPos", mScrambleDepth );
|
130 |
|
|
bundle.putInt("animPos", mAnimationMode );
|
131 |
|
|
|
132 |
|
|
RubikDialogFreePlaySettings setDiag = new RubikDialogFreePlaySettings();
|
133 |
|
|
setDiag.setArguments(bundle);
|
134 |
|
|
setDiag.show(act.getSupportFragmentManager(), null);
|
135 |
|
|
}
|
136 |
|
|
});
|
137 |
|
|
}
|
138 |
|
|
|
139 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
140 |
|
|
|
141 |
|
|
private void setupSolveButton(final RubikActivity act)
|
142 |
|
|
{
|
143 |
|
|
int icon = RubikActivity.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);
|
144 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
145 |
|
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
146 |
|
|
|
147 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
148 |
|
|
{
|
149 |
|
|
@Override
|
150 |
|
|
public void onClick(View v)
|
151 |
|
|
{
|
152 |
|
|
ObjectControl control = act.getControl();
|
153 |
|
|
if( mAnimationMode==ANIMATION_OFF ) control.solveOnly();
|
154 |
|
|
if( mAnimationMode==ANIMATION_ON ) control.solveObject();
|
155 |
|
|
mMovesController.clearMoves(act);
|
156 |
|
|
}
|
157 |
|
|
});
|
158 |
|
|
}
|
159 |
|
|
|
160 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161 |
|
|
|
162 |
|
|
private void setupScrambleButton(final RubikActivity act)
|
163 |
|
|
{
|
164 |
|
|
int icon = RubikActivity.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);
|
165 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
166 |
|
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
167 |
|
|
|
168 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
169 |
|
|
{
|
170 |
|
|
@Override
|
171 |
|
|
public void onClick(View v)
|
172 |
|
|
{
|
173 |
|
|
ObjectControl control = act.getControl();
|
174 |
|
|
TwistyObject object = control.getObject();
|
175 |
|
|
|
176 |
|
|
int depth = DEPTHS[mScrambleDepth];
|
177 |
|
|
|
178 |
|
|
if( mAnimationMode==ANIMATION_OFF )
|
179 |
|
|
{
|
180 |
|
|
if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
|
181 |
|
|
if( mRnd==null ) mRnd = new Random();
|
182 |
|
|
|
183 |
|
|
for(int move=0; move<depth; move++)
|
184 |
|
|
{
|
185 |
|
|
object.randomizeNewScramble(mMoves, mRnd, move, depth);
|
186 |
|
|
}
|
187 |
|
|
for(int move=0; move<depth; move++)
|
188 |
|
|
{
|
189 |
|
|
int row = mMoves[move][1];
|
190 |
|
|
mMoves[move][1] = (1<<row);
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
control.initializeObject(mMoves);
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
if( mAnimationMode==ANIMATION_ON )
|
197 |
|
|
{
|
198 |
|
|
control.scrambleObject(depth);
|
199 |
|
|
}
|
200 |
|
|
}
|
201 |
|
|
});
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
205 |
|
|
|
206 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
207 |
|
|
{
|
208 |
|
|
editor.putInt("freePlayScreen_scramble" , mScrambleDepth);
|
209 |
|
|
editor.putInt("freePlayScreen_animation", mAnimationMode);
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213 |
|
|
|
214 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
215 |
|
|
{
|
216 |
|
|
mScrambleDepth = preferences.getInt("freePlayScreen_scramble" ,3);
|
217 |
|
|
mAnimationMode = preferences.getInt("freePlayScreen_animation",ANIMATION_OFF);
|
218 |
|
|
}
|
219 |
|
|
|
220 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
221 |
|
|
|
222 |
|
|
public void setAnimationMode(int mode)
|
223 |
|
|
{
|
224 |
|
|
mAnimationMode = mode;
|
225 |
|
|
}
|
226 |
|
|
|
227 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
228 |
|
|
|
229 |
|
|
public void setScrambleDepth(int depth)
|
230 |
|
|
{
|
231 |
|
|
mScrambleDepth = depth;
|
232 |
|
|
}
|
233 |
|
|
}
|