Android Open Source - smoke-or-fire Buttons






From Project

Back to project page smoke-or-fire.

License

The source code is released under:

GNU General Public License

If you think the Android project smoke-or-fire listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *  Copyright 2012 Brian Flores/*w  w w  .  j  av  a 2s.c  om*/
 *
 *  This file is part of SmokeOrFire.
 *
 *  SmokeOrFire is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  SmokeOrFire is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with SmokeOrFire.  If not, see <http://www.gnu.org/licenses/>.
 */

package net.votebrian.games.sof;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.util.Log;

public class Buttons {
    private Context mCtx;
    private Global  gbl;

    private Btn mBtnHigher;
    private Btn mBtnLower;
    private Btn mBtnSmoke;
    private Btn mBtnFire;

    private float mBtnBaseZ = 5.2f;
    private float[] mBtn;

    public Buttons(Context context, GL10 gl) {
        mCtx = context;
        gbl = (Global) mCtx.getApplicationContext();

        mBtnHigher = new Btn(mCtx, gl);
        mBtnLower = new Btn(mCtx, gl);
        mBtnSmoke = new Btn(mCtx, gl);
        mBtnFire = new Btn(mCtx, gl);

        mBtnHigher.setModelColor(gbl.WHITE_LITE);
        mBtnLower.setModelColor(gbl.WHITE_LITE);
        mBtnSmoke.setModelColor(gbl.BLACK_LITE);
        mBtnFire.setModelColor(gbl.RED_LITE);

        enableAll();
        disableRelative();
    }

    public void draw(GL10 gl) {
        mBtnHigher.draw(gl);
        mBtnLower.draw(gl);
        mBtnSmoke.draw(gl);
        mBtnFire.draw(gl);
    }

    public void highlightBtn(int btn) {

        mBtnHigher.setModelColor(gbl.WHITE_LITE);
        mBtnLower.setModelColor(gbl.WHITE_LITE);
        mBtnSmoke.setModelColor(gbl.BLACK_LITE);
        mBtnFire.setModelColor(gbl.RED_LITE);

        switch (btn) {
            case Global.SMOKE:
                mBtnSmoke.setModelColor(gbl.BLACK_FULL);
                sink(btn);
                // mBtnSmoke.setRotOffset(2f);
                break;
            case Global.FIRE:
                mBtnFire.setModelColor(gbl.RED_FULL);
                sink(btn);
                break;
            case Global.HIGHER:
                mBtnHigher.setModelColor(gbl.WHITE_FULL);
                sink(btn);
                break;
            case Global.LOWER:
                mBtnLower.setModelColor(gbl.WHITE_FULL);
                sink(btn);
                break;
            default:
                break;
        }
    }

    private void sink(final int index) {
        Thread t = new Thread(new Runnable() {
            public void run() {
                long curr = System.currentTimeMillis();
                long startTime = curr;

                int duration = 50;
                float fullRotation = 35f;
                while(curr < startTime + duration) {
                    float x = fullRotation*(curr-startTime)/duration;

                    switch(index) {
                        case Global.SMOKE:
                            mBtnSmoke.setRotOffset(x);
                            break;
                        case Global.FIRE:
                            mBtnFire.setRotOffset(x);
                            break;
                        case Global.HIGHER:
                            mBtnHigher.setRotOffset(x);
                            break;
                        case Global.LOWER:
                            mBtnLower.setRotOffset(x);
                            break;
                    }

                    curr = System.currentTimeMillis();
                }

                switch(index) {
                    case Global.SMOKE:
                        mBtnSmoke.setRotOffset(fullRotation);
                        break;
                    case Global.FIRE:
                        mBtnFire.setRotOffset(fullRotation);
                        break;
                    case Global.HIGHER:
                        mBtnHigher.setRotOffset(fullRotation);
                        break;
                    case Global.LOWER:
                        mBtnLower.setRotOffset(fullRotation);
                        break;
                }
            }
        });

        t.run();
    }

    public void highlightAll() {
        mBtnHigher.setModelColor(gbl.WHITE_FULL);
        mBtnFire.setModelColor(gbl.RED_FULL);
        mBtnLower.setModelColor(gbl.WHITE_FULL);
        mBtnSmoke.setModelColor(gbl.BLACK_FULL);
    }

    public void highlightAbsolute() {
        mBtnFire.setModelColor(gbl.RED_FULL);
        mBtnSmoke.setModelColor(gbl.BLACK_FULL);
    }

    public void disableAll() {
        mBtnHigher.disableModel();
        mBtnHigher.disableOutline();

        mBtnLower.disableModel();
        mBtnLower.disableOutline();

        mBtnSmoke.disableModel();
        mBtnSmoke.disableOutline();

        mBtnFire.disableModel();
        mBtnFire.disableOutline();
    }

    public void disableRelative() {
        mBtnHigher.disableModel();
        mBtnHigher.disableOutline();

        mBtnLower.disableModel();
        mBtnLower.disableOutline();
    }

    public void enableAll() {
        mBtnHigher.enableModel();
        mBtnHigher.enableOutline();
        mBtnHigher.setModelColor(gbl.WHITE_LITE);
        mBtnHigher.setOutlineColor(gbl.WHITE_FULL);

        mBtnLower.enableModel();
        mBtnLower.enableOutline();
        mBtnLower.setModelColor(gbl.WHITE_LITE);
        mBtnLower.setOutlineColor(gbl.WHITE_FULL);

        mBtnSmoke.enableModel();
        mBtnSmoke.enableOutline();
        mBtnSmoke.setModelColor(gbl.BLACK_LITE);
        mBtnSmoke.setOutlineColor(gbl.BLACK_FULL);

        mBtnFire.enableModel();
        mBtnFire.enableOutline();
        mBtnFire.setModelColor(gbl.RED_LITE);
        mBtnFire.setOutlineColor(gbl.RED_FULL);
    }

    public void enableRelative() {
        mBtnHigher.enableModel();
        mBtnHigher.enableOutline();
        mBtnHigher.setModelColor(gbl.WHITE_LITE);
        mBtnHigher.setOutlineColor(gbl.WHITE_FULL);

        mBtnLower.enableModel();
        mBtnLower.enableOutline();
        mBtnLower.setModelColor(gbl.WHITE_LITE);
        mBtnLower.setOutlineColor(gbl.WHITE_FULL);
    }

    public void enableAbsolute() {
        mBtnSmoke.enableModel();
        mBtnSmoke.enableOutline();
        mBtnSmoke.setModelColor(gbl.BLACK_LITE);
        mBtnSmoke.setOutlineColor(gbl.BLACK_FULL);

        mBtnFire.enableModel();
        mBtnFire.enableOutline();
        mBtnFire.setModelColor(gbl.RED_LITE);
        mBtnFire.setOutlineColor(gbl.RED_FULL);
    }


    public void settle() {
        mBtnHigher.setModelColor(gbl.WHITE_LITE);
        mBtnHigher.setRotOffset(0f);

        mBtnFire.setModelColor(gbl.RED_LITE);
        mBtnFire.setRotOffset(0f);

        mBtnLower.setModelColor(gbl.WHITE_LITE);
        mBtnLower.setRotOffset(0f);

        mBtnSmoke.setModelColor(gbl.BLACK_LITE);
        mBtnSmoke.setRotOffset(0f);
    }

    public void setVertices(float viewW, float viewH, float viewAngle) {
        float ratio = viewW / viewH;

        float h = (float) (mBtnBaseZ * (Math.tan(Math.toRadians(viewAngle))));
        float w = h * ratio;

        // HIGHER
        mBtn = new float[9];

        mBtn[0] = -w;
        mBtn[1] =  h;
        mBtn[2] = -mBtnBaseZ;

        mBtn[3] =  0;
        mBtn[4] =  h/10;
        mBtn[5] = -mBtnBaseZ;

        mBtn[6] =  w;
        mBtn[7] =  h;
        mBtn[8] = -mBtnBaseZ;

        mBtnHigher.setVertices(mBtn);
        mBtnHigher.setOffsets(0, h, -mBtnBaseZ);
        mBtnHigher.setRotAxes(new float[] {1f, 0f, 0f});


        // LOWER
        mBtn = new float[9];

        mBtn[0] = -w;
        mBtn[1] = -h;
        mBtn[2] = -mBtnBaseZ;

        mBtn[3] =  w;
        mBtn[4] = -h;
        mBtn[5] = -mBtnBaseZ;

        mBtn[6] =  0;
        mBtn[7] = -h/10;
        mBtn[8] = -mBtnBaseZ;

        mBtnLower.setVertices(mBtn);
        mBtnLower.setOffsets(0, -h, -mBtnBaseZ);
        mBtnLower.setRotAxes(new float[] {-1f, 0f, 0f});


        // SMOKE
        mBtn = new float[9];

        mBtn[0] = -w;
        mBtn[1] =  h;
        mBtn[2] = -mBtnBaseZ;

        mBtn[3] = -w;
        mBtn[4] = -h;
        mBtn[5] = -mBtnBaseZ;

        mBtn[6] = -w/10;
        mBtn[7] =  0;
        mBtn[8] = -mBtnBaseZ;

        mBtnSmoke.setVertices(mBtn);
        mBtnSmoke.setOffsets(-w, 0, -mBtnBaseZ);
        mBtnSmoke.setRotAxes(new float[] {0f, 1f, 0f});


        // FIRE
        mBtn = new float[9];

        mBtn[0] =  w;
        mBtn[1] =  h;
        mBtn[2] = -mBtnBaseZ;

        mBtn[3] =  w/10;
        mBtn[4] =  0;
        mBtn[5] = -mBtnBaseZ;

        mBtn[6] =  w;
        mBtn[7] = -h;
        mBtn[8] = -mBtnBaseZ;

        mBtnFire.setVertices(mBtn);
        mBtnFire.setOffsets(w, 0, -mBtnBaseZ);
        mBtnFire.setRotAxes(new float[] {0f, -1f, 0f});



        mBtnHigher.setOutlineIndices(new int[] {0, 1, 1, 2});
        mBtnLower.setOutlineIndices(new int[] {0, 2, 1, 2});
        mBtnSmoke.setOutlineIndices(new int[] {0, 2, 1, 2});
        mBtnFire.setOutlineIndices(new int[] {0, 1, 2, 1});
    }
}




Java Source Code List

net.votebrian.games.sof.AboutActivity.java
net.votebrian.games.sof.Base64DecoderException.java
net.votebrian.games.sof.Base64.java
net.votebrian.games.sof.Btn.java
net.votebrian.games.sof.Buttons.java
net.votebrian.games.sof.Card.java
net.votebrian.games.sof.Deck.java
net.votebrian.games.sof.GLESRenderer.java
net.votebrian.games.sof.Global.java
net.votebrian.games.sof.IabException.java
net.votebrian.games.sof.IabHelper.java
net.votebrian.games.sof.IabResult.java
net.votebrian.games.sof.Inventory.java
net.votebrian.games.sof.Labels.java
net.votebrian.games.sof.Model.java
net.votebrian.games.sof.PassButton.java
net.votebrian.games.sof.PurchaseActivity.java
net.votebrian.games.sof.Purchase.java
net.votebrian.games.sof.Security.java
net.votebrian.games.sof.SkuDetails.java
net.votebrian.games.sof.SoFActivity.java
net.votebrian.games.sof.SurfaceView.java
net.votebrian.games.sof.TutorialActivity.java