Project

General

Profile

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

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

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.MovesController;
27
import org.distorted.objectlib.main.ObjectPreRender;
28
import org.distorted.objectlib.main.ObjectType;
29

    
30
import org.distorted.helpers.LockController;
31
import org.distorted.objectlib.helpers.TwistyActivity;
32
import org.distorted.main.R;
33
import org.distorted.main.RubikActivity;
34
import org.distorted.screens.RubikScreenPlay;
35
import org.distorted.screens.ScreenList;
36
import org.distorted.helpers.TransparentImageButton;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TutorialScreen
41
{
42
  private ImageButton mSolveButton, mScrambleButton, mBackButton;
43
  private final LockController mLockController;
44
  private final MovesController mMovesController;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

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

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

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

    
71
    mScrambleButton.setOnClickListener( new View.OnClickListener()
72
      {
73
      @Override
74
      public void onClick(View v)
75
        {
76
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
77
        int numScrambles = ObjectType.getNumScramble(play.getObject());
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
        ObjectPreRender pre = act.getPreRender();
96
        if( pre!=null ) pre.unblockEverything();
97
        act.finish();
98
        }
99
      });
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

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

    
109
    mMovesController.setupButton(act,width);
110
    mLockController.setupButton(act,width);
111
    setupSolveButton(act,width);
112
    setupScrambleButton(act,width);
113
    setupBackButton(act,width);
114

    
115
    layout.addView(mSolveButton);
116
    layout.addView(mMovesController.getButton());
117
    layout.addView(mScrambleButton);
118
    layout.addView(mLockController.getButton());
119
    layout.addView(mBackButton);
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

    
124
  void addMove(TwistyActivity act, int axis, int row, int angle)
125
    {
126
    mMovesController.addMove(act, axis,row,angle);
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130
// PUBLIC API
131

    
132
  public TutorialScreen()
133
    {
134
    mLockController = new LockController();
135
    mMovesController = new MovesController();
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

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