Project

General

Profile

« Previous | Next » 

Revision 769d7b9f

Added by Leszek Koltunski over 4 years ago

Bugfixes.

View differences:

src/main/java/org/distorted/effect/scramble/ScrambleEffect.java
97 97
// the time a single quarter-turn takes!
98 98
//
99 99
// Only works for
100
// basicAngle==4, i.e. something whose rotations are by 90 degrees (RubikCube) or
100
// basicAngle==4, i.e. something whose rotations are by  90 degrees (RubikCube) or
101 101
// basicAngle==3, i.e. something whose rotations are by 120 degrees (a Pyramix) or
102
// basicAngle==2, i.e. something whose rotations are by 180 degrees (is there something like that?)
102
// basicAngle==2, i.e. something whose rotations are by 180 degrees (e.g. a 3x2x1 'Bunny')
103 103

  
104 104
  private void createBaseEffects(int duration, int numScrambles)
105 105
    {
......
124 124
    }
125 125

  
126 126
///////////////////////////////////////////////////////////////////////////////////////////////////
127
// only works if basicAngle<=4, i.e. wont work for something whose basic rotations are by no less
127
// only works if basicAngle<=4, i.e. won't work for something whose basic rotations are by less
128 128
// than 90 degrees.
129 129

  
130 130
  private void addNewScramble()
......
168 168
    }
169 169

  
170 170
///////////////////////////////////////////////////////////////////////////////////////////////////
171
// only works for basicAngle==4, i.e. RubikCube or basicAngle==3, i.e. a Pyramix.
171
// only works for basicAngle<=4.
172 172

  
173 173
  private int randomizeAngle()
174 174
    {
src/main/java/org/distorted/effect/win/WinEffect.java
48 48
    }
49 49

  
50 50
  private static final int NUM_EFFECTS = Type.values().length;
51
  private static final int FAKE_EFFECT_ID = -2;
51
  private static final int FAKE_EFFECT_ID = -4;
52 52
  private static final Type[] types;
53 53

  
54 54
  static
src/main/java/org/distorted/magic/RubikActivity.java
118 118
    @Override
119 119
    public void onClick(View v)
120 120
      {
121
      switch(v.getId())
121
      if( v.getId() == RubikStateAbstract.BUTTON_ID_BACK )
122 122
        {
123
        case RubikStateAbstract.BUTTON_ID_OBJECT: RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
124
                                                  play.bringUpPopup(this,v);
125
                                                  break;
126
        case RubikStateAbstract.BUTTON_ID_BACK:   RubikState.goBack(this);
127
                                                  break;
123
        RubikState.goBack(this);
128 124
        }
129 125
      }
130 126

  
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

  
133
    public void changeObject(int object, int size)
134
      {
135
      RubikObjectList obj = RubikObjectList.getObject(object);
136
      int objectSize = obj.getSizes()[size];
137

  
138
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
139
      view.getRenderer().createObject(obj,objectSize);
140
      }
141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

  
144
    public boolean isVertical()
145
      {
146
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
147
      return view.isVertical();
148
      }
149

  
150 127
///////////////////////////////////////////////////////////////////////////////////////////////////
151 128

  
152 129
    private void savePreferences()
......
195 172

  
196 173
///////////////////////////////////////////////////////////////////////////////////////////////////
197 174
// PUBLIC API
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
    public void changeObject(int object, int size)
178
      {
179
      RubikObjectList obj = RubikObjectList.getObject(object);
180
      int objectSize = obj.getSizes()[size];
181

  
182
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
183
      view.getRenderer().createObject(obj,objectSize);
184
      }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

  
188
    public boolean isVertical()
189
      {
190
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
191
      return view.isVertical();
192
      }
193

  
198 194
///////////////////////////////////////////////////////////////////////////////////////////////////
199 195

  
200 196
    public void Play(View v)
src/main/java/org/distorted/scores/RubikScores.java
296 296
    }
297 297

  
298 298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
// TODO
300 299

  
301 300
  public void setName(String newName)
302 301
    {
src/main/java/org/distorted/uistate/RubikStatePlay.java
79 79
    // BOT ////////////////////////////
80 80
    DisplayMetrics metrics = act.getResources().getDisplayMetrics();
81 81
    final float scale = metrics.density;
82
    int padding = (int)(3*scale + 0.5f);
83 82

  
84
    if( mObjButton==null )
85
      {
86
      LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
87
      mObjButton = new ImageButton(act);
88
      mObjButton.setLayoutParams(objectParams);
89
      mObjButton.setId(BUTTON_ID_OBJECT);
90
      mObjButton.setPadding(padding,0,padding,0);
91
      mObjButton.setImageResource(R.drawable.cube_menu);
92
      mObjButton.setOnClickListener(act);
93
      }
83
    if( mObjButton==null ) setupObjectButton(act,scale);
84

  
94 85
    LinearLayout layoutLeft = act.findViewById(R.id.mainBarLeft);
95 86
    layoutLeft.removeAllViews();
96 87
    layoutLeft.addView(mObjButton);
97 88

  
98
    if( mBackButton==null )
99
      {
100
      LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
101
      mBackButton = new Button(act);
102
      mBackButton.setLayoutParams(backParams);
103
      mBackButton.setId(BUTTON_ID_BACK);
104
      mBackButton.setPadding(padding,0,padding,0);
105
      mBackButton.setText(R.string.back);
106
      mBackButton.setOnClickListener(act);
107
      }
89
    if( mBackButton==null ) setupBackButton(act,scale);
90

  
108 91
    LinearLayout layoutRight = act.findViewById(R.id.mainBarRight);
109 92
    layoutRight.removeAllViews();
110 93
    layoutRight.addView(mBackButton);
......
114 97
    mPicker.setMax(MAX_SCRAMBLE);
115 98
    mPicker.setValue(mPickerValue);
116 99

  
117
    if( mPopup==null )
118
      {
119
      LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
120
      final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
121
      mLayout = layout.findViewById(R.id.popup);
122

  
123
      mPopup = new PopupWindow(act);
124
      mPopup.setContentView(layout);
125
      mPopup.setFocusable(true);
126
      int margin = (int)(5*scale + 0.5f);
127

  
128
      BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2);
129
      int cubeWidth  = bd.getIntrinsicWidth();
130
      int cubeHeight = bd.getIntrinsicHeight();
100
    if( mPopup==null ) setupPopupWindow(act, scale);
101
    }
131 102

  
132
      mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
133
      mLayoutHeight= (int)(cubeHeight+ 2*margin + 0.5f);
103
///////////////////////////////////////////////////////////////////////////////////////////////////
134 104

  
135
      for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
105
  private void setupObjectButton(final RubikActivity act, final float scale)
106
    {
107
    int padding = (int)(3*scale + 0.5f);
108
    LinearLayout.LayoutParams objectParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.MATCH_PARENT);
109
    mObjButton = new ImageButton(act);
110
    mObjButton.setLayoutParams(objectParams);
111
    mObjButton.setId(BUTTON_ID_OBJECT);
112
    mObjButton.setPadding(padding,0,padding,0);
113
    mObjButton.setImageResource(R.drawable.cube_menu);
114

  
115
    mObjButton.setOnClickListener( new View.OnClickListener()
116
      {
117
      @Override
118
      public void onClick(View view)
136 119
        {
137
        RubikObjectList list = RubikObjectList.getObject(object);
138
        int[] sizes = list.getSizes();
139
        int[] icons = list.getIconIDs();
140
        int len = sizes.length;
141
        final int obj = object;
120
        int total = RubikObjectList.getTotal();
121
        boolean vertical = act.isVertical();
122
        mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
142 123

  
143
        for(int i=0; i<len; i++)
144
          {
145
          final int size = i;
124
        int height = view.getHeight();
125
        int width  = view.getWidth();
126
        int laywid = mLayoutWidth * (vertical? 1:total);
127
        int layhei = mLayoutHeight* (vertical? total:1);
146 128

  
147
          LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
148
          p.setMargins(margin, margin, margin, margin);
129
        mPopup.showAsDropDown(view, (width-laywid)/2, -height-layhei, Gravity.LEFT);
130
        }
131
      });
132
    }
149 133

  
150
          ImageButton button = new ImageButton(act);
151
          button.setLayoutParams(p);
134
///////////////////////////////////////////////////////////////////////////////////////////////////
152 135

  
153
          button.setBackgroundResource(icons[i]);
154
          button.setOnClickListener( new View.OnClickListener()
155
            {
156
            @Override
157
            public void onClick(View v)
158
              {
159
              mObject = obj;
160
              mSize   = size;
161
              act.changeObject(obj,size);
162
              mPopup.dismiss();
163
              }
164
            });
165

  
166
          mLayout.addView(button);
167
          }
168
        }
169
      }
136
  private void setupBackButton(final RubikActivity act, final float scale)
137
    {
138
    int padding = (int)(3*scale + 0.5f);
139
    LinearLayout.LayoutParams backParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
140
    mBackButton = new Button(act);
141
    mBackButton.setLayoutParams(backParams);
142
    mBackButton.setId(BUTTON_ID_BACK);
143
    mBackButton.setPadding(padding,0,padding,0);
144
    mBackButton.setText(R.string.back);
145
    mBackButton.setOnClickListener(act);
170 146
    }
171 147

  
172 148
///////////////////////////////////////////////////////////////////////////////////////////////////
173 149

  
174
  public void bringUpPopup(RubikActivity act, View view)
150
  private void setupPopupWindow(final RubikActivity act, final float scale)
175 151
    {
176
    int total = RubikObjectList.getTotal();
177
    boolean vertical = act.isVertical();
178
    mLayout.setOrientation(vertical ? LinearLayout.VERTICAL:LinearLayout.HORIZONTAL);
152
    LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
153
    final View layout = layoutInflater.inflate(R.layout.popup_objects, null);
154
    mLayout = layout.findViewById(R.id.popup);
155

  
156
    mPopup = new PopupWindow(act);
157
    mPopup.setContentView(layout);
158
    mPopup.setFocusable(true);
159
    int margin = (int)(5*scale + 0.5f);
160

  
161
    BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(R.drawable.cube2);
162
    int cubeWidth  = bd.getIntrinsicWidth();
163
    int cubeHeight = bd.getIntrinsicHeight();
164

  
165
    mLayoutWidth = (int)(cubeWidth + 2*margin + 0.5f);
166
    mLayoutHeight= (int)(cubeHeight+ 2*margin + 0.5f);
179 167

  
180
    int height = view.getHeight();
181
    int width  = view.getWidth();
182
    int laywid = mLayoutWidth * (vertical? 1:total);
183
    int layhei = mLayoutHeight* (vertical? total:1);
168
    for(int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
169
      {
170
      RubikObjectList list = RubikObjectList.getObject(object);
171
      int[] sizes = list.getSizes();
172
      int[] icons = list.getIconIDs();
173
      int len = sizes.length;
174
      final int obj = object;
175

  
176
      for(int i=0; i<len; i++)
177
        {
178
        final int size = i;
179

  
180
        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
181
        p.setMargins(margin, margin, margin, margin);
182

  
183
        ImageButton button = new ImageButton(act);
184
        button.setLayoutParams(p);
184 185

  
185
    mPopup.showAsDropDown(view, (width-laywid)/2, -height-layhei, Gravity.LEFT);
186
        button.setBackgroundResource(icons[i]);
187
        button.setOnClickListener( new View.OnClickListener()
188
          {
189
          @Override
190
          public void onClick(View v)
191
            {
192
            mObject = obj;
193
            mSize   = size;
194
            act.changeObject(obj,size);
195
            mPopup.dismiss();
196
            }
197
          });
198

  
199
        mLayout.addView(button);
200
        }
201
      }
186 202
    }
187 203

  
188 204
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff