introduce virtual items for UIItem
This commit is contained in:
parent
3e841cd7b6
commit
266917cc3c
|
@ -1,6 +1,8 @@
|
||||||
function UIItem:onDragEnter(mousePos)
|
function UIItem:onDragEnter(mousePos)
|
||||||
|
if self:isVirtual() then return false end
|
||||||
|
|
||||||
local item = self:getItem()
|
local item = self:getItem()
|
||||||
if not item then return false end
|
if not item then return true end
|
||||||
|
|
||||||
self:setBorderWidth(1)
|
self:setBorderWidth(1)
|
||||||
|
|
||||||
|
@ -11,6 +13,8 @@ function UIItem:onDragEnter(mousePos)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIItem:onDragLeave(widget, mousePos)
|
function UIItem:onDragLeave(widget, mousePos)
|
||||||
|
if self:isVirtual() then return false end
|
||||||
|
|
||||||
if not self.parsed then
|
if not self.parsed then
|
||||||
self.currentDragThing = nil
|
self.currentDragThing = nil
|
||||||
end
|
end
|
||||||
|
@ -21,7 +25,9 @@ function UIItem:onDragLeave(widget, mousePos)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIItem:onDrop(widget, mousePos)
|
function UIItem:onDrop(widget, mousePos)
|
||||||
if not widget or not widget.currentDragThing then return false end
|
if self:isVirtual() then return false end
|
||||||
|
|
||||||
|
if not widget or not widget.currentDragThing then return true end
|
||||||
|
|
||||||
local pos = self.position
|
local pos = self.position
|
||||||
local data = widget.currentDragThing:getData()
|
local data = widget.currentDragThing:getData()
|
||||||
|
@ -45,6 +51,8 @@ function UIItem:onDrop(widget, mousePos)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIItem:onHoverChange(hovered)
|
function UIItem:onHoverChange(hovered)
|
||||||
|
if self:isVirtual() then return end
|
||||||
|
|
||||||
if g_ui.getDraggingWidget() and self ~= g_ui.getDraggingWidget() then
|
if g_ui.getDraggingWidget() and self ~= g_ui.getDraggingWidget() then
|
||||||
if hovered then
|
if hovered then
|
||||||
self:setBorderWidth(1)
|
self:setBorderWidth(1)
|
||||||
|
@ -55,6 +63,8 @@ function UIItem:onHoverChange(hovered)
|
||||||
end
|
end
|
||||||
|
|
||||||
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
function UIItem:onMouseRelease(mousePosition, mouseButton)
|
||||||
|
if self:isVirtual() then return false end
|
||||||
|
|
||||||
local item = self:getItem()
|
local item = self:getItem()
|
||||||
if not item or not self:containsPoint(mousePosition) then return false end
|
if not item or not self:containsPoint(mousePosition) then return false end
|
||||||
return Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item)
|
return Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item)
|
||||||
|
|
|
@ -26,7 +26,7 @@ local function onUseWithMouseRelease(self, mousePosition, mouseButton)
|
||||||
if tile then
|
if tile then
|
||||||
Game.useWith(Game.selectedThing, tile:getTopMultiUseThing())
|
Game.useWith(Game.selectedThing, tile:getTopMultiUseThing())
|
||||||
end
|
end
|
||||||
elseif clickedWidget.getItem then
|
elseif clickedWidget.getItem and not clickedWidget:isVirtual() then
|
||||||
Game.useWith(Game.selectedThing, clickedWidget:getItem())
|
Game.useWith(Game.selectedThing, clickedWidget:getItem())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,19 +7,5 @@ varying vec2 textureCoords; // map texture coords
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec4 outColor = texture2D(texture, textureCoords) * opacity;
|
vec4 outColor = texture2D(texture, textureCoords) * opacity;
|
||||||
/*
|
|
||||||
float refinement = 0;
|
|
||||||
if(refinement > 0) {
|
|
||||||
vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
|
|
||||||
for(int i=-1;i<=1;++i) {
|
|
||||||
for(int j=-1;j<=1;++j) {
|
|
||||||
vec4 pixel = texture2D(texture, textureCoords + vec2(i,j)*(1.0/32.0));
|
|
||||||
sum += pixel * (1.0/9.0) * pixel.a * (0.5 + (pixel.r + pixel.g + pixel.b)/3.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float factor = refinement*((1.0 + sin(time*2))/2.0);
|
|
||||||
outColor += sum * sum * factor;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
gl_FragColor = outColor;
|
gl_FragColor = outColor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,9 +221,16 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassStaticFunction<Game>("getProtocolGame", std::bind(&Game::getProtocolGame, &g_game));
|
g_lua.bindClassStaticFunction<Game>("getProtocolGame", std::bind(&Game::getProtocolGame, &g_game));
|
||||||
|
|
||||||
g_lua.registerClass<UIItem, UIWidget>();
|
g_lua.registerClass<UIItem, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); } );
|
g_lua.bindClassStaticFunction<UIItem>("create", []{ return UIItemPtr(new UIItem); });
|
||||||
g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem);
|
g_lua.bindClassMemberFunction<UIItem>("setItemId", &UIItem::setItemId);
|
||||||
|
g_lua.bindClassMemberFunction<UIItem>("setItemCount", &UIItem::setItemCount);
|
||||||
g_lua.bindClassMemberFunction<UIItem>("setItem", &UIItem::setItem);
|
g_lua.bindClassMemberFunction<UIItem>("setItem", &UIItem::setItem);
|
||||||
|
g_lua.bindClassMemberFunction<UIItem>("setVirtual", &UIItem::setVirtual);
|
||||||
|
g_lua.bindClassMemberFunction<UIItem>("getItemId", &UIItem::getItemId);
|
||||||
|
g_lua.bindClassMemberFunction<UIItem>("getItemCount", &UIItem::getItemCount);
|
||||||
|
g_lua.bindClassMemberFunction<UIItem>("getItem", &UIItem::getItem);
|
||||||
|
g_lua.bindClassMemberFunction<UIItem>("isVirtual", &UIItem::isVirtual);
|
||||||
|
|
||||||
|
|
||||||
g_lua.registerClass<UICreature, UIWidget>();
|
g_lua.registerClass<UICreature, UIWidget>();
|
||||||
g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } );
|
g_lua.bindClassStaticFunction<UICreature>("create", []{ return UICreaturePtr(new UICreature); } );
|
||||||
|
|
|
@ -51,3 +51,31 @@ void UIItem::draw()
|
||||||
|
|
||||||
drawChildren();
|
drawChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UIItem::setItemId(int id)
|
||||||
|
{
|
||||||
|
if(!m_item)
|
||||||
|
m_item = Item::create(id);
|
||||||
|
else
|
||||||
|
m_item->setId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIItem::setItemCount(int count)
|
||||||
|
{
|
||||||
|
if(m_item)
|
||||||
|
m_item->setData(count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||||
|
{
|
||||||
|
UIWidget::onStyleApply(styleName, styleNode);
|
||||||
|
|
||||||
|
for(const OTMLNodePtr& node : styleNode->children()) {
|
||||||
|
if(node->tag() == "item-id")
|
||||||
|
setItemId(node->value<int>());
|
||||||
|
else if(node->tag() == "item-count")
|
||||||
|
setItemCount(node->value<int>());
|
||||||
|
else if(node->tag() == "virtual")
|
||||||
|
setVirtual(node->value<bool>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -33,12 +33,21 @@ public:
|
||||||
UIItem();
|
UIItem();
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
|
void setItemId(int id);
|
||||||
|
void setItemCount(int count);
|
||||||
void setItem(const ItemPtr& item) { m_item = item; }
|
void setItem(const ItemPtr& item) { m_item = item; }
|
||||||
|
void setVirtual(bool virt) { m_virtual = virt; }
|
||||||
|
|
||||||
|
int getItemId() { return m_item->getId(); }
|
||||||
|
int getItemCount() { return m_item->getData(); }
|
||||||
ItemPtr getItem() { return m_item; }
|
ItemPtr getItem() { return m_item; }
|
||||||
|
bool isVirtual() { return m_virtual; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
||||||
|
|
||||||
ItemPtr m_item;
|
ItemPtr m_item;
|
||||||
|
Boolean<false> m_virtual;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue