Advertisement
Guest User

ShopViewItem

a guest
Feb 25th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.72 KB | None | 0 0
  1. import com.badlogic.gdx.graphics.Color;
  2. import com.badlogic.gdx.math.Vector2;
  3. import com.badlogic.gdx.scenes.scene2d.Group;
  4. import com.badlogic.gdx.scenes.scene2d.Touchable;
  5. import com.badlogic.gdx.scenes.scene2d.ui.Label;
  6. import com.badlogic.gdx.scenes.scene2d.ui.Table;
  7. import com.badlogic.gdx.utils.Align;
  8. import com.badlogic.gdx.utils.Array;
  9. import com.erow.growpet.common.LabelStyles;
  10. import com.erow.growpet.ext.DarkGroup;
  11. import com.erow.growpet.ext.DarkImage;
  12. import com.erow.growpet.ext.DarkStage;
  13.  
  14. /**
  15.  * Created by user on 23.01.17.
  16.  */
  17.  
  18. public class ShopViewItem extends Group {
  19.  
  20.     public DarkImage holder;
  21.     public DarkImage icon;
  22.     public Label name;
  23.     public Label upgrade;
  24.     public Label gives;
  25.  
  26.     public Group freeGrp;
  27.     public DarkImage freeHolder;
  28.     public DarkImage freeImage;
  29.  
  30.     public Group priceGrp;
  31.     public DarkImage priceHolder;
  32.     public DarkImage priceImage;
  33.     public Label price;
  34.  
  35.     public Group superPriceGrp;
  36.     public DarkImage superPriceHolder;
  37.     public DarkImage superPriceImage;
  38.     public Label superPrice;
  39.  
  40.     private String UPGRADE_TEXT = "UPGRADE ";
  41.     private String GIVES_TEXT = "GIVES ";
  42.  
  43.     Array<DarkImage> stars = new Array<DarkImage>();
  44.  
  45.     public ShopViewItem(
  46.             String iconName,
  47.             String nameValue,
  48.             String upgradeValue,
  49.             String givesValue,
  50.             String priceValue,
  51.             String superPriceValue) {
  52.  
  53.         holder = new DarkImage("shopitemback");
  54.         icon = new DarkImage(iconName);
  55.         name = new Label(nameValue, LabelStyles.shopName30);
  56.         upgrade = new Label(UPGRADE_TEXT + upgradeValue, LabelStyles.shopCountGives25);
  57.         gives = new Label(GIVES_TEXT + givesValue, LabelStyles.shopCountGives25);
  58.  
  59.         freeHolder = new DarkImage("pan_freet");
  60.         freeImage = new DarkImage("shopitemfree");
  61.         priceHolder = new DarkImage("pan_forheart");
  62.         priceImage = new DarkImage("shopitemprice");
  63.         price = new Label(priceValue, LabelStyles.whiteFont30);
  64.         superPriceHolder = new DarkImage("pan_fortopaz");
  65.         superPriceImage = new DarkImage("shopitemsuperprice");
  66.         superPrice = new Label(superPriceValue, LabelStyles.whiteFont30);
  67.  
  68.         for(int i = 0; i < 5; i++)
  69.             stars.add(new DarkImage("star"));
  70.  
  71.         //--------------------
  72.  
  73.         setSize(holder.getWidth(), holder.getHeight() + priceImage.getHeight()/2 + 20);
  74.         holder.setPosition(0, priceImage.getHeight()/2 + 20);
  75.  
  76.         price.setTouchable(Touchable.disabled);
  77.         superPrice.setTouchable(Touchable.disabled);
  78.         price.setAlignment(Align.right);
  79.         superPrice.setAlignment(Align.right);
  80.         priceImage.setOrigin(Align.center);
  81.         superPriceImage.setOrigin(Align.center);
  82.  
  83.         icon.setPosition(95, holder.getY(Align.center) + 13, Align.center);
  84.  
  85.         name.setPosition(icon.getX(Align.right) + 50, holder.getY(Align.top) - 23, Align.topLeft);
  86.         upgrade.setPosition(name.getX(), name.getY() + 5, Align.topLeft);
  87.         gives.setPosition(name.getX(), upgrade.getY() + 5, Align.topLeft);
  88.  
  89.  
  90.         priceImage.setPosition(holder.getX(Align.right), holder.getY(), Align.right);
  91.         superPriceImage.setPosition(priceImage.getX() - 20, holder.getY(), Align.right);
  92.         price.setPosition(priceImage.getX(Align.right) - 30, priceImage.getY(Align.center), Align.right);
  93.         superPrice.setPosition(superPriceImage.getX(Align.right) - 30,superPriceImage.getY(Align.center), Align.right);
  94.         freeImage.setPosition(superPriceImage.getX() - 30, superPriceImage.getY(Align.center), Align.right);
  95.  
  96.         priceHolder.setPosition(priceImage.getX(Align.center), priceImage.getY(Align.center), Align.center);
  97.         superPriceHolder.setPosition(superPriceImage.getX(Align.center), superPriceImage.getY(Align.center), Align.center);
  98.         freeHolder.setPosition(freeImage.getX(Align.center), freeImage.getY(Align.center), Align.center);
  99.  
  100.         DarkImage lastStar = stars.peek();
  101.         lastStar.setPosition(holder.getX(Align.right) - 40, name.getY(Align.center), Align.right);
  102.  
  103.         Vector2 lastPos = new Vector2(lastStar.getX(Align.left), lastStar.getY(Align.center));
  104.  
  105.         for(int i = stars.size - 2; i >= 0; i--) {
  106.             DarkImage star = stars.get(i);
  107.             star.setPosition(lastPos.x, lastPos.y, Align.right);
  108.             lastPos. x = star.getX(Align.left);
  109.         }
  110.  
  111.         freeGrp = new Group();
  112.         freeGrp.addActor(freeHolder);
  113.         freeGrp.addActor(freeImage);
  114.  
  115.         priceGrp = new Group();
  116.         priceGrp.addActor(priceHolder);
  117.         priceGrp.addActor(priceImage);
  118.         priceGrp.addActor(price);
  119.  
  120.         superPriceGrp = new Group();
  121.         superPriceGrp.addActor(superPriceHolder);
  122.         superPriceGrp.addActor(superPriceImage);
  123.         superPriceGrp.addActor(superPrice);
  124.  
  125.         addActor(holder);
  126.         addActor(icon);
  127.  
  128.         addActor(name);
  129.         addActor(upgrade);
  130.         addActor(gives);
  131.  
  132.         addActor(priceGrp);
  133.         addActor(superPriceGrp);
  134.         addActor(freeGrp);
  135.  
  136.         for(DarkImage star : stars) {
  137.             addActor(star);
  138.             star.setVisible(false);
  139.         }
  140.     }
  141.  
  142.     public void setUpgrade(String upgradeValue) {
  143.         upgrade.setText(UPGRADE_TEXT + upgradeValue);
  144.     }
  145.  
  146.     public void setGives(String givesValue) {
  147.         gives.setText(GIVES_TEXT + givesValue);
  148.     }
  149.  
  150.     public void setStars(boolean visible, int starsCount) {
  151.         for(int i = 0; i < stars.size; i++) {
  152.             DarkImage star = stars.get(i);
  153.             boolean open = ((i + 1) <= starsCount);
  154.             star.setColor(open ? Color.WHITE : Color.BLUE);
  155.             star.setVisible(visible);
  156.         }
  157.     }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement