Refix items on UIItem, cancel button to hotkeys

This commit is contained in:
Henrique Santiago 2013-01-10 16:45:35 -02:00
parent 00a574fe10
commit adba4b0da9
4 changed files with 104 additions and 86 deletions

View File

@ -32,11 +32,11 @@ hotkeyList = {}
-- public functions -- public functions
function init() function init()
hotkeysWindow = g_ui.displayUI('hotkeys_manager.otui') hotkeysWindow = g_ui.displayUI('hotkeys_manager')
local hotkeyListPanel = hotkeysWindow:getChildById('currentHotkeys') local hotkeyListPanel = hotkeysWindow:getChildById('currentHotkeys')
hotkeysWindow:setVisible(false) hotkeysWindow:setVisible(false)
hotkeysButton = TopMenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', '/game_hotkeys/icon.png', toggle) hotkeysButton = TopMenu.addLeftGameButton('hotkeysButton', tr('Hotkeys') .. ' (Ctrl+K)', 'icon.png', toggle)
g_keyboard.bindKeyDown('Ctrl+K', toggle) g_keyboard.bindKeyDown('Ctrl+K', toggle)
g_keyboard.bindKeyPress('Down', function() hotkeyListPanel:focusNextChild(KeyboardFocusReason) end, hotkeysWindow) g_keyboard.bindKeyPress('Down', function() hotkeyListPanel:focusNextChild(KeyboardFocusReason) end, hotkeysWindow)
g_keyboard.bindKeyPress('Up', function() hotkeyListPanel:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow) g_keyboard.bindKeyPress('Up', function() hotkeyListPanel:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow)
@ -59,22 +59,20 @@ function init()
itemWidget:setVisible(false) itemWidget:setVisible(false)
itemWidget:setFocusable(false) itemWidget:setFocusable(false)
connect(g_game, { onGameEnd = hide }) connect(g_game, { onGameStart = onGameStart,
onGameEnd = hide })
connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) checkSelectedHotkey(focusedChild) end } ) connect(currentHotkeysList, { onChildFocusChange = function (self, focusedChild) checkSelectedHotkey(focusedChild) end } )
hotkeysManagerLoaded = true hotkeysManagerLoaded = true
load()
end end
function terminate() function terminate()
hotkeysManagerLoaded = false hotkeysManagerLoaded = false
disconnect(g_game, { onGameEnd = hide }) disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = hide })
g_keyboard.unbindKeyDown('Ctrl+K') g_keyboard.unbindKeyDown('Ctrl+K')
save()
for keyCombo,v in pairs(hotkeyList) do for keyCombo,v in pairs(hotkeyList) do
g_keyboard.unbindKeyPress(keyCombo) g_keyboard.unbindKeyPress(keyCombo)
end end
@ -119,9 +117,7 @@ function save()
end end
function toggle() function toggle()
if hotkeysWindow:isVisible() then if not hotkeysWindow:isVisible() then
hide()
else
show() show()
end end
end end
@ -139,7 +135,28 @@ function hide()
hotkeysWindow:hide() hotkeysWindow:hide()
end end
function ok()
save()
hide()
end
function cancel()
local children = currentHotkeysList:getChildren()
for i=1,#children do
hotkeyList[children[i].keyCombo] = nil
g_keyboard.unbindKeyPress(children[i].keyCombo)
end
currentHotkeysList:destroyChildren()
hotkeyLabelSelectedOnList = nil
load()
hide()
end
-- private functions -- private functions
function onGameStart()
load()
end
function onChooseItemMouseRelease(self, mousePosition, mouseButton) function onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil local item = nil
if mouseButton == MouseLeftButton then if mouseButton == MouseLeftButton then
@ -164,9 +181,10 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton)
hotkeyLabelSelectedOnList.itemId = item:getId() hotkeyLabelSelectedOnList.itemId = item:getId()
changeUseType(HOTKEY_MANAGER_USEONSELF) changeUseType(HOTKEY_MANAGER_USEONSELF)
checkSelectedHotkey(hotkeyLabelSelectedOnList) checkSelectedHotkey(hotkeyLabelSelectedOnList)
show()
end end
show()
g_mouse.restoreCursor() g_mouse.restoreCursor()
self:ungrabMouse() self:ungrabMouse()
self:destroy() self:destroy()
@ -196,56 +214,13 @@ function clearObject()
end end
function addHotkey() function addHotkey()
local widget local assignWindow = g_ui.createWidget('HotkeyAssignWindow', rootWidget)
assignWindow:grabKeyboard()
messageBox = g_ui.createWidget('MainWindow', rootWidget) local comboLabel = assignWindow:getChildById('comboPreview')
messageBox:grabKeyboard() comboLabel.keyCombo = ''
messageBox:setId('assignWindow')
messageBox:setText(tr('Button Assign'))
messageBox:setWidth(420)
messageBox:setHeight(140)
messageBox:setDraggable(false)
widget = g_ui.createWidget('Label', messageBox) connect(assignWindow, { onKeyDown = hotkeyCapture }, true)
widget:setText(tr('Please, press the key you wish to add onto your hotkeys manager'))
widget:resizeToText()
widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
widget:addAnchor(AnchorTop, 'parent', AnchorTop)
widget = g_ui.createWidget('Label', messageBox)
widget:setId('comboPreview')
widget:setText(tr('Current hotkey to add: %s', 'none'))
widget.keyCombo = ''
widget:resizeToText()
widget:addAnchor(AnchorHorizontalCenter, 'parent', AnchorHorizontalCenter)
widget:addAnchor(AnchorTop, 'prev', AnchorBottom)
widget:setMarginTop(20)
widget = g_ui.createWidget('Button', messageBox)
widget:setId('cancelButton')
widget:setText(tr('Cancel'))
widget:setWidth(64)
widget:addAnchor(AnchorBottom, 'parent', AnchorBottom)
widget:addAnchor(AnchorRight, 'parent', AnchorRight)
widget.onClick = function (self)
messageBox = nil
self:getParent():destroy()
end
widget = g_ui.createWidget('Button', messageBox)
widget:setId('addButton')
widget:setText(tr('Add'))
widget:setWidth(64)
widget:disable()
widget:addAnchor(AnchorBottom, 'cancelButton', AnchorBottom)
widget:addAnchor(AnchorRight, 'cancelButton', AnchorLeft)
widget:setMarginRight(10)
widget.onClick = function (self)
messageBox = nil
addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo)
end
connect(messageBox, { onKeyDown = hotkeyCapture }, true)
end end
function addKeyCombo(messageBox, keyCombo, keySettings) function addKeyCombo(messageBox, keyCombo, keySettings)

View File

@ -4,6 +4,6 @@ Module
author: andrefaramir, BeniS author: andrefaramir, BeniS
website: www.otclient.info website: www.otclient.info
sandboxed: true sandboxed: true
scripts: [ hotkeys_manager.lua ] scripts: [ hotkeys_manager ]
@onLoad: init() @onLoad: init()
@onUnload: terminate() @onUnload: terminate()

View File

@ -11,10 +11,10 @@ HotkeyListLabel < UILabel
MainWindow MainWindow
id: hotkeysWindow id: hotkeysWindow
!text: tr('Hotkeys') !text: tr('Hotkeys')
size: 340 460 size: 340 410
@onEnter: modules.game_hotkeys.hide() @onEnter: modules.game_hotkeys.ok()
@onEscape: modules.game_hotkeys.hide() @onEscape: modules.game_hotkeys.cancel()
Label Label
id: currentHotkeysLabel id: currentHotkeysLabel
@ -38,7 +38,6 @@ MainWindow
anchors.right: prev.left anchors.right: prev.left
anchors.top: prev.top anchors.top: prev.top
anchors.bottom: prev.bottom anchors.bottom: prev.bottom
padding: 1
focusable: false focusable: false
Label Label
@ -52,9 +51,9 @@ MainWindow
id: addHotkeyButton id: addHotkeyButton
!text: tr('Add') !text: tr('Add')
width: 64 width: 64
anchors.left: parent.left anchors.right: next.left
anchors.top: prev.bottom anchors.top: next.top
margin-top: 2 margin-right: 5
@onClick: modules.game_hotkeys.addHotkey() @onClick: modules.game_hotkeys.addHotkey()
Button Button
@ -62,9 +61,9 @@ MainWindow
!text: tr('Remove') !text: tr('Remove')
width: 64 width: 64
enabled: false enabled: false
anchors.left: prev.right anchors.right: parent.right
anchors.top: prev.top anchors.top: currentHotkeys.bottom
margin-left: 10 margin-top: 8
@onClick: modules.game_hotkeys.removeHotkey() @onClick: modules.game_hotkeys.removeHotkey()
Label Label
@ -74,7 +73,7 @@ MainWindow
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
margin-top: 20 margin-top: 10
TextEdit TextEdit
id: hotkeyText id: hotkeyText
@ -82,7 +81,7 @@ MainWindow
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
margin-bottom: 2 margin-top: 2
@onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getId(), self:getText()) @onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getId(), self:getText())
CheckBox CheckBox
@ -92,7 +91,7 @@ MainWindow
anchors.right: parent.right anchors.right: parent.right
anchors.top: prev.bottom anchors.top: prev.bottom
enabled:false enabled:false
margin-top: 10 margin-top: 5
@onCheckChange: modules.game_hotkeys.setSendAutomatically(self:isChecked()) @onCheckChange: modules.game_hotkeys.setSendAutomatically(self:isChecked())
Item Item
@ -167,8 +166,61 @@ MainWindow
margin-bottom: 10 margin-bottom: 10
Button Button
!text: tr('Close') !text: tr('Ok')
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
@onClick: modules.game_hotkeys.ok()
margin-right: 10
Button
!text: tr('Cancel')
width: 64 width: 64
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: modules.game_hotkeys.hide() @onClick: modules.game_hotkeys.cancel()
HotkeyAssignWindow < MainWindow
id: assignWindow
!text: tr('Button Assign')
size: 360 150
@onEscape: self:destroy()
Label
!text: tr('Please, press the key you wish to add onto your hotkeys manager')
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
text-auto-resize: true
text-align: left
Label
id: comboPreview
!text: tr('Current hotkey to add: %s', 'none')
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: prev.bottom
margin-top: 10
text-auto-resize: true
HorizontalSeparator
id: separator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: next.top
margin-bottom: 10
Button
id: addButton
!text: tr('Add')
width: 64
anchors.right: next.left
anchors.bottom: parent.bottom
@onClick: modules.game_hotkeys.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo)
margin-right: 10
Button
!text: tr('Cancel')
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
@onClick: self:getParent():destroy()

View File

@ -65,12 +65,6 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate, LightView *l
// determine animation phase // determine animation phase
int animationPhase = calculateAnimationPhase(animate); int animationPhase = calculateAnimationPhase(animate);
if(getAnimationPhases() > 1) {
if(animate)
animationPhase = (g_clock.millis() % (Otc::ITEM_TICKS_PER_FRAME * getAnimationPhases())) / Otc::ITEM_TICKS_PER_FRAME;
else
animationPhase = getAnimationPhases()-1;
}
// determine x,y,z patterns // determine x,y,z patterns
int xPattern = 0, yPattern = 0, zPattern = 0; int xPattern = 0, yPattern = 0, zPattern = 0;
@ -359,12 +353,9 @@ int Item::calculateAnimationPhase(bool animate)
int Item::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase) int Item::getExactSize(int layer, int xPattern, int yPattern, int zPattern, int animationPhase)
{ {
int exactSize = 0;
calculatePatterns(xPattern, yPattern, zPattern); calculatePatterns(xPattern, yPattern, zPattern);
animationPhase = calculateAnimationPhase(true); animationPhase = calculateAnimationPhase(true);
for(layer = 0; layer < getLayers(); ++layer) return Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase);
exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase));
return exactSize;
} }
const ThingTypePtr& Item::getThingType() const ThingTypePtr& Item::getThingType()