Project

General

Profile

« Previous | Next » 

Revision 7654a99d

Added by Leszek Koltunski almost 2 years ago

Purchase Pane: further progress.

View differences:

src/main/java/org/distorted/external/RubikScores.java
408 408
    editor.putInt("scores_numStars", mNumStars );
409 409
    }
410 410

  
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

  
413
  public synchronized void savePreferencesMinimal(SharedPreferences.Editor editor)
414
    {
415
    editor.putInt("scores_numStars", mNumStars );
416
    }
417

  
411 418
///////////////////////////////////////////////////////////////////////////////////////////////////
412 419

  
413 420
  public synchronized void restorePreferences(SharedPreferences preferences)
src/main/java/org/distorted/objects/RubikObjectList.java
369 369
      }
370 370
    }
371 371

  
372
///////////////////////////////////////////////////////////////////////////////////////////////////
373

  
374
  public static void savePreferencesMinimal(SharedPreferences.Editor editor)
375
    {
376
    RubikObject obj = getObject(mObject);
377
    if( obj!=null ) editor.putString("rol_objName", obj.getUpperName() );
378
    }
379

  
372 380
///////////////////////////////////////////////////////////////////////////////////////////////////
373 381

  
374 382
  public static void restorePreferences(Context context, SharedPreferences preferences, boolean justStarted)
src/main/java/org/distorted/overlays/OverlayStars.java
84 84
      float heighS = mRandom.nextFloat()*mHeight*0.2f;
85 85
      float heighM = (mRandom.nextFloat()-0.5f)*mHeight*0.2f;
86 86

  
87
      Static3D pointS = new Static3D(widthS,mHeight*0.55f+heighS,0);
87
      Static3D pointS = new Static3D(widthS,mHeight*0.60f+heighS,0);
88 88
      Static3D pointM = new Static3D(widthM,mHeight*0.25f+heighM,0);
89 89
      Static3D pointE = new Static3D(0,0,0);
90 90
      Static3D pointF = new Static3D(0,0,-10000);
src/main/java/org/distorted/purchase/PurchaseActivity.java
9 9

  
10 10
package org.distorted.purchase;
11 11

  
12
import android.content.SharedPreferences;
12 13
import android.os.Build;
13 14
import android.os.Bundle;
15
import android.preference.PreferenceManager;
14 16
import android.util.DisplayMetrics;
15 17
import android.view.View;
16 18
import android.view.ViewGroup;
......
19 21
import androidx.appcompat.app.AppCompatActivity;
20 22

  
21 23
import org.distorted.dialogs.RubikDialogError;
24
import org.distorted.external.RubikScores;
22 25
import org.distorted.library.main.DistortedLibrary;
23 26
import org.distorted.main.R;
24 27
import org.distorted.objectlib.main.ObjectControl;
......
165 168
      PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView);
166 169
      view.onPause();
167 170
      DistortedLibrary.onPause(ACTIVITY_NUMBER);
171
      savePreferences();
168 172
      }
169 173

  
170 174
///////////////////////////////////////////////////////////////////////////////////////////////////
......
196 200
      DistortedLibrary.onDestroy(ACTIVITY_NUMBER);
197 201
      }
198 202

  
203

  
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

  
206
    private void savePreferences()
207
      {
208
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
209
      SharedPreferences.Editor editor = preferences.edit();
210
      RubikScores scores = RubikScores.getInstance();
211

  
212
      scores.savePreferencesMinimal(editor);
213
      RubikObjectList.savePreferencesMinimal(editor);
214

  
215
      boolean success = editor.commit();
216
      if( !success ) android.util.Log.e("D", "Failed to save preferences");
217
      }
218

  
199 219
///////////////////////////////////////////////////////////////////////////////////////////////////
200 220

  
201 221
    void OpenGLError()
......
252 272
      return view.getRenderer();
253 273
      }
254 274

  
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

  
277
    void blockUI()
278
      {
279
      mScreen.blockUI();
280
      }
281

  
255 282
///////////////////////////////////////////////////////////////////////////////////////////////////
256 283

  
257 284
    public static int getDrawableSize()
src/main/java/org/distorted/purchase/PurchaseRenderer.java
12 12
import android.opengl.GLSurfaceView;
13 13

  
14 14
import org.distorted.library.effect.EffectType;
15
import org.distorted.library.effect.VertexEffectQuaternion;
16
import org.distorted.library.effect.VertexEffectRotate;
15
import org.distorted.library.effect.PostprocessEffectGlow;
17 16
import org.distorted.library.main.DistortedLibrary;
18 17
import org.distorted.library.main.DistortedScreen;
19
import org.distorted.objectlib.effects.BaseEffect;
20 18
import org.distorted.objectlib.main.ObjectControl;
19
import org.distorted.overlays.OverlayStars;
21 20

  
22 21
import javax.microedition.khronos.egl.EGLConfig;
23 22
import javax.microedition.khronos.opengles.GL10;
......
77 76
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
78 77
      {
79 78
      DistortedLibrary.setMax(EffectType.VERTEX, ObjectControl.MAX_QUATS+1);
80
      VertexEffectRotate.enable();
81
      VertexEffectQuaternion.enable();
82
      BaseEffect.Type.enableEffects();
79
      OverlayStars.enableEffects();
80
      PostprocessEffectGlow.enable();
83 81

  
84 82
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
85 83
      DistortedLibrary.setCull(true);
src/main/java/org/distorted/purchase/PurchaseScreen.java
22 22
public class PurchaseScreen
23 23
{
24 24
  private TransparentImageButton mBackButton;
25
  private boolean mBlocked;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
  void blockUI()
30
    {
31
    mBlocked = true;
32
    }
25 33

  
26 34
///////////////////////////////////////////////////////////////////////////////////////////////////
27 35

  
......
36 44
      @Override
37 45
      public void onClick(View v)
38 46
        {
39
        ObjectControl control = act.getControl();
40
        if( control!=null ) control.unblockEverything();
41
        act.finish();
47
        if( !mBlocked )
48
          {
49
          ObjectControl control = act.getControl();
50
          if( control!=null ) control.unblockEverything();
51
          act.finish();
52
          }
42 53
        }
43 54
      });
44 55
    }
......
47 58

  
48 59
  void onAttachedToWindow(final PurchaseActivity act, final int ordinal)
49 60
    {
61
    mBlocked = false;
50 62
    int width = act.getScreenWidthInPixels();
51 63

  
52 64
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
src/main/java/org/distorted/purchase/PurchaseScreenPane.java
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.main.R;
27 27
import org.distorted.objectlib.json.JsonReader;
28
import org.distorted.objectlib.main.ObjectControl;
28 29
import org.distorted.objects.RubikObject;
29 30
import org.distorted.objects.RubikObjectList;
30 31
import org.distorted.overlays.DataStars;
32
import org.distorted.overlays.ListenerOverlay;
31 33
import org.distorted.overlays.OverlayStars;
32 34

  
33 35
import java.io.InputStream;
36
import java.lang.ref.WeakReference;
34 37

  
35 38
///////////////////////////////////////////////////////////////////////////////////////////////////
36 39

  
37
public class PurchaseScreenPane
40
public class PurchaseScreenPane implements ListenerOverlay
38 41
{
39 42
  public static final int UNLOCK_ALL_PRICE = 500;
40 43

  
......
51 54
  public  static final float PADDING_RATIO = 0.025f;
52 55
  private static final float TEXT_RATIO    = 0.050f;
53 56

  
57
  private final WeakReference<PurchaseActivity> mAct;
54 58
  private RubikObject mObject;
55 59

  
56 60
///////////////////////////////////////////////////////////////////////////////////////////////////
......
84 88

  
85 89
  private void showSuccess(PurchaseActivity act, RubikObject object)
86 90
    {
91
    act.blockUI();
87 92
    RubikScores scores = RubikScores.getInstance();
88 93
    int totStars = scores.getNumStars();
89 94
    int price = object==null ? UNLOCK_ALL_PRICE:object.getPrice();
90 95
    PurchaseRenderer renderer = act.getRenderer();
91 96
    DistortedScreen screen = renderer.getScreen();
92 97
    OverlayStars stars = new OverlayStars();
93
    DataStars data = new DataStars(totStars,-price,act.getResources());
94
    stars.startOverlay(screen,null,data);
98
    DataStars data = new DataStars(totStars+price,-price,act.getResources());
99
    stars.startOverlay(screen,this,data);
95 100
    }
96 101

  
97 102
///////////////////////////////////////////////////////////////////////////////////////////////////
......
220 225

  
221 226
  PurchaseScreenPane(final PurchaseActivity act)
222 227
    {
228
    mAct = new WeakReference<>(act);
223 229
    int width = act.getScreenWidthInPixels();
224 230
    float textSize = width*TEXT_RATIO;
225 231
    int margin = (int)(width*PADDING_RATIO);
......
267 273

  
268 274
    setUpButtons(act,oneLayout,allLayout);
269 275
    }
276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  public void overlayFinished(long id)
280
    {
281
    PurchaseActivity act = mAct.get();
282

  
283
    if( act!=null )
284
      {
285
      String upperName = mObject.getUpperName();
286
      int ordinal = RubikObjectList.getOrdinal(upperName);
287
      RubikObjectList.setCurrObject(ordinal);
288
      ObjectControl control = act.getControl();
289
      if( control!=null ) control.unblockEverything();
290
      act.finish();
291
      }
292
    }
270 293
}

Also available in: Unified diff