Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialState.java @ 3f7a4363

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.tutorials;
21

    
22
import android.view.View;
23
import android.widget.ImageButton;
24
import android.widget.LinearLayout;
25

    
26
import org.distorted.objectlib.main.ObjectList;
27

    
28
import org.distorted.helpers.MovesAndLockController;
29
import org.distorted.helpers.TwistyActivity;
30
import org.distorted.helpers.TwistyPreRender;
31
import org.distorted.main.R;
32
import org.distorted.main.RubikActivity;
33
import org.distorted.screens.RubikScreenPlay;
34
import org.distorted.screens.ScreenList;
35
import org.distorted.helpers.TransparentImageButton;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public class TutorialState
40
{
41
  private ImageButton mSolveButton, mScrambleButton, mBackButton;
42
  private final MovesAndLockController mController;
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  private void setupSolveButton(final TutorialActivity act, final float width)
47
    {
48
    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);
49
    mSolveButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
50

    
51
    mSolveButton.setOnClickListener( new View.OnClickListener()
52
      {
53
      @Override
54
      public void onClick(View v)
55
        {
56
        act.getPreRender().solveObject();
57
        mController.clearMoves(act);
58
        }
59
      });
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  private void setupScrambleButton(final TutorialActivity act, final float width)
65
    {
66
    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);
67
    mScrambleButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
68

    
69
    mScrambleButton.setOnClickListener( new View.OnClickListener()
70
      {
71
      @Override
72
      public void onClick(View v)
73
        {
74
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
75
        int size = play.getSize();
76
        int object= play.getObject();
77
        int sizeIndex = ObjectList.getSizeIndex(object,size);
78
        int numScrambles = ObjectList.getNumScramble(object, sizeIndex);
79

    
80
        act.getPreRender().scrambleObject(numScrambles);
81
        }
82
      });
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  private void setupBackButton(final TutorialActivity act, final float width)
88
    {
89
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
90
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
91

    
92
    mBackButton.setOnClickListener( new View.OnClickListener()
93
      {
94
      @Override
95
      public void onClick(View v)
96
        {
97
        TwistyPreRender pre = act.getPreRender();
98
        if( pre!=null ) pre.unblockEverything();
99
        act.finish();
100
        }
101
      });
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

    
106
  void createRightPane(final TutorialActivity act, float width)
107
    {
108
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
109
    layout.removeAllViews();
110

    
111
    mController.setupPrevButton(act,width);
112
    mController.setupLockButton(act,width);
113
    setupSolveButton(act,width);
114
    setupScrambleButton(act,width);
115
    setupBackButton(act,width);
116

    
117
    layout.addView(mSolveButton);
118
    layout.addView(mController.getPrevButton());
119
    layout.addView(mScrambleButton);
120
    layout.addView(mController.getLockButton());
121
    layout.addView(mBackButton);
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  void addMove(TwistyActivity act, int axis, int row, int angle)
127
    {
128
    mController.addMove(act, axis,row,angle);
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132
// PUBLIC API
133

    
134
  public TutorialState()
135
    {
136
    mController = new MovesAndLockController();
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  public void reddenLock(final TwistyActivity act)
142
    {
143
    mController.reddenLock(act);
144
    }
145
}
(5-5/7)