rework and classic controls

This commit is contained in:
Henrique Santiago 2012-01-09 18:54:37 -02:00
parent 911584e816
commit 4de5e45d52
15 changed files with 94 additions and 90 deletions

View File

@ -1,6 +1,6 @@
Creature < UICreature
size: 66 66
creature-margin: 1
padding: 1
border-image:
source: /core_styles/images/panel_flat.png
border: 1

View File

@ -1,6 +1,6 @@
Item < UIItem
size: 34 34
item margin: 1
padding: 1
border-image:
source: /core_styles/images/panel_flat.png
border: 1

View File

@ -28,7 +28,7 @@ InterfacePanel2 < Panel
border: 4
Map< UIMap
map margin: 4
padding: 4
border-image:
source: /core_styles/images/map_panel.png
border: 4

View File

@ -1,26 +1,5 @@
function UIMap:onMouseRelease(mousePos, mouseButton)
local tile = self:getTile(mousePos)
if not tile then return false 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
function UIMap:onMouseRelease(mousePosition, mouseButton)
local tile = self:getTile(mousePosition)
if tile and Game.processMouseAction(mousePosition, mouseButton, nil, tile:getTopLookThing(), tile:getTopUseThing(), tile:getTopCreature(), tile:getTopMultiUseThing()) then return true end
return false
end

View File

@ -1,5 +1,61 @@
-- 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)
local menu = createWidget('PopupMenu')

View File

@ -29,13 +29,10 @@ function Inventory.onSoulChange(soul)
widget:setText("Soul:\n" .. soul)
end
function Inventory.onInventoryItemMousePress(itemWidget, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then return end
function Inventory.onInventoryItemMousePress(itemWidget, mousePosition, mouseButton)
local item = itemWidget:getItem()
if not item then return end
Game.createThingMenu(mousePos, item, item, nil)
if item and Game.processMouseAction(mousePosition, mouseButton, nil, item, item, nil, item) then return true end
return false
end
connect(Game, { onLogin = Inventory.create,
@ -43,3 +40,4 @@ connect(Game, { onLogin = Inventory.create,
onInventoryChange = Inventory.onInventoryChange,
onFreeCapacityChange = Inventory.onFreeCapacityChange,
onSoulChange = Inventory.onSoulChange })

View File

@ -238,6 +238,24 @@ CreaturePtr Tile::getTopCreature()
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()
{
if(!getGround())

View File

@ -48,6 +48,7 @@ public:
ThingPtr getTopLookThing();
ThingPtr getTopUseThing();
CreaturePtr getTopCreature();
ThingPtr getTopMultiUseThing();
const Position& getPos() { return m_position; }
int getDrawElevation() { return m_drawElevation; }

View File

@ -152,6 +152,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Tile>("getTopLookThing", &Tile::getTopLookThing);
g_lua.bindClassMemberFunction<Tile>("getTopUseThing", &Tile::getTopUseThing);
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>("getDrawElevation", &Tile::getDrawElevation);
g_lua.bindClassMemberFunction<Tile>("getCreatures", &Tile::getCreatures);

View File

@ -24,29 +24,14 @@
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
UICreature::UICreature()
{
m_creatureMargin = 0;
}
void UICreature::render()
{
renderSelf();
if(m_creature) {
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();
}
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);
}

View File

@ -30,19 +30,14 @@
class UICreature : public UIWidget
{
public:
UICreature();
void render();
void setCreature(const CreaturePtr& creature) { m_creature = creature; }
CreaturePtr getCreature() { return m_creature; }
protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
private:
CreaturePtr m_creature;
int m_creatureMargin;
};
#endif

View File

@ -27,7 +27,6 @@
UIItem::UIItem()
{
m_itemMargin = 0;
m_font = g_fonts.getFont("verdana-11px-rounded");
}
@ -36,7 +35,7 @@ void UIItem::render()
renderSelf();
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);
m_item->draw(topLeft, m_rect);
@ -49,13 +48,3 @@ void UIItem::render()
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);
}

View File

@ -36,12 +36,8 @@ public:
void setItem(const ItemPtr& item) { m_item = item; }
ItemPtr getItem() { return m_item; }
protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
private:
ItemPtr m_item;
int m_itemMargin;
FontPtr m_font;
};

View File

@ -27,11 +27,6 @@
#include <framework/graphics/graphics.h>
#include <otclient/core/localplayer.h>
UIMap::UIMap()
{
m_mapMargin = 0;
}
void UIMap::render()
{
renderSelf();
@ -43,16 +38,6 @@ void UIMap::render()
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)
{
if(!m_mapRect.contains(mousePos))
@ -96,7 +81,11 @@ TilePtr UIMap::getTile(const Point& mousePos)
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);
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);

View File

@ -30,17 +30,14 @@
class UIMap : public UIWidget
{
public:
UIMap();
void render();
TilePtr getTile(const Point& mousePos);
protected:
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
private:
int m_mapMargin;
Rect m_mapRect;
};