Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (499)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Andre Lopes (posted 2014-01-28 14:57:53, viewed 148 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65   66   67   68   69   70   71   72   73   74   75   76   77   78   79   80   81   82   83   84   85   86   87   88   89   90   91   92   93   94   95   96   97   98   99   100   101   102   103   104   105   106   107   108   109   110   111   112   113   114   115   116   117   118   119   120   121   122   123   124   125   126   127   128   129   130   131   132   133   134   135   136   137   138   139   140   141   142   143   144   145   146   147   148   149   150   151   152   153   154   155   156   157   158   159   160   161   162   163   164   165   166   167   168   169   170   171   172   173   174   175   176   177   178   179   180   181   182   183   184   185   186   187   188   189   190   191   192   193   194   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235   236   237   238   239   240   241   242   243   244   245   246   247   248   249   250   251   252   253   254   255   256   257   258   259   260   261   262   263   264   265   266   267   268   269   270   271   272   273   274   275   276   277   278   279   280   281   282  
package br.npc;

import br.assets.AssetAccessor;
import br.data.Data;
import br.dir.DirectoriesViews;
import br.enemies.Enemy;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener;

/**
 *
 * @author André Vinícius Lopes
 */
public class TradeDiamonds extends NpcWindow {

    private final int LIGHT_ARROW_SELECTED = 1;
    private final int HEAVY_ARROW_SELECTED = 2;
    private final int MANA_POTION_SELECTED = 3;
    private final int HEALTH_POTION_SELECTED = 4;

    private final int MANA_POTION_RATE = 2;//2 Per Diamond
    private final int HEALTH_POTION_RATE = 2;//2 Per Diamond
    private final int LIGHT_ARROW_RATE = 40;//40 Per Diamond
    private final int HEAVY_ARROW_RATE = 15;//15 Per Diamond

    public Table topLeftTable, bottomLeftTable;
    public Table rightTable;
    public Label priceInformation;

    private int itemSelected = 0;
    private Data data;

    private Label tradeInformation;
    private Enemy enemy;

    public TradeDiamonds(String title, Data data, final Enemy enemy) {
        super(title);
        this.data = data;
        this.enemy = enemy;
        DirectoriesViews directoriesMenuView = new DirectoriesViews();
        TextureAtlas atlas = AssetAccessor.getInstance().manager.get("packed/archerresources.atlas", TextureAtlas.class);
        BitmapFont simpleWhiteFont = directoriesMenuView.getSimpleWhiteFont();
        simpleWhiteFont.setColor(new Color(Color.BLUE));

        TextureAtlas buttonSwitcherPack = new TextureAtlas();
        buttonSwitcherPack.addRegion("buttonNormal", atlas.findRegion("ui/buttons/buttonNormal"));
        buttonSwitcherPack.addRegion("buttonPressed", atlas.findRegion("ui/buttons/buttonPressed"));
        Skin skin = new Skin(buttonSwitcherPack);

        skin.add("manaPotion", atlas.createSprite("ui/tradeWindow/manaPotion"));

        skin.add("healthPotion", atlas.createSprite("ui/tradeWindow/healthPotion"));

        skin.add("lightArrow", atlas.createSprite("ui/tradeWindow/lightArrow"));

        skin.add("heavyArrow", atlas.createSprite("ui/tradeWindow/heavyArrow"));
        //********************************************************//
        //Mana Trade Potion
        TextButton.TextButtonStyle manaPotion = new TextButton.TextButtonStyle();
        manaPotion.up = skin.getDrawable("manaPotion");
        manaPotion.down = skin.getDrawable("manaPotion");
        manaPotion.font = simpleWhiteFont;
        manaPotion.pressedOffsetX = 1;
        manaPotion.pressedOffsetY = -1;

        TextButton manaTradeSlot = new TextButton("Mana Potion", manaPotion);
        manaTradeSlot.addCaptureListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                tradeInformation.setText("Trade For Mana Potions");
                itemSelected = MANA_POTION_SELECTED;
                resize();
            }
        });

        //********************************************************//
        //Health Trade Potion
        TextButton.TextButtonStyle healthPotion = new TextButton.TextButtonStyle();
        healthPotion.up = skin.getDrawable("healthPotion");
        healthPotion.down = skin.getDrawable("healthPotion");
        healthPotion.font = directoriesMenuView.getSimpleWhiteFont();
        healthPotion.pressedOffsetX = 1;
        healthPotion.pressedOffsetY = -1;

        TextButton healthTradeSlot = new TextButton("Health Potion", healthPotion);
        healthTradeSlot.addCaptureListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                tradeInformation.setText("Trade For Health Potions");
                itemSelected = HEALTH_POTION_SELECTED;
                resize();
            }
        });

        //********************************************************//
        //LightArrow Trade
        TextButton.TextButtonStyle lightArrow = new TextButton.TextButtonStyle();
        lightArrow.up = skin.getDrawable("lightArrow");
        lightArrow.down = skin.getDrawable("lightArrow");
        lightArrow.font = directoriesMenuView.getSimpleWhiteFont();
        lightArrow.pressedOffsetX = 1;
        lightArrow.pressedOffsetY = -1;

        TextButton lightArrowTradeSlot = new TextButton("Light Arrow", lightArrow);
        lightArrowTradeSlot.addCaptureListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                itemSelected = LIGHT_ARROW_SELECTED;
            }
        });
        //********************************************************//
        //HeavyArrow Trade
        TextButton.TextButtonStyle heavyArrow = new TextButton.TextButtonStyle();
        heavyArrow.up = skin.getDrawable("heavyArrow");
        heavyArrow.down = skin.getDrawable("heavyArrow");
        heavyArrow.font = directoriesMenuView.getSimpleWhiteFont();
        heavyArrow.pressedOffsetX = 1;
        heavyArrow.pressedOffsetY = -1;

        TextButton heavyArrowTradeSlot = new TextButton("Heavy Arrow", heavyArrow);
        heavyArrowTradeSlot.addCaptureListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                itemSelected = HEAVY_ARROW_SELECTED;
            }
        });

        //********************************************************//
        TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
        textButtonStyle.up = skin.getDrawable("buttonNormal");
        textButtonStyle.down = skin.getDrawable("buttonPressed");
        textButtonStyle.font = directoriesMenuView.getSimpleWhiteFont();
        textButtonStyle.pressedOffsetX = 1;
        textButtonStyle.pressedOffsetY = -1;

        TextButton tradeButton = new TextButton("Trade", textButtonStyle);
        tradeButton.addCaptureListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                trade();
                System.out.println("Item Selected = " + itemSelected);

            }
        });

        TextButton exitButton = new TextButton("Finish", textButtonStyle);
        exitButton.addCaptureListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                enemy.hideTradeWindow();
            }
        });

        getWindow().setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

        Label.LabelStyle ls = new Label.LabelStyle(directoriesMenuView.getSimpleWhiteFont(), null);
  

        tradeInformation = new Label("Trade", ls);

        //leftTable = new Table(); 
        topLeftTable = new Table();
        topLeftTable.add(manaTradeSlot).padRight(2).top();
        topLeftTable.add(healthTradeSlot).top();

        bottomLeftTable = new Table();

        bottomLeftTable.add(lightArrowTradeSlot).padRight(2);
        bottomLeftTable.add(heavyArrowTradeSlot);

        //leftTable.add(exitButton);
        rightTable = new Table();

        rightTable.add(tradeInformation).setWidgetWidth(20);
        rightTable.row();
        rightTable.add(tradeButton);
        rightTable.row();
        rightTable.add(exitButton);

        topLeftTable.debug();
        bottomLeftTable.debug();
        rightTable.debugTable();

      
        getWindow().add(bottomLeftTable);
        getWindow().add(topLeftTable);
        getWindow().add(rightTable);
        getWindow().setLayoutEnabled(true);
        getWindow().layout();
        resize();

        //
    }

    public void resize() {

        getWindow().layout();
        bottomLeftTable.layout();
        topLeftTable.layout();

        //Labels
        float adjustX = Gdx.graphics.getWidth() / 1.3333f;
        float adjustY = Gdx.graphics.getHeight() / 1.5f;
        //adjustX = adjustX - (tradeInformation.getText().length() * tradeInformation.getFontScaleX());

        tradeInformation.setPosition(adjustX, adjustY);
        
        //Tables

        float adjustXiLimit = 0;
        adjustXiLimit = (Gdx.graphics.getWidth() * 5) / 100;
        float adjustYiLimit = 0;
        adjustYiLimit = (Gdx.graphics.getHeight() * 8) / 100;
        //System.out.println("Adjust Xi limit = " + adjustXiLimit);

        //Invalidate
        //bottomLeftTable.invalidate();
        //topLeftTable.invalidate();
        //getWindow().invalidateHierarchy();
//Calculate Bounds
//Right Table
        rightTable.setBounds((Gdx.graphics.getWidth() / 2), adjustYiLimit, (Gdx.graphics.getWidth() / 2) - adjustXiLimit, (Gdx.graphics.getHeight() / 2) - adjustYiLimit);
        //rightTable.setSize(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight());

        //Left Tables
        topLeftTable.setBounds(adjustXiLimit, (Gdx.graphics.getHeight() / 2), (Gdx.graphics.getWidth() / 2) - adjustXiLimit, (Gdx.graphics.getHeight() / 2) - adjustYiLimit);
        //topLeftTable.setSize(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

        bottomLeftTable.setBounds(adjustXiLimit, adjustYiLimit, (Gdx.graphics.getWidth() / 2) - adjustXiLimit, (Gdx.graphics.getHeight() / 2) - adjustYiLimit);
        //bottomLeftTable.setSize(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);

        //Window 
        getWindow().setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());

    }

    private void trade() {
        if (data.getCurrent_Blue_Diamond() > 0 || data.getCurrent_Red_Diamond() > 0) {
            if (itemSelected == MANA_POTION_SELECTED) {

                payDiamonds(1);
                data.setCurrent_Mana_Potions(data.getCurrent_Mana_Potions() + MANA_POTION_RATE);

            } else if (itemSelected == LIGHT_ARROW_SELECTED) {
                payDiamonds(1);
                data.setCurrent_Normal_Arrows(data.getCurrent_Normal_Arrows() + LIGHT_ARROW_RATE);

            } else if (itemSelected == HEAVY_ARROW_SELECTED) {
                payDiamonds(1);
                data.setCurrent_Heavy_Arrows(data.getCurrent_Heavy_Arrows() + HEAVY_ARROW_RATE);
            } else if (itemSelected == HEALTH_POTION_SELECTED) {
                payDiamonds(1);
                data.setCurrent_Health_Potions(data.getCurrent_Health_Potions() + HEALTH_POTION_RATE);
            }

        }

    }

    private void payDiamonds(int cost) {
        if (data.getCurrent_Blue_Diamond() > 0) {
            data.setCurrent_Blue_Diamond(data.getCurrent_Blue_Diamond() - cost);
        } else {
            data.setCurrent_Red_Diamond(data.getCurrent_Red_Diamond() - cost);
        }
    }

}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (45 views)
2014-04-15 18:08:23

BurntPizza (41 views)
2014-04-15 03:46:01

UprightPath (57 views)
2014-04-14 17:39:50

UprightPath (39 views)
2014-04-14 17:35:47

Porlus (55 views)
2014-04-14 15:48:38

tom_mai78101 (78 views)
2014-04-10 04:04:31

BurntPizza (137 views)
2014-04-08 23:06:04

tom_mai78101 (237 views)
2014-04-05 13:34:39

trollwarrior1 (198 views)
2014-04-04 12:06:45

CJLetsGame (206 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!