Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / RubikObjectCategories.java @ master

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import org.distorted.main.R;
15

    
16
///////////////////////////////////////////////////////////////////////////////////////////////////
17

    
18
public abstract class RubikObjectCategories
19
{
20
  public static final int[] DIFF_IDS =
21
    {
22
    R.id.infoDifficulty0,
23
    R.id.infoDifficulty1,
24
    R.id.infoDifficulty2,
25
    R.id.infoDifficulty3,
26
    R.id.infoDifficulty4
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
  protected final int mNumCategories;
39
  protected int[] mIconIDs;
40
  protected String[] mTitles;
41
  protected int[][] mObjectIndices;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  public RubikObjectCategories()
46
    {
47
    buildIndices();
48
    mNumCategories = mObjectIndices.length;
49
    buildTitle();
50
    }
51

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

    
54
  abstract void buildIndices();
55
  abstract void buildTitle();
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  public static RubikObjectCategories create(int sortMode)
60
    {
61
    switch(sortMode)
62
      {
63
      case SORT_SHAPE     : return new RubikObjectCategoriesShape();
64
      case SORT_DIFFICULTY: return new RubikObjectCategoriesDiff();
65
      case SORT_AUTHOR    : return new RubikObjectCategoriesAuthor();
66
      case SORT_YEAR      : return new RubikObjectCategoriesYear();
67
      }
68

    
69
    android.util.Log.e("D", "sortMode = "+sortMode+" not implemented!");
70
    return null;
71
    }
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
      for(int object : mObjectIndices[c])
130
        if( object==objectIndex ) return c;
131

    
132
    android.util.Log.e("D", "returning category -1: index: "+objectIndex);
133

    
134
    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
      if( objects[o]==objectIndex ) return o;
146

    
147
    return -1;
148
    }
149
}
(2-2/7)