Project

General

Profile

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

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

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.main.ObjectControl;
16

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

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

    
26
public class TutorialScreen
27
{
28
  private TransparentImageButton mSolveButton, mScrambleButton, mBackButton;
29
  private final LockController mLockController;
30
  private final MovesController mMovesController;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
  private void setupSolveButton(final TutorialActivity act)
35
    {
36
    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);
37
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
38
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
39

    
40
    mSolveButton.setOnClickListener( new View.OnClickListener()
41
      {
42
      @Override
43
      public void onClick(View v)
44
        {
45
        act.getControl().solveObject();
46
        mMovesController.clearMoves(act);
47
        }
48
      });
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  private void setupScrambleButton(final TutorialActivity act)
54
    {
55
    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);
56
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
57
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
58

    
59
    mScrambleButton.setOnClickListener( new View.OnClickListener()
60
      {
61
      @Override
62
      public void onClick(View v)
63
        {
64
        int object = RubikObjectList.getCurrObject();
65
        RubikObject obj = RubikObjectList.getObject(object);
66
        int numScrambles = obj==null ? 0 : 2*obj.getNumScramble();
67
        act.getControl().fastScrambleObject(numScrambles);
68
        }
69
      });
70
    }
71

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

    
74
  private void setupBackButton(final TutorialActivity act)
75
    {
76
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
77
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
78
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
79

    
80
    mBackButton.setOnClickListener( new View.OnClickListener()
81
      {
82
      @Override
83
      public void onClick(View v)
84
        {
85
        ObjectControl control = act.getControl();
86
        if( control!=null ) control.unblockEverything();
87
        act.finish();
88
        }
89
      });
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  void createRightPane(final TutorialActivity act)
95
    {
96
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
97
    layout.removeAllViews();
98

    
99
    ObjectControl control = act.getControl();
100
    mMovesController.setupButton(act,control);
101
    mLockController.setupButton(act,control);
102
    setupSolveButton(act);
103
    setupScrambleButton(act);
104
    setupBackButton(act);
105

    
106
    layout.addView(mSolveButton);
107
    layout.addView(mScrambleButton);
108
    layout.addView(mMovesController.getButton());
109
    layout.addView(mLockController.getButton());
110
    layout.addView(mBackButton);
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  void addMove(Activity act, int axis, int row, int angle)
116
    {
117
    mMovesController.addMove(act, axis,row,angle);
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
// PUBLIC API
122

    
123
  public TutorialScreen()
124
    {
125
    mLockController = new LockController();
126
    mMovesController = new MovesController();
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public void reddenLock(final TutorialActivity act)
132
    {
133
    ObjectControl control = act.getControl();
134
    mLockController.reddenLock(act,control);
135
    }
136
}
(4-4/6)