Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialScreen.java @ f404152d

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
5
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
6
///////////////////////////////////////////////////////////////////////////////////////////////////
7

    
8
package org.distorted.tutorials;
9

    
10
import android.app.Activity;
11
import android.view.View;
12
import android.widget.LinearLayout;
13

    
14
import org.distorted.helpers.MovesController;
15
import org.distorted.objectlib.effects.BaseEffect;
16
import org.distorted.objectlib.main.ObjectControl;
17

    
18
import org.distorted.helpers.LockController;
19
import org.distorted.main.R;
20
import org.distorted.main.RubikActivity;
21
import org.distorted.objects.RubikObject;
22
import org.distorted.helpers.TransparentImageButton;
23

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

    
26
public class TutorialScreen
27
{
28
  private TransparentImageButton mSolveButton, mScrambleButton, mBackButton;
29
  private TransparentImageButton mLockButton, mEmptyButton1, mEmptyButton2, mEmptyButton3;
30
  private final LockController mLockController;
31
  private final MovesController mMovesController;
32
  private final boolean mFree;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  private void setupLockButton(final TutorialActivity act)
37
    {
38
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_locked,R.drawable.ui_medium_locked, R.drawable.ui_big_locked, R.drawable.ui_huge_locked);
39
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
40
    mLockButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
41

    
42
    mLockButton.setOnClickListener( new View.OnClickListener()
43
      {
44
      @Override
45
      public void onClick(View v)
46
        {
47
        act.switchToPurchase();
48
        }
49
      });
50
    }
51

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

    
54
  private void setupEmptyButton1(final TutorialActivity act)
55
    {
56
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
57
    mEmptyButton1 = new TransparentImageButton(act, params);
58
    mEmptyButton1.setClickable(false);
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

    
63
  private void setupEmptyButton2(final TutorialActivity act)
64
    {
65
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
66
    mEmptyButton2 = new TransparentImageButton(act, params);
67
    mEmptyButton2.setClickable(false);
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  private void setupEmptyButton3(final TutorialActivity act)
73
    {
74
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
75
    mEmptyButton3 = new TransparentImageButton(act, params);
76
    mEmptyButton3.setClickable(false);
77
    }
78

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

    
81
  private void setupSolveButton(final TutorialActivity act)
82
    {
83
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
84
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
85
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
86

    
87
    mSolveButton.setOnClickListener( new View.OnClickListener()
88
      {
89
      @Override
90
      public void onClick(View v)
91
        {
92
        act.getControl().solveObject();
93
        mMovesController.clearMoves(act);
94
        }
95
      });
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  private void setupScrambleButton(final TutorialActivity act)
101
    {
102
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
103
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
104
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
105

    
106
    mScrambleButton.setOnClickListener( new View.OnClickListener()
107
      {
108
      @Override
109
      public void onClick(View v)
110
        {
111
        int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
112
        act.getControl().fastScrambleObject(duration,RubikObject.FAST_SCRAMBLES);
113
        }
114
      });
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  private void setupBackButton(final TutorialActivity act)
120
    {
121
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
122
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
123
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
124

    
125
    mBackButton.setOnClickListener( new View.OnClickListener()
126
      {
127
      @Override
128
      public void onClick(View v)
129
        {
130
        act.finish();
131
        }
132
      });
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  void createRightPane(final TutorialActivity act)
138
    {
139
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
140
    layout.removeAllViews();
141

    
142
    if( mFree )
143
      {
144
      ObjectControl control = act.getControl();
145
      mMovesController.setupButton(act,control);
146
      mLockController.setupButton(act,control);
147
      setupSolveButton(act);
148
      setupScrambleButton(act);
149
      layout.addView(mSolveButton);
150
      layout.addView(mScrambleButton);
151
      layout.addView(mMovesController.getButton());
152
      layout.addView(mLockController.getButton());
153
      }
154
    else
155
      {
156
      setupLockButton(act);
157
      setupEmptyButton1(act);
158
      setupEmptyButton2(act);
159
      setupEmptyButton3(act);
160
      layout.addView(mLockButton);
161
      layout.addView(mEmptyButton1);
162
      layout.addView(mEmptyButton2);
163
      layout.addView(mEmptyButton3);
164
      }
165

    
166
    setupBackButton(act);
167
    layout.addView(mBackButton);
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  void addMove(Activity act, int axis, int row, int angle)
173
    {
174
    mMovesController.addMove(act, axis,row,angle);
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178
// PUBLIC API
179

    
180
  public TutorialScreen(boolean free)
181
    {
182
    mFree = free;
183
    mLockController = new LockController();
184
    mMovesController = new MovesController();
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  public void reddenLock(final TutorialActivity act)
190
    {
191
    ObjectControl control = act.getControl();
192
    mLockController.reddenLock(act,control);
193
    }
194
}
(4-4/6)