Skip to content
Snippets Groups Projects
Commit 6d915018 authored by dg's avatar dg
Browse files

Textbox/Numberbox should correctly work with movement keys

git-svn-id: http://svn.net-core.org/repos/t-engine4@4359 51575b47-30f0-44d4-a5cc-537603b46e54
parent 7be7e47c
No related branches found
No related tags found
No related merge requests found
......@@ -210,6 +210,8 @@ function _M:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup, key, ismouse)
self:handleStatus(sym, ctrl, shift, alt, meta, unicode, isup)
if self.ignore[sym] then return end
if self.any_key then self.any_key(sym, ctrl, shift, alt, meta, unicode, isup, key) end
local ks, us
......
......@@ -29,7 +29,6 @@ function _M:init()
self.commands = {}
self.ignore = {}
self.on_input = false
self.locale_convert = {}
-- Fullscreen toggle
self:addCommand(self._RETURN, {"alt"}, function() core.display.fullscreen() end)
......@@ -55,9 +54,6 @@ function _M:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup, key)
if self.ignore[sym] then return end
-- Convert locale
sym = self.locale_convert[sym] or sym
local handled = false
if not self.commands[sym] and not self.commands[self.__DEFAULT] then
......@@ -161,19 +157,3 @@ end
function _M:setTextInput(fct)
self.on_input = fct
end
--- Loads a locale converter
-- WARNING: This only converts the "sym" key, *NOT* the unicode key
-- @param file the locale conversion file to load
function _M:loadLocaleConversion(file)
local f, err = loadfile(file)
if not f and err then error(err) end
setfenv(f, setmetatable({
locale = config.settings.keyboard.locale,
}, {__index=engine.Key}))
conv = f() or {}
for k, e in pairs(conv) do
self.locale_convert[k] = e
end
end
......@@ -69,7 +69,9 @@ function _M:filterMessage(item)
end
function _M:addMessage(kind, channel, login, name, msg, extra_data, no_change)
local item = {kind=kind, login=login, name=name, msg=msg, extra_data=extra_data, timestamp=core.game.getTime()}
local color_name = colors.WHITE
if type(name) == "table" then name, color_name = name[1], name[2] end
local item = {kind=kind, login=login, name=name, color_name=color_name, msg=msg, extra_data=extra_data, timestamp=core.game.getTime()}
if self:filterMessage(item) then return end
if self.uc_ext and self.uc_ext.filterMessage then
if self.uc_ext:filterMessage(item) then return end
......@@ -94,50 +96,72 @@ end
function _M:event(e)
if e.se == "Talk" then
e.msg = e.msg:removeColorCodes()
local color = colors.WHITE
if e.donator == "oneshot" then color = colors.LIGHT_GREEN
elseif e.donator == "recurring" then color = colors.LIGHT_BLUE end
self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}}
self:addMessage("talk", e.channel, e.login, e.name, e.msg)
self:addMessage("talk", e.channel, e.login, {e.name, color}, e.msg)
if type(game) == "table" and game.logChat and self.cur_channel == e.channel then
game.logChat("#YELLOW#<%s> %s", e.name, e.msg)
end
elseif e.se == "Whisper" then
e.msg = e.msg:removeColorCodes()
local color = colors.WHITE
if e.donator == "oneshot" then color = colors.LIGHT_GREEN
elseif e.donator == "recurring" then color = colors.LIGHT_BLUE end
self.channels[self.cur_channel] = self.channels[self.cur_channel] or {users={}, log={}}
self:addMessage("whisper", self.cur_channel, e.login, e.name, "#GOLD#<whisper> #LAST#"..e.msg)
self:addMessage("whisper", self.cur_channel, e.login, {e.name, color}, "#GOLD#<whisper> #LAST#"..e.msg)
if type(game) == "table" and game.logChat then
game.logChat("#GOLD#<Whisper from %s> %s", e.name, e.msg)
end
elseif e.se == "Achievement" then
e.msg = e.msg:removeColorCodes()
local color = colors.WHITE
if e.donator == "oneshot" then color = colors.LIGHT_GREEN
elseif e.donator == "recurring" then color = colors.LIGHT_BLUE end
self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}}
self:addMessage("achievement", e.channel, e.login, e.name, "#{italic}##LIGHT_BLUE#has earned the achievement <"..e.msg..">#{normal}#", nil, true)
self:addMessage("achievement", e.channel, e.login, {e.name, color}, "#{italic}##LIGHT_BLUE#has earned the achievement <"..e.msg..">#{normal}#", nil, true)
if type(game) == "table" and game.logChat and self.cur_channel == e.channel then
game.logChat("#LIGHT_BLUE#%s has earned the achievement <%s>", e.name, e.msg)
end
elseif e.se == "SerialData" then
local color = colors.WHITE
if e.donator == "oneshot" then color = colors.LIGHT_GREEN
elseif e.donator == "recurring" then color = colors.LIGHT_BLUE end
e.color_name = color
self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}}
if self.uc_ext then
self.uc_ext:event(e)
end
elseif e.se == "Join" then
local color = colors.WHITE
if e.donator == "oneshot" then color = colors.LIGHT_GREEN
elseif e.donator == "recurring" then color = colors.LIGHT_BLUE end
self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}}
self.channels[e.channel].users[e.login] = {name=e.name, login=e.login}
self.channels[e.channel].users[e.login] = {name=e.name, donator=e.donator, login=e.login}
self.channels_changed = true
self:addMessage("join", e.channel, e.login, e.name, "#{italic}##FIREBRICK#has joined the channel#{normal}#", nil, true)
self:addMessage("join", e.channel, e.login, {e.name, color}, "#{italic}##FIREBRICK#has joined the channel#{normal}#", nil, true)
if type(game) == "table" and game.logChat and e.channel == self.cur_channel then
game.logChat("#{italic}##FIREBRICK#%s has joined channel %s (press space to talk).#{normal}#", e.login, e.channel)
end
self:updateChanList()
elseif e.se == "Part" then
local color = colors.WHITE
if e.donator == "oneshot" then color = colors.LIGHT_GREEN
elseif e.donator == "recurring" then color = colors.LIGHT_BLUE end
self.channels[e.channel] = self.channels[e.channel] or {users={}, log={}}
self.channels[e.channel].users[e.login] = nil
self.channels_changed = true
self:addMessage("join", e.channel, e.login, e.name, "#{italic}##FIREBRICK#has left the channel#{normal}#", nil, true)
self:addMessage("join", e.channel, e.login, {e.name, color}, "#{italic}##FIREBRICK#has left the channel#{normal}#", nil, true)
if type(game) == "table" and game.logChat and e.channel == self.cur_channel then
game.logChat("#{italic}##FIREBRICK#%s has left channel %s.#{normal}#", e.login, e.channel)
end
......@@ -154,6 +178,7 @@ function _M:event(e)
self.channels[e.channel].users[user.login] = {
login=user.login,
name=user.name,
donator=user.donator,
current_char=user.current_char and user.current_char.title or "unknown",
module=user.current_char and user.current_char.module or "unknown",
valid=user.current_char and user.current_char.valid and "validate" or "not validated",
......@@ -434,7 +459,8 @@ function _M:display()
local old_style = self.font:getStyle()
for z = 1 + self.scroll, #log do
local stop = false
local tstr = ("<%s> %s"):format(log[z].name, log[z].msg):toTString()
local tstr = tstring{"<", {"color",unpack(colors.simple(log[z].color_name))}, log[z].name, {"color", "LAST"}, "> "}
tstr:merge(log[z].msg:toTString())
local gen = tstring.makeLineTextures(tstr, self.w, self.font_mono)
for i = #gen, 1, -1 do
gen[i].login = log[z].login
......
......@@ -302,12 +302,12 @@ function _M:generate()
self.mouse:registerZone(self.display_x, self.display_y, self.w, self.h, function(...) self:mouseEvent(...) end)
end
self.key.receiveKey = function(_, ...) self:keyEvent(...) end
self.key:addCommand("_TAB", function(...) self.key:triggerVirtual("MOVE_DOWN") end)
self.key:addBinds{
MOVE_UP = function() self:moveFocus(-1) end,
MOVE_DOWN = function() self:moveFocus(1) end,
MOVE_LEFT = "MOVE_UP",
MOVE_RIGHT = "MOVE_DOWN",
self.key:addCommands{
_TAB = function() self:moveFocus(1) end,
_UP = function() self:moveFocus(-1) end,
_DOWN = function() self:moveFocus(1) end,
_LEFT = function() self:moveFocus(-1) end,
_RIGHT = function() self:moveFocus(1) end,
}
end
......
......@@ -88,12 +88,13 @@ function _M:generate()
end
end)
self.key:addBind("ACCEPT", function() self.first = false self.fct(self.text) end)
self.key:addBind("MOVE_UP", function() self.first = false self:updateText(1) end)
self.key:addBind("MOVE_DOWN", function() self.first = false self:updateText(-1) end)
self.key:addBind("MOVE_LEFT", function() self.first = false self.cursor = util.bound(self.cursor - 1, 1, #self.tmp+1) self.scroll = util.scroll(self.cursor, self.scroll, self.max_display) self:updateText() end)
self.key:addBind("MOVE_RIGHT", function() self.first = false self.cursor = util.bound(self.cursor + 1, 1, #self.tmp+1) self.scroll = util.scroll(self.cursor, self.scroll, self.max_display) self:updateText() end)
self.key:addIgnore("_ESCAPE", v)
self.key:addIgnore("_TAB", true)
self.key:addCommands{
_UP = function() self.first = false self:updateText(1) end,
_DOWN = function() self.first = false self:updateText(-1) end,
_LEFT = function() self.first = false self.cursor = util.bound(self.cursor - 1, 1, #self.tmp+1) self.scroll = util.scroll(self.cursor, self.scroll, self.max_display) self:updateText() end,
_RIGHT = function() self.first = false self.cursor = util.bound(self.cursor + 1, 1, #self.tmp+1) self.scroll = util.scroll(self.cursor, self.scroll, self.max_display) self:updateText() end,
_DELETE = function()
if self.first then self.first = false self.tmp = {} self:updateText() end
if self.cursor <= #self.tmp then
......
......@@ -93,6 +93,9 @@ function _M:generate()
self.key:addBind("ACCEPT", function() self.fct(self.text) end)
self.key:addIgnore("_ESCAPE", true)
self.key:addIgnore("_TAB", true)
self.key:addIgnore("_UP", true)
self.key:addIgnore("_DOWN", true)
self.key:addCommands{
_LEFT = function() self.cursor = util.bound(self.cursor - 1, 1, #self.tmp+1) self.scroll = util.scroll(self.cursor, self.scroll, self.max_display) self:updateText() end,
_RIGHT = function() self.cursor = util.bound(self.cursor + 1, 1, #self.tmp+1) self.scroll = util.scroll(self.cursor, self.scroll, self.max_display) self:updateText() end,
......
......@@ -1461,6 +1461,12 @@ function _M:setupMouse(reset)
if not item or not user or item.faded == 0 then self.mouse:delegate(button, mx, my, xrel, yrel, nil, nil, event, "playmap") return end
local str = tstring{{"color","GOLD"}, {"font","bold"}, user.name, {"color","LAST"}, {"font","normal"}, true}
if user.donator and user.donator ~= "none" then
local text, color = "Donator", colors.WHITE
if user.donator == "oneshot" then text, color = "Donator", colors.LIGHT_GREEN
elseif user.donator == "recurring" then text, color = "Recurring Donator", colors.LIGHT_BLUE end
str:add({"color",unpack(colors.simple(color))}, text, {"color", "LAST"}, true)
end
str:add({"color","ANTIQUE_WHITE"}, "Playing: ", {"color", "LAST"}, user.current_char, true)
str:add({"color","ANTIQUE_WHITE"}, "Game: ", {"color", "LAST"}, user.module, "(", user.valid, ")",true)
......
......@@ -30,30 +30,30 @@ end
function _M:event(e)
if e.e == "ChatTalk" then
cprofile.pushEvent(string.format("e='Chat' se='Talk' channel=%q login=%q name=%q msg=%q", e.channel, e.login, e.name, e.msg))
cprofile.pushEvent(string.format("e='Chat' se='Talk' channel=%q login=%q name=%q donator=%q msg=%q", e.channel, e.login, e.name, e.donator, e.msg))
print("[USERCHAT] channel talk", e.login, e.channel, e.msg)
elseif e.e == "ChatWhisper" then
cprofile.pushEvent(string.format("e='Chat' se='Whisper' login=%q name=%q msg=%q", e.login, e.name, e.msg))
cprofile.pushEvent(string.format("e='Chat' se='Whisper' login=%q name=%q donator=%q msg=%q", e.login, e.name, e.donator, e.msg))
print("[USERCHAT] whisper", e.login, e.msg)
elseif e.e == "ChatAchievement" then
cprofile.pushEvent(string.format("e='Chat' se='Achievement' channel=%q login=%q name=%q msg=%q", e.channel, e.login, e.name, e.msg))
cprofile.pushEvent(string.format("e='Chat' se='Achievement' channel=%q login=%q name=%q donator=%q msg=%q", e.channel, e.login, e.name, e.donator, e.msg))
print("[USERCHAT] channel achievement", e.login, e.channel, e.msg)
elseif e.e == "ChatSerialData" then
local data = self.client.psock:receive(e.size)
if data then
e.msg = data
cprofile.pushEvent(string.format("e='Chat' se='SerialData' channel=%q login=%q name=%q msg=%q", e.channel, e.login, e.name, e.msg))
cprofile.pushEvent(string.format("e='Chat' se='SerialData' channel=%q login=%q name=%q donator=%q msg=%q", e.channel, e.login, e.name, e.donator, e.msg))
print("[USERCHAT] channel serial data", e.login, e.channel, e.size)
end
elseif e.e == "ChatJoin" then
self.channels[e.channel] = self.channels[e.channel] or {}
self.channels[e.channel][e.login] = true
cprofile.pushEvent(string.format("e='Chat' se='Join' channel=%q login=%q name=%q ", e.channel, e.login, e.name))
cprofile.pushEvent(string.format("e='Chat' se='Join' channel=%q login=%q name=%q donator=%q", e.channel, e.login, e.name, e.donator))
print("[USERCHAT] channel join", e.login, e.channel)
elseif e.e == "ChatPart" then
self.channels[e.channel] = self.channels[e.channel] or {}
self.channels[e.channel][e.login] = nil
cprofile.pushEvent(string.format("e='Chat' se='Part' channel=%q login=%q name=%q ", e.channel, e.login, e.name))
cprofile.pushEvent(string.format("e='Chat' se='Part' channel=%q login=%q name=%q donator=%q", e.channel, e.login, e.name, e.donator))
print("[USERCHAT] channel part", e.login, e.channel)
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment