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.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
|
public static final int[] CATEGORY_IMAGES =
|
39
|
{
|
40
|
R.drawable.difficulty1,
|
41
|
R.drawable.difficulty2,
|
42
|
R.drawable.difficulty3,
|
43
|
R.drawable.difficulty4,
|
44
|
R.drawable.difficulty5,
|
45
|
};
|
46
|
|
47
|
protected final int mNumCategories;
|
48
|
protected int[] mIconIDs;
|
49
|
protected String[] mTitles;
|
50
|
protected int[][] mObjectIndices;
|
51
|
|
52
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
53
|
|
54
|
public RubikObjectCategories()
|
55
|
{
|
56
|
buildIndices();
|
57
|
mNumCategories = mObjectIndices.length;
|
58
|
buildTitle();
|
59
|
}
|
60
|
|
61
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
62
|
|
63
|
abstract void buildIndices();
|
64
|
abstract void buildTitle();
|
65
|
|
66
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
67
|
|
68
|
public static RubikObjectCategories create(int sortMode)
|
69
|
{
|
70
|
switch(sortMode)
|
71
|
{
|
72
|
case SORT_CATEGORY : return new RubikObjectCategoriesCat();
|
73
|
case SORT_DIFFICULTY: return new RubikObjectCategoriesDiff();
|
74
|
case SORT_AUTHOR : return new RubikObjectCategoriesAuthor();
|
75
|
case SORT_YEAR : return new RubikObjectCategoriesYear();
|
76
|
}
|
77
|
|
78
|
android.util.Log.e("D", "sortMode = "+sortMode+" not implemented!");
|
79
|
return null;
|
80
|
}
|
81
|
|
82
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
83
|
// PUBLIC API
|
84
|
|
85
|
public int getNumCategories()
|
86
|
{
|
87
|
return mNumCategories;
|
88
|
}
|
89
|
|
90
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91
|
|
92
|
public boolean hasIcons()
|
93
|
{
|
94
|
return mIconIDs!=null;
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
|
99
|
public int getIconId(int category)
|
100
|
{
|
101
|
return ( mIconIDs!=null && category>=0 && category<mNumCategories ) ? mIconIDs[category] : -1;
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
public String getTitle(int category)
|
107
|
{
|
108
|
return (mTitles!=null && category>=0 && category<mNumCategories) ? mTitles[category] : null;
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
public int getNumObjects(int category)
|
114
|
{
|
115
|
return (category>=0 && category<mNumCategories) ? mObjectIndices[category].length : 0;
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
|
120
|
public int getObjectIndex(int category, int index)
|
121
|
{
|
122
|
if( category>=0 && category<mNumCategories )
|
123
|
{
|
124
|
int[] objects = mObjectIndices[category];
|
125
|
if( index>=0 && index<objects.length ) return objects[index];
|
126
|
}
|
127
|
|
128
|
return -1;
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
|
133
|
public int getCategory(int objectIndex)
|
134
|
{
|
135
|
int numC = mObjectIndices.length;
|
136
|
|
137
|
for(int c=0; c<numC; c++)
|
138
|
for(int object : mObjectIndices[c])
|
139
|
if( object==objectIndex ) return c;
|
140
|
|
141
|
android.util.Log.e("D", "returning category -1: index: "+objectIndex);
|
142
|
|
143
|
return -1;
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
public int getPosInCat(int category, int objectIndex)
|
149
|
{
|
150
|
int[] objects = mObjectIndices[category];
|
151
|
int len = objects.length;
|
152
|
|
153
|
for(int o=0; o<len; o++)
|
154
|
if( objects[o]==objectIndex ) return o;
|
155
|
|
156
|
return -1;
|
157
|
}
|
158
|
}
|