Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialState.java @ cc88f2fa

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.helpers.MovesAndLockController;
27
import org.distorted.helpers.TwistyActivity;
28
import org.distorted.main.R;
29
import org.distorted.main.RubikActivity;
30
import org.distorted.objects.ObjectList;
31
import org.distorted.screens.RubikScreenPlay;
32
import org.distorted.screens.ScreenList;
33
import org.distorted.helpers.TransparentImageButton;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

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

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

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

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

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

    
78
        act.getPreRender().scrambleObject(numScrambles);
79
        }
80
      });
81
    }
82

    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

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

    
90
    mBackButton.setOnClickListener( new View.OnClickListener()
91
      {
92
      @Override
93
      public void onClick(View v)
94
        {
95
        act.finish();
96
        }
97
      });
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  void createRightPane(final TutorialActivity act, float width)
103
    {
104
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
105
    layout.removeAllViews();
106

    
107
    mController.setupPrevButton(act,width);
108
    mController.setupLockButton(act,width);
109
    setupSolveButton(act,width);
110
    setupScrambleButton(act,width);
111
    setupBackButton(act,width);
112

    
113
    layout.addView(mSolveButton);
114
    layout.addView(mController.getPrevButton());
115
    layout.addView(mScrambleButton);
116
    layout.addView(mController.getLockButton());
117
    layout.addView(mBackButton);
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  void addMove(TwistyActivity act, int axis, int row, int angle)
123
    {
124
    mController.addMove(act, axis,row,angle);
125
    }
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128
// PUBLIC API
129

    
130
  public TutorialState()
131
    {
132
    mController = new MovesAndLockController();
133
    }
134

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

    
137
  public void reddenLock(final TwistyActivity act)
138
    {
139
    mController.reddenLock(act);
140
    }
141
}
(5-5/7)