Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialState.java @ 55e6be1d

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

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

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

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

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

    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

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

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

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

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

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

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

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  void createRightPane(final TutorialActivity act, float width)
102
    {
103
    if( mController==null ) mController = new MovesAndLockController();
104

    
105
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
106
    layout.removeAllViews();
107

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

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

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  void addMove(int axis, int row, int angle)
124
    {
125
    mController.addMove(axis,row,angle);
126
    }
127
}
(5-5/7)