Some fixes in hotkeys and other improvements

* Save last logged character and world instead of character name
* Make focused label always visible in character list and hotkeys
* Other fixes in hotkeys
master
Eduardo Bart 11 years ago
parent 197a379933
commit d6e8e92a45

@ -38,7 +38,8 @@ local function tryLogin(charInfo, tries)
end }) end })
-- save last used character -- save last used character
g_settings.set('lastUsedCharacter', charInfo.characterName) g_settings.set('last-used-character', charInfo.characterName)
g_settings.set('last-used-world', charInfo.worldName)
end end
local function updateWait(timeStart, timeEnd) local function updateWait(timeStart, timeEnd)
@ -224,12 +225,15 @@ function CharacterList.create(characters, account, otui)
connect(widget, { onDoubleClick = function () CharacterList.doLogin() return true end } ) connect(widget, { onDoubleClick = function () CharacterList.doLogin() return true end } )
if i == 1 or g_settings.get('lastUsedCharacter') == widget.characterName then if i == 1 or (g_settings.get('last-used-character') == widget.characterName and g_settings.get('last-used-world') == widget.worldName) then
focusLabel = widget focusLabel = widget
end end
end end
characterList:focusChild(focusLabel, ActiveFocusReason) if focusLabel then
characterList:focusChild(focusLabel, KeyboardFocusReason)
addEvent(function() characterList:ensureChildVisible(focusLabel) end)
end
-- account -- account
if account.premDays > 0 and account.premDays < 65535 then if account.premDays > 0 and account.premDays < 65535 then

@ -62,10 +62,13 @@ local function onUpdateNeeded(protocol, signature)
loadBox:destroy() loadBox:destroy()
loadBox = nil loadBox = nil
if updateFunc then if EnterGame.updateFunc then
local continueFunc = EnterGame.show local continueFunc = EnterGame.show
local cancelFunc = EnterGame.show local cancelFunc = EnterGame.show
updateFunc(signature, continueFunc, cancelFunc) EnterGame.updateFunc(signature, continueFunc, cancelFunc)
else
local errorBox = displayErrorBox(tr('Update needed'), tr('Your client needs update, try redownloading it.'))
connect(errorBox, { onOk = EnterGame.show })
end end
end end

@ -116,26 +116,26 @@ function UIScrollArea:onMouseWheel(mousePos, mouseWheel)
return true return true
end end
function UIScrollArea:onChildFocusChange(focusedChild, oldFocused, reason) function UIScrollArea:ensureChildVisible(child)
if focusedChild and (reason == MouseFocusReason or reason == KeyboardFocusReason) then if child then
local paddingRect = self:getPaddingRect() local paddingRect = self:getPaddingRect()
if self.verticalScrollBar then if self.verticalScrollBar then
local deltaY = paddingRect.y - focusedChild:getY() local deltaY = paddingRect.y - child:getY()
if deltaY > 0 then if deltaY > 0 then
self.verticalScrollBar:decrement(deltaY) self.verticalScrollBar:decrement(deltaY)
end end
deltaY = (focusedChild:getY() + focusedChild:getHeight()) - (paddingRect.y + paddingRect.height) deltaY = (child:getY() + child:getHeight()) - (paddingRect.y + paddingRect.height)
if deltaY > 0 then if deltaY > 0 then
self.verticalScrollBar:increment(deltaY) self.verticalScrollBar:increment(deltaY)
end end
else else
local deltaX = paddingRect.x - focusedChild:getX() local deltaX = paddingRect.x - child:getX()
if deltaX > 0 then if deltaX > 0 then
self.horizontalScrollBar:decrement(deltaX) self.horizontalScrollBar:decrement(deltaX)
end end
deltaX = (focusedChild:getX() + focusedChild:getWidth()) - (paddingRect.x + paddingRect.width) deltaX = (child:getX() + child:getWidth()) - (paddingRect.x + paddingRect.width)
if deltaX > 0 then if deltaX > 0 then
self.horizontalScrollBar:increment(deltaX) self.horizontalScrollBar:increment(deltaX)
end end
@ -143,6 +143,12 @@ function UIScrollArea:onChildFocusChange(focusedChild, oldFocused, reason)
end end
end end
function UIScrollArea:onChildFocusChange(focusedChild, oldFocused, reason)
if focusedChild and (reason == MouseFocusReason or reason == KeyboardFocusReason) then
self:ensureChildVisible(focusedChild)
end
end
function UIScrollArea:onScrollWidthChange() function UIScrollArea:onScrollWidthChange()
if self.alwaysScrollMaximum and self.horizontalScrollBar then if self.alwaysScrollMaximum and self.horizontalScrollBar then
self.horizontalScrollBar:setValue(self.horizontalScrollBar:getMaximum()) self.horizontalScrollBar:setValue(self.horizontalScrollBar:getMaximum())

@ -213,7 +213,7 @@ function onChooseItemMouseRelease(self, mousePosition, mouseButton)
end end
end end
if item then if item and hotkeyLabelSelectedOnList then
currentItemPreview:setItemId(item:getId()) currentItemPreview:setItemId(item:getId())
hotkeyLabelSelectedOnList.itemId = item:getId() hotkeyLabelSelectedOnList.itemId = item:getId()
changeUseType(HOTKEY_MANAGER_USEONSELF) changeUseType(HOTKEY_MANAGER_USEONSELF)
@ -235,7 +235,7 @@ function startChooseItem()
connect(mouseGrabberWidget, { onMouseRelease = onChooseItemMouseRelease }) connect(mouseGrabberWidget, { onMouseRelease = onChooseItemMouseRelease })
mouseGrabberWidget:grabMouse() mouseGrabberWidget:grabMouse()
g_mouse.pushCursor('target-cursor') g_mouse.pushCursor('target')
hide() hide()
end end
@ -260,10 +260,11 @@ function addHotkey()
connect(assignWindow, { onKeyDown = hotkeyCapture }, true) connect(assignWindow, { onKeyDown = hotkeyCapture }, true)
end end
function addKeyCombo(messageBox, keyCombo, keySettings) function addKeyCombo(messageBox, keyCombo, keySettings, focus)
local label = nil if not keyCombo then return end
if currentHotkeysList:getChildById(keyCombo) == nil then local label = currentHotkeysList:getChildById(keyCombo)
local label = g_ui.createWidget('HotkeyListLabel') if not label then
label = g_ui.createWidget('HotkeyListLabel')
label:setId(keyCombo) label:setId(keyCombo)
label:setColor(HotkeyColors.text) label:setColor(HotkeyColors.text)
label:setText(keyCombo .. ': ') label:setText(keyCombo .. ': ')
@ -289,10 +290,9 @@ function addKeyCombo(messageBox, keyCombo, keySettings)
if keySettings then if keySettings then
hotkeyLabelSelectedOnList = label hotkeyLabelSelectedOnList = label
label.keyCombo = keyCombo label.keyCombo = keyCombo
setSendAutomatically(keySettings.autoSend) label.autoSend = keySettings.autoSend
label.itemId = keySettings.itemId label.itemId = keySettings.itemId
currentItemPreview:setItemId(keySettings.itemId) label.useType = tonumber(keySettings.useType)
changeUseType(tonumber(keySettings.useType))
label.value = keySettings.value label.value = keySettings.value
else else
label.keyCombo = keyCombo label.keyCombo = keyCombo
@ -308,6 +308,11 @@ function addKeyCombo(messageBox, keyCombo, keySettings)
g_keyboard.bindKeyPress(keyCombo, function () call(keyCombo) end, nil, 350) g_keyboard.bindKeyPress(keyCombo, function () call(keyCombo) end, nil, 350)
end end
if focus then
currentHotkeysList:focusChild(label)
currentHotkeysList:ensureChildVisible(label)
end
if messageBox then if messageBox then
messageBox:destroy() messageBox:destroy()
messageBox = nil messageBox = nil
@ -340,7 +345,6 @@ function call(keyCombo)
end end
function checkSelectedHotkey(focused) function checkSelectedHotkey(focused)
if not focused then return end
if hotkeysManagerLoaded then if hotkeysManagerLoaded then
hotkeyLabelSelectedOnList = focused hotkeyLabelSelectedOnList = focused
@ -352,6 +356,7 @@ function checkSelectedHotkey(focused)
hotkeyText:focus() hotkeyText:focus()
hotKeyTextLabel:enable() hotKeyTextLabel:enable()
hotkeyText:setText(hotkeyLabelSelectedOnList.value) hotkeyText:setText(hotkeyLabelSelectedOnList.value)
hotkeyText:setCursorPos(-1)
if hotkeyLabelSelectedOnList.value ~= '' then if hotkeyLabelSelectedOnList.value ~= '' then
sendAutomatically:setChecked(hotkeyLabelSelectedOnList.autoSend) sendAutomatically:setChecked(hotkeyLabelSelectedOnList.autoSend)
@ -452,6 +457,7 @@ function removeHotkey()
hotkeyList[hotkeyLabelSelectedOnList.keyCombo] = nil hotkeyList[hotkeyLabelSelectedOnList.keyCombo] = nil
g_keyboard.unbindKeyPress(hotkeyLabelSelectedOnList.keyCombo) g_keyboard.unbindKeyPress(hotkeyLabelSelectedOnList.keyCombo)
hotkeyLabelSelectedOnList:destroy() hotkeyLabelSelectedOnList:destroy()
hotkeyLabelSelectedOnList = nil
end end
end end
@ -470,11 +476,13 @@ function onHotkeyTextChange(id, value)
end end
function setSendAutomatically(value) function setSendAutomatically(value)
hotkeyLabelSelectedOnList.autoSend = value if hotkeyLabelSelectedOnList ~= nil then
if value then hotkeyLabelSelectedOnList.autoSend = value
hotkeyLabelSelectedOnList:setColor(HotkeyColors.autoSend) if value then
else hotkeyLabelSelectedOnList:setColor(HotkeyColors.autoSend)
hotkeyLabelSelectedOnList:setColor(HotkeyColors.text) else
hotkeyLabelSelectedOnList:setColor(HotkeyColors.text)
end
end end
end end

@ -215,7 +215,7 @@ HotkeyAssignWindow < MainWindow
width: 64 width: 64
anchors.right: next.left anchors.right: next.left
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
@onClick: modules.game_hotkeys.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo) @onClick: modules.game_hotkeys.addKeyCombo(self:getParent(), self:getParent():getChildById('comboPreview').keyCombo, nil, true)
margin-right: 10 margin-right: 10
Button Button

@ -217,7 +217,7 @@ function refresh()
end end
function offline() function offline()
expSpeedEvent:cancel() if expSpeedEvent then expSpeedEvent:cancel() expSpeedEvent = nil end
end end
function toggle() function toggle()

@ -33,7 +33,7 @@ public:
bool spawnProcess(const std::string& process, const std::vector<std::string>& args); bool spawnProcess(const std::string& process, const std::vector<std::string>& args);
int getProcessId(); int getProcessId();
std::string getTempPath(); std::string getTempPath();
void copyFile(std::string from, std::string to); bool copyFile(std::string from, std::string to);
void openUrl(std::string url); void openUrl(std::string url);
std::string getCPUName(); std::string getCPUName();
double getTotalSystemMemory(); double getTotalSystemMemory();

@ -28,6 +28,8 @@
#include <string.h> #include <string.h>
#include <framework/stdext/stdext.h> #include <framework/stdext/stdext.h>
#include <sys/stat.h>
void Platform::processArgs(std::vector<std::string>& args) void Platform::processArgs(std::vector<std::string>& args)
{ {
//nothing todo, linux args are already utf8 encoded //nothing todo, linux args are already utf8 encoded
@ -35,6 +37,10 @@ void Platform::processArgs(std::vector<std::string>& args)
bool Platform::spawnProcess(const std::string& process, const std::vector<std::string>& args) bool Platform::spawnProcess(const std::string& process, const std::vector<std::string>& args)
{ {
struct stat sts;
if(stat(process.c_str(), &sts) == -1 && errno == ENOENT)
return false;
pid_t pid = fork(); pid_t pid = fork();
if(pid == -1) if(pid == -1)
return false; return false;
@ -46,7 +52,8 @@ bool Platform::spawnProcess(const std::string& process, const std::vector<std::s
cargs[i] = (char*)args[i-1].c_str(); cargs[i] = (char*)args[i-1].c_str();
cargs[args.size()+1] = 0; cargs[args.size()+1] = 0;
execv(process.c_str(), cargs); if(execv(process.c_str(), cargs) == -1)
_exit(EXIT_FAILURE);
} }
return true; return true;
@ -62,9 +69,9 @@ std::string Platform::getTempPath()
return "/tmp/"; return "/tmp/";
} }
void Platform::copyFile(std::string from, std::string to) bool Platform::copyFile(std::string from, std::string to)
{ {
system(stdext::format("/bin/cp '%s' '%s'", from, to).c_str()); return system(stdext::format("/bin/cp '%s' '%s'", from, to).c_str()) == 0;
} }
void Platform::openUrl(std::string url) void Platform::openUrl(std::string url)

@ -68,11 +68,13 @@ std::string Platform::getTempPath()
return stdext::utf16_to_utf8(path); return stdext::utf16_to_utf8(path);
} }
void Platform::copyFile(std::string from, std::string to) bool Platform::copyFile(std::string from, std::string to)
{ {
boost::replace_all(from, "/", "\\"); boost::replace_all(from, "/", "\\");
boost::replace_all(to, "/", "\\"); boost::replace_all(to, "/", "\\");
CopyFileW(stdext::utf8_to_utf16(from).c_str(), stdext::utf8_to_utf16(to).c_str(), false); if(CopyFileW(stdext::utf8_to_utf16(from).c_str(), stdext::utf8_to_utf16(to).c_str(), FALSE) == 0)
return false;
return true;
} }
void Platform::openUrl(std::string url) void Platform::openUrl(std::string url)

Loading…
Cancel
Save