Back to project page diploma-assignment.
The source code is released under:
MIT License
If you think the Android project diploma-assignment listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.me.openingscreen; /*from w w w . ja va 2 s. c o m*/ import java.util.ArrayList; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.scenes.scene2d.Actor; import com.badlogic.gdx.scenes.scene2d.InputEvent; import com.badlogic.gdx.scenes.scene2d.InputListener; import com.badlogic.gdx.scenes.scene2d.Stage; import com.badlogic.gdx.scenes.scene2d.Touchable; import com.me.battlescreen.MyButton; import com.me.battlescreen.MyLabel; public class UpgradeMenu extends AbstractMenu{ BitmapFont font1; BitmapFont font2; MyButton toPlayerScreen; MyButton arrowUpgradeFirstRight; MyButton arrowUpgradeFirstLeft; MyButton arrowUpgradeSecondRight; MyButton arrowUpgradeSecondLeft; ArrayList<Actor> upgradeFirst; ArrayList<Actor> upgradeSecond; ArrayList<Actor> upgradeThird; ArrayList<UpgradeButton> upgradeButtons; MyLabel gold; public UpgradeMenu(OpeningScreen s, Stage st) { super(s, st); // TODO Auto-generated constructor stub font1=new BitmapFont(Gdx.files.internal("data/myFont.fnt"),Gdx.files.internal("data/myFont.png"),false); font1.setUseIntegerPositions(false); font1.setScale(s.getHeight()*0.10f/font1.getLineHeight()); font2=new BitmapFont(Gdx.files.internal("data/myFont.fnt"),Gdx.files.internal("data/myFont.png"),false); font2.setUseIntegerPositions(false); font2.setScale(screen.getHeight()*0.15f/font2.getLineHeight()); gold=new MyLabel(screen,"123456",font1,new int[]{0,screen.getHeight()}); gold.setTouchable(Touchable.disabled); updateGold(); stage.addActor(gold); upgradeFirst=new ArrayList<Actor>(); upgradeSecond=new ArrayList<Actor>(); upgradeThird=new ArrayList<Actor>(); upgradeButtons=new ArrayList<UpgradeButton>(); createButtons(); addListeners(); showArrayList(upgradeFirst); } @Override protected void createButtons(){ Texture t=new Texture(Gdx.files.internal("data/menus/player.png")); toPlayerScreen=new MyButton(t); createButton(toPlayerScreen,1,t,1); t=new Texture(Gdx.files.internal("data/menus/left.png")); arrowUpgradeFirstLeft=new MyButton(t); createButton(arrowUpgradeFirstLeft,1,t,2); arrowUpgradeFirstLeft.setPosition(0, arrowUpgradeFirstLeft.getY()); t=new Texture(Gdx.files.internal("data/menus/right.png")); arrowUpgradeFirstRight=new MyButton(t); createButton(arrowUpgradeFirstRight,1,t,2); arrowUpgradeFirstRight.setPosition(screen.getWidth()-arrowUpgradeFirstRight.getWidth(),arrowUpgradeFirstRight.getY()); t=new Texture(Gdx.files.internal("data/menus/left.png")); arrowUpgradeSecondLeft=new MyButton(t); createButton(arrowUpgradeSecondLeft,1,t,2); arrowUpgradeSecondLeft.setPosition(0, arrowUpgradeSecondLeft.getY()); t=new Texture(Gdx.files.internal("data/menus/right.png")); arrowUpgradeSecondRight=new MyButton(t); createButton(arrowUpgradeSecondRight,1,t,2); arrowUpgradeSecondRight.setPosition(screen.getWidth()-arrowUpgradeSecondRight.getWidth(),arrowUpgradeSecondRight.getY()); createUpgradeImages(); } private void createUpgradeImages() { // TODO Auto-generated method stub int heightButton=(int)(screen.getHeight()*0.2f); int height_offset=(int)(screen.getHeight()*0.6f); int width_offset=(int)(screen.getHeight()*0.1f); Texture[] first=new Texture[]{new Texture(Gdx.files.internal("data/thumbnails/centaur_t.png")),new Texture(Gdx.files.internal("data/thumbnails/dwarf_t.png")),new Texture(Gdx.files.internal("data/thumbnails/elf_t.png")),new Texture(Gdx.files.internal("data/thumbnails/pegasus_t.png")),new Texture(Gdx.files.internal("data/thumbnails/dendroidguard_t.png")),new Texture(Gdx.files.internal("data/thumbnails/unicorn_t.png")),new Texture(Gdx.files.internal("data/thumbnails/dragon_t.png")),new Texture(Gdx.files.internal("data/thumbnails/centaur_t_u.png")),new Texture(Gdx.files.internal("data/thumbnails/dwarf_t_u.png")),new Texture(Gdx.files.internal("data/thumbnails/elf_t_u.png")),new Texture(Gdx.files.internal("data/thumbnails/pegasus_t_u.png")),new Texture(Gdx.files.internal("data/thumbnails/dendroidguard_t_u.png")),new Texture(Gdx.files.internal("data/thumbnails/unicorn_t_u.png")),new Texture(Gdx.files.internal("data/thumbnails/dragon_t_u.png"))}; for (int i = 0; i < 7; i++) { MyLabel l=new MyLabel(screen,screen.game.getPlayer().getKilled()[i%7]+"",font2,new int[]{width_offset+(int)(1.2f*heightButton),height_offset+heightButton}); final UpgradeButton but=new UpgradeButton(screen,first[i],first[i+7],i,l); but.addListener(new InputListener(){ public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { but.setPressed(true); return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { but.setPressed(false); but.check(); update(); } }); but.setPosition(width_offset, height_offset); but.setSize(heightButton, heightButton); but.setTouchable(Touchable.enabled); if(i<4){ upgradeFirst.add(but); upgradeFirst.add(l); } else if (i<8){ upgradeSecond.add(but); upgradeSecond.add(l); } else { upgradeThird.add(but); upgradeThird.add(l); } stage.addActor(but); stage.addActor(l); if(i<7) upgradeButtons.add(but); height_offset-=(int)(screen.getHeight()*0.3f); if(i%2==1){ width_offset+=(int)(screen.getWidth()*0.5f); height_offset=(int)(screen.getHeight()*0.6f); } if(i==3 || i==7){ height_offset=(int)(screen.getHeight()*0.6f); width_offset=(int)(screen.getHeight()*0.1f); } } System.out.println("here"); } public void update(){ //screen.game.player.updateLabel(); updateGold(); for(UpgradeButton but:upgradeButtons){ but.update(); } } public void updateGold() { // TODO Auto-generated method stub long temp=screen.game.getPlayer().getGold(); if(temp==0) temp=1; int count=0; while(temp>0){ temp/=10; count++; } String s=""; for(int i=0;i<8-count;i++){ s=s+" "; } gold.setText("Gold:"+s+screen.game.getPlayer().getGold()); } private void showArrayList(ArrayList<Actor> upgradeList) { // TODO Auto-generated method stub stage.clear(); stage.addActor(screen.getBackground()); stage.addActor(gold); stage.addActor(toPlayerScreen); for(Actor act:upgradeList){ stage.addActor(act); } } @Override protected void addListeners(){ toPlayerScreen.addListener(new InputListener(){ public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { toPlayerScreen.setPressed(true); return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { toPlayerScreen.setPressed(false); screen.setMenu(new PlayerMenu(screen,stage)); } }); arrowUpgradeFirstLeft.addListener(new InputListener(){ public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeFirstLeft.setPressed(true); return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeFirstLeft.setPressed(false); showArrayList(upgradeFirst); } }); arrowUpgradeFirstRight.addListener(new InputListener(){ public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeFirstRight.setPressed(true); return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeFirstRight.setPressed(false); showArrayList(upgradeSecond); } }); arrowUpgradeSecondLeft.addListener(new InputListener(){ public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeSecondLeft.setPressed(true); return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeSecondLeft.setPressed(false); showArrayList(upgradeSecond); } }); arrowUpgradeSecondRight.addListener(new InputListener(){ public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeSecondRight.setPressed(true); return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { arrowUpgradeSecondRight.setPressed(false); showArrayList(upgradeThird); } }); upgradeFirst.add(arrowUpgradeFirstRight); upgradeSecond.add(arrowUpgradeFirstLeft); upgradeSecond.add(arrowUpgradeSecondRight); upgradeThird.add(arrowUpgradeSecondLeft); } }