[ebd3538] | 1 | package main;
|
---|
| 2 |
|
---|
| 3 | import java.awt.Color;
|
---|
| 4 | import java.awt.FontMetrics;
|
---|
| 5 | import java.awt.Font;
|
---|
| 6 | import java.awt.Graphics;
|
---|
| 7 | import java.awt.Point;
|
---|
| 8 | import java.util.ArrayList;
|
---|
| 9 | import utils.DynamicImage;
|
---|
| 10 |
|
---|
| 11 | public class Item extends MapObject
|
---|
| 12 | {
|
---|
| 13 | private String name;
|
---|
| 14 | private DynamicImage img;
|
---|
| 15 | private ArrayList<Effect> effects;
|
---|
| 16 | protected int extraLines;
|
---|
| 17 | protected int imgWidth;
|
---|
| 18 | protected int imgHeight;
|
---|
| 19 | public int invX;
|
---|
| 20 | public int invY;
|
---|
| 21 |
|
---|
| 22 | public Item(final String name, final DynamicImage img, final int imgWidth, final int imgHeight) {
|
---|
| 23 | super(0, 0, 0);
|
---|
| 24 | this.name = name;
|
---|
| 25 | this.img = img;
|
---|
| 26 | this.effects = new ArrayList<Effect>();
|
---|
| 27 | this.extraLines = 0;
|
---|
| 28 | this.imgWidth = imgWidth;
|
---|
| 29 | this.imgHeight = imgHeight;
|
---|
| 30 | final boolean b = false;
|
---|
| 31 | this.invY = (b ? 1 : 0);
|
---|
| 32 | this.invX = (b ? 1 : 0);
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | protected Item(final Item o, final int x, final int y, final int z) {
|
---|
| 36 | super(x, y, z);
|
---|
| 37 | this.name = o.name;
|
---|
| 38 | this.img = o.img;
|
---|
| 39 | this.effects = o.effects;
|
---|
| 40 | this.extraLines = o.extraLines;
|
---|
| 41 | this.imgWidth = o.imgWidth;
|
---|
| 42 | this.imgHeight = o.imgHeight;
|
---|
| 43 | final boolean b = false;
|
---|
| 44 | this.invY = (b ? 1 : 0);
|
---|
| 45 | this.invX = (b ? 1 : 0);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public Item copy(final Point newLoc) {
|
---|
| 49 | return new Item(this, newLoc.x, newLoc.y, 0);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | public String getName() {
|
---|
| 53 | return this.name;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | @Override
|
---|
| 57 | public double getSortZ() {
|
---|
| 58 | return super.getSortZ() + 0.5;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public DynamicImage getImg() {
|
---|
| 62 | return this.img;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | public int getImgWidth() {
|
---|
| 66 | return this.imgWidth;
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | public int getImgHeight() {
|
---|
| 70 | return this.imgHeight;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | public ArrayList<Effect> getEffects() {
|
---|
| 74 | return this.effects;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public void addEffect(final Effect e) {
|
---|
| 78 | this.effects.add(e);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | @Override
|
---|
| 82 | public void draw(final Graphics g, final int playerX, final int playerY) {
|
---|
| 83 | this.img.draw(g, this.loc.x + playerX, this.loc.y + playerY);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public void drawDesc(final Graphics g, int x, final int y, final Font f, final FontMetrics m) {
|
---|
| 87 | final int width = 200;
|
---|
| 88 | int height = m.getDescent() + m.getHeight() * (2 + this.effects.size() + this.extraLines);
|
---|
| 89 | if (width > 800 - x) {
|
---|
| 90 | x -= width;
|
---|
| 91 | }
|
---|
| 92 | if (this.effects.size() == 0) {
|
---|
| 93 | height -= m.getHeight();
|
---|
| 94 | }
|
---|
| 95 | g.setFont(f);
|
---|
| 96 | g.setColor(Color.black);
|
---|
| 97 | g.fillRect(x, y, width, height);
|
---|
| 98 | g.setColor(new Color(120, 120, 240));
|
---|
| 99 | g.drawRect(x, y, width, height);
|
---|
| 100 | g.drawString(this.name, x + (width - m.stringWidth(this.name)) / 2, y + m.getHeight());
|
---|
| 101 | this.addInfo(g, x, y, width, f, m);
|
---|
| 102 | for (int i = 0; i < this.effects.size(); ++i) {
|
---|
| 103 | g.drawString(this.effects.get(i).getDesc(), x + (width - m.stringWidth(this.effects.get(i).getDesc())) / 2, y + (i + 3 + this.extraLines) * m.getHeight());
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | public void addInfo(final Graphics g, final int x, final int y, final int width, final Font f, final FontMetrics m) {
|
---|
| 108 | }
|
---|
| 109 | }
|
---|