implement API to save lists in configs file and terminal history

This commit is contained in:
Eduardo Bart
2012-01-15 13:13:22 -02:00
parent a238111c07
commit 9ec40f016d
20 changed files with 228 additions and 58 deletions

View File

@@ -6,6 +6,7 @@ local LogColors = { [LogInfo] = 'white',
[LogError] = 'red' }
local MaxLogLines = 80
local LabelHeight = 16
local MaxHistory = 1000
-- private variables
local terminalWidget
@@ -109,6 +110,8 @@ function Terminal.init()
terminalButton = TopMenu.addButton('terminalButton', 'Terminal (Ctrl + T)', '/core_styles/icons/terminal.png', Terminal.toggle)
Hotkeys.bind('Ctrl+T', Terminal.toggle)
commandHistory = Settings.getList('terminal-history')
commandLineEdit = terminalWidget:getChildById('commandLineEdit')
Hotkeys.bind('Up', function() navigateCommand(1) end, commandLineEdit)
Hotkeys.bind('Down', function() navigateCommand(-1) end, commandLineEdit)
@@ -122,6 +125,7 @@ function Terminal.init()
end
function Terminal.terminate()
Settings.setList('terminal-history', commandHistory)
Hotkeys.unbind('Ctrl+T')
Logger.setOnLog(nil)
terminalButton:destroy()
@@ -186,6 +190,9 @@ function Terminal.executeCommand(command)
-- add new command to history
table.insert(commandHistory, command)
if #commandHistory > MaxHistory then
table.remove(commandHistory, 1)
end
-- add command line
Terminal.addLine(">> " .. command, "#ffffff")

View File

@@ -4,6 +4,7 @@ TopMenu = {}
local topMenu
local leftButtonsPanel
local rightButtonsPanel
local gameButtonsPanel
-- private functions
local function onLogout()
@@ -19,6 +20,7 @@ function TopMenu.init()
topMenu = displayUI('topmenu.otui')
leftButtonsPanel = topMenu:getChildById('leftButtonsPanel')
rightButtonsPanel = topMenu:getChildById('rightButtonsPanel')
gameButtonsPanel = topMenu:getChildById('gameButtonsPanel')
TopMenu.addRightButton('logoutButton', 'Logout (Ctrl+Q)', '/core_styles/icons/logout.png', onLogout)
Hotkeys.bind('Ctrl+Q', onLogout)
@@ -51,6 +53,15 @@ function TopMenu.addButton(id, description, icon, callback, right)
return button
end
function TopMenu.addGameButton(id, description, icon, callback)
local button = createWidget('GameTopButton', gameButtonsPanel)
button:setId(id)
button:setTooltip(description)
button:setIcon(resolvepath(icon, 2))
button.onClick = callback
return button
end
function TopMenu.addLeftButton(id, description, icon, callback)
return TopMenu.addButton(id, description, icon, callback, false)
end

View File

@@ -1,22 +1,45 @@
TopButton < UIButton
size: 26 26
image-color: white
image-source: /core_styles/images/top_button.png
image-clip: 0 0 26 26
image-border: 3
image-color: #ffffffff
icon-color: #ffffffff
$hover:
image-source: /core_styles/images/top_button.png
image-color: #ffffff99
image-clip: 26 0 26 26
image-border: 3
$pressed:
image-source: /core_styles/images/top_button.png
image-clip: 52 0 26 26
image-border: 3
$disabled:
image-color: #ffffff66
image-color: #ffffff44
icon-color: #ffffff44
GameTopButton < UIButton
size: 26 26
image-source: /core_styles/images/top_button2.png
image-clip: 26 0 26 26
image-color: #ffffff22
icon-color: #ffffffff
image-border: 3
$hover:
image-clip: 0 0 26 26
image-color: #ffffffff
icon-color: #ffffffff
$first:
anchors.top: parent.top
anchors.left: parent.left
margin-top: 4
margin-left: 6
$!first:
anchors.top: prev.top
anchors.left: prev.right
margin-left: 6
TopLeftButton < TopButton
$first:
@@ -54,6 +77,13 @@ TopPanel
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: parent.left
width: 150
Panel
id: gameButtonsPanel
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.left: prev.right
anchors.right: next.left
Panel

View File

@@ -10,6 +10,8 @@ local function convertSettingValue(value)
return sizetostring(value)
elseif value.r then
return colortostring(value)
else
return value
end
elseif value == nil then
return ''
@@ -30,6 +32,10 @@ function Settings.set(key, value)
g_configs.set(key, convertSettingValue(value))
end
function Settings.setList(key, list)
g_configs.setList(key, list)
end
function Settings.setDefault(key, value)
if Settings.exists(key) then return false end
Settings.set(key, value)
@@ -43,6 +49,10 @@ function Settings.get(key, default)
return g_configs.get(key)
end
function Settings.getList(key)
return g_configs.getList(key)
end
function Settings.getString(key, default)
return Settings.get(key, default)
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 391 B

After

Width:  |  Height:  |  Size: 646 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 928 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 470 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

View File

@@ -2,16 +2,16 @@ UIComboBox = extends(UIWidget)
function UIComboBox.create()
local combobox = UIComboBox.internalCreate()
combobox.options = {}
combobox.currentIndex = -1
combobox.m_options = {}
combobox.m_currentIndex = -1
return combobox
end
function UIComboBox:setCurrentOption(text)
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
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
self:setText(text)
self:onOptionChange(text, data)
return
@@ -20,15 +20,15 @@ function UIComboBox:setCurrentOption(text)
end
function UIComboBox:addOption(text, data)
table.insert(self.options, { text = text, data = data })
local index = #self.options
table.insert(self.m_options, { text = text, data = data })
local index = #self.m_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.options) do
for i,v in ipairs(self.m_options) do
menu:addOption(v.text, function() self:setCurrentOption(v.text) end)
end
menu:setWidth(self:getWidth())

View File

@@ -0,0 +1,23 @@
UIMessageBox = extends(UIWindow)
function UIMessageBox.create(title, message)
local messagebox = UIMessageBox.internalCreate()
messagebox:setText(title)
local messageLabel = self:getChildById('messageLabel')
label:setText(message)
label:resizeToText()
window:setWidth(math.max(label:getWidth() + self:getPaddingLeft() + self:getPaddingRight(), self:getWidth()))
window:setHeight(label:getHeight() + self:getPaddingTop() + self:getPaddingBottom())
return messagebox
end
function UIMessageBox:setTitle(title)
end
function UIMessageBox:setMessage(message)
end
function

View File

@@ -4,19 +4,28 @@ function UIProgressBar.create()
local progressbar = UIProgressBar.internalCreate()
progressbar:setFocusable(false)
progressbar:setPhantom(true)
progressbar.percent = 0
progressbar:setBackgroundSize({width = 1, height = 1})
progressbar.m_percent = 0
progressbar:updateBackground()
return progressbar
end
function UIProgressBar:setPercent(percent)
self:setBackgroundHeight(self:getHeight())
local width = (percent * self:getWidth())/100
if width == 0 then width = 1 end
self:setBackgroundWidth(width)
self.percent = percent
self.m_percent = percent
self:updateBackground()
end
function UIProgressBar:getPercent()
return self.percent
return self.m_percent
end
function UIProgressBar:updateBackground()
local width = math.max((self.m_percent * self:getWidth())/100, 1)
local height = self:getHeight()
self:setBackgroundSize({width=width, height=height})
end
function UIProgressBar:onGeometryChange(oldRect, newRect)
self:updateBackground()
end

View File

@@ -7,9 +7,9 @@ Module
dependencies:
- game_healthbar
- game_inventory
- game_skills
//- game_skills
- game_textmessage
//- game_viplist
- game_viplist
- game_console
- game_outfit
- game_containers

View File

@@ -43,8 +43,7 @@ end
-- public functions
function Skills.create()
skillWindow = displayUI('skills.otui', { parent = Game.gameRightPanel })
--skillsButton = TopMenu.addButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
--skillsButton:setWidth(32)
skillsButton = TopMenu.addGameButton('skillsButton', 'Skills (Ctrl+S)', '/core_styles/icons/skills.png', Skills.toggle)
end
function Skills.destroy()

View File

@@ -7,6 +7,8 @@ local addVipWindow = nil
-- public functions
function VipList.create()
vipWindow = displayUI('viplist.otui', { parent = Game.gameRightPanel })
vipWindow:hide()
TopMenu.addGameButton('vipListButton', 'VIP list', '/core_styles/icons/viplist.png', VipList.toggle)
end
function VipList.destroy()
@@ -43,21 +45,21 @@ function VipList.onAddVip(id, name, online)
end
label.vipOnline = online
local nameLower = name:lower()
local childrenCount = vipList:getChildCount()
for i=1,childrenCount do
local child = vipList:getChildByIndex(i)
if online and not child.vipOnline then
vipList:insertChild(i, label)
return
end
if (not online and not child.vipOnline) or (online and child.vipOnline) then
local childText = child:getText():lower()
local length = math.min(childText:len(), nameLower:len())
for j=1,length do
if nameLower:byte(j) < childText:byte(j) then
vipList:insertChild(i, label)
@@ -68,7 +70,7 @@ function VipList.onAddVip(id, name, online)
end
end
end
vipList:insertChild(childrenCount+1, label)
end
@@ -77,7 +79,7 @@ function VipList.onVipStateChange(id, online)
local label = vipList:getChildById('vip' .. id)
local text = label:getText()
vipList:removeChild(label)
VipList.onAddVip(id, text, online)
end
@@ -89,7 +91,7 @@ function VipList.onVipListMousePress(widget, mousePos, mouseButton)
local menu = createWidget('PopupMenu')
menu:addOption('Add new VIP', function() VipList.createAddWindow() end)
menu:display(mousePos)
return true
end
@@ -104,7 +106,7 @@ function VipList.onVipListLabelMousePress(widget, mousePos, mouseButton)
menu:addSeparator()
menu:addOption('Copy Name', function() g_window.setClipboardText(widget:getText()) end)
menu:display(mousePos)
return true
end