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 |
44fec653
|
Leszek Koltunski
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
9530f6b0
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.bandaged;
|
11 |
|
|
|
12 |
88b94310
|
Leszek Koltunski
|
import android.app.Activity;
|
13 |
|
|
import android.content.SharedPreferences;
|
14 |
9530f6b0
|
Leszek Koltunski
|
import android.view.View;
|
15 |
|
|
import android.widget.LinearLayout;
|
16 |
|
|
|
17 |
|
|
import org.distorted.helpers.LockController;
|
18 |
|
|
import org.distorted.helpers.MovesController;
|
19 |
|
|
import org.distorted.helpers.TransparentImageButton;
|
20 |
|
|
import org.distorted.main.R;
|
21 |
b1629e16
|
Leszek Koltunski
|
import org.distorted.objectlib.effects.BaseEffect;
|
22 |
9530f6b0
|
Leszek Koltunski
|
import org.distorted.objectlib.main.ObjectControl;
|
23 |
21a1bb5d
|
Leszek Koltunski
|
import org.distorted.os.OSInterface;
|
24 |
9530f6b0
|
Leszek Koltunski
|
|
25 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26 |
|
|
|
27 |
|
|
public class BandagedPlayScreen
|
28 |
|
|
{
|
29 |
bb3bc6a9
|
Leszek Koltunski
|
private static final int NUM_SCRAMBLES = 300;
|
30 |
b72b71a1
|
Leszek Koltunski
|
|
31 |
ca280c3f
|
Leszek Koltunski
|
private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
|
32 |
9530f6b0
|
Leszek Koltunski
|
private final LockController mLockController;
|
33 |
b72b71a1
|
Leszek Koltunski
|
private final MovesController mMovesController;
|
34 |
972f9eae
|
Leszek Koltunski
|
private String mKey;
|
35 |
9530f6b0
|
Leszek Koltunski
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
public BandagedPlayScreen()
|
39 |
|
|
{
|
40 |
|
|
mLockController = new LockController();
|
41 |
|
|
mMovesController= new MovesController();
|
42 |
|
|
}
|
43 |
|
|
|
44 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
|
|
private void setupBackButton(final BandagedPlayActivity act)
|
47 |
|
|
{
|
48 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
|
49 |
70688a23
|
leszek
|
mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,params);
|
50 |
9530f6b0
|
Leszek Koltunski
|
|
51 |
|
|
mBackButton.setOnClickListener( new View.OnClickListener()
|
52 |
|
|
{
|
53 |
|
|
@Override
|
54 |
|
|
public void onClick(View v)
|
55 |
|
|
{
|
56 |
|
|
act.finish();
|
57 |
|
|
}
|
58 |
|
|
});
|
59 |
|
|
}
|
60 |
|
|
|
61 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62 |
|
|
|
63 |
f3563327
|
Leszek Koltunski
|
private void setupSolveButton(final BandagedPlayActivity act)
|
64 |
9530f6b0
|
Leszek Koltunski
|
{
|
65 |
f3563327
|
Leszek Koltunski
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
66 |
70688a23
|
leszek
|
mSolveButton = new TransparentImageButton(act,R.drawable.ui_cube_solve,params);
|
67 |
f3563327
|
Leszek Koltunski
|
|
68 |
|
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
69 |
|
|
{
|
70 |
|
|
@Override
|
71 |
|
|
public void onClick(View v)
|
72 |
|
|
{
|
73 |
b72b71a1
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
74 |
ca280c3f
|
Leszek Koltunski
|
control.solveObject();
|
75 |
f3563327
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
76 |
|
|
}
|
77 |
|
|
});
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81 |
9530f6b0
|
Leszek Koltunski
|
|
82 |
f3563327
|
Leszek Koltunski
|
private void setupScrambleButton(final BandagedPlayActivity act)
|
83 |
|
|
{
|
84 |
|
|
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
|
85 |
70688a23
|
leszek
|
mScrambleButton = new TransparentImageButton(act,R.drawable.ui_cube_scramble,params);
|
86 |
f3563327
|
Leszek Koltunski
|
|
87 |
|
|
mScrambleButton.setOnClickListener( new View.OnClickListener()
|
88 |
|
|
{
|
89 |
|
|
@Override
|
90 |
|
|
public void onClick(View v)
|
91 |
|
|
{
|
92 |
4844152a
|
Leszek Koltunski
|
ObjectControl control = act.getControl();
|
93 |
5c0c4988
|
leszek
|
int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
|
94 |
4e9aaebd
|
leszek
|
control.fastScrambleObject(duration,NUM_SCRAMBLES);
|
95 |
ca280c3f
|
Leszek Koltunski
|
mMovesController.clearMoves(act);
|
96 |
f3563327
|
Leszek Koltunski
|
}
|
97 |
|
|
});
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
101 |
|
|
|
102 |
972f9eae
|
Leszek Koltunski
|
void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
|
103 |
f3563327
|
Leszek Koltunski
|
{
|
104 |
972f9eae
|
Leszek Koltunski
|
mKey = "moveController_"+objectName;
|
105 |
|
|
|
106 |
f3563327
|
Leszek Koltunski
|
int width = act.getScreenWidthInPixels();
|
107 |
9530f6b0
|
Leszek Koltunski
|
|
108 |
|
|
LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
109 |
|
|
LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
|
110 |
|
|
LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
|
111 |
|
|
|
112 |
|
|
LinearLayout layoutLeft = new LinearLayout(act);
|
113 |
|
|
layoutLeft.setLayoutParams(paramsL);
|
114 |
|
|
LinearLayout layoutMid = new LinearLayout(act);
|
115 |
|
|
layoutMid.setLayoutParams(paramsM);
|
116 |
|
|
LinearLayout layoutRight= new LinearLayout(act);
|
117 |
|
|
layoutRight.setLayoutParams(paramsR);
|
118 |
|
|
|
119 |
|
|
setupBackButton(act);
|
120 |
|
|
ObjectControl control = act.getControl();
|
121 |
|
|
mMovesController.setupButton(act,control);
|
122 |
|
|
layoutLeft.addView(mMovesController.getButton());
|
123 |
|
|
mLockController.setupButton(act,control);
|
124 |
|
|
layoutMid.addView(mLockController.getButton());
|
125 |
|
|
|
126 |
|
|
layoutRight.addView(mBackButton);
|
127 |
|
|
|
128 |
f3563327
|
Leszek Koltunski
|
LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
|
129 |
|
|
layoutLower.removeAllViews();
|
130 |
|
|
layoutLower.addView(layoutLeft);
|
131 |
|
|
layoutLower.addView(layoutMid);
|
132 |
|
|
layoutLower.addView(layoutRight);
|
133 |
|
|
|
134 |
|
|
setupSolveButton(act);
|
135 |
1db19441
|
Leszek Koltunski
|
setupScrambleButton(act);
|
136 |
f3563327
|
Leszek Koltunski
|
|
137 |
|
|
LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
|
138 |
|
|
|
139 |
|
|
LinearLayout layoutLeftU = new LinearLayout(act);
|
140 |
|
|
layoutLeftU.setLayoutParams(paramsL);
|
141 |
|
|
LinearLayout layoutMidU = new LinearLayout(act);
|
142 |
|
|
layoutMidU.setLayoutParams(paramsM);
|
143 |
|
|
LinearLayout layoutRightU= new LinearLayout(act);
|
144 |
|
|
layoutRightU.setLayoutParams(paramsR);
|
145 |
|
|
|
146 |
|
|
layoutLeftU.addView(mSolveButton);
|
147 |
|
|
layoutRightU.addView(mScrambleButton);
|
148 |
|
|
|
149 |
775d5361
|
Leszek Koltunski
|
layoutUpper.removeAllViews();
|
150 |
f3563327
|
Leszek Koltunski
|
layoutUpper.addView(layoutLeftU);
|
151 |
|
|
layoutUpper.addView(layoutMidU);
|
152 |
|
|
layoutUpper.addView(layoutRightU);
|
153 |
9530f6b0
|
Leszek Koltunski
|
}
|
154 |
|
|
|
155 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156 |
|
|
|
157 |
88b94310
|
Leszek Koltunski
|
public void reddenLock(final BandagedPlayActivity act)
|
158 |
9530f6b0
|
Leszek Koltunski
|
{
|
159 |
|
|
ObjectControl control = act.getControl();
|
160 |
|
|
mLockController.reddenLock(act,control);
|
161 |
|
|
}
|
162 |
88b94310
|
Leszek Koltunski
|
|
163 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
164 |
|
|
|
165 |
|
|
public void addMove(Activity act, int axis, int row, int angle)
|
166 |
|
|
{
|
167 |
|
|
mMovesController.addMove(act,axis,row,angle);
|
168 |
|
|
}
|
169 |
|
|
|
170 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171 |
|
|
|
172 |
972f9eae
|
Leszek Koltunski
|
public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
|
173 |
88b94310
|
Leszek Koltunski
|
{
|
174 |
972f9eae
|
Leszek Koltunski
|
mMovesController.savePreferences(mKey,editor);
|
175 |
|
|
ObjectControl control = act.getControl();
|
176 |
21a1bb5d
|
Leszek Koltunski
|
OSInterface os = (OSInterface)control.getOS();
|
177 |
|
|
os.setEditor(editor);
|
178 |
|
|
control.savePreferences();
|
179 |
88b94310
|
Leszek Koltunski
|
}
|
180 |
|
|
|
181 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182 |
|
|
|
183 |
972f9eae
|
Leszek Koltunski
|
public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
|
184 |
88b94310
|
Leszek Koltunski
|
{
|
185 |
972f9eae
|
Leszek Koltunski
|
mMovesController.restorePreferences(act,mKey,preferences);
|
186 |
|
|
ObjectControl control = act.getControl();
|
187 |
21a1bb5d
|
Leszek Koltunski
|
OSInterface os = (OSInterface)control.getOS();
|
188 |
|
|
os.setPreferences(preferences);
|
189 |
|
|
control.restorePreferences();
|
190 |
b72b71a1
|
Leszek Koltunski
|
}
|
191 |
9530f6b0
|
Leszek Koltunski
|
}
|