Project

General

Profile

« Previous | Next » 

Revision f8e8a08e

Added by Leszek Koltunski almost 2 years ago

Purchase Pane: post-purchase dialogs.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogStarsError.java
42 42
    DisplayMetrics displaymetrics = new DisplayMetrics();
43 43
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
44 44
    final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
45
    final View view = inflater.inflate(R.layout.dialog_explain_stars, null);
45
    final View view = inflater.inflate(R.layout.dialog_stars_error, null);
46 46

  
47 47
    Bundle args = getArguments();
48 48
    long price;
src/main/java/org/distorted/dialogs/RubikDialogStarsExplain.java
41 41
    DisplayMetrics displaymetrics = new DisplayMetrics();
42 42
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
43 43
    final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
44
    final View view = inflater.inflate(R.layout.dialog_explain_stars, null);
44
    final View view = inflater.inflate(R.layout.dialog_stars_explain, null);
45 45

  
46 46
    builder.setCancelable(true);
47 47

  
src/main/java/org/distorted/dialogs/RubikDialogStarsSuccess.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

  
10
package org.distorted.dialogs;
11

  
12
import android.app.Dialog;
13
import android.content.DialogInterface;
14
import android.os.Bundle;
15
import android.util.DisplayMetrics;
16
import android.util.TypedValue;
17
import android.view.LayoutInflater;
18
import android.view.View;
19
import android.view.Window;
20
import android.widget.Button;
21

  
22
import androidx.annotation.NonNull;
23
import androidx.appcompat.app.AlertDialog;
24
import androidx.appcompat.app.AppCompatDialogFragment;
25
import androidx.fragment.app.FragmentActivity;
26

  
27
import org.distorted.main.R;
28
import org.distorted.main.RubikActivity;
29
import org.distorted.purchase.PurchaseScreenPane;
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

  
33
public class RubikDialogStarsSuccess extends AppCompatDialogFragment
34
  {
35
  @NonNull
36
  @Override
37
  public Dialog onCreateDialog(Bundle savedInstanceState)
38
    {
39
    FragmentActivity act = getActivity();
40
    LayoutInflater inflater = act.getLayoutInflater();
41
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
42
    DisplayMetrics displaymetrics = new DisplayMetrics();
43
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
44
    final float butSize = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
45
    final View view = inflater.inflate(R.layout.dialog_explain_stars, null);
46

  
47
    Bundle args = getArguments();
48
    String objectName;
49

  
50
    try
51
      {
52
      objectName = args.getString("object");
53
      }
54
    catch(Exception e)
55
      {
56
      objectName = null;
57
      }
58

  
59
    builder.setCancelable(true);
60

  
61
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
62
      {
63
      @Override
64
      public void onClick(DialogInterface dialog, int which) { }
65
      });
66

  
67
    builder.setView(view);
68

  
69
    final Dialog dialog = builder.create();
70
    dialog.setCanceledOnTouchOutside(false);
71
    Window window = dialog.getWindow();
72

  
73
    if( window!=null )
74
      {
75
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
76
      }
77

  
78
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
79
      {
80
      @Override
81
      public void onShow(DialogInterface dialog)
82
        {
83
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
84
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
85
        Button btnNegative = ((AlertDialog)dialog).getButton(Dialog.BUTTON_NEGATIVE);
86
        btnNegative.setTextSize(TypedValue.COMPLEX_UNIT_PX, butSize);
87
        }
88
      });
89

  
90
    return dialog;
91
    }
92
  }
src/main/java/org/distorted/overlays/OverlayStars.java
51 51
   private static final int DUR_MOV =  3000;
52 52
   private static final int DUR_GLO =   600;
53 53

  
54
   private static final int MAX_FALLING = 50;
55

  
54 56
   private ListenerOverlay mListener;
55 57
   private DistortedNode mNodeFalling, mNodeCentral;
56 58
   private DistortedScreen mScreen;
......
203 205
      {
204 206
      DistortedTexture texture = new DistortedTexture();
205 207
      texture.setTexture(mStarBitmap);
208
      int numFalling = Math.min(mNewStars,MAX_FALLING);
206 209

  
207
      MeshQuad[] mesh = new MeshQuad[mNewStars];
210
      MeshQuad[] mesh = new MeshQuad[numFalling];
208 211

  
209
      for(int i=0; i<mNewStars; i++)
212
      for(int i=0; i<numFalling; i++)
210 213
         {
211 214
         mesh[i] = new MeshQuad();
212 215
         mesh[i].setEffectAssociation(0,1,i+1);
......
219 222
      scaleE.setMeshAssociation(1,-1);
220 223
      effects.apply(scaleE);
221 224

  
222
      for(int i=0; i<mNewStars; i++)
225
      for(int i=0; i<numFalling; i++)
223 226
        {
224 227
        Dynamic3D moveP = createRandomMove(increase);
225 228
        VertexEffectMove moveE= new VertexEffectMove(moveP);
src/main/java/org/distorted/purchase/PurchaseActivity.java
244 244
      return view.getObjectControl();
245 245
      }
246 246

  
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248

  
249
    PurchaseRenderer getRenderer()
250
      {
251
      PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView);
252
      return view.getRenderer();
253
      }
254

  
247 255
///////////////////////////////////////////////////////////////////////////////////////////////////
248 256

  
249 257
    public static int getDrawableSize()
......
291 299

  
292 300
      return 0;
293 301
      }
294

  
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

  
297
    boolean isVertical()
298
      {
299
      PurchaseSurfaceView view = findViewById(R.id.purchaseSurfaceView);
300
      return view.isVertical();
301
      }
302 302
}
src/main/java/org/distorted/purchase/PurchaseScreenPane.java
22 22

  
23 23
import org.distorted.dialogs.RubikDialogStarsError;
24 24
import org.distorted.external.RubikScores;
25
import org.distorted.library.main.DistortedScreen;
25 26
import org.distorted.main.R;
26 27
import org.distorted.objectlib.json.JsonReader;
27 28
import org.distorted.objects.RubikObject;
28 29
import org.distorted.objects.RubikObjectList;
30
import org.distorted.overlays.DataStars;
31
import org.distorted.overlays.OverlayStars;
29 32

  
30 33
import java.io.InputStream;
31 34

  
......
81 84

  
82 85
  private void showSuccess(PurchaseActivity act, RubikObject object)
83 86
    {
84
    Bundle bundle = new Bundle();
85
    bundle.putString("object", object.getUpperName() );
86
    RubikDialogStarsError d = new RubikDialogStarsError();
87
    d.setArguments(bundle);
88
    d.show(act.getSupportFragmentManager(), null);
87
    RubikScores scores = RubikScores.getInstance();
88
    int totStars = scores.getNumStars();
89
    int price = object==null ? UNLOCK_ALL_PRICE:object.getPrice();
90
    PurchaseRenderer renderer = act.getRenderer();
91
    DistortedScreen screen = renderer.getScreen();
92
    OverlayStars stars = new OverlayStars();
93
    DataStars data = new DataStars(totStars,-price,act.getResources());
94
    stars.startOverlay(screen,null,data);
89 95
    }
90 96

  
91 97
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/purchase/PurchaseSurfaceView.java
50 50

  
51 51
///////////////////////////////////////////////////////////////////////////////////////////////////
52 52

  
53
    boolean isVertical()
53
    ObjectControl getObjectControl()
54 54
      {
55
      return mScreenHeight>mScreenWidth;
55
      return mObjectController;
56 56
      }
57 57

  
58 58
///////////////////////////////////////////////////////////////////////////////////////////////////
59 59

  
60
    ObjectControl getObjectControl()
60
    PurchaseRenderer getRenderer()
61 61
      {
62
      return mObjectController;
62
      return mRenderer;
63 63
      }
64 64

  
65 65
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/res/layout/dialog_explain_stars.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center|fill_horizontal"
6
    android:padding="10dp"
7
    android:background="@color/grey"
8
    android:orientation="vertical">
9

  
10
    <TextView
11
        android:id="@+id/privacy_string"
12
        android:background="@color/dark_grey"
13
        android:layout_width="match_parent"
14
        android:layout_height="match_parent"
15
        android:gravity="start"
16
        android:textSize="21sp"
17
        android:padding="10dp"
18
        android:text="@string/explain_stars_text"
19
        />
20
</LinearLayout>
src/main/res/layout/dialog_stars_error.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center|fill_horizontal"
6
    android:padding="10dp"
7
    android:background="@color/grey"
8
    android:orientation="vertical">
9

  
10
    <TextView
11
        android:id="@+id/privacy_string"
12
        android:background="@color/dark_grey"
13
        android:layout_width="match_parent"
14
        android:layout_height="match_parent"
15
        android:gravity="start"
16
        android:textSize="21sp"
17
        android:padding="10dp"
18
        android:text="@string/explain_stars_text"
19
        />
20
</LinearLayout>
src/main/res/layout/dialog_stars_explain.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center|fill_horizontal"
6
    android:padding="10dp"
7
    android:background="@color/grey"
8
    android:orientation="vertical">
9

  
10
    <TextView
11
        android:id="@+id/privacy_string"
12
        android:background="@color/dark_grey"
13
        android:layout_width="match_parent"
14
        android:layout_height="match_parent"
15
        android:gravity="start"
16
        android:textSize="21sp"
17
        android:padding="10dp"
18
        android:text="@string/explain_stars_text"
19
        />
20
</LinearLayout>

Also available in: Unified diff