Skip to content

Commit

Permalink
Added feature in Issue #5
Browse files Browse the repository at this point in the history
Removed Debug Text
  • Loading branch information
alecxvs committed Jan 27, 2014
1 parent d29134d commit 91f602b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
1 change: 0 additions & 1 deletion utchat/client/formats/motion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Motion Effect

Events:Subscribe( "ModulesLoad", function()
function UText:MoveTo(position, ...)
print("Move to ",position.x," ",position.y)
self:Move(position - self.position, ...)
end
function UText:Move(offset, duration, func)
Expand Down
48 changes: 45 additions & 3 deletions utchat/client/utext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
end
end
end



local function escape(s)
return (s:gsub('[%-%.%+%[%]%(%)%$%^%%%?%*]','%%%1'):gsub('%z','%%z'))
end

----:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::----
--::::::::::: User Access Function :::::::::::::--
Expand Down Expand Up @@ -101,15 +105,16 @@
self.text = self.text:sub(1,firstindex-1) .. self.text:sub(lastindex+1)

for i,f in ipairs(self.formats) do
if f.endpos > index then
if f.endpos > lastindex then
f.endpos = f.endpos - length
if f.startpos > index then
if f.startpos > lastindex then
f.startpos = f.startpos - length
end
end
end
elseif type(first) == "string" then
local str = first
str = escape(str)
local i = self.text:match(str)
if i and i > 0 then self:RemoveText(i,#str-1) end
return i
Expand All @@ -118,6 +123,43 @@
end
end

function UText:ReplaceText(text, repl)
text = escape(text)
print("^.-()"..text.."().*")
local firstindex, lastindex = self.text:match("^.-()"..text.."().*")
if not firstindex or not lastindex then return false end
local length = lastindex - firstindex + 1
local diff = #text - #repl

self.text = self.text:gsub("(.-)"..text.."(.-)","%1"..repl.."%2")

if diff != 0 then
local i = 1
::refresh::
while i <= #self.formats do
f = self.formats[i]
if f.startpos >= lastindex then
f.startpos = f.startpos + diff
elseif lastindex-diff < f.startpos then
f.startpos = lastindex + diff
end

if f.endpos >= lastindex then
f.endpos = f.endpos + diff
elseif lastindex-diff < f.endpos then
f.endpos = lastindex + diff
end

if f.endpos == f.startpos then
table.remove(self.formats,i)
goto refresh
end
i = i + 1
end
end
return true
end

--Returns the duration of the visibility of UText
function UText:GetDuration()
return self.lifetime
Expand Down

0 comments on commit 91f602b

Please sign in to comment.