xoreos  0.0.5
kotorinventoryitem.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/system.h"
26 #include "src/common/strutil.h"
27 
31 
33 
34 namespace Engines {
35 
37  : WidgetProtoItem(gui, tag) {
38  setDisableHighlight(true);
39 }
40 
42  std::vector<Common::UString> tokens;
43  Common::UString::split(contents, '|', tokens);
44  if (tokens.size() < 3)
45  return;
46 
47  if (_text)
48  _text->setText(tokens[0]);
49  if (_icon)
50  _icon->setTexture(tokens[1]);
51 
52  uint32 count;
53  Common::parseString(tokens[2], count);
54 
55  if (count > 1) {
56  _iconFrame->setTexture("lbl_hex_4");
57  _countText->setText(tokens[2]);
58  } else {
59  _iconFrame->setTexture("lbl_hex");
60  _countText->setText("");
61  }
62 }
63 
66 
67  float x, y, z;
68  getPosition(x, y, z);
69 
70  Graphics::Aurora::TextureHandle tex = TextureMan.get("lbl_hex");
71  float frameSize = tex.getTexture().getHeight();
72  _iconFrame.reset(new Graphics::Aurora::GUIQuad(tex, 0.0f, 0.0f, frameSize, frameSize));
73  _iconFrame->setPosition(x, y + (_height - frameSize) / 2.0f, 0.0f);
74 
75  _icon.reset(new Graphics::Aurora::GUIQuad("", 0.0f, 0.0f, frameSize, frameSize));
76  _icon->setPosition(x, y + (_height - frameSize) / 2.0f, 0.0f);
77 
78  if (_border) {
79  float bX, bY, bZ;
80  _border->getPosition(bX, bY, bZ);
81  _border->setPosition(bX + frameSize, bY, bZ);
82 
83  float width, height;
84  _border->getSize(width, height);
85  _border->setSize(width - frameSize, height);
86  }
87 
88  if (_text) {
89  float tX, tY, tZ;
90  _text->getPosition(tX, tY, tZ);
91  _text->setPosition(tX + frameSize, tY, tZ);
92 
93  float width = _text->getWidth();
94  float height = _text->getHeight();
95  _text->setSize(width - frameSize, height);
96 
97  _text->setVerticalAlign(Graphics::Aurora::kVAlignMiddle);
98 
99  float r, g, b, a;
100  _text->getColor(r, g, b, a);
101 
102  _countText.reset(new Graphics::Aurora::Text(FontMan.get("fnt_d16x16"),
103  "", r, g, b, a,
106 
107  _countText->setPosition(x - 4.0f, y + (_height - frameSize) / 2.0f - 2.0f, 0.0f);
108  _countText->setSize(frameSize, frameSize);
109  }
110 }
111 
113  if (isVisible() || isInvisible())
114  return;
115 
117 
118  if (_iconFrame)
119  _iconFrame->show();
120  if (_icon)
121  _icon->show();
122  if (_countText)
123  _countText->show();
124 }
125 
127  if (!isVisible())
128  return;
129 
130  if (_countText)
131  _countText->hide();
132  if (_icon)
133  _icon->hide();
134  if (_iconFrame)
135  _iconFrame->hide();
136 
138 }
139 
140 void KotORInventoryItem::setPosition(float x, float y, float z) {
141  float oX, oY, oZ;
142  getPosition(oX, oY, oZ);
143 
144  float dx = x - oX;
145  float dy = y - oY;
146  float dz = z - oZ;
147 
149 
150  if (_iconFrame) {
151  _iconFrame->getPosition(x, y, z);
152  _iconFrame->setPosition(x + dx, y + dy, z + dz);
153  }
154 
155  if (_icon) {
156  _icon->getPosition(x, y, z);
157  _icon->setPosition(x + dx, y + dy, z + dz);
158  }
159 
160  if (_countText) {
161  _countText->getPosition(x, y, z);
162  _countText->setPosition(x + dx, y + dy, z + dz);
163  }
164 }
165 
166 void KotORInventoryItem::setWidth(float width) {
167  float deltaWidth = _width - width;
168 
170 
171  if (_countText) {
172  width = _countText->getWidth();
173  _countText->setSize(width + deltaWidth, _countText->getHeight());
174  }
175 }
176 
177 } // End of namespace Engines
virtual void hide()
Hide the widget.
A class holding an UTF-8 string.
Definition: ustring.h:48
#define TextureMan
Shortcut for accessing the texture manager.
Definition: textureman.h:127
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
Common::ScopedPtr< Graphics::Aurora::BorderQuad > _border
void setWidth(float width)
Set the width of the widget.
The Aurora texture manager.
void setDisableHighlight(bool disableHighlight)
Definition: protoitem.cpp:89
KotORInventoryItem(GUI &gui, const Common::UString &tag)
void setContents(const Common::UString &contents)
Set item contents.
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
uint32 getHeight() const
Definition: texture.cpp:80
bool isVisible() const
Is the widget visible?
Definition: widget.cpp:59
Utility templates and functions for working with strings and streams.
The Aurora font manager.
void hide()
Hide the widget.
A GUI.
Definition: gui.h:43
bool isInvisible() const
Is the widget invisible (never visible)?
Definition: widget.cpp:67
A text object.
Definition: text.h:42
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _icon
Common::ScopedPtr< Graphics::Aurora::Text > _countText
virtual void show()
Show the widget.
void load(const Aurora::GFF3Struct &gff)
const float kVAlignBottom
Definition: types.h:48
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
const float kHAlignRight
Definition: types.h:44
virtual void load(const Aurora::GFF3Struct &gff)
Definition: protoitem.cpp:53
const float kVAlignMiddle
Definition: types.h:47
A struct within a GFF3.
Definition: gff3file.h:164
uint32_t uint32
Definition: types.h:204
Low-level detection of architecture/system properties.
An inventory item widget for Star Wars: Knights of the Old Republic.
void split(iterator splitPoint, UString &left, UString &right, bool remove=false) const
Definition: ustring.cpp:621
Common::ScopedPtr< Graphics::Aurora::HighlightableText > _text
A textured quad for a GUI element.
A handle to a texture.
Definition: texturehandle.h:51
virtual void setWidth(float width)
Set the width of the widget.
void parseString(const UString &str, T &value, bool allowEmpty)
Parse a string into any POD integer, float/double or bool type.
Definition: strutil.cpp:215
Common::ScopedPtr< Graphics::Aurora::GUIQuad > _iconFrame
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
virtual void setPosition(float x, float y, float z)
Set the widget&#39;s position.
void show()
Show the widget.