rework and classic controls
This commit is contained in:
parent
911584e816
commit
4de5e45d52
|
@ -1,6 +1,6 @@
|
||||||
Creature < UICreature
|
Creature < UICreature
|
||||||
size: 66 66
|
size: 66 66
|
||||||
creature-margin: 1
|
padding: 1
|
||||||
border-image:
|
border-image:
|
||||||
source: /core_styles/images/panel_flat.png
|
source: /core_styles/images/panel_flat.png
|
||||||
border: 1
|
border: 1
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
Item < UIItem
|
Item < UIItem
|
||||||
size: 34 34
|
size: 34 34
|
||||||
item margin: 1
|
padding: 1
|
||||||
border-image:
|
border-image:
|
||||||
source: /core_styles/images/panel_flat.png
|
source: /core_styles/images/panel_flat.png
|
||||||
border: 1
|
border: 1
|
||||||
|
|
|
@ -28,7 +28,7 @@ InterfacePanel2 < Panel
|
||||||
border: 4
|
border: 4
|
||||||
|
|
||||||
Map< UIMap
|
Map< UIMap
|
||||||
map margin: 4
|
padding: 4
|
||||||
border-image:
|
border-image:
|
||||||
source: /core_styles/images/map_panel.png
|
source: /core_styles/images/map_panel.png
|
||||||
border: 4
|
border: 4
|
||||||
|
|
|
@ -1,26 +1,5 @@
|
||||||
function UIMap:onMouseRelease(mousePos, mouseButton)
|
function UIMap:onMouseRelease(mousePosition, mouseButton)
|
||||||
local tile = self:getTile(mousePos)
|
local tile = self:getTile(mousePosition)
|
||||||
if not tile then return false end
|
if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
|
||||||
|
|
||||||
local keyboardModifiers = g_window.getKeyboardModifiers()
|
|
||||||
if not Options.classicControl then
|
|
||||||
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
|
|
||||||
-- auto walk
|
|
||||||
return true
|
|
||||||
elseif keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
|
||||||
Game.createThingMenu(mousePos, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature())
|
|
||||||
return true
|
|
||||||
elseif keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseRightButton or mouseButton == MouseLeftButton) then
|
|
||||||
Game.look(tile:getTopLookThing())
|
|
||||||
return true
|
|
||||||
elseif keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseRightButton or mouseButton == MouseLeftButton) then
|
|
||||||
Game.use(tile:getTopUseThing())
|
|
||||||
return true
|
|
||||||
elseif keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseRightButton or mouseButton == MouseLeftButton) then
|
|
||||||
Game.attack(tile:getTopCreature())
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,61 @@
|
||||||
|
|
||||||
-- public functions
|
-- public functions
|
||||||
|
function Game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThing, useThing, creatureThing, multiUseThing)
|
||||||
|
local keyboardModifiers = g_window.getKeyboardModifiers()
|
||||||
|
|
||||||
|
if autoWalk and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
|
||||||
|
-- todo auto walk
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if not Options.classicControl then
|
||||||
|
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||||
|
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
|
return true
|
||||||
|
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||||
|
Game.look(lookThing)
|
||||||
|
return true
|
||||||
|
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||||
|
if useThing:isContainer() then
|
||||||
|
print "open"
|
||||||
|
elseif useThing:isMultiUse() then
|
||||||
|
print "use with..."
|
||||||
|
else
|
||||||
|
Game.use(useThing)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||||
|
Game.attack(creatureThing)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if multiUseThing and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
|
||||||
|
if multiUseThing:asCreature() then
|
||||||
|
Game.attack(multiUseThing:asCreature())
|
||||||
|
elseif multiUseThing:isContainer() then
|
||||||
|
print "open"
|
||||||
|
elseif multiUseThing:isMultiUse() then
|
||||||
|
print "use with..."
|
||||||
|
else
|
||||||
|
Game.use(useThing)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
elseif lookThing and keyboardModifiers == KeyboardShiftModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||||
|
Game.look(lookThing)
|
||||||
|
return true
|
||||||
|
elseif useThing and keyboardModifiers == KeyboardCtrlModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||||
|
Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
|
return true
|
||||||
|
elseif creatureThing and keyboardModifiers == KeyboardAltModifier and (mouseButton == MouseLeftButton or mouseButton == MouseRightButton) then
|
||||||
|
Game.attack(creatureThing)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
local menu = createWidget('PopupMenu')
|
local menu = createWidget('PopupMenu')
|
||||||
|
|
||||||
|
|
|
@ -29,13 +29,10 @@ function Inventory.onSoulChange(soul)
|
||||||
widget:setText("Soul:\n" .. soul)
|
widget:setText("Soul:\n" .. soul)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
|
function Inventory.onInventoryItemMousePress(itemWidget, mousePosition, mouseButton)
|
||||||
if mouseButton ~= MouseRightButton then return end
|
|
||||||
|
|
||||||
local item = itemWidget:getItem()
|
local item = itemWidget:getItem()
|
||||||
if not item then return end
|
if item and Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then return true end
|
||||||
|
return false
|
||||||
Game.createThingMenu(mousePos, item, item, nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
connect(Game, { onLogin = Inventory.create,
|
connect(Game, { onLogin = Inventory.create,
|
||||||
|
@ -43,3 +40,4 @@ connect(Game, { onLogin = Inventory.create,
|
||||||
onInventoryChange = Inventory.onInventoryChange,
|
onInventoryChange = Inventory.onInventoryChange,
|
||||||
onFreeCapacityChange = Inventory.onFreeCapacityChange,
|
onFreeCapacityChange = Inventory.onFreeCapacityChange,
|
||||||
onSoulChange = Inventory.onSoulChange })
|
onSoulChange = Inventory.onSoulChange })
|
||||||
|
|
||||||
|
|
|
@ -238,6 +238,24 @@ CreaturePtr Tile::getTopCreature()
|
||||||
return creature;
|
return creature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThingPtr Tile::getTopMultiUseThing()
|
||||||
|
{
|
||||||
|
// this is related to classic controls, getting top item, forceuse or creature
|
||||||
|
if(isEmpty())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
for(uint i = 0; i < m_things.size(); ++i) {
|
||||||
|
ThingPtr thing = m_things[i];
|
||||||
|
if(thing->isForceUse() || (!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom() && !thing->isOnTop())) {
|
||||||
|
if(i > 0 && thing->isFluid())
|
||||||
|
return m_things[i-1];
|
||||||
|
return thing;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_things[0];
|
||||||
|
}
|
||||||
|
|
||||||
bool Tile::isWalkable()
|
bool Tile::isWalkable()
|
||||||
{
|
{
|
||||||
if(!getGround())
|
if(!getGround())
|
||||||
|
|
|
@ -48,6 +48,7 @@ public:
|
||||||
ThingPtr getTopLookThing();
|
ThingPtr getTopLookThing();
|
||||||
ThingPtr getTopUseThing();
|
ThingPtr getTopUseThing();
|
||||||
CreaturePtr getTopCreature();
|
CreaturePtr getTopCreature();
|
||||||
|
ThingPtr getTopMultiUseThing();
|
||||||
|
|
||||||
const Position& getPos() { return m_position; }
|
const Position& getPos() { return m_position; }
|
||||||
int getDrawElevation() { return m_drawElevation; }
|
int getDrawElevation() { return m_drawElevation; }
|
||||||
|
|
|
@ -152,6 +152,7 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
|
g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
|
||||||
g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
|
g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
|
||||||
g_lua.bindClassMemberFunction<Tile>("getTopCreature", &Tile::getTopCreature);
|
g_lua.bindClassMemberFunction<Tile>("getTopCreature", &Tile::getTopCreature);
|
||||||
|
g_lua.bindClassMemberFunction<Tile>("getTopMultiUseThing", &Tile::getTopMultiUseThing);
|
||||||
g_lua.bindClassMemberFunction<Tile>("getPos", &Tile::getPos);
|
g_lua.bindClassMemberFunction<Tile>("getPos", &Tile::getPos);
|
||||||
g_lua.bindClassMemberFunction<Tile>("getDrawElevation", &Tile::getDrawElevation);
|
g_lua.bindClassMemberFunction<Tile>("getDrawElevation", &Tile::getDrawElevation);
|
||||||
g_lua.bindClassMemberFunction<Tile>("getCreatures", &Tile::getCreatures);
|
g_lua.bindClassMemberFunction<Tile>("getCreatures", &Tile::getCreatures);
|
||||||
|
|
|
@ -24,29 +24,14 @@
|
||||||
#include <framework/otml/otml.h>
|
#include <framework/otml/otml.h>
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
|
|
||||||
UICreature::UICreature()
|
|
||||||
{
|
|
||||||
m_creatureMargin = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UICreature::render()
|
void UICreature::render()
|
||||||
{
|
{
|
||||||
renderSelf();
|
renderSelf();
|
||||||
|
|
||||||
if(m_creature) {
|
if(m_creature) {
|
||||||
g_painter.setColor(Fw::white);
|
g_painter.setColor(Fw::white);
|
||||||
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin, m_rect);
|
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop), m_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderChildren();
|
renderChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UICreature::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
|
||||||
{
|
|
||||||
for(OTMLNodePtr node : styleNode->children()) {
|
|
||||||
if(node->tag() == "creature-margin")
|
|
||||||
m_creatureMargin = node->value<int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
UIWidget::onStyleApply(styleName, styleNode);
|
|
||||||
}
|
|
||||||
|
|
|
@ -30,19 +30,14 @@
|
||||||
class UICreature : public UIWidget
|
class UICreature : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UICreature();
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
|
||||||
|
|
||||||
CreaturePtr getCreature() { return m_creature; }
|
CreaturePtr getCreature() { return m_creature; }
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CreaturePtr m_creature;
|
CreaturePtr m_creature;
|
||||||
int m_creatureMargin;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
|
|
||||||
UIItem::UIItem()
|
UIItem::UIItem()
|
||||||
{
|
{
|
||||||
m_itemMargin = 0;
|
|
||||||
m_font = g_fonts.getFont("verdana-11px-rounded");
|
m_font = g_fonts.getFont("verdana-11px-rounded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +35,7 @@ void UIItem::render()
|
||||||
renderSelf();
|
renderSelf();
|
||||||
|
|
||||||
if(m_item) {
|
if(m_item) {
|
||||||
Point topLeft = m_rect.bottomRight() - Point(32, 32) + m_itemMargin;
|
Point topLeft = m_rect.bottomRight() - Point(32, 32) + Point(m_paddingLeft, m_paddingTop);
|
||||||
|
|
||||||
g_painter.setColor(Fw::white);
|
g_painter.setColor(Fw::white);
|
||||||
m_item->draw(topLeft, m_rect);
|
m_item->draw(topLeft, m_rect);
|
||||||
|
@ -49,13 +48,3 @@ void UIItem::render()
|
||||||
|
|
||||||
renderChildren();
|
renderChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIItem::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
|
||||||
{
|
|
||||||
for(OTMLNodePtr node : styleNode->children()) {
|
|
||||||
if(node->tag() == "item margin")
|
|
||||||
m_itemMargin = node->value<int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
UIWidget::onStyleApply(styleName, styleNode);
|
|
||||||
}
|
|
||||||
|
|
|
@ -36,12 +36,8 @@ public:
|
||||||
void setItem(const ItemPtr& item) { m_item = item; }
|
void setItem(const ItemPtr& item) { m_item = item; }
|
||||||
ItemPtr getItem() { return m_item; }
|
ItemPtr getItem() { return m_item; }
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ItemPtr m_item;
|
ItemPtr m_item;
|
||||||
int m_itemMargin;
|
|
||||||
FontPtr m_font;
|
FontPtr m_font;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -27,11 +27,6 @@
|
||||||
#include <framework/graphics/graphics.h>
|
#include <framework/graphics/graphics.h>
|
||||||
#include <otclient/core/localplayer.h>
|
#include <otclient/core/localplayer.h>
|
||||||
|
|
||||||
UIMap::UIMap()
|
|
||||||
{
|
|
||||||
m_mapMargin = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UIMap::render()
|
void UIMap::render()
|
||||||
{
|
{
|
||||||
renderSelf();
|
renderSelf();
|
||||||
|
@ -43,16 +38,6 @@ void UIMap::render()
|
||||||
renderChildren();
|
renderChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIMap::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
|
||||||
{
|
|
||||||
for(OTMLNodePtr node : styleNode->children()) {
|
|
||||||
if(node->tag() == "map margin")
|
|
||||||
m_mapMargin = node->value<int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
UIWidget::onStyleApply(styleName, styleNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
TilePtr UIMap::getTile(const Point& mousePos)
|
TilePtr UIMap::getTile(const Point& mousePos)
|
||||||
{
|
{
|
||||||
if(!m_mapRect.contains(mousePos))
|
if(!m_mapRect.contains(mousePos))
|
||||||
|
@ -96,7 +81,11 @@ TilePtr UIMap::getTile(const Point& mousePos)
|
||||||
|
|
||||||
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
void UIMap::onGeometryChange(const Rect& oldRect, const Rect& newRect)
|
||||||
{
|
{
|
||||||
Rect mapRect = newRect.expanded(-m_mapMargin-1);
|
Rect mapRect = newRect.expanded(-1);
|
||||||
|
mapRect.addTop(m_paddingTop);
|
||||||
|
mapRect.addLeft(m_paddingLeft);
|
||||||
|
mapRect.addBottom(-m_paddingBottom);
|
||||||
|
mapRect.addRight(-m_paddingRight);
|
||||||
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
|
Size mapSize(g_map.getVibibleSize().width() * Map::NUM_TILE_PIXELS, g_map.getVibibleSize().height() * Map::NUM_TILE_PIXELS);
|
||||||
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
|
||||||
|
|
||||||
|
|
|
@ -30,17 +30,14 @@
|
||||||
class UIMap : public UIWidget
|
class UIMap : public UIWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UIMap();
|
|
||||||
void render();
|
void render();
|
||||||
|
|
||||||
TilePtr getTile(const Point& mousePos);
|
TilePtr getTile(const Point& mousePos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
|
||||||
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_mapMargin;
|
|
||||||
Rect m_mapRect;
|
Rect m_mapRect;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue