Revision 0b5e585c
Added by Leszek Koltunski almost 2 years ago
- ID 0b5e585cb8c00a1dd32b0f9da5a2c056eba34550
- Parent fad10885
src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
---|---|---|
25 | 25 |
import android.widget.Button; |
26 | 26 |
import android.widget.GridLayout; |
27 | 27 |
import android.widget.ImageButton; |
28 |
import android.widget.ImageView; |
|
28 | 29 |
import android.widget.LinearLayout; |
29 | 30 |
import android.widget.PopupWindow; |
30 | 31 |
import android.widget.RelativeLayout; |
... | ... | |
52 | 53 |
|
53 | 54 |
public class RubikScreenPlay extends RubikScreenBase implements RubikNetwork.Updatee |
54 | 55 |
{ |
55 |
public static final int NUM_COLUMNS = 5;
|
|
56 |
public static final int NUM_COLUMNS = 6;
|
|
56 | 57 |
public static final int LEVELS_SHOWN = 8; |
57 | 58 |
private static final int NUM_BUTTONS = 6; |
58 | 59 |
private static final int[] mLocation = new int[2]; |
... | ... | |
65 | 66 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mMenuButtonHeight, mMenuTextSize; |
66 | 67 |
private int mLevelValue; |
67 | 68 |
private int mColCount, mRowCount, mMaxRowCount; |
68 |
private int mUpperBarHeight;
|
|
69 |
private int mBarHeight; |
|
69 | 70 |
private boolean mShouldReactToEndOfScrambling; |
70 |
private float mScreenWidth; |
|
71 |
private float mScreenWidth, mScreenHeight; |
|
72 |
private int mMargin; |
|
71 | 73 |
|
72 | 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 75 |
|
... | ... | |
80 | 82 |
|
81 | 83 |
void enterScreen(final RubikActivity act) |
82 | 84 |
{ |
83 |
mWeakAct = new WeakReference<>(act); |
|
85 |
mWeakAct = new WeakReference<>(act);
|
|
84 | 86 |
mScreenWidth = act.getScreenWidthInPixels(); |
85 |
mUpperBarHeight = act.getHeightUpperBar(); |
|
87 |
mScreenHeight= act.getScreenHeightInPixels(); |
|
88 |
mBarHeight = act.getHeightUpperBar(); |
|
86 | 89 |
|
87 | 90 |
mMenuButtonHeight = (int)(mScreenWidth*RubikActivity.MENU_BUTTON_HEIGHT); |
88 | 91 |
mMenuTextSize = (int)(mScreenWidth*RubikActivity.MENU_MAIN_TEXT_SIZE); |
92 |
mMargin = (int)(mScreenWidth*RubikActivity.LARGE_MARGIN); |
|
89 | 93 |
|
90 | 94 |
mObjectPopup = null; |
91 | 95 |
|
... | ... | |
101 | 105 |
layoutTop.addView(mScrambleButton); |
102 | 106 |
|
103 | 107 |
// BOTTOM ///////////////////////// |
104 |
setupObjectButton(act,mScreenWidth); |
|
108 |
setupObjectButton(act,mScreenWidth,mScreenHeight);
|
|
105 | 109 |
createBottomPane(act,mObjButton,null); |
106 | 110 |
} |
107 | 111 |
|
108 | 112 |
////////////////////////////////////////////////////////////////////////////////////////////////// |
109 | 113 |
|
110 |
private void setupObjectButton(final RubikActivity act, final float width) |
|
114 |
private void setupObjectButton(final RubikActivity act, final float width, final float height)
|
|
111 | 115 |
{ |
112 | 116 |
final int margin = (int)(width*RubikActivity.SMALL_MARGIN); |
113 | 117 |
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu); |
... | ... | |
128 | 132 |
|
129 | 133 |
if( act.getControl().isUINotBlocked()) |
130 | 134 |
{ |
131 |
int rowCount = Math.min(mMaxRowCount,mRowCount); |
|
135 |
//int rowCount = Math.min(mMaxRowCount,mRowCount);
|
|
132 | 136 |
View popupView = mObjectPopup.getContentView(); |
133 | 137 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
134 |
displayPopup(act,view,mObjectPopup,mObjectSize*mColCount,mObjectSize*rowCount+5*margin,margin,margin); |
|
138 |
int popupWidth = (int)width; |
|
139 |
int popupHeight= (int)(height-2*mBarHeight); |
|
140 |
displayPopup(act,view,mObjectPopup,popupWidth,popupHeight,margin,margin); |
|
135 | 141 |
} |
136 | 142 |
} |
137 | 143 |
}); |
... | ... | |
171 | 177 |
|
172 | 178 |
private void setupObjectWindow(final RubikActivity act, final float width, final float height) |
173 | 179 |
{ |
180 |
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null); |
|
181 |
LinearLayout layout = view.findViewById(R.id.objectLayout); |
|
182 |
|
|
174 | 183 |
int numObjects = RubikObjectList.getNumObjects(); |
175 | 184 |
mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS; |
176 | 185 |
mColCount = NUM_COLUMNS; |
177 | 186 |
|
178 | 187 |
int cubeSize = (int)(width/9); |
179 |
int margin = (int)(width*RubikActivity.LARGE_MARGIN); |
|
180 |
mObjectSize = (int)(cubeSize + 2*margin + 0.5f); |
|
181 |
mMaxRowCount = (int)((height-1.8f*mUpperBarHeight)/mObjectSize); |
|
188 |
mObjectSize = (int)(cubeSize + 2*mMargin + 0.5f); |
|
189 |
mMaxRowCount = (int)((height-1.8f*mBarHeight)/mObjectSize); |
|
182 | 190 |
|
183 |
LinearLayout view = (LinearLayout)inflate( act, R.layout.popup_object, null); |
|
184 |
GridLayout objectGrid = view.findViewById(R.id.objectGrid); |
|
191 |
GridLayout section0 = produceSection(act, R.drawable.difficulty1, 0, cubeSize); |
|
192 |
GridLayout section1 = produceSection(act, R.drawable.difficulty2, 1, cubeSize); |
|
193 |
GridLayout section2 = produceSection(act, R.drawable.difficulty3, 2, cubeSize); |
|
194 |
GridLayout section3 = produceSection(act, R.drawable.difficulty4, 3, cubeSize); |
|
195 |
GridLayout section4 = produceSection(act, R.drawable.difficulty5, 4, cubeSize); |
|
185 | 196 |
|
186 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
|
187 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
|
188 |
|
|
189 |
objectGrid.setColumnCount(mColCount);
|
|
190 |
objectGrid.setRowCount(mRowCount);
|
|
197 |
layout.addView(section0);
|
|
198 |
layout.addView(section1);
|
|
199 |
layout.addView(section2); |
|
200 |
layout.addView(section3);
|
|
201 |
layout.addView(section4);
|
|
191 | 202 |
|
192 | 203 |
RelativeLayout bottomLayout = view.findViewById(R.id.bottomLayout); |
193 | 204 |
setupBottomLayout(act,bottomLayout); |
... | ... | |
195 | 206 |
mObjectPopup = new PopupWindow(act); |
196 | 207 |
mObjectPopup.setFocusable(true); |
197 | 208 |
mObjectPopup.setContentView(view); |
209 |
} |
|
210 |
|
|
211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
212 |
|
|
213 |
private GridLayout produceSection(final RubikActivity act, int iconID, int difficulty, int cubeSize) |
|
214 |
{ |
|
215 |
GridLayout objectGrid = (GridLayout)inflate( act, R.layout.popup_object_section, null); |
|
198 | 216 |
|
199 |
int[] nextInRow = new int[mRowCount]; |
|
217 |
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( |
|
218 |
LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
|
219 |
params.setMargins(0, (difficulty==0? 0:mMargin) ,0,0); |
|
220 |
objectGrid.setLayoutParams(params); |
|
200 | 221 |
|
201 |
for(int row=0; row<mRowCount; row++) |
|
222 |
int[] ordinals = RubikObjectList.produceListOfOrdinals(difficulty); |
|
223 |
int numObjects = ordinals.length; |
|
224 |
int colCount = NUM_COLUMNS-1; |
|
225 |
int rowCount = (numObjects + colCount-1) / colCount; |
|
226 |
|
|
227 |
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[rowCount]; |
|
228 |
GridLayout.Spec[] colSpecs = new GridLayout.Spec[colCount+1]; |
|
229 |
|
|
230 |
objectGrid.setColumnCount(colCount+1); |
|
231 |
objectGrid.setRowCount(rowCount); |
|
232 |
|
|
233 |
int[] nextInRow = new int[rowCount]; |
|
234 |
|
|
235 |
for(int row=0; row<rowCount; row++) |
|
202 | 236 |
{ |
203 | 237 |
rowSpecs[row] = GridLayout.spec(row); |
204 |
nextInRow[row]= 0;
|
|
238 |
nextInRow[row]= 1;
|
|
205 | 239 |
} |
206 |
for(int col=0; col<mColCount; col++)
|
|
240 |
for(int col=0; col<colCount+1; col++)
|
|
207 | 241 |
{ |
208 | 242 |
colSpecs[col] = GridLayout.spec(col); |
209 | 243 |
} |
210 | 244 |
|
245 |
GridLayout.Spec rs = rowSpecs[0]; |
|
246 |
GridLayout.Spec cs = colSpecs[0]; |
|
247 |
GridLayout.LayoutParams ps = new GridLayout.LayoutParams(rs,cs); |
|
248 |
ps.bottomMargin = mMargin; |
|
249 |
ps.topMargin = mMargin; |
|
250 |
ps.leftMargin = mMargin; |
|
251 |
ps.rightMargin = mMargin; |
|
252 |
ps.width = cubeSize; |
|
253 |
ps.height = cubeSize; |
|
254 |
|
|
255 |
ImageView image = new ImageView(act); |
|
256 |
image.setImageResource(iconID); |
|
257 |
objectGrid.addView(image,ps); |
|
258 |
|
|
211 | 259 |
for(int object=0; object<numObjects; object++) |
212 | 260 |
{ |
213 |
final int ordinal = object;
|
|
214 |
final RubikObject rObject = RubikObjectList.getObject(object);
|
|
215 |
int row = object/NUM_COLUMNS;
|
|
261 |
final int ordinal = ordinals[object];
|
|
262 |
final RubikObject rObject = RubikObjectList.getObject(ordinal);
|
|
263 |
int row = object/colCount;
|
|
216 | 264 |
ImageButton button = new ImageButton(act); |
217 | 265 |
if( rObject!=null ) rObject.setIconTo(act,button); |
218 | 266 |
|
... | ... | |
233 | 281 |
} |
234 | 282 |
}); |
235 | 283 |
|
236 |
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]); |
|
237 |
params.bottomMargin = margin; |
|
238 |
params.topMargin = margin; |
|
239 |
params.leftMargin = margin; |
|
240 |
params.rightMargin = margin; |
|
241 |
|
|
242 |
params.width = cubeSize; |
|
243 |
params.height= cubeSize; |
|
284 |
GridLayout.Spec r = rowSpecs[row]; |
|
285 |
GridLayout.Spec c = colSpecs[nextInRow[row]]; |
|
286 |
GridLayout.LayoutParams p = new GridLayout.LayoutParams(r,c); |
|
287 |
p.bottomMargin = mMargin; |
|
288 |
p.topMargin = mMargin; |
|
289 |
p.leftMargin = mMargin; |
|
290 |
p.rightMargin = mMargin; |
|
291 |
p.width = cubeSize; |
|
292 |
p.height = cubeSize; |
|
244 | 293 |
|
245 | 294 |
nextInRow[row]++; |
246 | 295 |
|
247 |
objectGrid.addView(button, params);
|
|
296 |
objectGrid.addView(button,p);
|
|
248 | 297 |
} |
298 |
|
|
299 |
return objectGrid; |
|
249 | 300 |
} |
250 | 301 |
|
251 | 302 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Sort the objects in the object popup by difficulty level.