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 |
88b94310
|
Leszek Koltunski
|
import android.app.Activity;
|
23 |
|
|
import android.content.SharedPreferences;
|
24 |
9530f6b0
|
Leszek Koltunski
|
import android.view.View;
|
25 |
|
|
import android.widget.LinearLayout;
|
26 |
|
|
|
27 |
|
|
import org.distorted.helpers.LockController;
|
28 |
|
|
import org.distorted.helpers.MovesController;
|
29 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
30 |
|
|
import org.distorted.main.R;
|
31 |
|
|
import org.distorted.objectlib.main.ObjectControl;
|
32 |
4844152a
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
33 |
|
|
import org.distorted.objectlib.scrambling.ObjectScrambler;
|
34 |
9530f6b0
|
Leszek Koltunski
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
public class BandagedPlayScreen
|
38 |
|
|
{
|
39 |
f3563327
|
Leszek Koltunski
|
private static final int NUM_SCRAMBLES = 24;
|
40 |
|
|
|
41 |
9530f6b0
|
Leszek Koltunski
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
|
42 |
|
|
private final LockController mLockController;
|
43 |
972f9eae
|
Leszek Koltunski
|
private MovesController mMovesController;
|
44 |
|
|
private String mKey;
|
45 |
9530f6b0
|
Leszek Koltunski
|
|
46 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47 |
|
|
|
48 |
|
|
public BandagedPlayScreen()
|
49 |
|
|
{
|
50 |
|
|
mLockController = new LockController();
|
51 |
|
|
mMovesController= new MovesController();
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55 |
|
|
|
56 |
|
|
private void setupBackButton(final BandagedPlayActivity act)
|
57 |
|
|
{
|
58 |
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);
|
59 |
9530f6b0
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
60 |
|
|
mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
61 |
|
|
|
62 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
63 |
|
|
{
|
64 |
|
|
@Override
|
65 |
|
|
public void onClick(View v)
|
66 |
|
|
{
|
67 |
|
|
ObjectControl control = act.getControl();
|
68 |
|
|
if( control!=null ) control.unblockEverything();
|
69 |
|
|
act.finish();
|
70 |
|
|
}
|
71 |
|
|
});
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75 |
|
|
|
76 |
f3563327
|
Leszek Koltunski
|
private void setupSolveButton(final BandagedPlayActivity act)
|
77 |
9530f6b0
|
Leszek Koltunski
|
{
|
78 |
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);
|
79 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
80 |
|
|
mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
|
81 |
|
|
|
82 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
83 |
|
|
{
|
84 |
|
|
@Override
|
85 |
|
|
public void onClick(View v)
|
86 |
|
|
{
|
87 |
|
|
act.getControl().solveObject();
|
88 |
|
|
mMovesController.clearMoves(act);
|
89 |
|
|
}
|
90 |
|
|
});
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
94 |
9530f6b0
|
Leszek Koltunski
|
|
95 |
f3563327
|
Leszek Koltunski
|
private void setupScrambleButton(final BandagedPlayActivity act)
|
96 |
|
|
{
|
97 |
|
|
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);
|
98 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
99 |
|
|
mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
|
100 |
|
|
|
101 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
102 |
|
|
{
|
103 |
|
|
@Override
|
104 |
|
|
public void onClick(View v)
|
105 |
|
|
{
|
106 |
4844152a
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
107 |
|
|
TwistyObject object = control.getObject();
|
108 |
|
|
ObjectScrambler.setSignature(object.getSignature());
|
109 |
|
|
control.scrambleObject(NUM_SCRAMBLES);
|
110 |
f3563327
|
Leszek Koltunski
|
}
|
111 |
|
|
});
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
972f9eae
|
Leszek Koltunski
|
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
117 |
f3563327
|
Leszek Koltunski
|
{
|
118 |
972f9eae
|
Leszek Koltunski
|
mKey = "moveController_"+objectName;
|
119 |
|
|
|
120 |
f3563327
|
Leszek Koltunski
|
int width = act.getScreenWidthInPixels();
|
121 |
9530f6b0
|
Leszek Koltunski
|
|
122 |
|
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
123 |
|
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
124 |
|
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
125 |
|
|
|
126 |
|
|
LinearLayout layoutLeft = new LinearLayout(act);
|
127 |
|
|
layoutLeft.setLayoutParams(paramsL);
|
128 |
|
|
LinearLayout layoutMid = new LinearLayout(act);
|
129 |
|
|
layoutMid.setLayoutParams(paramsM);
|
130 |
|
|
LinearLayout layoutRight= new LinearLayout(act);
|
131 |
|
|
layoutRight.setLayoutParams(paramsR);
|
132 |
|
|
|
133 |
|
|
setupBackButton(act);
|
134 |
|
|
ObjectControl control = act.getControl();
|
135 |
|
|
mMovesController.setupButton(act,control);
|
136 |
|
|
layoutLeft.addView(mMovesController.getButton());
|
137 |
|
|
mLockController.setupButton(act,control);
|
138 |
|
|
layoutMid.addView(mLockController.getButton());
|
139 |
|
|
|
140 |
|
|
layoutRight.addView(mBackButton);
|
141 |
|
|
|
142 |
f3563327
|
Leszek Koltunski
|
LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
|
143 |
|
|
layoutLower.removeAllViews();
|
144 |
|
|
layoutLower.addView(layoutLeft);
|
145 |
|
|
layoutLower.addView(layoutMid);
|
146 |
|
|
layoutLower.addView(layoutRight);
|
147 |
|
|
|
148 |
|
|
setupScrambleButton(act);
|
149 |
|
|
setupSolveButton(act);
|
150 |
|
|
|
151 |
|
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
152 |
|
|
|
153 |
|
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
154 |
|
|
layoutLeftU.setLayoutParams(paramsL);
|
155 |
|
|
LinearLayout layoutMidU = new LinearLayout(act);
|
156 |
|
|
layoutMidU.setLayoutParams(paramsM);
|
157 |
|
|
LinearLayout layoutRightU= new LinearLayout(act);
|
158 |
|
|
layoutRightU.setLayoutParams(paramsR);
|
159 |
|
|
|
160 |
|
|
layoutLeftU.addView(mSolveButton);
|
161 |
|
|
layoutRightU.addView(mScrambleButton);
|
162 |
|
|
|
163 |
775d5361
|
Leszek Koltunski
|
layoutUpper.removeAllViews();
|
164 |
f3563327
|
Leszek Koltunski
|
layoutUpper.addView(layoutLeftU);
|
165 |
|
|
layoutUpper.addView(layoutMidU);
|
166 |
|
|
layoutUpper.addView(layoutRightU);
|
167 |
9530f6b0
|
Leszek Koltunski
|
}
|
168 |
|
|
|
169 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170 |
|
|
|
171 |
88b94310
|
Leszek Koltunski
|
public void setLockState(final BandagedPlayActivity act)
|
172 |
9530f6b0
|
Leszek Koltunski
|
{
|
173 |
|
|
boolean locked = act.getControl().retLocked();
|
174 |
|
|
mLockController.setState(act,locked);
|
175 |
|
|
}
|
176 |
|
|
|
177 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
178 |
|
|
|
179 |
88b94310
|
Leszek Koltunski
|
public void reddenLock(final BandagedPlayActivity act)
|
180 |
9530f6b0
|
Leszek Koltunski
|
{
|
181 |
|
|
ObjectControl control = act.getControl();
|
182 |
|
|
mLockController.reddenLock(act,control);
|
183 |
|
|
}
|
184 |
88b94310
|
Leszek Koltunski
|
|
185 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
|
|
|
187 |
|
|
public void addMove(Activity act, int axis, int row, int angle)
|
188 |
|
|
{
|
189 |
|
|
mMovesController.addMove(act,axis,row,angle);
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
193 |
|
|
|
194 |
972f9eae
|
Leszek Koltunski
|
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
195 |
88b94310
|
Leszek Koltunski
|
{
|
196 |
972f9eae
|
Leszek Koltunski
|
mMovesController.savePreferences(mKey,editor);
|
197 |
|
|
ObjectControl control = act.getControl();
|
198 |
|
|
control.savePreferences(editor);
|
199 |
88b94310
|
Leszek Koltunski
|
}
|
200 |
|
|
|
201 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
|
|
|
203 |
972f9eae
|
Leszek Koltunski
|
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
204 |
88b94310
|
Leszek Koltunski
|
{
|
205 |
972f9eae
|
Leszek Koltunski
|
mMovesController.restorePreferences(act,mKey,preferences);
|
206 |
|
|
ObjectControl control = act.getControl();
|
207 |
|
|
control.restorePreferences(preferences);
|
208 |
88b94310
|
Leszek Koltunski
|
}
|
209 |
9530f6b0
|
Leszek Koltunski
|
}
|