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
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 })