source: lost-perception/main/Item.java@ a10d422

Last change on this file since a10d422 was a10d422, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Create a working makefile target for MapEditor

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