Skip to content

Commit 439079c

Browse files
BlockMenkahrl
authored andcommittedAug 25, 2013
Add support for using textures in hotbar
1 parent fead7a2 commit 439079c

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed
 

‎src/hud.cpp

+48-22
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Hud::Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
6464
selectionbox_argb = video::SColor(255, sbox_r, sbox_g, sbox_b);
6565

6666
use_crosshair_image = tsrc->isKnownSourceImage("crosshair.png");
67+
use_hotbar_bg_img = tsrc->isKnownSourceImage("hotbar.png");
68+
use_hotbar_border_img = tsrc->isKnownSourceImage("hotbar_selected.png");
6769
}
6870

6971

@@ -90,6 +92,18 @@ void Hud::drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
9092
driver->draw2DRectangle(bgcolor, barrect, NULL);*/
9193

9294
core::rect<s32> imgrect(0, 0, imgsize, imgsize);
95+
const video::SColor hbar_color(255, 255, 255, 255);
96+
const video::SColor hbar_colors[] = {hbar_color, hbar_color, hbar_color, hbar_color};
97+
98+
if (use_hotbar_bg_img) {
99+
core::rect<s32> imgrect2(-padding/2, -padding/2, width+padding/2, height+padding/2);
100+
core::rect<s32> rect2 = imgrect2 + pos;
101+
video::ITexture *texture = tsrc->getTexture("hotbar.png");
102+
core::dimension2di imgsize(texture->getOriginalSize());
103+
driver->draw2DImage(texture, rect2,
104+
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
105+
NULL, hbar_colors, true);
106+
}
93107

94108
for (s32 i = 0; i < itemcount; i++)
95109
{
@@ -112,62 +126,74 @@ void Hud::drawItem(v2s32 upperleftpos, s32 imgsize, s32 itemcount,
112126

113127
core::rect<s32> rect = imgrect + pos + steppos;
114128

115-
if (selectitem == i + 1)
116-
{
117-
video::SColor c_outside(255,255,0,0);
118-
//video::SColor c_outside(255,0,0,0);
119-
//video::SColor c_inside(255,192,192,192);
120-
s32 x1 = rect.UpperLeftCorner.X;
121-
s32 y1 = rect.UpperLeftCorner.Y;
122-
s32 x2 = rect.LowerRightCorner.X;
123-
s32 y2 = rect.LowerRightCorner.Y;
124-
// Black base borders
125-
driver->draw2DRectangle(c_outside,
129+
if (selectitem == i + 1) {
130+
if (use_hotbar_border_img) {
131+
core::rect<s32> imgrect2(-padding*2, -padding*2, height, height);
132+
rect = imgrect2 + pos + steppos;
133+
video::ITexture *texture = tsrc->getTexture("hotbar_selected.png");
134+
core::dimension2di imgsize(texture->getOriginalSize());
135+
driver->draw2DImage(texture, rect,
136+
core::rect<s32>(core::position2d<s32>(0,0), imgsize),
137+
NULL, hbar_colors, true);
138+
rect = imgrect + pos + steppos;
139+
} else {
140+
rect = imgrect + pos + steppos;
141+
video::SColor c_outside(255,255,0,0);
142+
//video::SColor c_outside(255,0,0,0);
143+
//video::SColor c_inside(255,192,192,192);
144+
s32 x1 = rect.UpperLeftCorner.X;
145+
s32 y1 = rect.UpperLeftCorner.Y;
146+
s32 x2 = rect.LowerRightCorner.X;
147+
s32 y2 = rect.LowerRightCorner.Y;
148+
// Black base borders
149+
driver->draw2DRectangle(c_outside,
126150
core::rect<s32>(
127151
v2s32(x1 - padding, y1 - padding),
128152
v2s32(x2 + padding, y1)
129153
), NULL);
130-
driver->draw2DRectangle(c_outside,
154+
driver->draw2DRectangle(c_outside,
131155
core::rect<s32>(
132156
v2s32(x1 - padding, y2),
133157
v2s32(x2 + padding, y2 + padding)
134158
), NULL);
135-
driver->draw2DRectangle(c_outside,
159+
driver->draw2DRectangle(c_outside,
136160
core::rect<s32>(
137161
v2s32(x1 - padding, y1),
138162
v2s32(x1, y2)
139163
), NULL);
140-
driver->draw2DRectangle(c_outside,
164+
driver->draw2DRectangle(c_outside,
141165
core::rect<s32>(
142166
v2s32(x2, y1),
143167
v2s32(x2 + padding, y2)
144168
), NULL);
145-
/*// Light inside borders
146-
driver->draw2DRectangle(c_inside,
169+
/*// Light inside borders
170+
driver->draw2DRectangle(c_inside,
147171
core::rect<s32>(
148172
v2s32(x1 - padding/2, y1 - padding/2),
149173
v2s32(x2 + padding/2, y1)
150174
), NULL);
151-
driver->draw2DRectangle(c_inside,
175+
driver->draw2DRectangle(c_inside,
152176
core::rect<s32>(
153177
v2s32(x1 - padding/2, y2),
154178
v2s32(x2 + padding/2, y2 + padding/2)
155179
), NULL);
156-
driver->draw2DRectangle(c_inside,
180+
driver->draw2DRectangle(c_inside,
157181
core::rect<s32>(
158182
v2s32(x1 - padding/2, y1),
159183
v2s32(x1, y2)
160184
), NULL);
161-
driver->draw2DRectangle(c_inside,
185+
driver->draw2DRectangle(c_inside,
162186
core::rect<s32>(
163187
v2s32(x2, y1),
164188
v2s32(x2 + padding/2, y2)
165189
), NULL);
166-
*/
190+
*/
191+
}
167192
}
168193

169194
video::SColor bgcolor2(128, 0, 0, 0);
170-
driver->draw2DRectangle(bgcolor2, rect, NULL);
195+
if (!use_hotbar_bg_img)
196+
driver->draw2DRectangle(bgcolor2, rect, NULL);
171197
drawItemStack(driver, font, item, rect, NULL, gamedef);
172198
}
173199
}
@@ -222,7 +248,7 @@ void Hud::drawLuaElements() {
222248
break; }
223249
default:
224250
infostream << "Hud::drawLuaElements: ignoring drawform " << e->type <<
225-
"of hud element ID " << i << " due to unrecognized type" << std::endl;
251+
" of hud element ID " << i << " due to unrecognized type" << std::endl;
226252
}
227253
}
228254
}

‎src/hud.h

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class Hud {
106106
video::SColor crosshair_argb;
107107
video::SColor selectionbox_argb;
108108
bool use_crosshair_image;
109+
bool use_hotbar_border_img;
110+
bool use_hotbar_bg_img;
109111

110112
Hud(video::IVideoDriver *driver, gui::IGUIEnvironment* guienv,
111113
gui::IGUIFont *font, u32 text_height, IGameDef *gamedef,

0 commit comments

Comments
 (0)
Please sign in to comment.