Project

General

Profile

Download (4.65 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / RubikObjectCategories.java @ 50a82b23

1 3eaf5f2a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2024 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objects;
11
12
import static org.distorted.main.MainSettingsPopup.*;
13
14 ff4a2a13 leszek
import org.distorted.main.R;
15
16 3eaf5f2a leszek
///////////////////////////////////////////////////////////////////////////////////////////////////
17
18 48e61813 leszek
public abstract class RubikObjectCategories
19 3eaf5f2a leszek
{
20 ff4a2a13 leszek
  public static final int[] DIFF_IDS =
21
    {
22
    R.id.configDifficulty0,
23
    R.id.configDifficulty1,
24
    R.id.configDifficulty2,
25
    R.id.configDifficulty3,
26
    R.id.configDifficulty4
27
    };
28
29
  public static final int[] DIFF_IMAGES =
30
    {
31
    R.drawable.difficulty1,
32
    R.drawable.difficulty2,
33
    R.drawable.difficulty3,
34
    R.drawable.difficulty4,
35
    R.drawable.difficulty5,
36
    };
37
38 48e61813 leszek
  protected final int mNumCategories;
39
  protected int[] mIconIDs;
40
  protected String[] mTitles;
41
  protected int[][] mObjectIndices;
42 3eaf5f2a leszek
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45 48e61813 leszek
  public RubikObjectCategories()
46 3eaf5f2a leszek
    {
47 48e61813 leszek
    buildIndices();
48 3eaf5f2a leszek
    mNumCategories = mObjectIndices.length;
49 48e61813 leszek
    buildTitle();
50 3eaf5f2a leszek
    }
51
52
///////////////////////////////////////////////////////////////////////////////////////////////////
53
54 48e61813 leszek
  abstract void buildIndices();
55
  abstract void buildTitle();
56 3eaf5f2a leszek
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59 48e61813 leszek
  public static RubikObjectCategories create(int sortMode)
60 3eaf5f2a leszek
    {
61 48e61813 leszek
    switch(sortMode)
62 3eaf5f2a leszek
      {
63 881697b3 leszek
      case SORT_SHAPE     : return new RubikObjectCategoriesShape();
64 48e61813 leszek
      case SORT_DIFFICULTY: return new RubikObjectCategoriesDiff();
65
      case SORT_AUTHOR    : return new RubikObjectCategoriesAuthor();
66
      case SORT_YEAR      : return new RubikObjectCategoriesYear();
67 3eaf5f2a leszek
      }
68
69 48e61813 leszek
    android.util.Log.e("D", "sortMode = "+sortMode+" not implemented!");
70
    return null;
71 3eaf5f2a leszek
    }
72
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74
// PUBLIC API
75
76
  public int getNumCategories()
77
    {
78
    return mNumCategories;
79
    }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83
  public boolean hasIcons()
84
    {
85
    return mIconIDs!=null;
86
    }
87
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90
  public int getIconId(int category)
91
    {
92
    return ( mIconIDs!=null && category>=0 && category<mNumCategories ) ? mIconIDs[category] : -1;
93
    }
94
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97
  public String getTitle(int category)
98
    {
99
    return (mTitles!=null && category>=0 && category<mNumCategories) ? mTitles[category] : null;
100
    }
101
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104
  public int getNumObjects(int category)
105
    {
106
    return (category>=0 && category<mNumCategories) ? mObjectIndices[category].length : 0;
107
    }
108
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
111
  public int getObjectIndex(int category, int index)
112
    {
113
    if( category>=0 && category<mNumCategories )
114
      {
115
      int[] objects = mObjectIndices[category];
116
      if( index>=0 && index<objects.length ) return objects[index];
117
      }
118
119
    return -1;
120
    }
121
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
124
  public int getCategory(int objectIndex)
125
    {
126
    int numC = mObjectIndices.length;
127
128
    for(int c=0; c<numC; c++)
129 74636fa3 leszek
      for(int object : mObjectIndices[c])
130
        if( object==objectIndex ) return c;
131 3eaf5f2a leszek
132 48e61813 leszek
    android.util.Log.e("D", "returning category -1: index: "+objectIndex);
133
134 3eaf5f2a leszek
    return -1;
135
    }
136
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139
  public int getPosInCat(int category, int objectIndex)
140
    {
141
    int[] objects = mObjectIndices[category];
142
    int len = objects.length;
143
144
    for(int o=0; o<len; o++)
145 74636fa3 leszek
      if( objects[o]==objectIndex ) return o;
146 3eaf5f2a leszek
147
    return -1;
148
    }
149
}