mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
Minimap, hotkeys and lot of other changes
* Begin working on a new layout system for UIMinimap and later UIMap, this new layout system allows to add widgets to the minimap * Add option to disable motd * Rework hotkey binding * Lots of fixes in hotkeys manager * Add fullmap view using Ctrl+Shift+M * Prevent some crashs in ThingType draw * Add function to load minimap from PNG files * Fixes in minimap saving * Fixes in Tile::isClickable * Add UIMapAnchorLayout, new layout for maps * Fix freezes in win32 when pressing alt key
This commit is contained in:
@@ -55,7 +55,7 @@ end
|
||||
function init()
|
||||
connect(g_app, { onRun = startup,
|
||||
onExit = exit })
|
||||
|
||||
|
||||
g_window.setMinimumSize({ width = 600, height = 480 })
|
||||
g_sounds.preload(musicFilename)
|
||||
|
||||
|
@@ -12,7 +12,6 @@ Module
|
||||
load-later:
|
||||
- client_styles
|
||||
- client_locales
|
||||
//- client_particles
|
||||
- client_topmenu
|
||||
- client_background
|
||||
- client_entergame
|
||||
|
@@ -1,18 +1,19 @@
|
||||
-- private variables
|
||||
local background
|
||||
local clientVersionLabel
|
||||
|
||||
-- public functions
|
||||
function init()
|
||||
background = g_ui.displayUI('background')
|
||||
background:lower()
|
||||
|
||||
local clientVersionLabel = background:getChildById('clientVersionLabel')
|
||||
clientVersionLabel = background:getChildById('clientVersionLabel')
|
||||
clientVersionLabel:setText(g_app.getName() .. ' ' .. g_app.getVersion() .. '\n' ..
|
||||
'Rev ' .. g_app.getBuildRevision() .. ' ('.. g_app.getBuildCommit() .. ')\n' ..
|
||||
'Built on ' .. g_app.getBuildDate())
|
||||
|
||||
if not g_game.isOnline() then
|
||||
g_effects.fadeIn(clientVersionLabel, 1500)
|
||||
addEvent(function() g_effects.fadeIn(clientVersionLabel, 1500) end)
|
||||
end
|
||||
|
||||
connect(g_game, { onGameStart = hide })
|
||||
@@ -40,3 +41,7 @@ end
|
||||
function hideVersionLabel()
|
||||
background:getChildById('clientVersionLabel'):hide()
|
||||
end
|
||||
|
||||
function setVersionText(text)
|
||||
clientVersionLabel:setText(text)
|
||||
end
|
||||
|
@@ -111,7 +111,7 @@ end
|
||||
|
||||
function onGameConnectionError(message, code)
|
||||
CharacterList.destroyLoadBox()
|
||||
errorBox = displayErrorBox(tr("Login Error"), message)
|
||||
errorBox = displayErrorBox(tr("Connection Error"), message)
|
||||
errorBox.onOk = function()
|
||||
errorBox = nil
|
||||
CharacterList.showAgain()
|
||||
|
@@ -8,6 +8,7 @@ local motdButton
|
||||
local enterGameButton
|
||||
local protocolBox
|
||||
local protocolLogin
|
||||
local motdEnabled = true
|
||||
|
||||
-- private functions
|
||||
local function onError(protocol, message, errorCode)
|
||||
@@ -27,7 +28,9 @@ end
|
||||
local function onMotd(protocol, motd)
|
||||
G.motdNumber = tonumber(motd:sub(0, motd:find("\n")))
|
||||
G.motdMessage = motd:sub(motd:find("\n") + 1, #motd)
|
||||
motdButton:show()
|
||||
if motdEnabled then
|
||||
motdButton:show()
|
||||
end
|
||||
end
|
||||
|
||||
local function onCharacterList(protocol, characters, account, otui)
|
||||
@@ -45,12 +48,14 @@ local function onCharacterList(protocol, characters, account, otui)
|
||||
CharacterList.create(characters, account, otui)
|
||||
CharacterList.show()
|
||||
|
||||
local lastMotdNumber = g_settings.getNumber("motd")
|
||||
if G.motdNumber and G.motdNumber ~= lastMotdNumber then
|
||||
g_settings.set("motd", motdNumber)
|
||||
motdWindow = displayInfoBox(tr('Message of the day'), G.motdMessage)
|
||||
connect(motdWindow, { onOk = function() CharacterList.show() motdWindow = nil end })
|
||||
CharacterList.hide()
|
||||
if motdEnabled then
|
||||
local lastMotdNumber = g_settings.getNumber("motd")
|
||||
if G.motdNumber and G.motdNumber ~= lastMotdNumber then
|
||||
g_settings.set("motd", motdNumber)
|
||||
motdWindow = displayInfoBox(tr('Message of the day'), G.motdMessage)
|
||||
connect(motdWindow, { onOk = function() CharacterList.show() motdWindow = nil end })
|
||||
CharacterList.hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -81,7 +86,7 @@ function EnterGame.init()
|
||||
motdButton:hide()
|
||||
g_keyboard.bindKeyDown('Ctrl+G', EnterGame.openWindow)
|
||||
|
||||
if G.motdNumber then
|
||||
if motdEnabled and G.motdNumber then
|
||||
motdButton:show()
|
||||
end
|
||||
|
||||
@@ -127,13 +132,15 @@ function EnterGame.firstShow()
|
||||
local host = g_settings.get('host')
|
||||
local autologin = g_settings.getBoolean('autologin')
|
||||
if #host > 0 and #password > 0 and #account > 0 and autologin then
|
||||
autoLoginEvent = addEvent(EnterGame.doLogin)
|
||||
connect(g_app, { onRun = function()
|
||||
if not g_settings.getBoolean('autologin') then return end
|
||||
EnterGame.doLogin()
|
||||
end})
|
||||
end
|
||||
end
|
||||
|
||||
function EnterGame.terminate()
|
||||
g_keyboard.unbindKeyDown('Ctrl+G')
|
||||
removeEvent(autoLoginEvent)
|
||||
enterGame:destroy()
|
||||
enterGame = nil
|
||||
enterGameButton:destroy()
|
||||
@@ -186,7 +193,6 @@ function EnterGame.clearAccountFields()
|
||||
end
|
||||
|
||||
function EnterGame.doLogin()
|
||||
autoLoginEvent = nil
|
||||
G.account = enterGame:getChildById('accountNameTextEdit'):getText()
|
||||
G.password = enterGame:getChildById('accountPasswordTextEdit'):getText()
|
||||
G.host = enterGame:getChildById('serverHostTextEdit'):getText()
|
||||
@@ -252,10 +258,6 @@ function EnterGame.setDefaultServer(host, port, protocol)
|
||||
protocolBox:setCurrentOption(protocol)
|
||||
accountTextEdit:setText('')
|
||||
passwordTextEdit:setText('')
|
||||
|
||||
if autoLoginEvent then
|
||||
autoLoginEvent:cancel()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -297,3 +299,7 @@ function EnterGame.setServerInfo(message)
|
||||
label:setText(message)
|
||||
end
|
||||
|
||||
function EnterGame.disableMotd()
|
||||
motdEnabled = false
|
||||
motdButton:hide()
|
||||
end
|
||||
|
@@ -25,6 +25,8 @@ end
|
||||
function terminate()
|
||||
disconnect(g_game, { onGameStart = onGameStart,
|
||||
onGameEnd = onGameEnd })
|
||||
removeEvent(firstReportEvent)
|
||||
removeEvent(sendReportEvent)
|
||||
end
|
||||
|
||||
function configure(host, port, delay)
|
||||
@@ -45,13 +47,15 @@ end
|
||||
|
||||
function onGameStart()
|
||||
if not HOST then return end
|
||||
removeEvent(firstReportEvent)
|
||||
removeEvent(sendReportEvent)
|
||||
firstReportEvent = addEvent(sendReport, FIRST_REPORT_DELAY*1000)
|
||||
sendReportEvent = cycleEvent(sendReport, REPORT_DELAY*1000)
|
||||
end
|
||||
|
||||
function onGameEnd()
|
||||
removeEvent(sendReportEvent)
|
||||
removeEvent(firstReportEvent)
|
||||
removeEvent(sendReportEvent)
|
||||
end
|
||||
|
||||
function onConnect(protocol)
|
||||
@@ -84,6 +88,7 @@ function onConnect(protocol)
|
||||
post = post .. '&cpu=' .. g_platform.getCPUName()
|
||||
post = post .. '&mem=' .. g_platform.getTotalSystemMemory()
|
||||
post = post .. '&os_name=' .. g_platform.getOSName()
|
||||
post = post .. getAdditionalData()
|
||||
|
||||
local message = ''
|
||||
message = message .. "POST /report HTTP/1.1\r\n"
|
||||
@@ -98,6 +103,10 @@ function onConnect(protocol)
|
||||
protocol:recv()
|
||||
end
|
||||
|
||||
function getAdditionalData()
|
||||
return ''
|
||||
end
|
||||
|
||||
function onRecv(protocol, message)
|
||||
if string.find(message, 'HTTP/1.1 200 OK') then
|
||||
--pinfo('Stats sent to server successfully!')
|
||||
|
@@ -4,7 +4,6 @@ g_keyboard = {}
|
||||
-- private functions
|
||||
function translateKeyCombo(keyCombo)
|
||||
if not keyCombo or #keyCombo == 0 then return nil end
|
||||
table.sort(keyCombo)
|
||||
local keyComboDesc = ''
|
||||
for k,v in pairs(keyCombo) do
|
||||
local keyDesc = KeyCodeDescs[v]
|
||||
@@ -65,47 +64,29 @@ function determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||
end
|
||||
table.insert(keyCombo, keyCode)
|
||||
end
|
||||
table.sort(keyCombo)
|
||||
return translateKeyCombo(keyCombo)
|
||||
end
|
||||
|
||||
local function onWidgetKeyDown(widget, keyCode, keyboardModifiers)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local callback = widget.boundAloneKeyDownCombos[determineKeyComboDesc(keyCode, KeyboardNoModifier)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
end
|
||||
signalcall(callback, widget, keyCode)
|
||||
callback = widget.boundKeyDownCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
return signalcall(callback, widget, keyCode)
|
||||
end
|
||||
|
||||
local function onWidgetKeyUp(widget, keyCode, keyboardModifiers)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local callback = widget.boundAloneKeyUpCombos[determineKeyComboDesc(keyCode, KeyboardNoModifier)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
end
|
||||
signalcall(callback, widget, keyCode)
|
||||
callback = widget.boundKeyUpCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
|
||||
if callback then
|
||||
callback(widget, keyCode)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
return signalcall(callback, widget, keyCode)
|
||||
end
|
||||
|
||||
local function onWidgetKeyPress(widget, keyCode, keyboardModifiers, autoRepeatTicks)
|
||||
if keyCode == KeyUnknown then return false end
|
||||
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
|
||||
local comboConf = widget.boundKeyPressCombos[keyComboDesc]
|
||||
if comboConf and (autoRepeatTicks >= comboConf.autoRepeatDelay or autoRepeatTicks == 0) and comboConf.callback then
|
||||
comboConf.callback(widget, keyCode)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
local callback = widget.boundKeyPressCombos[determineKeyComboDesc(keyCode, keyboardModifiers)]
|
||||
return signalcall(callback, widget, keyCode, autoRepeatTicks)
|
||||
end
|
||||
|
||||
local function connectKeyDownEvent(widget)
|
||||
@@ -133,13 +114,10 @@ function g_keyboard.bindKeyDown(keyComboDesc, callback, widget, alone)
|
||||
widget = widget or rootWidget
|
||||
connectKeyDownEvent(widget)
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if widget.boundKeyDownCombos[keyComboDesc] then
|
||||
pwarning('KeyDown event \'' .. keyComboDesc .. '\' redefined on widget ' .. widget:getId())
|
||||
end
|
||||
if alone then
|
||||
widget.boundAloneKeyDownCombos[keyComboDesc] = callback
|
||||
connect(widget.boundAloneKeyDownCombos, keyComboDesc, callback)
|
||||
else
|
||||
widget.boundKeyDownCombos[keyComboDesc] = callback
|
||||
connect(widget.boundKeyDownCombos, keyComboDesc, callback)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -147,53 +125,50 @@ function g_keyboard.bindKeyUp(keyComboDesc, callback, widget, alone)
|
||||
widget = widget or rootWidget
|
||||
connectKeyUpEvent(widget)
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if widget.boundKeyUpCombos[keyComboDesc] then
|
||||
pwarning('KeyUp event \'' .. keyComboDesc .. '\' redefined on widget ' .. widget:getId())
|
||||
end
|
||||
if alone then
|
||||
widget.boundAloneKeyUpCombos[keyComboDesc] = callback
|
||||
connect(widget.boundAloneKeyUpCombos, keyComboDesc, callback)
|
||||
else
|
||||
widget.boundKeyUpCombos[keyComboDesc] = callback
|
||||
connect(widget.boundKeyUpCombos, keyComboDesc, callback)
|
||||
end
|
||||
end
|
||||
|
||||
function g_keyboard.bindKeyPress(keyComboDesc, callback, widget, autoRepeatDelay)
|
||||
autoRepeatDelay = autoRepeatDelay or 500
|
||||
function g_keyboard.bindKeyPress(keyComboDesc, callback, widget)
|
||||
widget = widget or rootWidget
|
||||
connectKeyPressEvent(widget)
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if widget.boundKeyPressCombos[keyComboDesc] then
|
||||
pwarning('KeyPress event \'' .. keyComboDesc .. '\' redefined on widget ' .. widget:getId())
|
||||
end
|
||||
widget.boundKeyPressCombos[keyComboDesc] = { callback = callback, autoRepeatDelay = autoRepeatDelay }
|
||||
widget:setAutoRepeatDelay(math.min(autoRepeatDelay, widget:getAutoRepeatDelay()))
|
||||
connect(widget.boundKeyPressCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyDown(keyComboDesc, widget)
|
||||
local function getUnbindArgs(arg1, arg2)
|
||||
local callback
|
||||
local widget
|
||||
if type(arg1) == 'function' then callback = arg1
|
||||
elseif type(arg2) == 'function' then callback = arg2 end
|
||||
if type(arg1) == 'userdata' then widget = arg1
|
||||
elseif type(arg2) == 'userdata' then widget = arg2 end
|
||||
widget = widget or rootWidget
|
||||
return callback, widget
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyDown(keyComboDesc, arg1, arg2)
|
||||
local callback, widget = getUnbindArgs(arg1, arg2)
|
||||
if widget.boundKeyDownCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyDownCombos[keyComboDesc] = nil
|
||||
end
|
||||
disconnect(widget.boundKeyDownCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyUp(keyComboDesc, widget)
|
||||
widget = widget or rootWidget
|
||||
local callback, widget = getUnbindArgs(arg1, arg2)
|
||||
if widget.boundKeyUpCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyUpCombos[keyComboDesc] = nil
|
||||
end
|
||||
disconnect(widget.boundKeyUpCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.unbindKeyPress(keyComboDesc, widget)
|
||||
widget = widget or rootWidget
|
||||
function g_keyboard.unbindKeyPress(keyComboDesc, widget, callback)
|
||||
local callback, widget = getUnbindArgs(arg1, arg2)
|
||||
if widget.boundKeyPressCombos == nil then return end
|
||||
local keyComboDesc = retranslateKeyComboDesc(keyComboDesc)
|
||||
if keyComboDesc then
|
||||
widget.boundKeyPressCombos[keyComboDesc] = nil
|
||||
end
|
||||
disconnect(widget.boundKeyPressCombos, keyComboDesc, callback)
|
||||
end
|
||||
|
||||
function g_keyboard.getModifiers()
|
||||
|
@@ -13,6 +13,12 @@ function table.dump(t, depth)
|
||||
end
|
||||
end
|
||||
|
||||
function table.clear(t)
|
||||
for k,v in pairs(t) do
|
||||
t[k] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function table.copy(t)
|
||||
local res = {}
|
||||
for k,v in pairs(t) do
|
||||
|
@@ -224,7 +224,9 @@ end
|
||||
|
||||
function UIScrollBar:setText(text)
|
||||
local valueLabel = self:getChildById('valueLabel')
|
||||
valueLabel:setText(text)
|
||||
if valueLabel then
|
||||
valueLabel:setText(text)
|
||||
end
|
||||
end
|
||||
|
||||
function UIScrollBar:onGeometryChange()
|
||||
|
@@ -67,6 +67,11 @@ function connect(object, arg1, arg2, arg3)
|
||||
elseif type(object[signal]) == 'function' then
|
||||
object[signal] = { object[signal] }
|
||||
end
|
||||
|
||||
if type(slot) ~= 'function' then
|
||||
perror(debug.traceback('unable to connect a non function value'))
|
||||
end
|
||||
|
||||
if type(object[signal]) == 'table' then
|
||||
if pushFront then
|
||||
table.insert(object[signal], 1, slot)
|
||||
@@ -80,9 +85,15 @@ end
|
||||
function disconnect(object, arg1, arg2)
|
||||
local signalsAndSlots
|
||||
if type(arg1) == 'string' then
|
||||
if arg2 == nil then
|
||||
object[arg1] = nil
|
||||
return
|
||||
end
|
||||
signalsAndSlots = { [arg1] = arg2 }
|
||||
else
|
||||
elseif type(arg1) == 'table' then
|
||||
signalsAndSlots = arg1
|
||||
else
|
||||
perror(debug.traceback('unable to disconnect'))
|
||||
end
|
||||
|
||||
for signal,slot in pairs(signalsAndSlots) do
|
||||
|
@@ -34,6 +34,7 @@ perCharacter = true
|
||||
mouseGrabberWidget = nil
|
||||
useRadioGroup = nil
|
||||
currentHotkeys = nil
|
||||
boundCombosCallback = {}
|
||||
hotkeysList = {}
|
||||
|
||||
-- public functions
|
||||
@@ -149,6 +150,7 @@ function load(forceDefaults)
|
||||
if not forceDefaults then
|
||||
if not table.empty(hotkeys) then
|
||||
for keyCombo, setting in pairs(hotkeys) do
|
||||
keyCombo = tostring(keyCombo)
|
||||
addKeyCombo(keyCombo, setting)
|
||||
hotkeyList[keyCombo] = setting
|
||||
end
|
||||
@@ -163,12 +165,13 @@ function load(forceDefaults)
|
||||
end
|
||||
|
||||
function unload()
|
||||
for _,child in pairs(currentHotkeys:getChildren()) do
|
||||
g_keyboard.unbindKeyPress(child.keyCombo)
|
||||
for keyCombo,callback in pairs(boundCombosCallback) do
|
||||
g_keyboard.unbindKeyPress(keyCombo, callback)
|
||||
end
|
||||
boundCombosCallback = {}
|
||||
currentHotkeys:destroyChildren()
|
||||
currentHotkeyLabel = nil
|
||||
updateHotkeyForm()
|
||||
updateHotkeyForm(true)
|
||||
hotkeyList = {}
|
||||
end
|
||||
|
||||
@@ -196,6 +199,8 @@ function save()
|
||||
hotkeys = hotkeys[g_game.getCharacterName()]
|
||||
end
|
||||
|
||||
table.clear(hotkeys)
|
||||
|
||||
for _,child in pairs(currentHotkeys:getChildren()) do
|
||||
hotkeys[child.keyCombo] = {
|
||||
autoSend = child.autoSend,
|
||||
@@ -207,7 +212,7 @@ function save()
|
||||
|
||||
hotkeyList = hotkeys
|
||||
g_settings.setNode('game_hotkeys', hotkeySettings)
|
||||
--g_settings.save()
|
||||
g_settings.save()
|
||||
end
|
||||
|
||||
function loadDefautComboKeys()
|
||||
@@ -258,7 +263,7 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton)
|
||||
currentHotkeyLabel.value = nil
|
||||
currentHotkeyLabel.autoSend = false
|
||||
updateHotkeyLabel(currentHotkeyLabel)
|
||||
updateHotkeyForm()
|
||||
updateHotkeyForm(true)
|
||||
end
|
||||
|
||||
show()
|
||||
@@ -281,7 +286,7 @@ function clearObject()
|
||||
currentHotkeyLabel.autoSend = nil
|
||||
currentHotkeyLabel.value = nil
|
||||
updateHotkeyLabel(currentHotkeyLabel)
|
||||
updateHotkeyForm()
|
||||
updateHotkeyForm(true)
|
||||
end
|
||||
|
||||
function addHotkey()
|
||||
@@ -294,6 +299,7 @@ function addHotkey()
|
||||
end
|
||||
|
||||
function addKeyCombo(keyCombo, keySettings, focus)
|
||||
if keyCombo == nil or #keyCombo == 0 then return end
|
||||
if not keyCombo then return end
|
||||
local hotkeyLabel = currentHotkeys:getChildById(keyCombo)
|
||||
if not hotkeyLabel then
|
||||
@@ -321,27 +327,28 @@ function addKeyCombo(keyCombo, keySettings, focus)
|
||||
if keySettings then
|
||||
currentHotkeyLabel = hotkeyLabel
|
||||
hotkeyLabel.keyCombo = keyCombo
|
||||
hotkeyLabel.autoSend = keySettings.autoSend
|
||||
hotkeyLabel.itemId = keySettings.itemId
|
||||
hotkeyLabel.autoSend = toboolean(keySettings.autoSend)
|
||||
hotkeyLabel.itemId = tonumber(keySettings.itemId)
|
||||
hotkeyLabel.useType = tonumber(keySettings.useType)
|
||||
hotkeyLabel.value = keySettings.value
|
||||
if keySettings.value then hotkeyLabel.value = tostring(keySettings.value) end
|
||||
else
|
||||
hotkeyLabel.keyCombo = keyCombo
|
||||
hotkeyLabel.autoSend = nil
|
||||
hotkeyLabel.autoSend = false
|
||||
hotkeyLabel.itemId = nil
|
||||
hotkeyLabel.useType = nil
|
||||
hotkeyLabel.value = nil
|
||||
hotkeyLabel.value = ''
|
||||
end
|
||||
|
||||
updateHotkeyLabel(hotkeyLabel)
|
||||
|
||||
g_keyboard.bindKeyPress(keyCombo, function() doKeyCombo(keyCombo) end, nil, 350)
|
||||
boundCombosCallback[keyCombo] = function() doKeyCombo(keyCombo) end
|
||||
g_keyboard.bindKeyPress(keyCombo, boundCombosCallback[keyCombo])
|
||||
end
|
||||
|
||||
if focus then
|
||||
currentHotkeys:focusChild(hotkeyLabel)
|
||||
currentHotkeys:ensureChildVisible(hotkeyLabel)
|
||||
updateHotkeyForm()
|
||||
updateHotkeyForm(true)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -398,7 +405,7 @@ function updateHotkeyLabel(hotkeyLabel)
|
||||
end
|
||||
end
|
||||
|
||||
function updateHotkeyForm()
|
||||
function updateHotkeyForm(reset)
|
||||
if currentHotkeyLabel then
|
||||
removeHotkeyButton:enable()
|
||||
if currentHotkeyLabel.itemId ~= nil then
|
||||
@@ -435,8 +442,10 @@ function updateHotkeyForm()
|
||||
hotkeyText:enable()
|
||||
hotkeyText:focus()
|
||||
hotKeyTextLabel:enable()
|
||||
if reset then
|
||||
hotkeyText:setCursorPos(-1)
|
||||
end
|
||||
hotkeyText:setText(currentHotkeyLabel.value)
|
||||
hotkeyText:setCursorPos(-1)
|
||||
sendAutomatically:setChecked(currentHotkeyLabel.autoSend)
|
||||
sendAutomatically:setEnabled(currentHotkeyLabel.value and #currentHotkeyLabel.value > 0)
|
||||
selectObjectButton:enable()
|
||||
@@ -461,7 +470,8 @@ end
|
||||
|
||||
function removeHotkey()
|
||||
if currentHotkeyLabel == nil then return end
|
||||
g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo)
|
||||
g_keyboard.unbindKeyPress(currentHotkeyLabel.keyCombo, boundCombosCallback[currentHotkeyLabel.keyCombo])
|
||||
boundCombosCallback[currentHotkeyLabel.keyCombo] = nil
|
||||
currentHotkeyLabel:destroy()
|
||||
currentHotkeyLabel = nil
|
||||
end
|
||||
@@ -504,7 +514,7 @@ end
|
||||
|
||||
function onSelectHotkeyLabel(hotkeyLabel)
|
||||
currentHotkeyLabel = hotkeyLabel
|
||||
updateHotkeyForm()
|
||||
updateHotkeyForm(true)
|
||||
end
|
||||
|
||||
function hotkeyCapture(assignWindow, keyCode, keyboardModifiers)
|
||||
|
@@ -1,4 +1,3 @@
|
||||
WALK_AUTO_REPEAT_DELAY = 90
|
||||
WALK_STEPS_RETRY = 10
|
||||
|
||||
gameRootPanel = nil
|
||||
@@ -25,7 +24,7 @@ function init()
|
||||
onGameStart = onGameStart,
|
||||
onGMActions = onGMActions,
|
||||
onGameEnd = onGameEnd,
|
||||
onLoginAdvice = onLoginAdvice
|
||||
onLoginAdvice = onLoginAdvice,
|
||||
}, true)
|
||||
|
||||
gameRootPanel = g_ui.displayUI('gameinterface')
|
||||
@@ -57,6 +56,7 @@ function init()
|
||||
end
|
||||
|
||||
function bindKeys()
|
||||
gameRootPanel:setAutoRepeatDelay(250)
|
||||
g_keyboard.bindKeyDown('Up', function() changeWalkDir(North) end, gameRootPanel, true)
|
||||
g_keyboard.bindKeyDown('Right', function() changeWalkDir(East) end, gameRootPanel, true)
|
||||
g_keyboard.bindKeyDown('Down', function() changeWalkDir(South) end, gameRootPanel, true)
|
||||
@@ -81,30 +81,30 @@ function bindKeys()
|
||||
g_keyboard.bindKeyUp('Numpad1', function() changeWalkDir(SouthWest, true) end, gameRootPanel, true)
|
||||
g_keyboard.bindKeyUp('Numpad4', function() changeWalkDir(West, true) end, gameRootPanel, true)
|
||||
g_keyboard.bindKeyUp('Numpad7', function() changeWalkDir(NorthWest, true) end, gameRootPanel, true)
|
||||
g_keyboard.bindKeyPress('Up', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Right', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Down', function() smartWalk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Left', function() smartWalk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad8', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad9', function() smartWalk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad6', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad3', function() smartWalk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad2', function() smartWalk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad1', function() smartWalk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad4', function() smartWalk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Numpad7', function() smartWalk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Up', function() smartWalk(North) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Right', function() smartWalk(East) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Down', function() smartWalk(South) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Left', function() smartWalk(West) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad8', function() smartWalk(North) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad9', function() smartWalk(NorthEast) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad6', function() smartWalk(East) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad3', function() smartWalk(SouthEast) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad2', function() smartWalk(South) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad1', function() smartWalk(SouthWest) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad4', function() smartWalk(West) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Numpad7', function() smartWalk(NorthWest) end, gameRootPanel)
|
||||
|
||||
g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
|
||||
g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel, 250)
|
||||
g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel, 250)
|
||||
g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Left', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad8', function() g_game.turn(North) changeWalkDir(North) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad6', function() g_game.turn(East) changeWalkDir(East) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad2', function() g_game.turn(South) changeWalkDir(South) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+Numpad4', function() g_game.turn(West) changeWalkDir(West) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Escape', function() g_game.cancelAttackAndFollow() end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+=', function() gameMapPanel:zoomIn() end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Ctrl+-', function() gameMapPanel:zoomOut() end, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+Q', logout, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+L', logout, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+W', function() g_map.cleanTexts() modules.game_textmessage.clearMessages() end, gameRootPanel)
|
||||
@@ -591,7 +591,6 @@ function processMouseAction(menuPosition, mouseButton, autoWalkPos, lookThing, u
|
||||
player:stopAutoWalk()
|
||||
|
||||
if autoWalkPos and keyboardModifiers == KeyboardNoModifier and mouseButton == MouseLeftButton then
|
||||
player.onAutoWalkFail = function() modules.game_textmessage.displayFailureMessage(tr('There is no way.')) end
|
||||
player:autoWalk(autoWalkPos)
|
||||
return true
|
||||
end
|
||||
|
@@ -3,6 +3,9 @@ minimapButton = nil
|
||||
minimapWindow = nil
|
||||
otmm = true
|
||||
preloaded = false
|
||||
fullmapView = false
|
||||
oldZoom = nil
|
||||
oldPos = nil
|
||||
|
||||
function init()
|
||||
minimapButton = modules.client_topmenu.addRightGameToggleButton('minimapButton', tr('Minimap') .. ' (Ctrl+M)', '/images/topbuttons/minimap', toggle)
|
||||
@@ -19,6 +22,7 @@ function init()
|
||||
g_keyboard.bindKeyPress('Alt+Up', function() minimapWidget:move(0,1) end, gameRootPanel)
|
||||
g_keyboard.bindKeyPress('Alt+Down', function() minimapWidget:move(0,-1) end, gameRootPanel)
|
||||
g_keyboard.bindKeyDown('Ctrl+M', toggle)
|
||||
g_keyboard.bindKeyDown('Ctrl+Shift+M', toggleFullMap)
|
||||
|
||||
minimapWindow:setup()
|
||||
|
||||
@@ -27,6 +31,10 @@ function init()
|
||||
onGameEnd = offline,
|
||||
})
|
||||
|
||||
connect(LocalPlayer, {
|
||||
onPositionChange = updateCameraPosition
|
||||
})
|
||||
|
||||
if g_game.isOnline() then
|
||||
online()
|
||||
end
|
||||
@@ -48,6 +56,7 @@ function terminate()
|
||||
g_keyboard.unbindKeyPress('Alt+Up', gameRootPanel)
|
||||
g_keyboard.unbindKeyPress('Alt+Down', gameRootPanel)
|
||||
g_keyboard.unbindKeyDown('Ctrl+M')
|
||||
g_keyboard.unbindKeyDown('Ctrl+Shift+M')
|
||||
|
||||
minimapWindow:destroy()
|
||||
minimapButton:destroy()
|
||||
@@ -74,7 +83,6 @@ end
|
||||
|
||||
function online()
|
||||
loadMap(not preloaded)
|
||||
minimapWidget:followLocalPlayer()
|
||||
end
|
||||
|
||||
function offline()
|
||||
@@ -114,6 +122,36 @@ function saveMap()
|
||||
minimapWidget:save()
|
||||
end
|
||||
|
||||
function getMinimap()
|
||||
return minimapWidget
|
||||
function updateCameraPosition()
|
||||
local player = g_game.getLocalPlayer()
|
||||
if not minimapWidget:isDragging() then
|
||||
if not fullmapView then
|
||||
minimapWidget:setCameraPosition(player:getPosition())
|
||||
end
|
||||
minimapWidget:setCrossPosition(player:getPosition())
|
||||
end
|
||||
end
|
||||
|
||||
function toggleFullMap()
|
||||
if not fullmapView then
|
||||
fullmapView = true
|
||||
minimapWindow:hide()
|
||||
minimapWidget:setParent(modules.game_interface.getRootPanel())
|
||||
minimapWidget:fill('parent')
|
||||
minimapWidget:setAlternativeWidgetsVisible(true)
|
||||
else
|
||||
fullmapView = false
|
||||
minimapWidget:setParent(minimapWindow:getChildById('contentsPanel'))
|
||||
minimapWidget:fill('parent')
|
||||
minimapWindow:show()
|
||||
minimapWidget:setAlternativeWidgetsVisible(false)
|
||||
end
|
||||
|
||||
local zoom = oldZoom or 0
|
||||
local pos = oldPos or minimapWidget:getCameraPosition()
|
||||
pos.z = 7
|
||||
oldZoom = minimapWidget:getZoom()
|
||||
oldPos = minimapWidget:getCameraPosition()
|
||||
minimapWidget:setZoom(zoom)
|
||||
minimapWidget:setCameraPosition(pos)
|
||||
end
|
||||
|
@@ -151,7 +151,8 @@ function onTradeTypeChange(radioTabs, selected, deselected)
|
||||
ignoreCapacity:setVisible(currentTradeType == BUY)
|
||||
ignoreEquipped:setVisible(currentTradeType == SELL)
|
||||
showAllItems:setVisible(currentTradeType == SELL)
|
||||
sellAllButton:setVisible(currentTradeType == SELL)
|
||||
sellAllButton:setVisible(false)
|
||||
--sellAllButton:setVisible(currentTradeType == SELL)
|
||||
|
||||
refreshTradeItems()
|
||||
refreshPlayerGoods()
|
||||
|
@@ -252,6 +252,7 @@ MainWindow
|
||||
margin-right: 10
|
||||
visible: false
|
||||
@onClick: modules.game_npctrade.sellAll()
|
||||
visible: false
|
||||
|
||||
Button
|
||||
id: tradeButton
|
||||
|
@@ -123,3 +123,7 @@ function clearMessages()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function LocalPlayer:onAutoWalkFail(player)
|
||||
modules.game_textmessage.displayFailureMessage(tr('There is no way.'))
|
||||
end
|
||||
|
@@ -3,7 +3,8 @@ vipButton = nil
|
||||
addVipWindow = nil
|
||||
|
||||
function init()
|
||||
connect(g_game, { onGameEnd = clear,
|
||||
connect(g_game, { onGameStart = refresh,
|
||||
onGameEnd = clear,
|
||||
onAddVip = onAddVip,
|
||||
onVipStateChange = onVipStateChange })
|
||||
|
||||
@@ -20,7 +21,8 @@ end
|
||||
|
||||
function terminate()
|
||||
g_keyboard.unbindKeyDown('Ctrl+P')
|
||||
disconnect(g_game, { onGameEnd = clear,
|
||||
disconnect(g_game, { onGameStart = refresh,
|
||||
onGameEnd = clear,
|
||||
onAddVip = onAddVip,
|
||||
onVipStateChange = onVipStateChange })
|
||||
|
||||
|
@@ -161,4 +161,4 @@ function Player:hasState(_state, states)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@@ -1,45 +1,39 @@
|
||||
function UIMinimap:onSetup()
|
||||
self.flagWindow = nil
|
||||
self.flagsWidget = self:getChildById('flags')
|
||||
self.floorUpWidget = self:getChildById('floorUp')
|
||||
self.floorDownWidget = self:getChildById('floorDown')
|
||||
self.zoomInWidget = self:getChildById('zoomIn')
|
||||
self.zoomOutWidget = self:getChildById('zoomOut')
|
||||
self.dx = 0
|
||||
self.dy = 0
|
||||
self.flags = {}
|
||||
self.alternatives = {}
|
||||
self.autowalk = true
|
||||
self.allowFollowLocalPlayer = true
|
||||
self.onPositionChange = function() self:followLocalPlayer() end
|
||||
self.onAddAutomapFlag = function(pos, icon, description) self:addFlag(pos, icon, description) end
|
||||
self.onRemoveAutomapFlag = function(pos, icon, description) self:removeFlag(pos, icon, description) end
|
||||
connect(g_game, {
|
||||
onAddAutomapFlag = self.onAddAutomapFlag,
|
||||
onRemoveAutomapFlag = self.onRemoveAutomapFlag,
|
||||
})
|
||||
connect(LocalPlayer, { onPositionChange = self.onPositionChange })
|
||||
end
|
||||
|
||||
function UIMinimap:onDestroy()
|
||||
disconnect(LocalPlayer, { onPositionChange = self.onPositionChange })
|
||||
for _,widget in pairs(self.alternatives) do
|
||||
widget:destroy()
|
||||
end
|
||||
self.alternatives = {}
|
||||
disconnect(g_game, {
|
||||
onAddAutomapFlag = self.onAddAutomapFlag,
|
||||
onRemoveAutomapFlag = self.onRemoveAutomapFlag,
|
||||
})
|
||||
self:destroyFlagWindow()
|
||||
self:destroyFullPanel()
|
||||
self.flags = {}
|
||||
end
|
||||
|
||||
function UIMinimap:onVisibilityChange()
|
||||
if not self:isVisible() then
|
||||
self:destroyFlagWindow()
|
||||
self:destroyFullPanel()
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:hideFlags()
|
||||
self.flagsWidget:hide()
|
||||
end
|
||||
|
||||
function UIMinimap:hideFloor()
|
||||
self.floorUpWidget:hide()
|
||||
self.floorDownWidget:hide()
|
||||
@@ -54,33 +48,21 @@ function UIMinimap:disableAutoWalk()
|
||||
self.autowalk = false
|
||||
end
|
||||
|
||||
function UIMinimap:disableFollowPlayer()
|
||||
self.allowFollowLocalPlayer = false
|
||||
end
|
||||
|
||||
function UIMinimap:enableFullPanel(image)
|
||||
self.fullImage = image
|
||||
end
|
||||
|
||||
function UIMinimap:load()
|
||||
local settings = g_settings.getNode('Minimap')
|
||||
if settings then
|
||||
if settings.flags then
|
||||
for i=1,#settings.flags do
|
||||
local flag = settings.flags[i]
|
||||
for _,flag in pairs(settings.flags) do
|
||||
self:addFlag(flag.position, flag.icon, flag.description)
|
||||
end
|
||||
end
|
||||
self:setZoom(settings.zoom)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:save()
|
||||
local settings = { flags={} }
|
||||
local children = self.flagsWidget:getChildren()
|
||||
for i=1,#children do
|
||||
local flag = children[i]
|
||||
for _,flag in pairs(self.flags) do
|
||||
table.insert(settings.flags, {
|
||||
position = flag.pos,
|
||||
icon = flag.icon,
|
||||
@@ -91,134 +73,114 @@ function UIMinimap:save()
|
||||
g_settings.setNode('Minimap', settings)
|
||||
end
|
||||
|
||||
function UIMinimap:addFlag(pos, icon, description)
|
||||
local flag = self:getFlag(pos, icon, description)
|
||||
if flag then
|
||||
return
|
||||
local function onFlagMouseRelease(widget, pos, button)
|
||||
if button == MouseRightButton then
|
||||
local menu = g_ui.createWidget('PopupMenu')
|
||||
menu:addOption(tr('Delete mark'), function() widget:destroy() end)
|
||||
menu:display(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
flag = g_ui.createWidget('MinimapFlag', self.flagsWidget)
|
||||
flag.pos = pos
|
||||
flag.icon = icon
|
||||
flag.description = description
|
||||
flag:setIcon('/images/game/minimap/flag' .. icon)
|
||||
flag:setTooltip(description)
|
||||
flag.onMouseRelease = function(widget, pos, button)
|
||||
if button == MouseRightButton then
|
||||
local menu = g_ui.createWidget('PopupMenu')
|
||||
menu:addOption(tr('Delete mark'), function() widget:destroy() end)
|
||||
menu:display(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
self:updateFlag(flag)
|
||||
return false
|
||||
end
|
||||
|
||||
function UIMinimap:getFlag(pos, icon, description)
|
||||
local children = self.flagsWidget:getChildren()
|
||||
for i=1,#children do
|
||||
local flag = children[i]
|
||||
function UIMinimap:setCrossPosition(pos)
|
||||
local cross = self.cross
|
||||
if not self.cross then
|
||||
cross = g_ui.createWidget('MinimapCross', self)
|
||||
cross:setIcon('/images/game/minimap/cross')
|
||||
self.cross = cross
|
||||
end
|
||||
|
||||
cross.pos = pos
|
||||
if pos then
|
||||
self:centerInPosition(cross, pos)
|
||||
else
|
||||
cross:breakAnchors()
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:addFlag(pos, icon, description)
|
||||
if not pos or not icon then return end
|
||||
local flag = self:getFlag(pos, icon, description)
|
||||
if flag or not icon then
|
||||
return
|
||||
end
|
||||
|
||||
flag = g_ui.createWidget('MinimapFlag', self)
|
||||
flag.pos = pos
|
||||
flag.description = description
|
||||
flag.icon = icon
|
||||
flag:setIcon('/images/game/minimap/flag' .. icon)
|
||||
flag:setTooltip(description)
|
||||
flag.onMouseRelease = onFlagMouseRelease
|
||||
table.insert(self.flags, flag)
|
||||
self:centerInPosition(flag, pos)
|
||||
end
|
||||
|
||||
function UIMinimap:addAlternativeWidget(widget, pos, maxZoom)
|
||||
widget.pos = pos
|
||||
widget.maxZoom = maxZoom or 0
|
||||
widget.minZoom = minZoom
|
||||
table.insert(self.alternatives, widget)
|
||||
end
|
||||
|
||||
function UIMinimap:setAlternativeWidgetsVisible(show)
|
||||
local layout = self:getLayout()
|
||||
layout:disableUpdates()
|
||||
for _,widget in pairs(self.alternatives) do
|
||||
if show then
|
||||
self:addChild(widget)
|
||||
self:centerInPosition(widget, widget.pos)
|
||||
else
|
||||
self:removeChild(widget)
|
||||
end
|
||||
end
|
||||
layout:enableUpdates()
|
||||
layout:update()
|
||||
end
|
||||
|
||||
function UIMinimap:onZoomChange(zoom)
|
||||
for _,widget in pairs(self.alternatives) do
|
||||
if (not widget.minZoom or widget.minZoom >= zoom) and widget.maxZoom <= zoom then
|
||||
widget:show()
|
||||
else
|
||||
widget:hide()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:getFlag(pos)
|
||||
for _,flag in pairs(self.flags) do
|
||||
if flag.pos.x == pos.x and flag.pos.y == pos.y and flag.pos.z == pos.z then
|
||||
return flag
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function UIMinimap:removeFlag(pos, icon, description)
|
||||
local flag = self:getFlag(pos, icon, description)
|
||||
local flag = self:getFlag(pos)
|
||||
if flag then
|
||||
flag:destroy()
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:updateFlag(flag)
|
||||
local point = self:getPoint(flag.pos)
|
||||
if self:containsPoint(point) and self:getZoom() >= 0 and flag.pos.z == self:getCameraPosition().z then
|
||||
flag:setVisible(true)
|
||||
flag:setMarginLeft(point.x - self:getX() - flag:getWidth()/2)
|
||||
flag:setMarginTop(point.y - self:getY() - flag:getHeight()/2)
|
||||
else
|
||||
flag:setVisible(false)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:updateFlags()
|
||||
local children = self.flagsWidget:getChildren()
|
||||
for i=1,#children do
|
||||
self:updateFlag(children[i])
|
||||
end
|
||||
end
|
||||
|
||||
UIMinimap.realSetCameraPosition = UIMinimap.realSetCameraPosition or UIMinimap.setCameraPosition
|
||||
function UIMinimap:setCameraPosition(pos)
|
||||
self:realSetCameraPosition(pos)
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
UIMinimap.realZoomIn = UIMinimap.realZoomIn or UIMinimap.zoomIn
|
||||
function UIMinimap:zoomIn()
|
||||
self:realZoomIn()
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
UIMinimap.realZoomOut = UIMinimap.realZoomOut or UIMinimap.zoomOut
|
||||
function UIMinimap:zoomOut()
|
||||
self:realZoomOut()
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
UIMinimap.realSetZoom = UIMinimap.realSetZoom or UIMinimap.setZoom
|
||||
function UIMinimap:setZoom(zoom)
|
||||
self:realSetZoom(zoom)
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:floorUp(floors)
|
||||
local pos = self:getCameraPosition()
|
||||
pos.z = pos.z - floors
|
||||
if pos.z >= FloorHigher then
|
||||
self:setCameraPosition(pos)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:floorDown(floors)
|
||||
local pos = self:getCameraPosition()
|
||||
pos.z = pos.z + floors
|
||||
if pos.z <= FloorLower then
|
||||
self:setCameraPosition(pos)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:followLocalPlayer()
|
||||
if not self:isDragging() and self.allowFollowLocalPlayer then
|
||||
local player = g_game.getLocalPlayer()
|
||||
self:followCreature(player)
|
||||
self:updateFlags()
|
||||
table.removevalue(self.flags, flag)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:reset()
|
||||
self:followLocalPlayer()
|
||||
self:setZoom(0)
|
||||
if self.cross then
|
||||
self:setCameraPosition(self.cross.pos)
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:move(x, y)
|
||||
local topLeft, bottomRight = self:getArea()
|
||||
self.dx = self.dx + ((bottomRight.x - topLeft.x) / self:getWidth() ) * x
|
||||
self.dy = self.dy + ((bottomRight.y - topLeft.y) / self:getHeight()) * y
|
||||
local dx = math.floor(self.dx)
|
||||
local dy = math.floor(self.dy)
|
||||
self.dx = self.dx - dx
|
||||
self.dy = self.dy - dy
|
||||
|
||||
local cameraPos = self:getCameraPosition()
|
||||
local scale = self:getScale()
|
||||
if scale > 1 then scale = 1 end
|
||||
local dx = x/scale
|
||||
local dy = y/scale
|
||||
local pos = {x = cameraPos.x - dx, y = cameraPos.y - dy, z = cameraPos.z}
|
||||
self:setCameraPosition(pos)
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:onMouseWheel(mousePos, direction)
|
||||
@@ -232,7 +194,6 @@ function UIMinimap:onMouseWheel(mousePos, direction)
|
||||
elseif direction == MouseWheelUp and keyboardModifiers == KeyboardCtrlModifier then
|
||||
self:floorDown(1)
|
||||
end
|
||||
self:updateFlags()
|
||||
end
|
||||
|
||||
function UIMinimap:onMousePress(pos, button)
|
||||
@@ -245,20 +206,18 @@ function UIMinimap:onMouseRelease(pos, button)
|
||||
if not self.allowNextRelease then return true end
|
||||
self.allowNextRelease = false
|
||||
|
||||
local mapPos = self:getPosition(pos)
|
||||
local mapPos = self:getTilePosition(pos)
|
||||
if not mapPos then return end
|
||||
|
||||
if button == MouseLeftButton then
|
||||
local player = g_game.getLocalPlayer()
|
||||
if self.autowalk then
|
||||
player.onAutoWalkFail = function() modules.game_textmessage.displayFailureMessage(tr('There is no way.')) end
|
||||
player:autoWalk(mapPos)
|
||||
end
|
||||
return true
|
||||
elseif button == MouseRightButton then
|
||||
local menu = g_ui.createWidget('PopupMenu')
|
||||
menu:addOption(tr('Create mark'), function() self:createFlagWindow(mapPos) end)
|
||||
if self.fullImage then menu:addOption(tr('Full map'), function() self:createFullPanel() end) end
|
||||
menu:display(pos)
|
||||
return true
|
||||
end
|
||||
@@ -266,11 +225,17 @@ function UIMinimap:onMouseRelease(pos, button)
|
||||
end
|
||||
|
||||
function UIMinimap:onDragEnter(pos)
|
||||
self.dragReference = pos
|
||||
self.dragCameraReference = self:getCameraPosition()
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMinimap:onDragMove(pos, moved)
|
||||
self:move(moved.x, moved.y)
|
||||
local scale = self:getScale()
|
||||
local dx = (self.dragReference.x - pos.x)/scale
|
||||
local dy = (self.dragReference.y - pos.y)/scale
|
||||
local pos = {x = self.dragCameraReference.x + dx, y = self.dragCameraReference.y + dy, z = self.dragCameraReference.z}
|
||||
self:setCameraPosition(pos)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -278,20 +243,6 @@ function UIMinimap:onDragLeave(widget, pos)
|
||||
return true
|
||||
end
|
||||
|
||||
function UIMinimap:createFullPanel()
|
||||
self.fullPanel = g_ui.createWidget('MinimapFullPanel', rootWidget)
|
||||
self.fullPanel.onDestroy = function() self.fullPanel = nil end
|
||||
local image = self.fullPanel:getChildById('image')
|
||||
image:setImage(self.fullImage)
|
||||
end
|
||||
|
||||
function UIMinimap:destroyFullPanel()
|
||||
if self.fullPanel then
|
||||
self.fullPanel:destroy()
|
||||
self.fullPanel = nil
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:createFlagWindow(pos)
|
||||
if self.flagWindow then return end
|
||||
if not pos then return end
|
||||
@@ -311,16 +262,14 @@ function UIMinimap:createFlagWindow(pos)
|
||||
checkbox.icon = i
|
||||
flagRadioGroup:addWidget(checkbox)
|
||||
end
|
||||
|
||||
|
||||
flagRadioGroup:selectWidget(flagRadioGroup:getFirstWidget())
|
||||
|
||||
|
||||
okButton.onClick = function()
|
||||
self:addFlag(pos, flagRadioGroup:getSelectedWidget().icon, description:getText())
|
||||
self:destroyFlagWindow()
|
||||
end
|
||||
cancelButton.onClick = function()
|
||||
self:destroyFlagWindow()
|
||||
end
|
||||
self:addFlag(pos, flagRadioGroup:getSelectedWidget().icon, description:getText())
|
||||
self:destroyFlagWindow()
|
||||
end
|
||||
cancelButton.onClick = function() self:destroyFlagWindow() end
|
||||
|
||||
self.flagWindow.onDestroy = function() flagRadioGroup:destroy() end
|
||||
end
|
||||
@@ -331,9 +280,3 @@ function UIMinimap:destroyFlagWindow()
|
||||
self.flagWindow = nil
|
||||
end
|
||||
end
|
||||
|
||||
function UIMinimap:getArea()
|
||||
local topLeft = self:getPosition({ x = self:getX() + 1, y = self:getY() + 1 })
|
||||
local bottomRight = self:getPosition({ x = self:getX() + self:getWidth() - 2, y = self:getY() + self:getHeight() - 2 })
|
||||
return topLeft, bottomRight
|
||||
end
|
||||
|
Reference in New Issue
Block a user