modules changes

* speedup widget destruction checks
* rework outfit module using grid layout and the new design
* fixes in console, terminal, textmessage modules
master
Eduardo Bart 12 年前
父節點 159eb98df2
當前提交 33458a3e39

@ -10,6 +10,7 @@ function Background.init()
local clientVersionLabel = background:getChildById('clientVersionLabel')
clientVersionLabel:setText('OTClient ' .. g_app.getVersion() .. '\n' ..
'Rev ' .. g_app.getBuildRevision() .. '\n' ..
'Built on ' .. g_app.getBuildDate())
if not g_game.isOnline() then

@ -15,8 +15,8 @@ Panel
background-color: #00000099
anchors.right: parent.right
anchors.bottom: parent.bottom
text-offset: 4 2
height: 32
text-align: center
height: 48
width: 120
color: #ffffff
font: verdana-11px-monochrome

@ -2,12 +2,11 @@ TerminalLabel < UILabel
font: terminus-14px-bold
height: 16
Panel
id: terminalPanel
UIWidget
id: terminalWidget
background-color: #000000
opacity: 0.85
anchors.fill: parent
@onEscape: Terminal.hide()
Panel
id: terminalBuffer

@ -2,16 +2,16 @@ UIComboBox = extends(UIWidget)
function UIComboBox.create()
local combobox = UIComboBox.internalCreate()
combobox.m_options = {}
combobox.m_currentIndex = -1
combobox.options = {}
combobox.currentIndex = -1
return combobox
end
function UIComboBox:setCurrentOption(text)
if not self.m_options then return end
for i,v in ipairs(self.m_options) do
if v.text == text and self.m_currentIndex ~= i then
self.m_currentIndex = i
if not self.options then return end
for i,v in ipairs(self.options) do
if v.text == text and self.currentIndex ~= i then
self.currentIndex = i
self:setText(text)
self:onOptionChange(text, v.data)
return
@ -20,24 +20,24 @@ function UIComboBox:setCurrentOption(text)
end
function UIComboBox:setCurrentIndex(index)
if index >= 1 and index <= #self.m_options then
local v = self.m_options[index]
self.m_currentIndex = index
if index >= 1 and index <= #self.options then
local v = self.options[index]
self.currentIndex = index
self:setText(v.text)
self:onOptionChange(v.text, v.data)
end
end
function UIComboBox:addOption(text, data)
table.insert(self.m_options, { text = text, data = data })
local index = #self.m_options
table.insert(self.options, { text = text, data = data })
local index = #self.options
if index == 1 then self:setCurrentOption(text) end
return index
end
function UIComboBox:onMousePress(mousePos, mouseButton)
local menu = createWidget(self:getStyleName() .. 'PopupMenu', self)
for i,v in ipairs(self.m_options) do
for i,v in ipairs(self.options) do
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
end
menu:setWidth(self:getWidth())
@ -48,10 +48,10 @@ function UIComboBox:onMousePress(mousePos, mouseButton)
end
function UIComboBox:onMouseWheel(mousePos, direction)
if direction == MouseWheelUp and self.m_currentIndex > 1 then
self:setCurrentIndex(self.m_currentIndex - 1)
elseif direction == MouseWheelDown and self.m_currentIndex < #self.m_options then
self:setCurrentIndex(self.m_currentIndex + 1)
if direction == MouseWheelUp and self.currentIndex > 1 then
self:setCurrentIndex(self.currentIndex - 1)
elseif direction == MouseWheelDown and self.currentIndex < #self.options then
self:setCurrentIndex(self.currentIndex + 1)
end
return true
end

@ -4,23 +4,23 @@ function UIProgressBar.create()
local progressbar = UIProgressBar.internalCreate()
progressbar:setFocusable(false)
progressbar:setPhantom(true)
progressbar.m_percent = 0
progressbar.percent = 0
progressbar:updateBackground()
return progressbar
end
function UIProgressBar:setPercent(percent)
self.m_percent = math.max(math.min(percent, 100), 0)
self.percent = math.max(math.min(percent, 100), 0)
self:updateBackground()
end
function UIProgressBar:getPercent()
return self.m_percent
return self.percent
end
function UIProgressBar:updateBackground()
local width = math.max((self.m_percent * self:getWidth())/100, 1)
local width = math.max((self.percent * self:getWidth())/100, 1)
local height = self:getHeight()
self:setBackgroundSize({width=width, height=height})
end

@ -3,54 +3,54 @@ UISpinBox = extends(UILineEdit)
function UISpinBox.create()
local spinbox = UISpinBox.internalCreate()
spinbox:setValidCharacters('0123456789')
spinbox.m_minimum = 0
spinbox.m_maximum = 0
spinbox.minimum = 0
spinbox.maximum = 0
spinbox:setCurrentIndex(0)
spinbox:setText("0")
return spinbox
end
function UISpinBox:setCurrentIndex(index)
if index >= self.m_minimum and index <= self.m_maximum then
if index >= self.minimum and index <= self.maximum then
if self:getText():len() > 0 then
self:setText(index)
end
self.m_currentIndex = index
self.currentIndex = index
self:onIndexChange(index)
end
end
function UISpinBox:setMinimum(minimum)
if minimum > self.m_maximum then
if minimum > self.maximum then
print("[UISpinBox:setMinimum]: minimum value cant be greater than maximum")
return false
end
if self.m_currentIndex < minimum then
if self.currentIndex < minimum then
self:setCurrentIndex(minimum)
end
self.m_minimum = minimum
self.minimum = minimum
end
function UISpinBox:setMaximum(maximum)
if maximum < self.m_minimum then
if maximum < self.minimum then
print("[UISpinBox:setMaximum]: maximum value cant be lower than minimum")
return false
end
if self.m_currentIndex > maximum then
if self.currentIndex > maximum then
self:setCurrentIndex(maximum)
end
self.m_maximum = maximum
self.maximum = maximum
end
function UISpinBox:getCurrentIndex()
return self.m_currentIndex
return self.currentIndex
end
function UISpinBox:onMouseWheel(mousePos, direction)
if direction == MouseWheelUp then
self:setCurrentIndex(self.m_currentIndex + 1)
self:setCurrentIndex(self.currentIndex + 1)
elseif direction == MouseWheelDown then
self:setCurrentIndex(self.m_currentIndex - 1)
self:setCurrentIndex(self.currentIndex - 1)
end
return true
end
@ -58,12 +58,12 @@ end
function UISpinBox:onTextChange(text, oldText)
if text:len() == 0 then
self:setCurrentIndex(self.m_minimum)
self:setCurrentIndex(self.minimum)
return
end
local number = tonumber(text)
if not number or number > self.m_maximum or number < self.m_minimum then
if not number or number > self.maximum or number < self.minimum then
self:setText(oldText)
return
end

@ -13,6 +13,13 @@ Module
load-later:
- game_textmessage
- game_console
- game_outfit
//- game_healthbar
//- game_inventory
//- game_combatcontrols
//- game_skills
//- game_viplist
//- game_hotkeys
@onLoad: |
importStyle 'styles/items.otui'

@ -211,7 +211,7 @@ function GameInterface.processMouseAction(menuPosition, mouseButton, autoWalk, l
return true
end
if not Options.classicControl then
if not Options['classicControl'] then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
GameInterface.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true

@ -26,7 +26,7 @@ UIWidget
GameSidePanel
id: gameLeftPanel
width: 190
width: 0
layout: verticalBox
anchors.left: parent.left
anchors.top: parent.top

@ -36,7 +36,7 @@ table.insert(lifeBarColors, {percentAbove = -1, color = '#4F0000' } )
-- public functions
function Battle.create()
battleWindow = displayUI('battle.otui', g_game.gameRightPanel)
battleWindow = displayUI('battle.otui', GameInterface.getRightPanel())
battleWindow:hide()
battleButton = TopMenu.addGameButton('battleButton', 'Battle (Ctrl+B)', '/game_battle/battle.png', Battle.toggle)
Keyboard.bindKeyDown('Ctrl+B', Battle.toggle)

@ -3,5 +3,6 @@ Module
description: Manage battle window
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'battle'

@ -50,7 +50,7 @@ end
function CombatControls.init()
combatControlsButton = TopMenu.addGameButton('combatControlsButton', 'Combat Controls', 'combatcontrols.png', CombatControls.toggle)
combatControlsButton:setOn(true)
combatControlsWindow = loadUI('combatcontrols.otui')
combatControlsWindow = loadUI('combatcontrols.otui', GameInterface.getRightPanel())
fightOffensiveBox = combatControlsWindow:getChildById('fightOffensiveBox')
fightBalancedBox = combatControlsWindow:getChildById('fightBalancedBox')
@ -101,7 +101,6 @@ function CombatControls.terminate()
end
function CombatControls.online()
g_game.gameRightPanel:addChild(combatControlsWindow)
combatControlsWindow:setVisible(combatControlsButton:isOn())
local fightMode = g_game.getFightMode()
@ -121,7 +120,6 @@ function CombatControls.online()
end
function CombatControls.offline()
g_game.gameRightPanel:removeChild(combatControlsWindow)
end
function CombatControls.toggle()

@ -4,9 +4,9 @@ Module
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'combatcontrols'
CombatControls.init()
onUnload: |
@onUnload: |
CombatControls.terminate()

@ -50,6 +50,7 @@ local channels
local messageHistory = { }
local currentMessageIndex = 0
local MaxHistory = 1000
local channelsWindow
-- private functions
local function navigateMessageHistory(step)
@ -67,7 +68,7 @@ end
function applyMessagePrefixies(name, level, message)
if name then
if Options.showLevelsInConsole and level > 0 then
if Options.getOption('showLevelsInConsole') and level > 0 then
message = name .. ' [' .. level .. ']: ' .. message
else
message = name .. ': ' .. message
@ -109,7 +110,7 @@ local function onOpenPrivateChannel(receiver)
end
end
local function doChannelListSubmit(channelsWindow)
local function doChannelListSubmit()
local channelListPanel = channelsWindow:getChildById('channelList')
local openPrivateChannelWith = channelsWindow:getChildById('openPrivateChannelWith'):getText()
if openPrivateChannelWith ~= '' then
@ -119,13 +120,16 @@ local function doChannelListSubmit(channelsWindow)
if not selectedChannelLabel then return end
g_game.joinChannel(selectedChannelLabel.channelId)
end
channelsWindow:destroy()
end
local function onChannelList(channelList)
local channelsWindow = displayUI('channelswindow.otui')
if channelsWindow then channelsWindow:destroy() end
channelsWindow = displayUI('channelswindow.otui')
local channelListPanel = channelsWindow:getChildById('channelList')
channelsWindow.onEnter = function() doChannelListSubmit(channelsWindow) end
channelsWindow.onEnter = doChannelListSubmit
channelsWindow.onDestroy = function() channelsWindow = nil end
Keyboard.bindKeyPress('Down', function() channelListPanel:focusNextChild(KeyboardFocusReason) end, channelsWindow)
Keyboard.bindKeyPress('Up', function() channelListPanel:focusPreviousChild(KeyboardFocusReason) end, channelsWindow)
@ -139,7 +143,7 @@ local function onChannelList(channelList)
label:setText(channelName)
label:setPhantom(false)
label.onDoubleClick = function() doChannelListSubmit(channelsWindow) end
label.onDoubleClick = doChannelListSubmit
end
end
end
@ -150,7 +154,8 @@ function Console.init()
connect(g_game, { onCreatureSpeak = onCreatureSpeak,
onChannelList = onChannelList,
onOpenChannel = onOpenChannel,
onOpenPrivateChannel = onOpenPrivateChannel})
onOpenPrivateChannel = onOpenPrivateChannel,
onGameEnd = Console.clean })
consolePanel = displayUI('console.otui', GameInterface.getBottomPanel())
consoleLineEdit = consolePanel:getChildById('consoleLineEdit')
@ -182,15 +187,24 @@ function Console.terminate()
disconnect(g_game, { onCreatureSpeak = onCreatureSpeak,
onChannelList = onChannelList,
onOpenChannel = onOpenChannel,
onOpenPrivateChannel = onOpenPrivateChannel })
onOpenPrivateChannel = onOpenPrivateChannel,
onGameEnd = Console.clean })
for channelid, channelname in ipairs(channels) do
g_game.leaveChannel(channelid)
for channelid, channelname in pairs(channels) do
if channelid ~= 0 then
g_game.leaveChannel(channelid)
end
end
channels = {}
Keyboard.unbindKeyDown('Ctrl+O')
Keyboard.unbindKeyDown('Ctrl+E')
if channelsWindow then
channelsWindow:destroy()
channelsWindow = nil
end
consolePanel:destroy()
consolePanel = nil
consoleLineEdit = nil
@ -200,6 +214,28 @@ function Console.terminate()
Console = nil
end
function Console.debug()
print(#channels)
end
function Console.clean()
for channelid, channelname in pairs(channels) do
if channelid ~= 0 then
local tab = consoleTabBar:getTab(channelname)
consoleTabBar:removeTab(tab)
end
end
channels = {}
consoleTabBar:getTab('Default').tabPanel:destroyChildren()
consoleTabBar:getTab('Server Log').tabPanel:destroyChildren()
if channelsWindow then
channelsWindow:destroy()
channelsWindow = nil
end
end
function Console.setLineEditText(text)
consoleLineEdit:setText(text)
end
@ -260,7 +296,7 @@ function Console.addPrivateText(text, speaktype, name, isPrivateCommand)
local privateTab = Console.getTab(name)
if privateTab == nil then
if Options.showPrivateMessagesInConsole or (isPrivateCommand and not privateTab) then
if Options['showPrivateMessagesInConsole'] or (isPrivateCommand and not privateTab) then
privateTab = Console.getTab('Default')
else
privateTab = Console.addTab(name, focus)
@ -280,7 +316,7 @@ function Console.addText(text, speaktype, tabName)
end
function Console.addTabText(text, speaktype, tab)
if Options.showTimestampsInConsole then
if Options['showTimestampsInConsole'] then
text = os.date('%H:%M') .. ' ' .. text
end

@ -1,16 +1,16 @@
Containers = {}
-- private variables
local m_containers = {}
local containers = {}
-- public functions
function Containers.clean()
m_containers = {}
containers = {}
end
function Containers.getFreeContainerId()
for i=0,15 do
if not m_containers[i] then
if not containers[i] then
return i
end
end
@ -19,12 +19,12 @@ end
-- hooked events
function Containers.onOpenContainer(containerId, itemId, name, capacity, hasParent, items)
local container = m_containers[containerId]
local container = containers[containerId]
if container then
g_game.gameRightPanel:removeChild(container)
GameInterface.getRightPanel():removeChild(container)
end
container = displayUI('container.otui', g_game.gameRightPanel)
container = displayUI('container.otui', GameInterface.getRightPanel())
name = name:sub(1,1):upper() .. name:sub(2)
container:setText(name)
@ -51,19 +51,19 @@ function Containers.onOpenContainer(containerId, itemId, name, capacity, hasPare
end
end
m_containers[containerId] = container
containers[containerId] = container
end
function Containers.onCloseContainer(containerId)
local container = m_containers[containerId]
local container = containers[containerId]
if container then
g_game.gameRightPanel:removeChild(container)
GameInterface.getRightPanel():removeChild(container)
end
m_containers[containerId] = nil
containers[containerId] = nil
end
function Containers.onContainerAddItem(containerId, item)
local container = m_containers[containerId]
local container = containers[containerId]
if not container or not item or container.itemCount >= container.capacity then return end
local i = container.itemCount
@ -92,7 +92,7 @@ function Containers.onContainerAddItem(containerId, item)
end
function Containers.onContainerUpdateItem(containerId, slot, item)
local container = m_containers[containerId]
local container = containers[containerId]
if not container then return end
local itemWidget = container:getChildByIndex(slot + 1)
@ -102,7 +102,7 @@ function Containers.onContainerUpdateItem(containerId, slot, item)
end
function Containers.onContainerRemoveItem(containerId, slot)
local container = m_containers[containerId]
local container = containers[containerId]
if not container then return end
local itemWidget = container:getChildByIndex(slot+1)

@ -3,5 +3,6 @@ Module
description: Manage containers
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'containers'

@ -9,7 +9,7 @@ local manaLabel
-- public functions
function HealthBar.create()
healthBarWindow = displayUI('healthbar.otui', g_game.gameRightPanel)
healthBarWindow = displayUI('healthbar.otui', GameInterface.getRightPanel())
healthBarButton = TopMenu.addGameButton('healthBarButton', 'Healh Bar', 'healthbar.png', HealthBar.toggle)
healthBarButton:setOn(true)
healthBar = healthBarWindow:getChildById('healthBar')

@ -3,5 +3,6 @@ Module
description: Displays health and mana points
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'healthbar'

@ -37,7 +37,7 @@ function HotkeysManager.init()
hotkeysWindow = displayUI('hotkeys_manager.otui')
hotkeysWindow:setVisible(false)
hotkeysButton = TopMenu.addButton('hotkeysButton', 'Hotkeys (Ctrl+K)', '/game_hotkeys/icon.png', HotkeysManager.toggle)
hotkeysButton = TopMenu.addLeftButton('hotkeysButton', 'Hotkeys (Ctrl+K)', '/game_hotkeys/icon.png', HotkeysManager.toggle)
Keyboard.bindKeyDown('Ctrl+K', HotkeysManager.toggle)
currentHotkeysList = hotkeysWindow:getChildById('currentHotkeys')

@ -3,13 +3,13 @@ Module
description: Manage client hotkeys
author: OTClient team
website: https://github.com/edubart/otclient
dependencies:
- client_tibiafiles
onLoad: |
- game
@onLoad: |
dofile 'hotkeys_manager'
HotkeysManager.init()
onUnload: |
@onUnload: |
HotkeysManager.terminate()

@ -7,7 +7,7 @@ Module
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'uiminiwindow'
dofile 'uiminiwindowcontainer'
dofile 'uiitem'
@ -16,5 +16,5 @@ Module
GameInterface.init()
onUnload: |
@onUnload: |
GameInterface.terminate()

@ -6,7 +6,7 @@ local inventoryButton
-- public functions
function Inventory.create()
inventoryWindow = displayUI('inventory.otui', g_game.gameRightPanel)
inventoryWindow = displayUI('inventory.otui', GameInterface.getRightPanel())
inventoryButton = TopMenu.addGameButton('inventoryButton', 'Inventory (Ctrl+I)', 'inventory.png', Inventory.toggle)
inventoryButton:setOn(true)
Keyboard.bindKeyDown('Ctrl+I', Inventory.toggle)

@ -3,5 +3,6 @@ Module
description: View local player equipments window
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'inventory'

@ -1,84 +1,84 @@
Outfit = {}
-- private variables
local window = nil
local m_creature = nil
local m_outfit = nil
local m_outfits = nil
local m_currentOutfit = 1
local m_currentColor = nil
local m_currentClothe = nil
local outfitWindow
local outfitCreature
local outfit
local outfits
local currentOutfit = 1
local currentColorBox
local currentClotheButtonBox
-- private functions
local function onAddonCheckChange(addon, value)
if addon:isChecked() then
m_outfit.addons = m_outfit.addons + value
outfit.addons = outfit.addons + value
else
m_outfit.addons = m_outfit.addons - value
outfit.addons = outfit.addons - value
end
m_creature:setOutfit(m_outfit)
outfitCreature:setOutfit(outfit)
end
local function onColorCheckChange(color)
if color == m_currentColor then
color.onCheckChange = nil
color:setChecked(true)
color.onCheckChange = onColorCheckChange
local function onColorCheckChange(colorBox)
if colorBox == currentColorBox then
colorBox.onCheckChange = nil
colorBox:setChecked(true)
colorBox.onCheckChange = onColorCheckChange
else
m_currentColor.onCheckChange = nil
m_currentColor:setChecked(false)
m_currentColor.onCheckChange = onColorCheckChange
m_currentColor = color
if m_currentClothe:getId() == 'head' then
m_outfit.head = m_currentColor.colorId
elseif m_currentClothe:getId() == 'primary' then
m_outfit.body = m_currentColor.colorId
elseif m_currentClothe:getId() == 'secondary' then
m_outfit.legs = m_currentColor.colorId
elseif m_currentClothe:getId() == 'detail' then
m_outfit.feet = m_currentColor.colorId
currentColorBox.onCheckChange = nil
currentColorBox:setChecked(false)
currentColorBox.onCheckChange = onColorCheckChange
currentColorBox = colorBox
if currentClotheButtonBox:getId() == 'head' then
outfit.head = currentColorBox.colorId
elseif currentClotheButtonBox:getId() == 'primary' then
outfit.body = currentColorBox.colorId
elseif currentClotheButtonBox:getId() == 'secondary' then
outfit.legs = currentColorBox.colorId
elseif currentClotheButtonBox:getId() == 'detail' then
outfit.feet = currentColorBox.colorId
end
m_creature:setOutfit(m_outfit)
outfitCreature:setOutfit(outfit)
end
end
local function onClotheCheckChange(clothe)
if clothe == m_currentClothe then
clothe.onCheckChange = nil
clothe:setChecked(true)
clothe.onCheckChange = onClotheCheckChange
local function onClotheCheckChange(clotheButtonBox)
if clotheButtonBox == currentClotheButtonBox then
clotheButtonBox.onCheckChange = nil
clotheButtonBox:setChecked(true)
clotheButtonBox.onCheckChange = onClotheCheckChange
else
m_currentClothe.onCheckChange = nil
m_currentClothe:setChecked(false)
m_currentClothe.onCheckChange = onClotheCheckChange
m_currentClothe = clothe
local color = 0
if m_currentClothe:getId() == 'head' then
color = m_outfit.head
elseif m_currentClothe:getId() == 'primary' then
color = m_outfit.body
elseif m_currentClothe:getId() == 'secondary' then
color = m_outfit.legs
elseif m_currentClothe:getId() == 'detail' then
color = m_outfit.feet
currentClotheButtonBox.onCheckChange = nil
currentClotheButtonBox:setChecked(false)
currentClotheButtonBox.onCheckChange = onClotheCheckChange
currentClotheButtonBox = clotheButtonBox
local colorId = 0
if currentClotheButtonBox:getId() == 'head' then
colorId = outfit.head
elseif currentClotheButtonBox:getId() == 'primary' then
colorId = outfit.body
elseif currentClotheButtonBox:getId() == 'secondary' then
colorId = outfit.legs
elseif currentClotheButtonBox:getId() == 'detail' then
colorId = outfit.feet
end
window:getChildById('color' .. color):setChecked(true)
outfitWindow:recursiveGetChildById('colorBox' .. colorId):setChecked(true)
end
end
local function update()
local nameWidget = window:getChildById('name')
nameWidget:setText(m_outfits[m_currentOutfit][2])
local nameWidget = outfitWindow:getChildById('outfitName')
nameWidget:setText(outfits[currentOutfit][2])
local availableAddons = m_outfits[m_currentOutfit][3]
local addon1 = window:getChildById('addon1')
local addon2 = window:getChildById('addon2')
local addon3 = window:getChildById('addon3')
local availableAddons = outfits[currentOutfit][3]
local addon1 = outfitWindow:getChildById('addon1')
local addon2 = outfitWindow:getChildById('addon2')
local addon3 = outfitWindow:getChildById('addon3')
addon1:setChecked(false)
addon2:setChecked(false)
addon3:setChecked(false)
@ -111,55 +111,63 @@ local function update()
addon3:setEnabled(true)
end
m_outfit.type = m_outfits[m_currentOutfit][1]
m_outfit.addons = 0
m_creature:setOutfit(m_outfit)
outfit.type = outfits[currentOutfit][1]
outfit.addons = 0
outfitCreature:setOutfit(outfit)
end
-- public functions
function Outfit.init()
connect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy })
end
function Outfit.terminate()
disconnect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy })
Outfit.destroy()
end
function Outfit.create(creature, outfitList)
outfitCreature = creature
outfits = outfitList
Outfit.destroy()
window = displayUI('outfit.otui')
window:lock()
m_outfit = creature:getOutfit()
outfitWindow = displayUI('outfit.otui')
--outfitWindow:lock()
m_currentClothe = window:getChildById('head')
window:getChildById('head').onCheckChange = onClotheCheckChange
window:getChildById('primary').onCheckChange = onClotheCheckChange
window:getChildById('secondary').onCheckChange = onClotheCheckChange
window:getChildById('detail').onCheckChange = onClotheCheckChange
outfit = outfitCreature:getOutfit()
local creatureWidget = window:getChildById('creature')
creatureWidget:setCreature(creature)
currentClotheButtonBox = outfitWindow:getChildById('head')
outfitWindow:getChildById('head').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('primary').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('secondary').onCheckChange = onClotheCheckChange
outfitWindow:getChildById('detail').onCheckChange = onClotheCheckChange
for i=0,18 do
for j=0,6 do
local color = createWidget('Color', window)
local outfitCreatureBox = outfitWindow:getChildById('outfitCreatureBox')
local colorBoxPanel = outfitWindow:getChildById('colorBoxPanel')
outfitCreatureBox:setCreature(outfitCreature)
for j=0,6 do
for i=0,18 do
local colorBox = createWidget('ColorBox', colorBoxPanel)
local outfitColor = getOufitColor(j*19 + i)
color:setId('color' .. j*19+i)
color.colorId = j*19 + i
color:setImageColor(outfitColor)
color:setMarginTop(j * 3 + j * 14)
color:setMarginLeft(10 + i * 3 + i * 14)
if j*19 + i == m_outfit.head then
m_currentColor = color
color:setChecked(true)
end
colorBox:setImageColor(outfitColor)
colorBox:setId('colorBox' .. j*19+i)
colorBox.colorId = j*19 + i
color.onCheckChange = onColorCheckChange
if j*19 + i == outfit.head then
currentColorBox = colorBox
colorBox:setChecked(true)
end
colorBox.onCheckChange = onColorCheckChange
end
end
m_creature = creature
m_outfits = outfitList
m_currentOutfit = 1
currentOutfit = 1
for i=1,#outfitList do
if outfitList[i][1] == m_outfit.type then
m_currentOutfit = i
if outfitList[i][1] == outfit.type then
currentOutfit = i
break
end
end
@ -168,35 +176,33 @@ function Outfit.create(creature, outfitList)
end
function Outfit.destroy()
if window ~= nil then
window:destroy()
window = nil
if outfitWindow then
outfitWindow:destroy()
outfitWindow = nil
outfitCreature = nil
currentColorBox = nil
currentClotheButtonBox = nil
end
end
function Outfit.accept()
g_game.changeOutfit(m_outfit)
g_game.changeOutfit(outfit)
Outfit.destroy()
end
function Outfit.nextType()
m_currentOutfit = m_currentOutfit + 1
if m_currentOutfit > #m_outfits then
m_currentOutfit = 1
currentOutfit = currentOutfit + 1
if currentOutfit > #outfits then
currentOutfit = 1
end
update()
end
function Outfit.previousType()
m_currentOutfit = m_currentOutfit - 1
if m_currentOutfit <= 0 then
m_currentOutfit = #m_outfits
currentOutfit = currentOutfit - 1
if currentOutfit <= 0 then
currentOutfit = #outfits
end
update()
end
-- hooked events
connect(g_game, { onOpenOutfitWindow = Outfit.create,
onGameEnd = Outfit.destroy })

@ -3,5 +3,11 @@ Module
description: Change local player outfit
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
reloadable: true
@onLoad: |
dofile 'outfit'
Outfit.init()
@onUnload: |
Outfit.terminate()

@ -1,7 +1,3 @@
Color < ColorBox
anchors.top: head.top
anchors.left: head.right
Window
text: Select Outfit
size: 550 280
@ -14,7 +10,7 @@ Window
@onEscape: Outfit.destroy()
Label
id: name
id: outfitName
text: Outfit Name
width: 100
anchors.top: parent.top
@ -23,60 +19,81 @@ Window
margin-left: 20
Creature
id: creature
anchors.top: name.bottom
anchors.left: name.left
id: outfitCreatureBox
anchors.top: outfitName.bottom
anchors.left: outfitName.left
margin-top: 5
padding: 16 4 4 16
fixed-creature-size: true
Panel
id: colorBoxPanel
anchors.top: parent.top
anchors.right: parent.right
margin-top: 54
margin-right: 20
width: 323
height: 119
layout:
type: grid
cell-size: 16 16
cell-spacing: 2
num-columns: 19
num-lines: 7
ButtonBox
id: head
text: Head
anchors.top: creature.top
anchors.left: creature.right
anchors.top: outfitCreatureBox.top
anchors.left: outfitCreatureBox.right
margin-left: 10
checked: true
width: 90
ButtonBox
id: primary
text: Primary
anchors.top: prev.bottom
anchors.left: prev.left
width: 90
ButtonBox
id: secondary
text: Secondary
anchors.top: prev.bottom
anchors.left: prev.left
width: 90
ButtonBox
id: detail
text: Detail
anchors.top: prev.bottom
anchors.left: prev.left
width: 90
Button
id: outfitNextButton
@onClick: Outfit.nextType()
text: >>
width: 32
margin-top: 4
anchors.top: creature.bottom
anchors.right: creature.right
anchors.top: outfitCreatureBox.bottom
anchors.right: outfitCreatureBox.right
Button
id: outfitPreviousButton
@onClick: Outfit.previousType()
text: <<
width: 32
margin-top: 4
anchors.top: creature.bottom
anchors.left: creature.left
anchors.top: outfitCreatureBox.bottom
anchors.left: outfitCreatureBox.left
CheckBox
id: addon1
text: Addon 1
enabled: false
margin-top: 10
margin-top: 6
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@ -85,7 +102,7 @@ Window
id: addon2
text: Addon 2
enabled: false
margin-top: 10
margin-top: 2
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@ -94,7 +111,7 @@ Window
id: addon3
text: Addon 3
enabled: false
margin-top: 10
margin-top: 2
width: 100
anchors.top: prev.bottom
anchors.left: prev.left
@ -108,7 +125,7 @@ Window
margin-bottom: 10
Button
id: buttonOk
id: outfitOkButton
text: Ok
width: 64
anchors.right: next.left
@ -118,7 +135,7 @@ Window
@onClick: Outfit.accept()
Button
id: buttonCancel
id: outfitCancelButton
text: Cancel
width: 64
anchors.right: parent.right

@ -42,7 +42,7 @@ end
-- public functions
function Skills.create()
skillsWindow = displayUI('skills.otui', g_game.gameRightPanel)
skillsWindow = displayUI('skills.otui', GameInterface.getRightPanel())
skillsWindow:hide()
skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
Keyboard.bindKeyDown('Ctrl+S', Skills.toggle)

@ -3,5 +3,6 @@ Module
description: Manage skills window
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'skills'

@ -24,7 +24,7 @@ local function displayMessage(msgtype, msg, time)
if not g_game.isOnline() then return end
if msgtype.consoleTab ~= nil then
if msgtype.consoleOption == nil or Options[msgtype.consoleOption] then
if msgtype.consoleOption == nil or Options.getOption(msgtype.consoleOption) then
Console.addText(msg, msgtype, msgtype.consoleTab)
end
end
@ -93,7 +93,7 @@ end
function TextMessage.terminate()
disconnect(g_game, { onDeath = TextMessage.displayDeadMessage,
onTextMessage = TextMessage.display,
onGameStart = TextMessage.clearMessages })
onGameEnd = TextMessage.clearMessages })
centerTextMessagePanel:destroy()
centerTextMessagePanel = nil
bottomStatusLabel:destroy()

@ -7,7 +7,7 @@ local addVipWindow
-- public functions
function VipList.create()
vipWindow = displayUI('viplist.otui', g_game.gameRightPanel)
vipWindow = displayUI('viplist.otui', GameInterface.getRightPanel())
vipWindow:hide()
vipButton = TopMenu.addGameButton('vipListButton', 'VIP list', 'viplist.png', VipList.toggle)
end

@ -3,5 +3,6 @@ Module
description: Manage vip list window
author: OTClient team
website: https://github.com/edubart/otclient
onLoad: |
@onLoad: |
dofile 'viplist'

@ -1,5 +1,5 @@
-- private variables
local m_mouseGrabberWidget
local mouseGrabberWidget
-- private functions
local function onGameKeyPress(self, keyCode, keyboardModifiers)
@ -41,7 +41,7 @@ end
-- public functions
function g_game.startUseWith(thing)
g_game.selectedThing = thing
m_mouseGrabberWidget:grabMouse()
mouseGrabberWidget:grabMouse()
Mouse.setTargetCursor()
end
@ -49,11 +49,11 @@ function g_game.createInterface()
rootWidget:moveChildToIndex(g_game.gameUi, 1)
g_game.gameMapPanel = g_game.gameUi:getChildById('gameMapPanel')
g_game.gameRightPanel = g_game.gameUi:getChildById('gameRightPanel')
GameInterface.getRightPanel() = g_game.gameUi:getChildById('gameRightPanel')
g_game.gameBottomPanel = g_game.gameUi:getChildById('gameBottomPanel')
m_mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber')
mouseGrabberWidget = g_game.gameUi:getChildById('mouseGrabber')
connect(g_game.gameUi, { onKeyPress = onGameKeyPress })
connect(m_mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
connect(mouseGrabberWidget, { onMouseRelease = onUseWithMouseRelease })
end
function g_game.destroyInterface()

@ -19,7 +19,7 @@ function g_game.processMouseAction(menuPosition, mouseButton, autoWalk, lookThin
return true
end
if not Options.classicControl then
if not Options.getOption('classicControl') then
if keyboardModifiers == KeyboardNoModifier and mouseButton == MouseRightButton then
g_game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
return true

@ -44,6 +44,8 @@ void Logger::log(Fw::LogLevel level, const std::string& message)
std::size_t now = std::time(NULL);
m_logMessages.push_back(LogMessage(level, outmsg, now));
if(m_logMessages.size() > MAX_LOG_HISTORY)
m_logMessages.pop_front();
if(m_onLog)
m_onLog(level, outmsg, now);

@ -34,6 +34,10 @@ struct LogMessage {
class Logger
{
enum {
MAX_LOG_HISTORY = 1000
};
typedef std::function<void(Fw::LogLevel, std::string, std::size_t)> OnLogCallback;
public:

@ -171,7 +171,6 @@ void Texture::generateSoftwareMipmaps(std::vector<uint8> inPixels)
Size outSize = inSize / 2;
std::vector<uint8> outPixels(outSize.area()*4);
dump << "yeah";
int mipmap = 1;
while(true) {
// this is a simple bilinear filtering algorithm, it combines every 4 pixels in one pixel

@ -225,6 +225,31 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget)
updateDraggingWidget(nullptr);
}
void UIManager::addDestroyedWidget(const UIWidgetPtr& widget)
{
static UIWidgetList destroyedWidgets;
static ScheduledEventPtr checkEvent;
if(widget == m_rootWidget)
return;
destroyedWidgets.push_back(widget);
if(checkEvent && !checkEvent->isExecuted())
return;
checkEvent = g_eventDispatcher.scheduleEvent([] {
g_lua.collectGarbage();
g_eventDispatcher.addEvent([] {
g_lua.collectGarbage();
for(const UIWidgetPtr& widget : destroyedWidgets) {
if(widget->getUseCount() != 1)
logWarning("widget '", widget->getId(), "' destroyed but still have ", widget->getUseCount()-1, " reference(s) left");
}
});
}, 1000);
}
bool UIManager::importStyle(const std::string& file)
{
try {

@ -68,6 +68,7 @@ protected:
void onWidgetAppear(const UIWidgetPtr& widget);
void onWidgetDisappear(const UIWidgetPtr& widget);
void onWidgetDestroy(const UIWidgetPtr& widget);
void addDestroyedWidget(const UIWidgetPtr& widget);
friend class UIWidget;

@ -636,10 +636,8 @@ void UIWidget::destroy()
g_ui.onWidgetDestroy(asUIWidget());
// remove itself from parent
if(UIWidgetPtr parent = getParent()) {
assert(parent->hasChild(asUIWidget()));
if(UIWidgetPtr parent = getParent())
parent->removeChild(asUIWidget());
}
destroyChildren();
m_focusedChild = nullptr;
@ -649,15 +647,7 @@ void UIWidget::destroy()
releaseLuaFieldsTable();
#ifdef DEBUG
auto self = asUIWidget();
g_lua.collectGarbage();
if(self != g_ui.getRootWidget()) {
g_eventDispatcher.scheduleEvent([self] {
g_lua.collectGarbage();
if(self->getUseCount() != 1)
logWarning("widget '", self->getId(), "' destroyed but still have ", self->getUseCount()-1, " reference(s) left");
}, 500);
}
g_ui.addDestroyedWidget(asUIWidget());
#endif
}

@ -207,6 +207,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<Creature>("setEmblemTexture", &Creature::setEmblemTexture);
g_lua.bindClassMemberFunction<Creature>("showStaticSquare", &Creature::showStaticSquare);
g_lua.bindClassMemberFunction<Creature>("hideStaticSquare", &Creature::hideStaticSquare);
g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking);
g_lua.bindClassMemberFunction<Creature>("asMonster", &Creature::asMonster);
g_lua.bindClassMemberFunction<Creature>("asNpc", &Creature::asNpc);
@ -220,7 +221,9 @@ void OTClient::registerLuaFunctions()
g_lua.registerClass<AnimatedText, Thing>();
g_lua.registerClass<Player, Creature>();
g_lua.bindClassMemberFunction<Creature>("isWalking", &Creature::isWalking);
g_lua.bindClassMemberFunction<Player>("isPartyMember", &LocalPlayer::isPartyMember);
g_lua.bindClassMemberFunction<Player>("isPartyLeader", &LocalPlayer::isPartyLeader);
g_lua.bindClassMemberFunction<Player>("isPartySharedExperienceActive", &LocalPlayer::isPartySharedExperienceActive);
g_lua.registerClass<Npc, Creature>();
g_lua.registerClass<Monster, Creature>();

載入中…
取消
儲存