Add pressed inventory slot background image
This commit is contained in:
parent
88c52130f8
commit
f22951ab2b
@ -2913,6 +2913,7 @@ Some types may inherit styles from parent types.
|
||||
* spacing - 2d vector, sets the space between inventory slots in coordinates.
|
||||
* bgimg - slot background image. Defaults to none.
|
||||
* bgimg_hovered - hovered slot background image.
|
||||
* bgimg_pressed - pressed slot background image.
|
||||
* bgimg_middle - Makes the bgimg textures render in 9-sliced mode and defines the middle rect.
|
||||
* image_button (additional properties)
|
||||
* fgimg - standard image. Defaults to none.
|
||||
|
@ -540,12 +540,13 @@ void GUIFormSpecMenu::parseList(parserData *data, const std::string &element)
|
||||
|
||||
video::ITexture *bgimg = style.getTexture(StyleSpec::BGIMG, m_tsrc, nullptr);
|
||||
video::ITexture *bgimg_hovered = style.getTexture(StyleSpec::BGIMG_HOVERED, m_tsrc, nullptr);
|
||||
video::ITexture *bgimg_pressed = style.getTexture(StyleSpec::BGIMG_PRESSED, m_tsrc, nullptr);
|
||||
core::rect<s32> bgimg_middle = style.getRect(StyleSpec::BGIMG_MIDDLE, core::rect<s32>());
|
||||
|
||||
GUIInventoryList *e = new GUIInventoryList(Environment, data->current_parent,
|
||||
spec.fid, rect, m_invmgr, loc, listname, geom, start_i,
|
||||
v2s32(slot_size.X, slot_size.Y), slot_spacing, bgimg, bgimg_hovered,
|
||||
bgimg_middle, this, data->inventorylist_options, m_font);
|
||||
bgimg_pressed, bgimg_middle, this, data->inventorylist_options, m_font);
|
||||
|
||||
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
|
||||
|
||||
|
@ -36,6 +36,7 @@ GUIInventoryList::GUIInventoryList(gui::IGUIEnvironment *env,
|
||||
const v2f32 &slot_spacing,
|
||||
video::ITexture* slotbg_n_texture,
|
||||
video::ITexture* slotbg_h_texture,
|
||||
video::ITexture* slotbg_p_texture,
|
||||
const core::rect<s32> &slotbg_middle,
|
||||
GUIFormSpecMenu *fs_menu,
|
||||
const Options &options,
|
||||
@ -50,11 +51,13 @@ GUIInventoryList::GUIInventoryList(gui::IGUIEnvironment *env,
|
||||
m_slot_spacing(slot_spacing),
|
||||
m_slotbg_n_texture(slotbg_n_texture),
|
||||
m_slotbg_h_texture(slotbg_h_texture),
|
||||
m_slotbg_p_texture(slotbg_p_texture),
|
||||
m_slotbg_middle(slotbg_middle),
|
||||
m_fs_menu(fs_menu),
|
||||
m_options(options),
|
||||
m_font(font),
|
||||
m_hovered_i(-1),
|
||||
m_pressed(false),
|
||||
m_already_warned(false)
|
||||
{
|
||||
}
|
||||
@ -118,8 +121,12 @@ void GUIInventoryList::draw()
|
||||
// layer 0
|
||||
if (m_slotbg_n_texture) {
|
||||
video::ITexture *texture = m_slotbg_n_texture;
|
||||
if (hovering && m_slotbg_h_texture)
|
||||
texture = m_slotbg_h_texture;
|
||||
if (hovering) {
|
||||
if (m_pressed && m_slotbg_p_texture)
|
||||
texture = m_slotbg_p_texture;
|
||||
else if (m_slotbg_h_texture)
|
||||
texture = m_slotbg_h_texture;
|
||||
}
|
||||
|
||||
core::rect<s32> srcrect(core::position2d<s32>(0, 0),
|
||||
core::dimension2di(texture->getOriginalSize()));
|
||||
@ -198,8 +205,15 @@ bool GUIInventoryList::OnEvent(const SEvent &event)
|
||||
|
||||
m_hovered_i = getItemIndexAtPos(v2s32(event.MouseInput.X, event.MouseInput.Y));
|
||||
|
||||
if (m_hovered_i != -1)
|
||||
if (m_hovered_i != -1) {
|
||||
if (event.MouseInput.Event == EMIE_LMOUSE_PRESSED_DOWN)
|
||||
m_pressed = true;
|
||||
else if (event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP)
|
||||
m_pressed = false;
|
||||
return IGUIElement::OnEvent(event);
|
||||
}
|
||||
|
||||
m_pressed = false;
|
||||
|
||||
// no item slot at pos of mouse event => allow clicking through
|
||||
// find the element that would be hovered if this inventorylist was invisible
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
const v2f32 &slot_spacing,
|
||||
video::ITexture* slotbg_n_texture,
|
||||
video::ITexture* slotbg_h_texture,
|
||||
video::ITexture* slotbg_p_texture,
|
||||
const core::rect<s32> &slotbg_middle,
|
||||
GUIFormSpecMenu *fs_menu,
|
||||
const Options &options,
|
||||
@ -123,6 +124,7 @@ private:
|
||||
// Slot textures
|
||||
video::ITexture* m_slotbg_n_texture;
|
||||
video::ITexture* m_slotbg_h_texture;
|
||||
video::ITexture* m_slotbg_p_texture;
|
||||
core::rect<s32> m_slotbg_middle;
|
||||
|
||||
// the GUIFormSpecMenu can have an item selected and co.
|
||||
@ -136,6 +138,9 @@ private:
|
||||
// the index of the hovered item; -1 if no item is hovered
|
||||
s32 m_hovered_i;
|
||||
|
||||
// Whether the hovered item is being pressed
|
||||
bool m_pressed;
|
||||
|
||||
// we do not want to write a warning on every draw
|
||||
bool m_already_warned;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user