Use new coding style in game modules

Lots of refactoring and changes
Remove docs folder
This commit is contained in:
Eduardo Bart
2012-07-24 02:30:08 -03:00
parent 1c3e630237
commit c54cd1fdf1
69 changed files with 1629 additions and 2634 deletions

View File

@@ -1,8 +1,8 @@
MainWindow
size: 256 128
!text: tr('Add to VIP list')
@onEnter: VipList.addVip()
@onEscape: VipList.destroyAddWindow()
@onEnter: addVip()
@onEscape: destroyAddWindow()
Label
!text: tr('Please enter a character name:')
@@ -29,11 +29,11 @@ MainWindow
anchors.right: next.left
anchors.bottom: parent.bottom
margin-right: 10
@onClick: VipList.addVip()
@onClick: addVip()
Button
!text: tr('Cancel')
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
@onClick: VipList.destroyAddWindow()
@onClick: destroyAddWindow()

View File

@@ -1,53 +1,45 @@
VipList = {}
vipWindow = nil
vipButton = nil
addVipWindow = nil
-- private variables
local vipWindow
local vipButton
local addVipWindow
-- public functions
function VipList.init()
connect(g_game, { onGameEnd = VipList.clear,
onAddVip = VipList.onAddVip,
onVipStateChange = VipList.onVipStateChange })
function init()
connect(g_game, { onGameEnd = clear,
onAddVip = onAddVip,
onVipStateChange = onVipStateChange })
g_keyboard.bindKeyDown('Ctrl+P', VipList.toggle)
g_keyboard.bindKeyDown('Ctrl+P', toggle)
vipWindow = g_ui.loadUI('viplist.otui', GameInterface.getRightPanel())
vipButton = TopMenu.addRightGameToggleButton('vipListButton', tr('VIP list') .. ' (Ctrl+P)', 'viplist.png', VipList.toggle)
vipWindow = g_ui.loadUI('viplist.otui', modules.game_interface.getRightPanel())
vipButton = TopMenu.addRightGameToggleButton('vipListButton', tr('VIP list') .. ' (Ctrl+P)', 'viplist.png', toggle)
vipButton:setOn(true)
VipList.refresh()
refresh()
end
function VipList.terminate()
function terminate()
g_keyboard.unbindKeyDown('Ctrl+P')
disconnect(g_game, { onGameEnd = VipList.clear,
onAddVip = VipList.onAddVip,
onVipStateChange = VipList.onVipStateChange })
disconnect(g_game, { onGameEnd = clear,
onAddVip = onAddVip,
onVipStateChange = onVipStateChange })
vipWindow:destroy()
vipWindow = nil
vipButton:destroy()
vipButton = nil
VipList = nil
end
function VipList.refresh()
VipList.clear()
function refresh()
clear()
for id,vip in pairs(g_game.getVips()) do
VipList.onAddVip(id, unpack(vip))
onAddVip(id, unpack(vip))
end
end
function VipList.clear()
function clear()
local vipList = vipWindow:getChildById('contentsPanel')
vipList:destroyChildren()
end
function VipList.toggle()
function toggle()
if vipButton:isOn() then
vipWindow:close()
vipButton:setOn(false)
@@ -57,26 +49,25 @@ function VipList.toggle()
end
end
function VipList.onMiniWindowClose()
function onMiniWindowClose()
vipButton:setOn(false)
end
function VipList.createAddWindow()
function createAddWindow()
addVipWindow = g_ui.displayUI('addvip.otui')
end
function VipList.destroyAddWindow()
function destroyAddWindow()
addVipWindow:destroy()
addVipWindow = nil
end
function VipList.addVip()
function addVip()
g_game.addVip(addVipWindow:getChildById('name'):getText())
VipList.destroyAddWindow()
destroyAddWindow()
end
-- hooked events
function VipList.onAddVip(id, name, online)
function onAddVip(id, name, online)
local vipList = vipWindow:getChildById('contentsPanel')
local label = g_ui.createWidget('VipListLabel')
@@ -122,34 +113,34 @@ function VipList.onAddVip(id, name, online)
vipList:insertChild(childrenCount+1, label)
end
function VipList.onVipStateChange(id, online)
function onVipStateChange(id, online)
local vipList = vipWindow:getChildById('contentsPanel')
local label = vipList:getChildById('vip' .. id)
local text = label:getText()
label:destroy()
VipList.onAddVip(id, text, online)
onAddVip(id, text, online)
end
function VipList.onVipListMousePress(widget, mousePos, mouseButton)
function onVipListMousePress(widget, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then return end
local vipList = vipWindow:getChildById('contentsPanel')
local menu = g_ui.createWidget('PopupMenu')
menu:addOption(tr('Add new VIP'), function() VipList.createAddWindow() end)
menu:addOption(tr('Add new VIP'), function() createAddWindow() end)
menu:display(mousePos)
return true
end
function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
function onVipListLabelMousePress(widget, mousePos, mouseButton)
if mouseButton ~= MouseRightButton then return end
local vipList = vipWindow:getChildById('contentsPanel')
local menu = g_ui.createWidget('PopupMenu')
menu:addOption(tr('Add new VIP'), function() VipList.createAddWindow() end)
menu:addOption(tr('Add new VIP'), function() createAddWindow() end)
menu:addOption(tr('Remove %s', widget:getText()), function() if widget then g_game.removeVip(widget:getId():sub(4)) vipList:removeChild(widget) end end)
menu:addSeparator()
menu:addOption(tr('Copy Name'), function() g_window.setClipboardText(widget:getText()) end)

View File

@@ -3,10 +3,7 @@ Module
description: Manage vip list window
author: baxnie, edubart
website: www.otclient.info
@onLoad: |
dofile 'viplist'
VipList.init()
@onUnload: |
VipList.terminate()
sandboxed: true
scripts: [ viplist.lua ]
@onLoad: init()
@onUnload: terminate()

View File

@@ -1,17 +1,17 @@
VipListLabel < GameLabel
font: verdana-11px-monochrome
phantom: false
&onMousePress: VipList.onVipListLabelMousePress
&onMousePress: onVipListLabelMousePress
MiniWindow
id: vipWindow
!text: tr('VIP List')
height: 100
icon: viplist.png
@onClose: VipList.onMiniWindowClose()
@onClose: onMiniWindowClose()
&save: true
MiniWindowContents
layout: verticalBox
anchors.fill: parent
&onMousePress: VipList.onVipListMousePress
&onMousePress: onVipListMousePress