Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialScreen.java @ 18d47965

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
        ObjectControl control = act.getControl();
131
        if( control!=null ) control.unblockEverything();
132
        act.finish();
133
        }
134
      });
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

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

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

    
168
    setupBackButton(act);
169
    layout.addView(mBackButton);
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

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

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
// PUBLIC API
181

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

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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