local miningWindow local miningButton local transferWindow local PLAYER_PLACEHOLDER = 'Nome do player' local function say(text) if not g_game.isOnline() then return end g_game.talk(text) end function init() g_ui.importStyle('mining') miningButton = modules.client_topmenu.addRightGameToggleButton('miningButton', 'Mining', '/images/topbuttons/mining', toggle, false, 5) miningButton:setOn(false) miningWindow = g_ui.createWidget('MiningWindow', modules.game_interface.getRightPanel()) if not miningWindow then perror('[Mining] Nao foi possivel carregar a janela mining.otui') if miningButton then miningButton:destroy() miningButton = nil end return end miningWindow:setup() miningWindow:close() setupInputs() end function terminate() if transferWindow then transferWindow:destroy() transferWindow = nil end if miningWindow then miningWindow:destroy() miningWindow = nil end if miningButton then miningButton:destroy() miningButton = nil end end local function getTransferWindow() if not transferWindow then transferWindow = g_ui.displayUI('mining_transfer') end return transferWindow end function toggle() if miningButton:isOn() then miningWindow:close() miningButton:setOn(false) else miningWindow:open() miningButton:setOn(true) end end function onMiniWindowClose() if miningButton then miningButton:setOn(false) end end function command(param) param = param or '' if param == '' then say('!mining') else say('!mining ' .. param) end end local function getEditText(id, defaultValue) if not miningWindow then return defaultValue or '' end local widget = miningWindow:recursiveGetChildById(id) if not widget then return defaultValue or '' end local value = widget:getText() if value == nil or value == '' then return defaultValue or '' end return value end function focusPlayerEdit() local window = getTransferWindow() local playerEdit = window:getChildById('playerEdit') if not playerEdit then return end if playerEdit:getText() == PLAYER_PLACEHOLDER then playerEdit:clearText() end if playerEdit.setEditable then playerEdit:setEditable(true) end window:raise() window:focus() playerEdit:focus() playerEdit:setCursorVisible(true) end function setupInputs() local window = getTransferWindow() local playerEdit = window:getChildById('playerEdit') if playerEdit then playerEdit.onFocusChange = function(widget, focused) if focused and widget:getText() == PLAYER_PLACEHOLDER then widget:clearText() end end playerEdit.onClick = function(widget) if widget:getText() == PLAYER_PLACEHOLDER then widget:clearText() end if widget.setEditable then widget:setEditable(true) end window:raise() window:focus() widget:focus() widget:setCursorVisible(true) end end window:hide() end function openTransfer() local window = getTransferWindow() setupInputs() window:show() focusPlayerEdit() end function closeTransfer() if transferWindow then transferWindow:hide() end end function deposit() local value = getEditText('amountEdit', 'all') command('deposit ' .. value) end function withdraw() local value = getEditText('amountEdit', 'all') command('withdraw ' .. value) end function transfer() local window = getTransferWindow() local playerEdit = window:getChildById('playerEdit') local amountEdit = window:getChildById('transferAmountEdit') local playerName = playerEdit and playerEdit:getText() or '' local amount = amountEdit and amountEdit:getText() or '' if playerName == '' or amount == '' or playerName == PLAYER_PLACEHOLDER then command('history') return end command('transfer ' .. playerName .. ', ' .. amount) closeTransfer() end