Project

General

Profile

« Previous | Next » 

Revision c5fca790

Added by Leszek Koltunski almost 2 years ago

Progress with new UI

View differences:

src/main/java/org/distorted/objects/MainEntry.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objects;
21

  
22
import android.app.Activity;
23
import android.graphics.drawable.Drawable;
24
import android.widget.ImageButton;
25

  
26
import org.distorted.main.RubikActivity;
27

  
28
///////////////////////////////////////////////////////////////////////////////////////////////////
29

  
30
public class MainEntry
31
{
32
  public final static int TYPE_OBJECT  = 0;
33
  public final static int TYPE_CREATOR = 1;
34

  
35
  private final RubikObject mObject;
36
  private final int mType;
37
  private final int mIconID;
38
  private Drawable mIconDrawable;
39
  private boolean mPrepared;
40

  
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

  
43
  MainEntry(RubikObject object)
44
    {
45
    mType         = TYPE_OBJECT;
46
    mIconID       = 0;
47
    mIconDrawable = null;
48
    mObject       = object;
49
    mPrepared     = false;
50
    }
51

  
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53

  
54
  MainEntry(int type, int iconID)
55
    {
56
    mType         = type;
57
    mIconID       = iconID;
58
    mIconDrawable = null;
59
    mObject       = null;
60
    mPrepared     = false;
61
    }
62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
  private void prepare(Activity act)
66
    {
67
    mIconDrawable = act.getDrawable(mIconID);
68
    mPrepared = true;
69
    }
70

  
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72
// PUBLIC API
73

  
74
  public void setIconTo(RubikActivity act, ImageButton button)
75
    {
76
    if( mType==TYPE_OBJECT )
77
      {
78
      if( mObject!=null ) mObject.setIconTo(act,button);
79
      else android.util.Log.e("D", "MainListEntry: object null!!");
80
      }
81
    else if( mType==TYPE_CREATOR )
82
      {
83
      if( !mPrepared ) prepare(act);
84
      button.setBackground(mIconDrawable);
85
      }
86
    }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  public void onClick(RubikActivity act)
91
    {
92
    if( mType==TYPE_OBJECT )
93
      {
94
      if( mObject!=null )
95
        {
96
        android.util.Log.e("D", "clicked on "+ mObject.getLowerName());
97
        }
98
      else android.util.Log.e("D", "MainListEntry: object null!!");
99
      }
100
    else if( mType==TYPE_CREATOR )
101
      {
102
      act.switchToBandagedCreator();
103
      }
104
    }
105
}
src/main/java/org/distorted/objects/MainEntryList.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objects;
21

  
22
import java.util.ArrayList;
23

  
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

  
26
public class MainEntryList
27
{
28
  private final ArrayList<MainEntry> mList;
29
  private static MainEntryList mThis;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
  private MainEntryList()
34
    {
35
    mList = new ArrayList<>();
36

  
37
    int numObjects = RubikObjectList.getNumObjects();
38

  
39
    for(int i=0; i<numObjects; i++)
40
      {
41
      RubikObject object = RubikObjectList.getObject(i);
42

  
43
      if( object!=null )
44
        {
45
        MainEntry entry = new MainEntry(object);
46
        mList.add(entry);
47

  
48
        String name = object.getLowerName();
49

  
50
        if( name!=null && name.equals("ban4_3") )
51
          {
52
          MainEntry creator = new MainEntry(MainEntry.TYPE_CREATOR, org.distorted.main.R.drawable.gl);
53
          mList.add(creator);
54
          }
55
        }
56
      }
57
    }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
  public static MainEntryList getInstance()
62
    {
63
    if( mThis==null ) mThis = new MainEntryList();
64
    return mThis;
65
    }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  public void addEntry(MainEntry entry)
70
    {
71
    mList.add(entry);
72
    }
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
  public int getNumOfEntries()
77
    {
78
    return mList.size();
79
    }
80

  
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
  public MainEntry getEntry(int index)
84
    {
85
    return mList.get(index);
86
    }
87
}
src/main/java/org/distorted/objects/RubikObjectList.java
29 29
import org.distorted.main.RubikActivity;
30 30
import org.distorted.objectlib.main.ObjectSignatures;
31 31
import org.distorted.objectlib.main.ObjectType;
32
import org.distorted.screens.RubikScreenPlay;
33
import org.distorted.screens.ScreenList;
34 32

  
35 33
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
36 34
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
......
395 393

  
396 394
///////////////////////////////////////////////////////////////////////////////////////////////////
397 395

  
398
  public static boolean setCurrObject(RubikActivity act, int ordinal)
396
  public static boolean setCurrObject(int ordinal)
399 397
    {
400 398
    if( mObject!=ordinal )
401 399
      {
src/main/java/org/distorted/screens/RubikScreenPattern.java
62 62
    {
63 63
    int object = RubikPatternList.getObject(mPatternOrdinal);
64 64

  
65
    if( !RubikObjectList.setCurrObject(act,object) )
65
    if( !RubikObjectList.setCurrObject(object) )
66 66
      {
67 67
      act.changeObject(object,false);
68 68
      }
src/main/java/org/distorted/screens/RubikScreenPlay.java
42 42
import org.distorted.main.RubikActivity;
43 43
import org.distorted.dialogs.RubikDialogAbout;
44 44
import org.distorted.helpers.TransparentImageButton;
45
import org.distorted.objects.RubikObject;
46
import org.distorted.objects.RubikObjectList;
45
import org.distorted.objects.MainEntry;
46
import org.distorted.objects.MainEntryList;
47 47

  
48 48
///////////////////////////////////////////////////////////////////////////////////////////////////
49 49

  
......
56 56
  private TextView mBubbleUpdates;
57 57
  private int mCurrentBubbleNumber;
58 58
  private int mLevelValue;
59
  private int mColCount, mRowCount;
59
  private int mColCount, mRowCount, mNumObjects;
60 60
  private float mScreenWidth;
61 61
  private WeakReference<RubikActivity> mWeakAct;
62 62

  
......
75 75
    {
76 76
    act.switchRenderingOff();
77 77
    mWeakAct = new WeakReference<>(act);
78
    int numObjects = RubikObjectList.getNumObjects();
79 78
    mScreenWidth = act.getScreenWidthInPixels();
80 79
    int screenHeight= act.getScreenHeightInPixels();
81 80
    int upperBarHeight = act.getHeightUpperBar();
82 81
    int lowerBarHeight = act.getHeightLowerBar();
83 82

  
84
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
85
    mColCount = NUM_COLUMNS;
83
    computeRowAndColCounts();
86 84

  
87 85
    float titleSize = mScreenWidth*RubikActivity.TITLE_TEXT_SIZE;
88 86
    LayoutInflater inflater = act.getLayoutInflater();
......
228 226
      colSpecs[col] = GridLayout.spec(col);
229 227
      }
230 228

  
231
    int numObjects = RubikObjectList.getNumObjects();
229
    MainEntryList list = MainEntryList.getInstance();
232 230

  
233
    for(int object=0; object<numObjects; object++)
231
    for(int index=0; index<mNumObjects; index++)
234 232
      {
235
      final int ordinal = object;
236
      RubikObject rObject = RubikObjectList.getObject(ordinal);
237
      int row = object/NUM_COLUMNS;
233
      MainEntry entry = list.getEntry(index);
234
      int row = index/NUM_COLUMNS;
238 235
      ImageButton button = new ImageButton(act);
239
      if( rObject!=null ) rObject.setIconTo(act,button);
236
      if( entry!=null ) entry.setIconTo(act,button);
240 237

  
241 238
      button.setOnClickListener( new View.OnClickListener()
242 239
        {
243 240
        @Override
244 241
        public void onClick(View v)
245 242
          {
246
          // TODO
247
          android.util.Log.e("D", "object "+ordinal+" clicked");
243
          entry.onClick(act);
248 244
          }
249 245
        });
250 246

  
......
290 286

  
291 287
  public void recreateListOfObjects()
292 288
    {
293
    int numObjects = RubikObjectList.getNumObjects();
294
    mRowCount = (numObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
295
    mColCount = NUM_COLUMNS;
296

  
289
    computeRowAndColCounts();
297 290
    RubikActivity act = mWeakAct.get();
298 291
    LayoutInflater inflater = act.getLayoutInflater();
299 292

  
......
314 307
      });
315 308
    }
316 309

  
310
///////////////////////////////////////////////////////////////////////////////////////////////////
311

  
312
  private void computeRowAndColCounts()
313
    {
314
    MainEntryList list = MainEntryList.getInstance();
315
    mNumObjects = list.getNumOfEntries();
316
    mRowCount = (mNumObjects + NUM_COLUMNS-1) / NUM_COLUMNS;
317
    mColCount = NUM_COLUMNS;
318
    }
319

  
317 320
///////////////////////////////////////////////////////////////////////////////////////////////////
318 321

  
319 322
  private void updateNumberOfNewObjects()
src/main/java/org/distorted/screens/RubikScreenSolver.java
87 87
    act.changeIfDifferent(currentObject,control);
88 88
    control.solveOnly();
89 89

  
90
    RubikObjectList.setCurrObject(act, currentObject);
90
    RubikObjectList.setCurrObject(currentObject);
91 91

  
92 92
    generateFaceColors();
93 93

  

Also available in: Unified diff