fix some keyboard issues, chat tab, fix loadScript exception

This commit is contained in:
Eduardo Bart 2012-01-13 18:37:44 -02:00
parent f57d46de0e
commit aae784468b
11 changed files with 62 additions and 29 deletions

View File

@ -8,10 +8,10 @@ local characterList
-- private functions
local function onCharactersWindowKeyPress(self, keyCode, keyText, keyboardModifiers)
if keyboardModifiers == KeyboardNoModifier then
if keyCode == KeyUp or keyCode == KeyTab then
if keyCode == KeyUp then
characterList:focusPreviousChild(ActiveFocusReason)
return true
elseif keyCode == KeyDown then
elseif keyCode == KeyDown or keyCode == KeyTab then
characterList:focusNextChild(ActiveFocusReason)
return true
end

View File

@ -29,7 +29,7 @@ end
local function determineKeyComboDesc(keyCode, keyboardModifiers)
local keyCombo = {}
if keyCode == KeyShift or keyCode == KeyAlt or keyCode == KeyAltGr then
if keyCode == KeyCtrl or keyCode == KeyShift or keyCode == KeyAlt or keyCode == KeyAltGr then
table.insert(keyCombo, keyCode)
elseif KeyCodeDescs[keyCode] ~= nil then
if keyboardModifiers == KeyboardCtrlModifier then
@ -59,6 +59,7 @@ local function determineKeyComboDesc(keyCode, keyboardModifiers)
end
local function onWidgetKeyPress(widget, keyCode, keyText, keyboardModifiers)
if keyCode == KeyUnknown then return end
local keyComboDesc = determineKeyComboDesc(keyCode, keyboardModifiers)
local callback = widget.boundKeyCombos[keyComboDesc]
if callback then

View File

@ -16,7 +16,6 @@ InterfacePanel < Panel
image-border: 4
InterfacePanel2 < Panel
focusable: false
image-source: /core_styles/images/interface_panel2.png
image-border: 4

View File

@ -14,6 +14,7 @@ end
-- public functions
function UITabBar.create()
local tabbar = UITabBar.internalCreate()
tabbar:setFocusable(false)
tabbar.tabs = {}
return tabbar
end
@ -46,6 +47,7 @@ function UITabBar:addTab(text, panel)
end
function UITabBar:selectTab(tabButton)
if self.currentTabButton == tabButton then return end
if self.contentWidget then
local selectedWidget = self.contentWidget:getFirstChild()
if selectedWidget then
@ -55,13 +57,31 @@ function UITabBar:selectTab(tabButton)
tabButton.tabPanel:fill('parent')
end
tabButton:setChecked(true)
tabButton:setOn(false)
tabButton.blinking = false
if self.currentTabButton then
self.currentTabButton:setChecked(false)
end
self.currentTabButton = tabButton
tabButton:setChecked(true)
tabButton:setOn(false)
tabButton.blinking = false
end
function UITabBar:selectNextTab()
if self.currentTabButton == nil then return end
local index = table.find(self.tabs, self.currentTabButton)
if index == nil then return end
local nextTab = self.tabs[index + 1] or self.tabs[1]
if not nextTab then return end
self:selectTab(nextTab)
end
function UITabBar:selectPrevTab()
if self.currentTabButton == nil then return end
local index = table.find(self.tabs, self.currentTabButton)
if index == nil then return end
local prevTab = self.tabs[index - 1] or self.tabs[#self.tabs]
if not prevTab then return end
self:selectTab(prevTab)
end
function UITabBar:blinkTab(tabButton)

View File

@ -18,9 +18,9 @@ function Game.createInterface()
CharacterList.destroyLoadBox()
Game.gameUi = displayUI('game.otui')
rootWidget:moveChildToIndex(Game.gameUi, 1)
Game.gameMapPanel = Game.gameUi:getChildById('mapPanel')
Game.gameRightPanel = Game.gameUi:getChildById('rightPanel')
Game.gameBottomPanel = Game.gameUi:getChildById('bottomPanel')
Game.gameMapPanel = Game.gameUi:getChildById('gameMapPanel')
Game.gameRightPanel = Game.gameUi:getChildById('gameRightPanel')
Game.gameBottomPanel = Game.gameUi:getChildById('gameBottomPanel')
Game.gameUi.onKeyPress = onGameKeyPress
end

View File

@ -4,7 +4,7 @@ UIGame
anchors.top: topMenu.bottom
InterfacePanel
id: rightPanel
id: gameRightPanel
width: 200
layout: verticalBox
anchors.right: parent.right
@ -12,16 +12,17 @@ UIGame
anchors.bottom: parent.bottom
InterfacePanel2
id: bottomPanel
id: gameBottomPanel
height: 170
anchors.left: parent.left
anchors.right: rightPanel.left
anchors.right: gameRightPanel.left
anchors.bottom: parent.bottom
Map
id: mapPanel
id: gameMapPanel
anchors.left: parent.left
anchors.right: rightPanel.left
anchors.right: gameRightPanel.left
anchors.top: parent.top
anchors.bottom: bottomPanel.top
anchors.bottom: gameBottomPanel.top
focusable: false

View File

@ -23,7 +23,7 @@ local consoleBuffer
local consoleTabBar
local defaultChannelTab
local serverLogTab
local current
local currentTab
-- public functions
function Console.create()
@ -33,6 +33,9 @@ function Console.create()
consoleTabBar:setContentWidget(consoleBuffer)
defaultChannelTab = consoleTabBar:addTab('Default')
serverLogTab = consoleTabBar:addTab('Server Log')
Hotkeys.bind('Tab', function() consoleTabBar:selectNextTab() end, consolePanel)
Hotkeys.bind('Shift+Tab', function() consoleTabBar:selectPrevTab() end, consolePanel)
end
function Console.destroy()

View File

@ -69,4 +69,5 @@ Panel
margin-right: 6
margin-left: 6
margin-bottom: 6
always-active: true
always-active: true
focusable: false

View File

@ -297,9 +297,13 @@ void LuaInterface::loadScript(const std::string& fileName)
if(!boost::starts_with(fileName, "/"))
filePath = getCurrentSourcePath() + "/" + filePath;
std::string buffer = g_resources.loadFile(filePath);
std::string source = "@" + filePath;
loadBuffer(buffer, source);
try {
std::string buffer = g_resources.loadFile(filePath);
std::string source = "@" + filePath;
loadBuffer(buffer, source);
} catch(Exception& e) {
throw LuaException(e.what());
}
}
void LuaInterface::loadFunction(const std::string& buffer, const std::string& source)

View File

@ -77,8 +77,8 @@ X11Window::X11Window()
m_keyMap[XK_Control_R] = Fw::KeyCtrl;
m_keyMap[XK_Shift_R] = Fw::KeyShift;
m_keyMap[XK_Shift_L] = Fw::KeyShift;
m_keyMap[XK_Alt_R] = Fw::KeyAlt;
m_keyMap[XK_Alt_L] = Fw::KeyAltGr;
m_keyMap[XK_Alt_R] = Fw::KeyAltGr;
m_keyMap[XK_Alt_L] = Fw::KeyAlt;
m_keyMap[XK_Meta_L] = Fw::KeyMeta;
m_keyMap[XK_Meta_R] = Fw::KeyMeta;
m_keyMap[XK_Menu] = Fw::KeyMenu;
@ -642,13 +642,14 @@ void X11Window::poll()
//logDebug("char: ", buf[0], " code: ", (uint)buf[0]);
m_inputEvent.keyText = buf;
}
} else {
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0);
if(len > 0)
m_inputEvent.keyText = buf;
}
XKeyEvent xkey = event.xkey;
xkey.state = xkey.state & ~(ShiftMask);
len = XLookupString(&xkey, buf, sizeof(buf), &keysym, 0);
if(len > 0 && m_inputEvent.keyText.length() == 0)
m_inputEvent.keyText = buf;
if(m_keyMap.find(keysym) != m_keyMap.end())
m_inputEvent.keyCode = m_keyMap[keysym];

View File

@ -27,6 +27,9 @@
bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifiers)
{
if(UIWidget::onKeyPress(keyCode, keyText, keyboardModifiers))
return true;
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("consoleLineEdit"));
if(keyboardModifiers == Fw::KeyboardNoModifier) {
@ -108,5 +111,5 @@ bool UIGame::onKeyPress(uchar keyCode, std::string keyText, int keyboardModifier
return true;
}
return UIWidget::onKeyPress(keyCode, keyText, keyboardModifiers);
return false;
}