Revision aa171dee
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
---|---|---|
34 | 34 |
import org.distorted.dialog.RubikDialogPattern; |
35 | 35 |
import org.distorted.magic.R; |
36 | 36 |
import org.distorted.magic.RubikActivity; |
37 |
import org.distorted.object.RubikObject; |
|
37 | 38 |
import org.distorted.object.RubikObjectList; |
38 | 39 |
import org.distorted.patterns.RubikPattern; |
39 | 40 |
|
... | ... | |
48 | 49 |
private Button mBackButton; |
49 | 50 |
private ImageButton mPrevButton, mNextButton; |
50 | 51 |
private TextView mMovesText; |
51 |
private int mSize; |
|
52 |
private int mNumMoves, mCurrMove; |
|
53 |
private int mSizeIndex, mCategory, mPattern; |
|
52 | 54 |
|
53 | 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
54 | 56 |
|
... | ... | |
62 | 64 |
void leaveState(RubikActivity act) |
63 | 65 |
{ |
64 | 66 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
67 |
int s = RubikObjectList.CUBE.getSizes()[mSizeIndex]; |
|
65 | 68 |
|
66 |
if( !play.setObjectAndSize(RubikObjectList.CUBE, mSize) )
|
|
69 |
if( !play.setObjectAndSize(RubikObjectList.CUBE, s) )
|
|
67 | 70 |
{ |
68 | 71 |
int object= play.getObject(); |
69 | 72 |
int size = play.getSize(); |
70 | 73 |
|
71 |
act.changeObject(RubikObjectList.getObject(object),size); |
|
74 |
act.changeObject(RubikObjectList.getObject(object),size,null);
|
|
72 | 75 |
} |
73 | 76 |
} |
74 | 77 |
|
... | ... | |
82 | 85 |
|
83 | 86 |
if( size>=RubikPattern.MIN_CUBE && size<=RubikPattern.MAX_CUBE && obj==RubikObjectList.CUBE.ordinal() ) |
84 | 87 |
{ |
85 |
mSize = size;
|
|
88 |
mSizeIndex = RubikObjectList.getSizeIndex(obj,size);
|
|
86 | 89 |
} |
87 | 90 |
else |
88 | 91 |
{ |
89 |
mSize = RubikStatePlay.DEF_SIZE;
|
|
90 |
act.changeObject(RubikObjectList.CUBE,mSize);
|
|
92 |
mSizeIndex = RubikObjectList.getSizeIndex(RubikObjectList.CUBE.ordinal(),RubikStatePlay.DEF_SIZE);
|
|
93 |
act.changeObject(RubikObjectList.CUBE,RubikStatePlay.DEF_SIZE,null);
|
|
91 | 94 |
} |
92 | 95 |
|
93 | 96 |
FragmentManager mana = act.getSupportFragmentManager(); |
... | ... | |
131 | 134 |
{ |
132 | 135 |
Bundle bundle = new Bundle(); |
133 | 136 |
int object = RubikObjectList.CUBE.ordinal(); |
134 |
int sizeIndex = RubikObjectList.getSizeIndex(object,mSize); |
|
135 |
bundle.putInt("tab", RubikObjectList.pack(object,sizeIndex) ); |
|
137 |
bundle.putInt("tab", RubikObjectList.pack(object,mSizeIndex) ); |
|
136 | 138 |
|
137 | 139 |
RubikDialogPattern diag = new RubikDialogPattern(); |
138 | 140 |
diag.setArguments(bundle); |
... | ... | |
190 | 192 |
@Override |
191 | 193 |
public void onClick(View v) |
192 | 194 |
{ |
193 |
android.util.Log.e("patt", "prev button clicked!"); |
|
195 |
if( --mCurrMove< 0 ) mCurrMove=mNumMoves; |
|
196 |
|
|
197 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
198 |
RubikObject object = act.getObject(); |
|
199 |
RubikPattern.getInstance().backMove( object, mSizeIndex, mCategory, mPattern); |
|
194 | 200 |
} |
195 | 201 |
}); |
196 | 202 |
} |
... | ... | |
211 | 217 |
@Override |
212 | 218 |
public void onClick(View v) |
213 | 219 |
{ |
214 |
android.util.Log.e("patt", "next button clicked!"); |
|
220 |
if( ++mCurrMove> mNumMoves ) mCurrMove=0; |
|
221 |
|
|
222 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
223 |
RubikObject object = act.getObject(); |
|
224 |
RubikPattern.getInstance().makeMove( object, mSizeIndex, mCategory, mPattern); |
|
215 | 225 |
} |
216 | 226 |
}); |
217 | 227 |
} |
... | ... | |
224 | 234 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,2.0f); |
225 | 235 |
|
226 | 236 |
mMovesText = new TextView(act); |
237 |
mMovesText.setTextSize(20); |
|
227 | 238 |
mMovesText.setLayoutParams(params); |
228 | 239 |
mMovesText.setPadding(padding,0,padding,0); |
229 | 240 |
mMovesText.setGravity(Gravity.CENTER); |
230 | 241 |
|
231 |
mMovesText.setText("aaa");
|
|
242 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves));
|
|
232 | 243 |
} |
233 | 244 |
|
234 | 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
235 | 246 |
|
236 |
public void setPattern(int sizeIndex, int category, int pattern) |
|
247 |
public void setPattern(final RubikActivity act, int sizeIndex, int category, int pattern)
|
|
237 | 248 |
{ |
238 |
mSize = RubikObjectList.CUBE.getSizes()[sizeIndex]; |
|
249 |
mSizeIndex = sizeIndex; |
|
250 |
mCategory = category; |
|
251 |
mPattern = pattern; |
|
239 | 252 |
|
240 | 253 |
RubikPattern patt = RubikPattern.getInstance(); |
241 | 254 |
String patternName = patt.getPatternName(sizeIndex,category,pattern); |
242 | 255 |
mText.setText(patternName); |
256 |
|
|
257 |
mNumMoves = patt.getNumMoves(sizeIndex,category,pattern); |
|
258 |
mCurrMove = patt.getCurMove(sizeIndex,category,pattern); |
|
259 |
|
|
260 |
mMovesText.setText(act.getString(R.string.mo_placeholder,mCurrMove,mNumMoves)); |
|
243 | 261 |
} |
244 | 262 |
|
245 | 263 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
More support for actual patterns!