Revision b498f3f6
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/uistate/RubikStatePattern.java | ||
---|---|---|
37 | 37 |
import org.distorted.magic.RubikPostRender; |
38 | 38 |
import org.distorted.object.RubikObjectList; |
39 | 39 |
import org.distorted.patterns.RubikPattern; |
40 |
import org.distorted.patterns.RubikPatternList; |
|
40 | 41 |
|
41 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
42 | 43 |
|
43 | 44 |
public class RubikStatePattern extends RubikStateAbstract |
44 | 45 |
{ |
45 |
// TODO: read this from upper_text.xml; this is the height of the TextView there. |
|
46 |
private static final int DEFAULT_TEXT_SIZE = 30; |
|
47 |
|
|
48 | 46 |
private TextView mText; |
49 | 47 |
private Button mBackButton; |
50 | 48 |
private ImageButton mPrevButton, mNextButton; |
51 | 49 |
private TextView mMovesText; |
52 | 50 |
private int mNumMoves; |
53 |
private int mSizeIndex, mCategory, mPattern;
|
|
51 |
private int mPatternOrdinal, mCategory, mPattern;
|
|
54 | 52 |
|
55 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 54 |
|
... | ... | |
64 | 62 |
void leaveState(RubikActivity act) |
65 | 63 |
{ |
66 | 64 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
67 |
int s = RubikObjectList.CUBE.getSizes()[mSizeIndex]; |
|
68 | 65 |
|
69 |
if( !play.setObjectAndSize(RubikObjectList.CUBE, s) ) |
|
66 |
RubikObjectList object = RubikPatternList.getObject(mPatternOrdinal); |
|
67 |
int size = RubikPatternList.getSize(mPatternOrdinal); |
|
68 |
|
|
69 |
if( !play.setObjectAndSize(object,size) ) |
|
70 | 70 |
{ |
71 |
int object= play.getObject(); |
|
72 |
int size = play.getSize(); |
|
71 |
int objectPlay= play.getObject();
|
|
72 |
int sizePlay = play.getSize();
|
|
73 | 73 |
|
74 |
act.changeObject(RubikObjectList.getObject(object),size,null);
|
|
74 |
act.changeObject(RubikObjectList.getObject(objectPlay),sizePlay,null);
|
|
75 | 75 |
} |
76 | 76 |
} |
77 | 77 |
|
... | ... | |
83 | 83 |
int obj = play.getObject(); |
84 | 84 |
int size = play.getSize(); |
85 | 85 |
|
86 |
if( size>=RubikPattern.MIN_CUBE && size<=RubikPattern.MAX_CUBE && obj==RubikObjectList.CUBE.ordinal() ) |
|
87 |
{ |
|
88 |
mSizeIndex = RubikObjectList.getSizeIndex(obj,size); |
|
89 |
} |
|
90 |
else |
|
86 |
mPatternOrdinal = RubikPatternList.getOrdinal(obj,size); |
|
87 |
|
|
88 |
if( mPatternOrdinal<0 ) |
|
91 | 89 |
{ |
92 |
mSizeIndex = RubikObjectList.getSizeIndex(RubikObjectList.CUBE.ordinal(),RubikStatePlay.DEF_SIZE);
|
|
93 |
act.changeObject(RubikObjectList.CUBE,RubikStatePlay.DEF_SIZE,null);
|
|
90 |
mPatternOrdinal = RubikObjectList.getSizeIndex(RubikStatePlay.DEF_OBJECT,RubikStatePlay.DEF_SIZE);
|
|
91 |
act.changeObject(RubikObjectList.getObject(RubikStatePlay.DEF_OBJECT),RubikStatePlay.DEF_SIZE,null);
|
|
94 | 92 |
} |
95 | 93 |
|
96 | 94 |
FragmentManager mana = act.getSupportFragmentManager(); |
... | ... | |
132 | 130 |
|
133 | 131 |
private void showDialog(FragmentManager manager) |
134 | 132 |
{ |
135 |
Bundle bundle = new Bundle(); |
|
136 |
int object = RubikObjectList.CUBE.ordinal(); |
|
137 |
bundle.putInt("tab", RubikObjectList.pack(object,mSizeIndex) ); |
|
138 |
|
|
139 | 133 |
RubikDialogPattern diag = new RubikDialogPattern(); |
134 |
Bundle bundle = new Bundle(); |
|
135 |
bundle.putInt("tab", mPatternOrdinal ); |
|
140 | 136 |
diag.setArguments(bundle); |
141 | 137 |
diag.show( manager, RubikDialogPattern.getDialogTag() ); |
142 | 138 |
} |
... | ... | |
162 | 158 |
|
163 | 159 |
if( diag==null ) |
164 | 160 |
{ |
165 |
mText.setTextSize(DEFAULT_TEXT_SIZE); |
|
166 | 161 |
showDialog(mana); |
167 | 162 |
} |
168 | 163 |
else |
... | ... | |
193 | 188 |
{ |
194 | 189 |
RubikPattern pattern = RubikPattern.getInstance(); |
195 | 190 |
RubikPostRender post = act.getPostRender(); |
196 |
pattern.backMove( post, mSizeIndex, mCategory, mPattern);
|
|
197 |
int currMove = pattern.getCurMove(mSizeIndex, mCategory, mPattern);
|
|
191 |
pattern.backMove( post, mPatternOrdinal, mCategory, mPattern);
|
|
192 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
|
198 | 193 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
199 | 194 |
} |
200 | 195 |
}); |
... | ... | |
218 | 213 |
{ |
219 | 214 |
RubikPattern pattern = RubikPattern.getInstance(); |
220 | 215 |
RubikPostRender post = act.getPostRender(); |
221 |
pattern.makeMove( post, mSizeIndex, mCategory, mPattern);
|
|
222 |
int currMove = pattern.getCurMove(mSizeIndex, mCategory, mPattern);
|
|
216 |
pattern.makeMove( post, mPatternOrdinal, mCategory, mPattern);
|
|
217 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
|
223 | 218 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
224 | 219 |
} |
225 | 220 |
}); |
... | ... | |
239 | 234 |
mMovesText.setGravity(Gravity.CENTER); |
240 | 235 |
|
241 | 236 |
RubikPattern pattern = RubikPattern.getInstance(); |
242 |
int currMove = pattern.getCurMove(mSizeIndex, mCategory, mPattern);
|
|
237 |
int currMove = pattern.getCurMove(mPatternOrdinal, mCategory, mPattern);
|
|
243 | 238 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
244 | 239 |
} |
245 | 240 |
|
246 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
247 | 242 |
|
248 |
public void setPattern(final RubikActivity act, int sizeIndex, int category, int pattern)
|
|
243 |
public void setPattern(final RubikActivity act, int ordinal, int category, int pattern)
|
|
249 | 244 |
{ |
250 |
mSizeIndex = sizeIndex;
|
|
251 |
mCategory = category; |
|
252 |
mPattern = pattern; |
|
245 |
mPatternOrdinal = ordinal;
|
|
246 |
mCategory = category;
|
|
247 |
mPattern = pattern;
|
|
253 | 248 |
|
254 | 249 |
RubikPattern patt = RubikPattern.getInstance(); |
255 |
String patternName = patt.getPatternName(sizeIndex,category,pattern);
|
|
250 |
String patternName = patt.getPatternName(ordinal,category,pattern);
|
|
256 | 251 |
mText.setText(patternName); |
257 | 252 |
|
258 |
mNumMoves = patt.getNumMoves(sizeIndex,category,pattern);
|
|
259 |
int currMove= patt.getCurMove(sizeIndex,category,pattern);
|
|
253 |
mNumMoves = patt.getNumMoves(ordinal,category,pattern);
|
|
254 |
int currMove= patt.getCurMove(ordinal,category,pattern);
|
|
260 | 255 |
|
261 | 256 |
mMovesText.setText(act.getString(R.string.mo_placeholder,currMove,mNumMoves)); |
262 | 257 |
} |
Also available in: Unified diff
Introduce RubikPatternsList. Now, if one wants to contribute patterns for a new object, all one has to be is give the list of strings describing the patterns and add them to the List.