mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
preliminary lua scripting framework for objects
This commit is contained in:
parent
c57637b4c3
commit
69dbc046eb
81 changed files with 18685 additions and 193 deletions
132
src/main.cpp
132
src/main.cpp
|
@ -1186,138 +1186,6 @@ void updateViewingRange(f32 frametime_in, Client *client)
|
|||
frametime_old = frametime;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// TODO: Remove
|
||||
class GUIQuickInventory
|
||||
{
|
||||
public:
|
||||
GUIQuickInventory(
|
||||
gui::IGUIEnvironment* env,
|
||||
gui::IGUIElement* parent,
|
||||
v2s32 pos,
|
||||
s32 itemcount,
|
||||
Inventory *inventory):
|
||||
m_itemcount(itemcount),
|
||||
m_inventory(inventory)
|
||||
{
|
||||
core::rect<s32> imgsize(0,0,quickinv_size,quickinv_size);
|
||||
core::rect<s32> textsize(0,0,quickinv_size,quickinv_size);
|
||||
bgtext = env->addStaticText(L"", core::rect<s32>(0,0,1,1), false, false);
|
||||
bgtext->setBackgroundColor(
|
||||
video::SColor(128,0,0,0));
|
||||
for(s32 i=0; i<m_itemcount; i++)
|
||||
{
|
||||
m_images.push_back(env->addImage(
|
||||
imgsize
|
||||
));
|
||||
m_images[i]->setScaleImage(true);
|
||||
m_texts.push_back(env->addStaticText(
|
||||
L"",
|
||||
textsize,
|
||||
false, false
|
||||
));
|
||||
/*m_texts[i]->setBackgroundColor(
|
||||
video::SColor(128,0,0,0));*/
|
||||
m_texts[i]->setTextAlignment(
|
||||
gui::EGUIA_LOWERRIGHT,
|
||||
gui::EGUIA_LOWERRIGHT);
|
||||
}
|
||||
|
||||
updatePosition(pos);
|
||||
}
|
||||
|
||||
~GUIQuickInventory()
|
||||
{
|
||||
for(u32 i=0; i<m_texts.size(); i++)
|
||||
{
|
||||
m_texts[i]->remove();
|
||||
}
|
||||
for(u32 i=0; i<m_images.size(); i++)
|
||||
{
|
||||
m_images[i]->remove();
|
||||
}
|
||||
bgtext->remove();
|
||||
}
|
||||
|
||||
void updatePosition(v2s32 pos)
|
||||
{
|
||||
v2s32 spacing(quickinv_spacing, 0);
|
||||
for(s32 i=0; i<m_itemcount; i++)
|
||||
{
|
||||
m_images[i]->setRelativePosition(pos + spacing*i);
|
||||
m_texts[i]->setRelativePosition(pos + spacing*i);
|
||||
}
|
||||
core::rect<s32> bgrect(-quickinv_outer_padding,-quickinv_outer_padding,
|
||||
(quickinv_itemcount-1)*quickinv_spacing+quickinv_size+quickinv_outer_padding,
|
||||
quickinv_size+quickinv_outer_padding);
|
||||
bgtext->setRelativePosition(bgrect+pos);
|
||||
}
|
||||
|
||||
void setSelection(s32 i)
|
||||
{
|
||||
m_selection = i;
|
||||
}
|
||||
|
||||
void update()
|
||||
{
|
||||
s32 start = 0;
|
||||
|
||||
//start = m_selection - m_itemcount / 2;
|
||||
|
||||
InventoryList *mainlist = m_inventory->getList("main");
|
||||
|
||||
for(s32 i=0; i<m_itemcount; i++)
|
||||
{
|
||||
s32 j = i + start;
|
||||
|
||||
if(j > (s32)mainlist->getSize() - 1)
|
||||
j -= mainlist->getSize();
|
||||
if(j < 0)
|
||||
j += mainlist->getSize();
|
||||
|
||||
InventoryItem *item = mainlist->getItem(j);
|
||||
// Null items
|
||||
if(item == NULL)
|
||||
{
|
||||
m_images[i]->setImage(NULL);
|
||||
|
||||
if(m_selection == j)
|
||||
m_texts[i]->setText(L"->");
|
||||
else
|
||||
m_texts[i]->setText(L"");
|
||||
|
||||
// The next ifs will segfault with a NULL pointer
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
m_images[i]->setImage(item->getImage());
|
||||
|
||||
std::ostringstream os;
|
||||
if(m_selection == j)
|
||||
os<<"-> ";
|
||||
os<<item->getText();
|
||||
m_texts[i]->setText(narrow_to_wide(os.str()).c_str());
|
||||
|
||||
/*wchar_t t[10];
|
||||
if(m_selection == j)
|
||||
swprintf(t, 10, SWPRINTF_CHARSTRING L" <-", item->getText().c_str());
|
||||
else
|
||||
swprintf(t, 10, SWPRINTF_CHARSTRING, item->getText().c_str());
|
||||
m_texts[i]->setText(t);*/
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
s32 m_itemcount;
|
||||
gui::IGUIStaticText *bgtext;
|
||||
core::array<gui::IGUIStaticText*> m_texts;
|
||||
core::array<gui::IGUIImage*> m_images;
|
||||
Inventory *m_inventory;
|
||||
s32 m_selection;
|
||||
};
|
||||
#endif
|
||||
|
||||
void draw_hotbar(video::IVideoDriver *driver, gui::IGUIFont *font,
|
||||
v2s32 centerlowerpos, s32 imgsize, s32 itemcount,
|
||||
Inventory *inventory)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue