Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialScreen.java @ 1d23a7d8

1 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
21 344f290c Leszek Koltunski
22 e019c70b Leszek Koltunski
import android.app.Activity;
23 344f290c Leszek Koltunski
import android.view.View;
24
import android.widget.LinearLayout;
25
26 dd1a65c1 Leszek Koltunski
import org.distorted.helpers.MovesController;
27 2afc6754 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
28 3f7a4363 Leszek Koltunski
29 dd1a65c1 Leszek Koltunski
import org.distorted.helpers.LockController;
30 344f290c Leszek Koltunski
import org.distorted.main.R;
31
import org.distorted.main.RubikActivity;
32 fcd5b990 Leszek Koltunski
import org.distorted.screens.RubikScreenPlay;
33
import org.distorted.screens.ScreenList;
34 55e6be1d Leszek Koltunski
import org.distorted.helpers.TransparentImageButton;
35 344f290c Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 dd1a65c1 Leszek Koltunski
public class TutorialScreen
39 344f290c Leszek Koltunski
{
40 dd874ae8 Leszek Koltunski
  private TransparentImageButton mSolveButton, mScrambleButton, mBackButton;
41 dd1a65c1 Leszek Koltunski
  private final LockController mLockController;
42
  private final MovesController mMovesController;
43 344f290c Leszek Koltunski
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46 dd874ae8 Leszek Koltunski
  private void setupSolveButton(final TutorialActivity act)
47 344f290c Leszek Koltunski
    {
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 dd874ae8 Leszek Koltunski
    mSolveButton = new TransparentImageButton(act, icon, LinearLayout.LayoutParams.MATCH_PARENT, TransparentImageButton.GRAVITY_MIDDLE);
50 344f290c Leszek Koltunski
51
    mSolveButton.setOnClickListener( new View.OnClickListener()
52
      {
53
      @Override
54
      public void onClick(View v)
55
        {
56 2afc6754 Leszek Koltunski
        act.getControl().solveObject();
57 dd1a65c1 Leszek Koltunski
        mMovesController.clearMoves(act);
58 344f290c Leszek Koltunski
        }
59
      });
60
    }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 dd874ae8 Leszek Koltunski
  private void setupScrambleButton(final TutorialActivity act)
65 344f290c Leszek Koltunski
    {
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 dd874ae8 Leszek Koltunski
    mScrambleButton = new TransparentImageButton(act, icon, LinearLayout.LayoutParams.MATCH_PARENT, TransparentImageButton.GRAVITY_MIDDLE);
68 344f290c Leszek Koltunski
69
    mScrambleButton.setOnClickListener( new View.OnClickListener()
70
      {
71
      @Override
72
      public void onClick(View v)
73
        {
74 f5da732a Leszek Koltunski
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
75 88bad160 Leszek Koltunski
        int numScrambles = play.getObject().getNumScramble();
76 2afc6754 Leszek Koltunski
        act.getControl().scrambleObject(numScrambles);
77 344f290c Leszek Koltunski
        }
78
      });
79
    }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
83 dd874ae8 Leszek Koltunski
  private void setupBackButton(final TutorialActivity act)
84 344f290c Leszek Koltunski
    {
85 e314f6ae Leszek Koltunski
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
86 dd874ae8 Leszek Koltunski
    mBackButton = new TransparentImageButton(act, icon, LinearLayout.LayoutParams.MATCH_PARENT, TransparentImageButton.GRAVITY_MIDDLE);
87 344f290c Leszek Koltunski
88
    mBackButton.setOnClickListener( new View.OnClickListener()
89
      {
90
      @Override
91
      public void onClick(View v)
92
        {
93 2afc6754 Leszek Koltunski
        ObjectControl control = act.getControl();
94
        if( control!=null ) control.unblockEverything();
95 344f290c Leszek Koltunski
        act.finish();
96
        }
97
      });
98
    }
99
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 dd874ae8 Leszek Koltunski
  void createRightPane(final TutorialActivity act)
103 344f290c Leszek Koltunski
    {
104 2971588c Leszek Koltunski
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
105 344f290c Leszek Koltunski
    layout.removeAllViews();
106
107 e019c70b Leszek Koltunski
    ObjectControl control = act.getControl();
108 dd874ae8 Leszek Koltunski
    mMovesController.setupButton(act,control);
109
    mLockController.setupButton(act,control);
110
    setupSolveButton(act);
111
    setupScrambleButton(act);
112
    setupBackButton(act);
113 344f290c Leszek Koltunski
114
    layout.addView(mSolveButton);
115
    layout.addView(mScrambleButton);
116 dd874ae8 Leszek Koltunski
    layout.addView(mMovesController.getButton());
117 dd1a65c1 Leszek Koltunski
    layout.addView(mLockController.getButton());
118 344f290c Leszek Koltunski
    layout.addView(mBackButton);
119
    }
120
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123 e019c70b Leszek Koltunski
  void addMove(Activity act, int axis, int row, int angle)
124 146661ec Leszek Koltunski
    {
125 dd1a65c1 Leszek Koltunski
    mMovesController.addMove(act, axis,row,angle);
126 146661ec Leszek Koltunski
    }
127
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
// PUBLIC API
130
131 dd1a65c1 Leszek Koltunski
  public TutorialScreen()
132 344f290c Leszek Koltunski
    {
133 dd1a65c1 Leszek Koltunski
    mLockController = new LockController();
134
    mMovesController = new MovesController();
135 344f290c Leszek Koltunski
    }
136 cc88f2fa Leszek Koltunski
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139 e019c70b Leszek Koltunski
  public void reddenLock(final TutorialActivity act)
140 cc88f2fa Leszek Koltunski
    {
141 e019c70b Leszek Koltunski
    ObjectControl control = act.getControl();
142
    mLockController.reddenLock(act,control);
143 cc88f2fa Leszek Koltunski
    }
144 344f290c Leszek Koltunski
}