12 |
12 |
import static android.view.View.GONE;
|
13 |
13 |
|
14 |
14 |
import android.content.Context;
|
|
15 |
import android.content.res.ColorStateList;
|
|
16 |
import android.content.res.Resources;
|
15 |
17 |
import android.util.TypedValue;
|
16 |
18 |
import android.view.Gravity;
|
17 |
19 |
import android.view.LayoutInflater;
|
... | ... | |
21 |
23 |
import android.widget.PopupWindow;
|
22 |
24 |
import android.widget.TextView;
|
23 |
25 |
|
|
26 |
import org.distorted.external.RubikScores;
|
24 |
27 |
import org.distorted.objects.RubikObject;
|
25 |
28 |
import org.distorted.objects.RubikObjectList;
|
26 |
29 |
|
... | ... | |
37 |
40 |
|
38 |
41 |
private final PopupWindow mPopup;
|
39 |
42 |
private final int mMenuTextSize;
|
40 |
|
private Button[] mLevel;
|
|
43 |
private final int mObjectOrdinal;
|
41 |
44 |
|
42 |
45 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43 |
46 |
|
... | ... | |
49 |
52 |
mPopup.setContentView(layout);
|
50 |
53 |
mPopup.setFocusable(true);
|
51 |
54 |
|
|
55 |
mObjectOrdinal = ordinal;
|
52 |
56 |
boolean firstButtonShown = false;
|
53 |
57 |
|
54 |
58 |
mMenuTextSize = (int)(height*MENU_TEXT_SIZE);
|
... | ... | |
156 |
160 |
|
157 |
161 |
private void setupLevelButtons(MainActivity act, RubikObject object, View layout, int width,int padding, int margin)
|
158 |
162 |
{
|
|
163 |
RubikScores scores = RubikScores.getInstance();
|
|
164 |
Resources res = act.getResources();
|
|
165 |
ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
|
|
166 |
ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
|
|
167 |
|
159 |
168 |
int layoutWidth = (int)(width*MENU_WIDTH);
|
160 |
169 |
int levelHeight = (int)(width*BUTTON_HEIGHT);
|
161 |
170 |
int levelWidth = (layoutWidth-4*padding)/3;
|
... | ... | |
163 |
172 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(levelWidth,levelHeight);
|
164 |
173 |
params.setMargins(margin,-margin,margin,-margin);
|
165 |
174 |
|
166 |
|
mLevel = new Button[LEVELS_SHOWN+1];
|
|
175 |
Button[] level = new Button[LEVELS_SHOWN+1];
|
167 |
176 |
|
168 |
|
mLevel[0] = layout.findViewById(R.id.level0);
|
169 |
|
mLevel[1] = layout.findViewById(R.id.level1);
|
170 |
|
mLevel[2] = layout.findViewById(R.id.level2);
|
171 |
|
mLevel[3] = layout.findViewById(R.id.level3);
|
172 |
|
mLevel[4] = layout.findViewById(R.id.level4);
|
173 |
|
mLevel[5] = layout.findViewById(R.id.level5);
|
174 |
|
mLevel[6] = layout.findViewById(R.id.level6);
|
175 |
|
mLevel[7] = layout.findViewById(R.id.level7);
|
176 |
|
mLevel[8] = layout.findViewById(R.id.levelM);
|
|
177 |
level[0] = layout.findViewById(R.id.level0);
|
|
178 |
level[1] = layout.findViewById(R.id.level1);
|
|
179 |
level[2] = layout.findViewById(R.id.level2);
|
|
180 |
level[3] = layout.findViewById(R.id.level3);
|
|
181 |
level[4] = layout.findViewById(R.id.level4);
|
|
182 |
level[5] = layout.findViewById(R.id.level5);
|
|
183 |
level[6] = layout.findViewById(R.id.level6);
|
|
184 |
level[7] = layout.findViewById(R.id.level7);
|
|
185 |
level[8] = layout.findViewById(R.id.levelM);
|
177 |
186 |
|
178 |
187 |
int numScramble = object==null ? 1 : object.getNumScramble();
|
179 |
188 |
int min = Math.min(numScramble,LEVELS_SHOWN);
|
180 |
189 |
|
181 |
190 |
if( numScramble>=1 && numScramble<=7 )
|
182 |
191 |
{
|
183 |
|
mLevel[numScramble].setText(R.string.levelM);
|
184 |
|
for(int i=numScramble+1; i<=8; i++) mLevel[i].setVisibility(GONE);
|
|
192 |
level[numScramble].setText(R.string.levelM);
|
|
193 |
for(int i=numScramble+1; i<=8; i++) level[i].setVisibility(GONE);
|
185 |
194 |
}
|
186 |
195 |
|
187 |
|
for(int i=0; i<=min; i++)
|
|
196 |
for(int l=0; l<=min; l++)
|
188 |
197 |
{
|
189 |
|
mLevel[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
190 |
|
mLevel[i].setLayoutParams(params);
|
191 |
|
mLevel[i].setPadding(0,0,0,0);
|
|
198 |
level[l].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
|
199 |
level[l].setLayoutParams(params);
|
|
200 |
level[l].setPadding(0,0,0,0);
|
|
201 |
|
|
202 |
boolean isSolved = scores.isSolved(mObjectOrdinal,l);
|
|
203 |
level[l].setBackgroundTintList( isSolved ? colorG : colorD);
|
192 |
204 |
|
193 |
|
final int ii=i;
|
194 |
|
boolean free = i==0;
|
195 |
|
int scrambles = (i>0 && i<min) ? i : numScramble;
|
|
205 |
final int ll=l;
|
|
206 |
boolean free = l==0;
|
|
207 |
int scrambles = (l>0 && l<min) ? l : numScramble;
|
196 |
208 |
|
197 |
|
mLevel[i].setOnClickListener( new View.OnClickListener()
|
|
209 |
level[l].setOnClickListener( new View.OnClickListener()
|
198 |
210 |
{
|
199 |
211 |
@Override
|
200 |
212 |
public void onClick(View v)
|
201 |
213 |
{
|
202 |
214 |
mPopup.dismiss();
|
203 |
|
act.switchToPlay(object,scrambles,free,ii);
|
|
215 |
if( ll==0 ) scores.setRecord(mObjectOrdinal,0,0); // remember we've entered the 'Free'
|
|
216 |
// so that the button turns green
|
|
217 |
act.switchToPlay(object,scrambles,free,ll);
|
204 |
218 |
}
|
205 |
219 |
});
|
206 |
220 |
}
|
... | ... | |
208 |
222 |
int index = (numScramble>=1 && numScramble<=7) ? numScramble : LEVELS_SHOWN;
|
209 |
223 |
LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(levelWidth,levelHeight);
|
210 |
224 |
params2.setMargins(margin,-margin,margin,margin);
|
211 |
|
mLevel[index].setLayoutParams(params2);
|
212 |
|
|
213 |
|
setupLevelButtonVisibilityAndColor(act);
|
214 |
|
}
|
215 |
|
|
216 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217 |
|
|
218 |
|
private void setupLevelButtonVisibilityAndColor(MainActivity act)
|
219 |
|
{
|
220 |
|
/*
|
221 |
|
int currObject = RubikObjectList.getCurrObject();
|
222 |
|
RubikObject object = RubikObjectList.getObject(currObject);
|
223 |
|
int numScramble = object==null ? 1 : object.getNumScramble();
|
224 |
|
RubikScores scores = RubikScores.getInstance();
|
225 |
|
Resources res = act.getResources();
|
226 |
|
ColorStateList colorG = ColorStateList.valueOf(res.getColor(R.color.green));
|
227 |
|
ColorStateList colorD = ColorStateList.valueOf(res.getColor(R.color.dark_grey));
|
228 |
|
|
229 |
|
for(int level=0; level<=LEVELS_SHOWN; level++)
|
230 |
|
{
|
231 |
|
boolean isSolved = scores.isSolved(currObject,level);
|
232 |
|
mLevel[level].setBackgroundTintList( isSolved ? colorG : colorD);
|
233 |
|
}
|
234 |
|
|
235 |
|
if( numScramble<=LEVELS_SHOWN || mOldNumScramble<=LEVELS_SHOWN )
|
236 |
|
{
|
237 |
|
if( numScramble<mOldNumScramble )
|
238 |
|
{
|
239 |
|
int max = Math.min(LEVELS_SHOWN,mOldNumScramble-1);
|
240 |
|
for(int level=numScramble; level<=max; level++) mLevel[level].setVisibility(View.INVISIBLE);
|
241 |
|
mLevel[numScramble-1].setText(R.string.levelM);
|
242 |
|
}
|
243 |
|
if( numScramble>mOldNumScramble )
|
244 |
|
{
|
245 |
|
int max = Math.min(LEVELS_SHOWN,numScramble-1);
|
246 |
|
mLevel[mOldNumScramble-1].setText( String.valueOf(mOldNumScramble) );
|
247 |
|
|
248 |
|
for(int level=mOldNumScramble; level<=max; level++)
|
249 |
|
{
|
250 |
|
mLevel[level].setVisibility(View.VISIBLE);
|
251 |
|
if( level<max ) mLevel[level].setText( String.valueOf(level+1) );
|
252 |
|
else mLevel[level].setText( R.string.levelM );
|
253 |
|
}
|
254 |
|
}
|
255 |
|
}
|
256 |
|
|
257 |
|
mOldNumScramble = numScramble;
|
258 |
|
*/
|
|
225 |
level[index].setLayoutParams(params2);
|
259 |
226 |
}
|
260 |
227 |
|
261 |
228 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
progress with PlayActivity - colors of the level buttons.