Refix items on UIItem, cancel button to hotkeys

master
Henrique Santiago 11 years ago
parent 00a574fe10
commit adba4b0da9

@ -32,11 +32,11 @@ hotkeyList = {}
-- public functions
function init()
hotkeysWindow = g_ui.displayUI('hotkeys_manager.otui')
hotkeysWindow = g_ui.displayUI('hotkeys_manager')
local hotkeyListPanel = hotkeysWindow:getChildById('currentHotkeys')
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.bindKeyPress('Down', function() hotkeyListPanel:focusNextChild(KeyboardFocusReason) end, hotkeysWindow)
g_keyboard.bindKeyPress('Up', function() hotkeyListPanel:focusPreviousChild(KeyboardFocusReason) end, hotkeysWindow)
@ -59,22 +59,20 @@ function init()
itemWidget:setVisible(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 } )
hotkeysManagerLoaded = true
load()
end
function terminate()
hotkeysManagerLoaded = false
disconnect(g_game, { onGameEnd = hide })
disconnect(g_game, { onGameStart = onGameStart,
onGameEnd = hide })
g_keyboard.unbindKeyDown('Ctrl+K')
save()
for keyCombo,v in pairs(hotkeyList) do
g_keyboard.unbindKeyPress(keyCombo)
end
@ -119,9 +117,7 @@ function save()
end
function toggle()
if hotkeysWindow:isVisible() then
hide()
else
if not hotkeysWindow:isVisible() then
show()
end
end
@ -139,7 +135,28 @@ function hide()
hotkeysWindow:hide()
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
function onGameStart()
load()
end
function onChooseItemMouseRelease(self, mousePosition, mouseButton)
local item = nil
if mouseButton == MouseLeftButton then
@ -164,9 +181,10 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton)
hotkeyLabelSelectedOnList.itemId = item:getId()
changeUseType(HOTKEY_MANAGER_USEONSELF)
checkSelectedHotkey(hotkeyLabelSelectedOnList)
show()
end
show()
g_mouse.restoreCursor()
self:ungrabMouse()
self:destroy()
@ -196,56 +214,13 @@ function clearObject()
end
function addHotkey()
local widget
messageBox = g_ui.createWidget('MainWindow', rootWidget)
messageBox:grabKeyboard()
messageBox:setId('assignWindow')
messageBox:setText(tr('Button Assign'))
messageBox:setWidth(420)
messageBox:setHeight(140)
messageBox:setDraggable(false)
widget = g_ui.createWidget('Label', messageBox)
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)
local assignWindow = g_ui.createWidget('HotkeyAssignWindow', rootWidget)
assignWindow:grabKeyboard()
local comboLabel = assignWindow:getChildById('comboPreview')
comboLabel.keyCombo = ''
connect(assignWindow, { onKeyDown = hotkeyCapture }, true)
end
function addKeyCombo(messageBox, keyCombo, keySettings)

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

@ -11,10 +11,10 @@ HotkeyListLabel < UILabel
MainWindow
id: hotkeysWindow
!text: tr('Hotkeys')
size: 340 460
size: 340 410
@onEnter: modules.game_hotkeys.hide()
@onEscape: modules.game_hotkeys.hide()
@onEnter: modules.game_hotkeys.ok()
@onEscape: modules.game_hotkeys.cancel()
Label
id: currentHotkeysLabel
@ -38,7 +38,6 @@ MainWindow
anchors.right: prev.left
anchors.top: prev.top
anchors.bottom: prev.bottom
padding: 1
focusable: false
Label
@ -52,9 +51,9 @@ MainWindow
id: addHotkeyButton
!text: tr('Add')
width: 64
anchors.left: parent.left
anchors.top: prev.bottom
margin-top: 2
anchors.right: next.left
anchors.top: next.top
margin-right: 5
@onClick: modules.game_hotkeys.addHotkey()
Button
@ -62,9 +61,9 @@ MainWindow
!text: tr('Remove')
width: 64
enabled: false
anchors.left: prev.right
anchors.top: prev.top
margin-left: 10
anchors.right: parent.right
anchors.top: currentHotkeys.bottom
margin-top: 8
@onClick: modules.game_hotkeys.removeHotkey()
Label
@ -74,7 +73,7 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin-top: 20
margin-top: 10
TextEdit
id: hotkeyText
@ -82,7 +81,7 @@ MainWindow
anchors.left: parent.left
anchors.right: parent.right
anchors.top: prev.bottom
margin-bottom: 2
margin-top: 2
@onTextChange: modules.game_hotkeys.onHotkeyTextChange(self:getId(), self:getText())
CheckBox
@ -92,7 +91,7 @@ MainWindow
anchors.right: parent.right
anchors.top: prev.bottom
enabled:false
margin-top: 10
margin-top: 5
@onCheckChange: modules.game_hotkeys.setSendAutomatically(self:isChecked())
Item
@ -167,8 +166,61 @@ MainWindow
margin-bottom: 10
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
anchors.right: parent.right
anchors.bottom: parent.bottom
@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: modules.game_hotkeys.hide()
@onClick: self:getParent():destroy()

@ -65,12 +65,6 @@ void Item::draw(const Point& dest, float scaleFactor, bool animate, LightView *l
// determine animation phase
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
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 exactSize = 0;
calculatePatterns(xPattern, yPattern, zPattern);
animationPhase = calculateAnimationPhase(true);
for(layer = 0; layer < getLayers(); ++layer)
exactSize = std::max(exactSize, Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase));
return exactSize;
return Thing::getExactSize(layer, xPattern, yPattern, zPattern, animationPhase);
}
const ThingTypePtr& Item::getThingType()

Loading…
Cancel
Save