1
0
Fork 0

Add pressed inventory slot background image

main-2-0-4
luk3yx 2023-06-07 10:28:41 +12:00 committed by GitHub
parent 88c52130f8
commit f22951ab2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

@ -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.

View File

@ -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));

View File

@ -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

View File

@ -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;
};