| @@ -0,0 +1,69 @@ | |||
| 1 | + | function OutputMessage:addData(data) | |
| 2 | + | if type(data) == 'boolean' then | |
| 3 | + | self:addU8(NetworkMessageTypes.Boolean) | |
| 4 | + | self:addU8(booleantonumber(data)) | |
| 5 | + | elseif type(data) == 'number' then | |
| 6 | + | if math.isu8(data) then | |
| 7 | + | self:addU8(NetworkMessageTypes.U8) | |
| 8 | + | self:addU8(data) | |
| 9 | + | elseif math.isu16(data) then | |
| 10 | + | self:addU8(NetworkMessageTypes.U16) | |
| 11 | + | self:addU16(data) | |
| 12 | + | elseif math.isu32(data) then | |
| 13 | + | self:addU8(NetworkMessageTypes.U32) | |
| 14 | + | self:addU32(data) | |
| 15 | + | elseif math.isu64(data) then | |
| 16 | + | self:addU8(NetworkMessageTypes.U64) | |
| 17 | + | self:addU64(data) | |
| 18 | + | else -- negative or non integer numbers | |
| 19 | + | self:addU8(NetworkMessageTypes.NumberString) | |
| 20 | + | self:addString(tostring(data)) | |
| 21 | + | end | |
| 22 | + | elseif type(data) == 'string' then | |
| 23 | + | self:addU8(NetworkMessageTypes.String) | |
| 24 | + | self:addString(data) | |
| 25 | + | elseif type(data) == 'table' then | |
| 26 | + | self:addU8(NetworkMessageTypes.Table) | |
| 27 | + | self:addTable(data) | |
| 28 | + | else | |
| 29 | + | perror('Invalid data type ' .. type(data)) | |
| 30 | + | end | |
| 31 | + | end | |
| 32 | + | ||
| 33 | + | function OutputMessage:addTable(data) | |
| 34 | + | local size = 0 | |
| 35 | + | ||
| 36 | + | -- reserve for size (should be addData, find a way to use it further) | |
| 37 | + | local sizePos = self:getWritePos() | |
| 38 | + | self:addU16(size) | |
| 39 | + | local sizeSize = self:getWritePos() - sizePos | |
| 40 | + | ||
| 41 | + | -- add values | |
| 42 | + | for key,value in pairs(data) do | |
| 43 | + | self:addData(key) | |
| 44 | + | self:addData(value) | |
| 45 | + | size = size + 1 | |
| 46 | + | end | |
| 47 | + | ||
| 48 | + | -- write size | |
| 49 | + | local currentPos = self:getWritePos() | |
| 50 | + | self:setWritePos(sizePos) | |
| 51 | + | self:addU16(size) | |
| 52 | + | ||
| 53 | + | -- fix msg size and go back to end | |
| 54 | + | self:setMessageSize(self:getMessageSize() - sizeSize) | |
| 55 | + | self:setWritePos(currentPos) | |
| 56 | + | end | |
| 57 | + | ||
| 58 | + | function OutputMessage:addColor(color) | |
| 59 | + | self:addU8(color.r) | |
| 60 | + | self:addU8(color.g) | |
| 61 | + | self:addU8(color.b) | |
| 62 | + | self:addU8(color.a) | |
| 63 | + | end | |
| 64 | + | ||
| 65 | + | function OutputMessage:addPosition(position) | |
| 66 | + | self:addU16(position.x) | |
| 67 | + | self:addU16(position.y) | |
| 68 | + | self:addU8(position.z) | |
| 69 | + | end |
| @@ -0,0 +1,3 @@ | |||
| 1 | + | g_settings = makesingleton(g_configs.getSettings()) | |
| 2 | + | ||
| 3 | + | -- Reserved for future functionality |
| @@ -0,0 +1,59 @@ | |||
| 1 | + | -- @docclass string | |
| 2 | + | ||
| 3 | + | function string:split(delim) | |
| 4 | + | local start = 1 | |
| 5 | + | local results = {} | |
| 6 | + | while true do | |
| 7 | + | local pos = string.find(self, delim, start, true) | |
| 8 | + | if not pos then | |
| 9 | + | break | |
| 10 | + | end | |
| 11 | + | table.insert(results, string.sub(self, start, pos-1)) | |
| 12 | + | start = pos + string.len(delim) | |
| 13 | + | end | |
| 14 | + | table.insert(results, string.sub(self, start)) | |
| 15 | + | table.removevalue(results, '') | |
| 16 | + | return results | |
| 17 | + | end | |
| 18 | + | ||
| 19 | + | function string:starts(start) | |
| 20 | + | return string.sub(self, 1, #start) == start | |
| 21 | + | end | |
| 22 | + | ||
| 23 | + | function string:ends(test) | |
| 24 | + | return test =='' or string.sub(self,-string.len(test)) == test | |
| 25 | + | end | |
| 26 | + | ||
| 27 | + | function string:trim() | |
| 28 | + | return string.match(self, '^%s*(.*%S)') or '' | |
| 29 | + | end | |
| 30 | + | ||
| 31 | + | function string:explode(sep, limit) | |
| 32 | + | if type(sep) ~= 'string' or tostring(self):len() == 0 or sep:len() == 0 then | |
| 33 | + | return {} | |
| 34 | + | end | |
| 35 | + | ||
| 36 | + | local i, pos, tmp, t = 0, 1, "", {} | |
| 37 | + | for s, e in function() return string.find(self, sep, pos) end do | |
| 38 | + | tmp = self:sub(pos, s - 1):trim() | |
| 39 | + | table.insert(t, tmp) | |
| 40 | + | pos = e + 1 | |
| 41 | + | ||
| 42 | + | i = i + 1 | |
| 43 | + | if limit ~= nil and i == limit then | |
| 44 | + | break | |
| 45 | + | end | |
| 46 | + | end | |
| 47 | + | ||
| 48 | + | tmp = self:sub(pos):trim() | |
| 49 | + | table.insert(t, tmp) | |
| 50 | + | return t | |
| 51 | + | end | |
| 52 | + | ||
| 53 | + | function string:contains(str, checkCase, start, plain) | |
| 54 | + | if(not checkCase) then | |
| 55 | + | self = self:lower() | |
| 56 | + | str = str:lower() | |
| 57 | + | end | |
| 58 | + | return string.find(self, str, start and start or 1, plain == nil and true or false) | |
| 59 | + | end |
| @@ -0,0 +1,173 @@ | |||
| 1 | + | Struct = {} | |
| 2 | + | ||
| 3 | + | function Struct.pack(format, ...) | |
| 4 | + | local stream = {} | |
| 5 | + | local vars = {...} | |
| 6 | + | local endianness = true | |
| 7 | + | ||
| 8 | + | for i = 1, format:len() do | |
| 9 | + | local opt = format:sub(i, i) | |
| 10 | + | ||
| 11 | + | if opt == '>' then | |
| 12 | + | endianness = false | |
| 13 | + | elseif opt:find('[bBhHiIlL]') then | |
| 14 | + | local n = opt:find('[hH]') and 2 or opt:find('[iI]') and 4 or opt:find('[lL]') and 8 or 1 | |
| 15 | + | local val = tonumber(table.remove(vars, 1)) | |
| 16 | + | ||
| 17 | + | if val < 0 then | |
| 18 | + | val = val + 2 ^ (n * 8 - 1) | |
| 19 | + | end | |
| 20 | + | ||
| 21 | + | local bytes = {} | |
| 22 | + | for j = 1, n do | |
| 23 | + | table.insert(bytes, string.char(val % (2 ^ 8))) | |
| 24 | + | val = math.floor(val / (2 ^ 8)) | |
| 25 | + | end | |
| 26 | + | ||
| 27 | + | if not endianness then | |
| 28 | + | table.insert(stream, string.reverse(table.concat(bytes))) | |
| 29 | + | else | |
| 30 | + | table.insert(stream, table.concat(bytes)) | |
| 31 | + | end | |
| 32 | + | elseif opt:find('[fd]') then | |
| 33 | + | local val = tonumber(table.remove(vars, 1)) | |
| 34 | + | local sign = 0 | |
| 35 | + | ||
| 36 | + | if val < 0 then | |
| 37 | + | sign = 1 | |
| 38 | + | val = -val | |
| 39 | + | end | |
| 40 | + | ||
| 41 | + | local mantissa, exponent = math.frexp(val) | |
| 42 | + | if val == 0 then | |
| 43 | + | mantissa = 0 | |
| 44 | + | exponent = 0 | |
| 45 | + | else | |
| 46 | + | mantissa = (mantissa * 2 - 1) * math.ldexp(0.5, (opt == 'd') and 53 or 24) | |
| 47 | + | exponent = exponent + ((opt == 'd') and 1022 or 126) | |
| 48 | + | end | |
| 49 | + | ||
| 50 | + | local bytes = {} | |
| 51 | + | if opt == 'd' then | |
| 52 | + | val = mantissa | |
| 53 | + | for i = 1, 6 do | |
| 54 | + | table.insert(bytes, string.char(math.floor(val) % (2 ^ 8))) | |
| 55 | + | val = math.floor(val / (2 ^ 8)) | |
| 56 | + | end | |
| 57 | + | else | |
| 58 | + | table.insert(bytes, string.char(math.floor(mantissa) % (2 ^ 8))) | |
| 59 | + | val = math.floor(mantissa / (2 ^ 8)) | |
| 60 | + | table.insert(bytes, string.char(math.floor(val) % (2 ^ 8))) | |
| 61 | + | val = math.floor(val / (2 ^ 8)) | |
| 62 | + | end | |
| 63 | + | ||
| 64 | + | table.insert(bytes, string.char(math.floor(exponent * ((opt == 'd') and 16 or 128) + val) % (2 ^ 8))) | |
| 65 | + | val = math.floor((exponent * ((opt == 'd') and 16 or 128) + val) / (2 ^ 8)) | |
| 66 | + | table.insert(bytes, string.char(math.floor(sign * 128 + val) % (2 ^ 8))) | |
| 67 | + | val = math.floor((sign * 128 + val) / (2 ^ 8)) | |
| 68 | + | ||
| 69 | + | if not endianness then | |
| 70 | + | table.insert(stream, string.reverse(table.concat(bytes))) | |
| 71 | + | else | |
| 72 | + | table.insert(stream, table.concat(bytes)) | |
| 73 | + | end | |
| 74 | + | elseif opt == 's' then | |
| 75 | + | table.insert(stream, tostring(table.remove(vars, 1))) | |
| 76 | + | table.insert(stream, string.char(0)) | |
| 77 | + | elseif opt == 'c' then | |
| 78 | + | local n = format:sub(i + 1):match('%d+') | |
| 79 | + | local length = tonumber(n) | |
| 80 | + | ||
| 81 | + | if length > 0 then | |
| 82 | + | local str = tostring(table.remove(vars, 1)) | |
| 83 | + | if length - str:len() > 0 then | |
| 84 | + | str = str .. string.rep(' ', length - str:len()) | |
| 85 | + | end | |
| 86 | + | table.insert(stream, str:sub(1, length)) | |
| 87 | + | end | |
| 88 | + | i = i + n:len() | |
| 89 | + | end | |
| 90 | + | end | |
| 91 | + | ||
| 92 | + | return table.concat(stream) | |
| 93 | + | end | |
| 94 | + | ||
| 95 | + | function Struct.unpack(format, stream) | |
| 96 | + | local vars = {} | |
| 97 | + | local iterator = 1 | |
| 98 | + | local endianness = true | |
| 99 | + | ||
| 100 | + | for i = 1, format:len() do | |
| 101 | + | local opt = format:sub(i, i) | |
| 102 | + | ||
| 103 | + | if opt == '>' then | |
| 104 | + | endianness = false | |
| 105 | + | elseif opt:find('[bBhHiIlL]') then | |
| 106 | + | local n = opt:find('[hH]') and 2 or opt:find('[iI]') and 4 or opt:find('[lL]') and 8 or 1 | |
| 107 | + | local signed = opt:lower() == opt | |
| 108 | + | ||
| 109 | + | local val = 0 | |
| 110 | + | for j = 1, n do | |
| 111 | + | local byte = string.byte(stream:sub(iterator, iterator)) | |
| 112 | + | if endianness then | |
| 113 | + | val = val + byte * (2 ^ ((j - 1) * 8)) | |
| 114 | + | else | |
| 115 | + | val = val + byte * (2 ^ ((n - j) * 8)) | |
| 116 | + | end | |
| 117 | + | iterator = iterator + 1 | |
| 118 | + | end | |
| 119 | + | ||
| 120 | + | if signed then | |
| 121 | + | val = val - 2 ^ (n * 8 - 1) | |
| 122 | + | end | |
| 123 | + | ||
| 124 | + | table.insert(vars, val) | |
| 125 | + | elseif opt:find('[fd]') then | |
| 126 | + | local n = (opt == 'd') and 8 or 4 | |
| 127 | + | local x = stream:sub(iterator, iterator + n - 1) | |
| 128 | + | iterator = iterator + n | |
| 129 | + | ||
| 130 | + | if not endianness then | |
| 131 | + | x = string.reverse(x) | |
| 132 | + | end | |
| 133 | + | ||
| 134 | + | local sign = 1 | |
| 135 | + | local mantissa = string.byte(x, (opt == 'd') and 7 or 3) % ((opt == 'd') and 16 or 128) | |
| 136 | + | for i = n - 2, 1, -1 do | |
| 137 | + | mantissa = mantissa * (2 ^ 8) + string.byte(x, i) | |
| 138 | + | end | |
| 139 | + | ||
| 140 | + | if string.byte(x, n) > 127 then | |
| 141 | + | sign = -1 | |
| 142 | + | end | |
| 143 | + | ||
| 144 | + | local exponent = (string.byte(x, n) % 128) * ((opt == 'd') and 16 or 2) + math.floor(string.byte(x, n - 1) / ((opt == 'd') and 16 or 128)) | |
| 145 | + | if exponent == 0 then | |
| 146 | + | table.insert(vars, 0.0) | |
| 147 | + | else | |
| 148 | + | mantissa = (math.ldexp(mantissa, (opt == 'd') and -52 or -23) + 1) * sign | |
| 149 | + | table.insert(vars, math.ldexp(mantissa, exponent - ((opt == 'd') and 1023 or 127))) | |
| 150 | + | end | |
| 151 | + | elseif opt == 's' then | |
| 152 | + | local bytes = {} | |
| 153 | + | for j = iterator, stream:len() do | |
| 154 | + | if stream:sub(j, j) == string.char(0) then | |
| 155 | + | break | |
| 156 | + | end | |
| 157 | + | ||
| 158 | + | table.insert(bytes, stream:sub(j, j)) | |
| 159 | + | end | |
| 160 | + | ||
| 161 | + | local str = table.concat(bytes) | |
| 162 | + | iterator = iterator + str:len() + 1 | |
| 163 | + | table.insert(vars, str) | |
| 164 | + | elseif opt == 'c' then | |
| 165 | + | local n = format:sub(i + 1):match('%d+') | |
| 166 | + | table.insert(vars, stream:sub(iterator, iterator + tonumber(n))) | |
| 167 | + | iterator = iterator + tonumber(n) | |
| 168 | + | i = i + n:len() | |
| 169 | + | end | |
| 170 | + | end | |
| 171 | + | ||
| 172 | + | return unpack(vars) | |
| 173 | + | end |
| @@ -0,0 +1,288 @@ | |||
| 1 | + | -- @docclass table | |
| 2 | + | ||
| 3 | + | function table.dump(t, depth) | |
| 4 | + | if not depth then depth = 0 end | |
| 5 | + | for k,v in pairs(t) do | |
| 6 | + | str = (' '):rep(depth * 2) .. k .. ': ' | |
| 7 | + | if type(v) ~= "table" then | |
| 8 | + | print(str .. tostring(v)) | |
| 9 | + | else | |
| 10 | + | print(str) | |
| 11 | + | table.dump(v, depth+1) | |
| 12 | + | end | |
| 13 | + | end | |
| 14 | + | end | |
| 15 | + | ||
| 16 | + | function table.clear(t) | |
| 17 | + | for k,v in pairs(t) do | |
| 18 | + | t[k] = nil | |
| 19 | + | end | |
| 20 | + | end | |
| 21 | + | ||
| 22 | + | function table.copy(t) | |
| 23 | + | local res = {} | |
| 24 | + | for k,v in pairs(t) do | |
| 25 | + | res[k] = v | |
| 26 | + | end | |
| 27 | + | return res | |
| 28 | + | end | |
| 29 | + | ||
| 30 | + | function table.recursivecopy(t) | |
| 31 | + | local res = {} | |
| 32 | + | for k,v in pairs(t) do | |
| 33 | + | if type(v) == "table" then | |
| 34 | + | res[k] = table.recursivecopy(v) | |
| 35 | + | else | |
| 36 | + | res[k] = v | |
| 37 | + | end | |
| 38 | + | end | |
| 39 | + | return res | |
| 40 | + | end | |
| 41 | + | ||
| 42 | + | function table.selectivecopy(t, keys) | |
| 43 | + | local res = { } | |
| 44 | + | for i,v in ipairs(keys) do | |
| 45 | + | res[v] = t[v] | |
| 46 | + | end | |
| 47 | + | return res | |
| 48 | + | end | |
| 49 | + | ||
| 50 | + | function table.merge(t, src) | |
| 51 | + | for k,v in pairs(src) do | |
| 52 | + | t[k] = v | |
| 53 | + | end | |
| 54 | + | end | |
| 55 | + | ||
| 56 | + | function table.find(t, value, lowercase) | |
| 57 | + | for k,v in pairs(t) do | |
| 58 | + | if lowercase and type(value) == 'string' and type(v) == 'string' then | |
| 59 | + | if v:lower() == value:lower() then return k end | |
| 60 | + | end | |
| 61 | + | if v == value then return k end | |
| 62 | + | end | |
| 63 | + | end | |
| 64 | + | ||
| 65 | + | function table.findbykey(t, key, lowercase) | |
| 66 | + | for k,v in pairs(t) do | |
| 67 | + | if lowercase and type(key) == 'string' and type(k) == 'string' then | |
| 68 | + | if k:lower() == key:lower() then return v end | |
| 69 | + | end | |
| 70 | + | if k == key then return v end | |
| 71 | + | end | |
| 72 | + | end | |
| 73 | + | ||
| 74 | + | function table.contains(t, value, lowercase) | |
| 75 | + | return table.find(t, value, lowercase) ~= nil | |
| 76 | + | end | |
| 77 | + | ||
| 78 | + | function table.findkey(t, key) | |
| 79 | + | if t and type(t) == 'table' then | |
| 80 | + | for k,v in pairs(t) do | |
| 81 | + | if k == key then return k end | |
| 82 | + | end | |
| 83 | + | end | |
| 84 | + | end | |
| 85 | + | ||
| 86 | + | function table.haskey(t, key) | |
| 87 | + | return table.findkey(t, key) ~= nil | |
| 88 | + | end | |
| 89 | + | ||
| 90 | + | function table.removevalue(t, value) | |
| 91 | + | for k,v in pairs(t) do | |
| 92 | + | if v == value then | |
| 93 | + | table.remove(t, k) | |
| 94 | + | return true | |
| 95 | + | end | |
| 96 | + | end | |
| 97 | + | return false | |
| 98 | + | end | |
| 99 | + | ||
| 100 | + | function table.popvalue(value) | |
| 101 | + | local index = nil | |
| 102 | + | for k,v in pairs(t) do | |
| 103 | + | if v == value or not value then | |
| 104 | + | index = k | |
| 105 | + | end | |
| 106 | + | end | |
| 107 | + | if index then | |
| 108 | + | table.remove(t, index) | |
| 109 | + | return true | |
| 110 | + | end | |
| 111 | + | return false | |
| 112 | + | end | |
| 113 | + | ||
| 114 | + | function table.compare(t, other) | |
| 115 | + | if #t ~= #other then return false end | |
| 116 | + | for k,v in pairs(t) do | |
| 117 | + | if v ~= other[k] then return false end | |
| 118 | + | end | |
| 119 | + | return true | |
| 120 | + | end | |
| 121 | + | ||
| 122 | + | function table.empty(t) | |
| 123 | + | if t and type(t) == 'table' then | |
| 124 | + | return next(t) == nil | |
| 125 | + | end | |
| 126 | + | return true | |
| 127 | + | end | |
| 128 | + | ||
| 129 | + | function table.permute(t, n, count) | |
| 130 | + | n = n or #t | |
| 131 | + | for i=1,count or n do | |
| 132 | + | local j = math.random(i, n) | |
| 133 | + | t[i], t[j] = t[j], t[i] | |
| 134 | + | end | |
| 135 | + | return t | |
| 136 | + | end | |
| 137 | + | ||
| 138 | + | function table.findbyfield(t, fieldname, fieldvalue) | |
| 139 | + | for _i,subt in pairs(t) do | |
| 140 | + | if subt[fieldname] == fieldvalue then | |
| 141 | + | return subt | |
| 142 | + | end | |
| 143 | + | end | |
| 144 | + | return nil | |
| 145 | + | end | |
| 146 | + | ||
| 147 | + | function table.size(t) | |
| 148 | + | local size = 0 | |
| 149 | + | for i, n in pairs(t) do | |
| 150 | + | size = size + 1 | |
| 151 | + | end | |
| 152 | + | ||
| 153 | + | return size | |
| 154 | + | end | |
| 155 | + | ||
| 156 | + | function table.tostring(t) | |
| 157 | + | local maxn = #t | |
| 158 | + | local str = "" | |
| 159 | + | for k,v in pairs(t) do | |
| 160 | + | v = tostring(v) | |
| 161 | + | if k == maxn and k ~= 1 then | |
| 162 | + | str = str .. " and " .. v | |
| 163 | + | elseif maxn > 1 and k ~= 1 then | |
| 164 | + | str = str .. ", " .. v | |
| 165 | + | else | |
| 166 | + | str = str .. " " .. v | |
| 167 | + | end | |
| 168 | + | end | |
| 169 | + | return str | |
| 170 | + | end | |
| 171 | + | ||
| 172 | + | function table.collect(t, func) | |
| 173 | + | local res = {} | |
| 174 | + | for k,v in pairs(t) do | |
| 175 | + | local a,b = func(k,v) | |
| 176 | + | if a and b then | |
| 177 | + | res[a] = b | |
| 178 | + | elseif a ~= nil then | |
| 179 | + | table.insert(res,a) | |
| 180 | + | end | |
| 181 | + | end | |
| 182 | + | return res | |
| 183 | + | end | |
| 184 | + | ||
| 185 | + | function table.equals(t, comp) | |
| 186 | + | if type(t) == "table" and type(comp) == "table" then | |
| 187 | + | for k,v in pairs(t) do | |
| 188 | + | if v ~= comp[k] then return false end | |
| 189 | + | end | |
| 190 | + | end | |
| 191 | + | return true | |
| 192 | + | end | |
| 193 | + | ||
| 194 | + | function table.equal(t1,t2,ignore_mt) | |
| 195 | + | local ty1 = type(t1) | |
| 196 | + | local ty2 = type(t2) | |
| 197 | + | if ty1 ~= ty2 then return false end | |
| 198 | + | -- non-table types can be directly compared | |
| 199 | + | if ty1 ~= 'table' and ty2 ~= 'table' then return t1 == t2 end | |
| 200 | + | -- as well as tables which have the metamethod __eq | |
| 201 | + | local mt = getmetatable(t1) | |
| 202 | + | if not ignore_mt and mt and mt.__eq then return t1 == t2 end | |
| 203 | + | for k1,v1 in pairs(t1) do | |
| 204 | + | local v2 = t2[k1] | |
| 205 | + | if v2 == nil or not table.equal(v1,v2) then return false end | |
| 206 | + | end | |
| 207 | + | for k2,v2 in pairs(t2) do | |
| 208 | + | local v1 = t1[k2] | |
| 209 | + | if v1 == nil or not table.equal(v1,v2) then return false end | |
| 210 | + | end | |
| 211 | + | return true | |
| 212 | + | end | |
| 213 | + | ||
| 214 | + | function table.isList(t) | |
| 215 | + | local size = #t | |
| 216 | + | return table.size(t) == size and size > 0 | |
| 217 | + | end | |
| 218 | + | ||
| 219 | + | function table.isStringList(t) | |
| 220 | + | if not table.isList(t) then return false end | |
| 221 | + | for k,v in ipairs(t) do | |
| 222 | + | if type(v) ~= 'string' then | |
| 223 | + | return false | |
| 224 | + | end | |
| 225 | + | end | |
| 226 | + | return true | |
| 227 | + | end | |
| 228 | + | ||
| 229 | + | function table.isStringPairList(t) | |
| 230 | + | if not table.isList(t) then return false end | |
| 231 | + | for k,v in ipairs(t) do | |
| 232 | + | if type(v) ~= 'table' or #v ~= 2 or type(v[1]) ~= 'string' or type(v[2]) ~= 'string' then | |
| 233 | + | return false | |
| 234 | + | end | |
| 235 | + | end | |
| 236 | + | return true | |
| 237 | + | end | |
| 238 | + | ||
| 239 | + | function table.encodeStringPairList(t) | |
| 240 | + | local ret = "" | |
| 241 | + | for k,v in ipairs(t) do | |
| 242 | + | if v[2]:find("\n") then | |
| 243 | + | ret = ret .. v[1] .. ":[[\n" .. v[2] .. "\n]]\n" | |
| 244 | + | else | |
| 245 | + | ret = ret .. v[1] .. ":" .. v[2] .. "\n" | |
| 246 | + | end | |
| 247 | + | end | |
| 248 | + | return ret | |
| 249 | + | end | |
| 250 | + | ||
| 251 | + | function table.decodeStringPairList(l) | |
| 252 | + | local ret = {} | |
| 253 | + | local r = regexMatch(l, "(?:^|\\n)([^:^\n]{1,20}):?(.*)(?:$|\\n)") | |
| 254 | + | local multiline = "" | |
| 255 | + | local multilineKey = "" | |
| 256 | + | local multilineActive = false | |
| 257 | + | for k,v in ipairs(r) do | |
| 258 | + | if multilineActive then | |
| 259 | + | local endPos = v[1]:find("%]%]") | |
| 260 | + | if endPos then | |
| 261 | + | if endPos > 1 then | |
| 262 | + | table.insert(ret, {multilineKey, multiline .. "\n" .. v[1]:sub(1, endPos - 1)}) | |
| 263 | + | else | |
| 264 | + | table.insert(ret, {multilineKey, multiline}) | |
| 265 | + | end | |
| 266 | + | multilineActive = false | |
| 267 | + | multiline = "" | |
| 268 | + | multilineKey = "" | |
| 269 | + | else | |
| 270 | + | if multiline:len() == 0 then | |
| 271 | + | multiline = v[1] | |
| 272 | + | else | |
| 273 | + | multiline = multiline .. "\n" .. v[1] | |
| 274 | + | end | |
| 275 | + | end | |
| 276 | + | else | |
| 277 | + | local bracketPos = v[3]:find("%[%[") | |
| 278 | + | if bracketPos == 1 then -- multiline begin | |
| 279 | + | multiline = v[3]:sub(bracketPos + 2) | |
| 280 | + | multilineActive = true | |
| 281 | + | multilineKey = v[2] | |
| 282 | + | elseif v[2]:len() > 0 and v[3]:len() > 0 then | |
| 283 | + | table.insert(ret, {v[2], v[3]}) | |
| 284 | + | end | |
| 285 | + | end | |
| 286 | + | end | |
| 287 | + | return ret | |
| 288 | + | end |
| @@ -0,0 +1,69 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | g_effects = {} | |
| 3 | + | ||
| 4 | + | function g_effects.fadeIn(widget, time, elapsed) | |
| 5 | + | if not elapsed then elapsed = 0 end | |
| 6 | + | if not time then time = 300 end | |
| 7 | + | widget:setOpacity(math.min(elapsed/time, 1)) | |
| 8 | + | removeEvent(widget.fadeEvent) | |
| 9 | + | if elapsed < time then | |
| 10 | + | removeEvent(widget.fadeEvent) | |
| 11 | + | widget.fadeEvent = scheduleEvent(function() | |
| 12 | + | g_effects.fadeIn(widget, time, elapsed + 30) | |
| 13 | + | end, 30) | |
| 14 | + | else | |
| 15 | + | widget.fadeEvent = nil | |
| 16 | + | end | |
| 17 | + | end | |
| 18 | + | ||
| 19 | + | function g_effects.fadeOut(widget, time, elapsed) | |
| 20 | + | if not elapsed then elapsed = 0 end | |
| 21 | + | if not time then time = 300 end | |
| 22 | + | elapsed = math.max((1 - widget:getOpacity()) * time, elapsed) | |
| 23 | + | removeEvent(widget.fadeEvent) | |
| 24 | + | widget:setOpacity(math.max((time - elapsed)/time, 0)) | |
| 25 | + | if elapsed < time then | |
| 26 | + | widget.fadeEvent = scheduleEvent(function() | |
| 27 | + | g_effects.fadeOut(widget, time, elapsed + 30) | |
| 28 | + | end, 30) | |
| 29 | + | else | |
| 30 | + | widget.fadeEvent = nil | |
| 31 | + | end | |
| 32 | + | end | |
| 33 | + | ||
| 34 | + | function g_effects.cancelFade(widget) | |
| 35 | + | if widget then | |
| 36 | + | removeEvent(widget.fadeEvent) | |
| 37 | + | widget.fadeEvent = nil | |
| 38 | + | end | |
| 39 | + | end | |
| 40 | + | ||
| 41 | + | function g_effects.startBlink(widget, duration, interval, clickCancel) | |
| 42 | + | duration = duration or 0 -- until stop is called | |
| 43 | + | interval = interval or 500 | |
| 44 | + | clickCancel = clickCancel or true | |
| 45 | + | ||
| 46 | + | removeEvent(widget.blinkEvent) | |
| 47 | + | removeEvent(widget.blinkStopEvent) | |
| 48 | + | ||
| 49 | + | widget.blinkEvent = cycleEvent(function() | |
| 50 | + | widget:setOn(not widget:isOn()) | |
| 51 | + | end, interval) | |
| 52 | + | ||
| 53 | + | if duration > 0 then | |
| 54 | + | widget.blinkStopEvent = scheduleEvent(function() | |
| 55 | + | g_effects.stopBlink(widget) | |
| 56 | + | end, duration) | |
| 57 | + | end | |
| 58 | + | ||
| 59 | + | connect(widget, { onClick = g_effects.stopBlink }) | |
| 60 | + | end | |
| 61 | + | ||
| 62 | + | function g_effects.stopBlink(widget) | |
| 63 | + | disconnect(widget, { onClick = g_effects.stopBlink }) | |
| 64 | + | removeEvent(widget.blinkEvent) | |
| 65 | + | removeEvent(widget.blinkStopEvent) | |
| 66 | + | widget.blinkEvent = nil | |
| 67 | + | widget.blinkStopEvent = nil | |
| 68 | + | widget:setOn(false) | |
| 69 | + | end |
| @@ -0,0 +1,1199 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | g_tooltip = {} | |
| 3 | + | ||
| 4 | + | -- private variables | |
| 5 | + | local toolTipLabel | |
| 6 | + | local currentHoveredWidget | |
| 7 | + | -- private functions | |
| 8 | + | local function moveToolTip(first) | |
| 9 | + | if first and (toolTipLabel:isVisible() or toolTipLabel:getOpacity() < 0.1) then | |
| 10 | + | ||
| 11 | + | local pos = g_window.getMousePosition() | |
| 12 | + | local windowSize = g_window.getSize() | |
| 13 | + | local labelSize = toolTipLabel:getSize() | |
| 14 | + | ||
| 15 | + | pos.x = pos.x + 1 | |
| 16 | + | pos.y = pos.y + 1 | |
| 17 | + | ||
| 18 | + | if windowSize.width - (pos.x + labelSize.width) < 10 then | |
| 19 | + | pos.x = pos.x - labelSize.width - 3 | |
| 20 | + | else | |
| 21 | + | pos.x = pos.x + 10 | |
| 22 | + | end | |
| 23 | + | ||
| 24 | + | if windowSize.height - (pos.y + labelSize.height) < 10 then | |
| 25 | + | pos.y = pos.y - labelSize.height - 3 | |
| 26 | + | else | |
| 27 | + | pos.y = pos.y + 10 | |
| 28 | + | end | |
| 29 | + | ||
| 30 | + | toolTipLabel:setPosition(pos) | |
| 31 | + | end | |
| 32 | + | end | |
| 33 | + | local function onWidgetHoverChange(widget, hovered) | |
| 34 | + | if hovered then | |
| 35 | + | if widget.tooltip and not g_mouse.isPressed() then | |
| 36 | + | g_tooltip.display(widget.tooltip) | |
| 37 | + | currentHoveredWidget = widget | |
| 38 | + | end | |
| 39 | + | else | |
| 40 | + | if widget == currentHoveredWidget then | |
| 41 | + | g_tooltip.hide() | |
| 42 | + | currentHoveredWidget = nil | |
| 43 | + | end | |
| 44 | + | end | |
| 45 | + | end | |
| 46 | + | ||
| 47 | + | local function onWidgetStyleApply(widget, styleName, styleNode) | |
| 48 | + | if styleNode.tooltip then | |
| 49 | + | widget.tooltip = styleNode.tooltip | |
| 50 | + | end | |
| 51 | + | end | |
| 52 | + | ||
| 53 | + | -- public functions | |
| 54 | + | function mask_number(n) | |
| 55 | + | local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$') | |
| 56 | + | return left..(num:reverse():gsub('(%d%d%d)','%1,'):reverse())..right | |
| 57 | + | end | |
| 58 | + | function g_tooltip.init() | |
| 59 | + | connect(UIWidget, { onStyleApply = onWidgetStyleApply, | |
| 60 | + | onHoverChange = onWidgetHoverChange}) | |
| 61 | + | ||
| 62 | + | addEvent(function() | |
| 63 | + | toolTipLabel = g_ui.createWidget('UILabel', rootWidget) | |
| 64 | + | toolTipLabel:setId('toolTip') | |
| 65 | + | ||
| 66 | + | Nome = g_ui.createWidget('UILabel', toolTipLabel) | |
| 67 | + | Nome:setId('itemName') | |
| 68 | + | Nome:addAnchor(AnchorTop, 'parent', AnchorTop) | |
| 69 | + | Nome:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 70 | + | Nome:setTextAlign(AlignCenter) | |
| 71 | + | Nome:setMarginTop(4) | |
| 72 | + | Nome:setMarginLeft(5) | |
| 73 | + | Nome:setSize({width = 185, height = 20}) | |
| 74 | + | ||
| 75 | + | MinName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 76 | + | MinName:setId('MinLabel') | |
| 77 | + | MinName:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 78 | + | MinName:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 79 | + | MinName:setFont('small-9px') | |
| 80 | + | MinName:setTextAlign(AlignCenter) | |
| 81 | + | MinName:setText('MINIMO') | |
| 82 | + | MinName:setMarginTop(25) | |
| 83 | + | MinName:setMarginLeft(08) | |
| 84 | + | MinName:setSize({width = 55, height = 20}) | |
| 85 | + | ||
| 86 | + | MINIMO = g_ui.createWidget('UILabel', toolTipLabel) | |
| 87 | + | MINIMO:setId('MinValue') | |
| 88 | + | MINIMO:addAnchor(AnchorTop, 'MinLabel', AnchorBottom) | |
| 89 | + | MINIMO:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 90 | + | MINIMO:setFont('sans-bold-16px') | |
| 91 | + | MINIMO:setTextAlign(AlignCenter) | |
| 92 | + | MINIMO:setMarginTop(02) | |
| 93 | + | MINIMO:setMarginLeft(08) | |
| 94 | + | MINIMO:setSize({width = 55, height = 20}) | |
| 95 | + | ||
| 96 | + | iconType = g_ui.createWidget('UILabel', toolTipLabel) | |
| 97 | + | iconType:setId('IconType') | |
| 98 | + | iconType:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 99 | + | iconType:addAnchor(AnchorLeft, 'MinValue', AnchorRight) | |
| 100 | + | iconType:setImageSource("/images/game/states/ammo") | |
| 101 | + | iconType:setMarginTop(38) | |
| 102 | + | iconType:setMarginLeft(22) | |
| 103 | + | iconType:setSize({width = 18, height = 18}) | |
| 104 | + | ||
| 105 | + | TypeDMG = g_ui.createWidget('UILabel', toolTipLabel) | |
| 106 | + | TypeDMG:setId('TypeDMG') | |
| 107 | + | TypeDMG:addAnchor(AnchorTop, 'IconType', AnchorBottom) | |
| 108 | + | TypeDMG:addAnchor(AnchorLeft, 'MinValue', AnchorRight) | |
| 109 | + | TypeDMG:setFont('small-9px') | |
| 110 | + | TypeDMG:setTextAlign(AlignCenter) | |
| 111 | + | TypeDMG:setText('100') | |
| 112 | + | TypeDMG:setMarginTop(02) | |
| 113 | + | TypeDMG:setMarginLeft(03) | |
| 114 | + | TypeDMG:setSize({width = 55, height = 20}) | |
| 115 | + | ||
| 116 | + | MaxName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 117 | + | MaxName:setId('MaxLabel') | |
| 118 | + | MaxName:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 119 | + | MaxName:addAnchor(AnchorRight, 'parent', AnchorRight) | |
| 120 | + | MaxName:setFont('small-9px') | |
| 121 | + | MaxName:setTextAlign(AlignCenter) | |
| 122 | + | MaxName:setText('MAXIMO') | |
| 123 | + | MaxName:setMarginTop(25) | |
| 124 | + | MaxName:setMarginRight(08) | |
| 125 | + | MaxName:setSize({width = 55, height = 20}) | |
| 126 | + | ||
| 127 | + | MAXIMO = g_ui.createWidget('UILabel', toolTipLabel) | |
| 128 | + | MAXIMO:setId('MaxValue') | |
| 129 | + | MAXIMO:addAnchor(AnchorTop, 'MaxLabel', AnchorBottom) | |
| 130 | + | MAXIMO:addAnchor(AnchorRight, 'parent', AnchorRight) | |
| 131 | + | MAXIMO:setFont('sans-bold-16px') | |
| 132 | + | MAXIMO:setTextAlign(AlignCenter) | |
| 133 | + | MAXIMO:setMarginTop(02) | |
| 134 | + | MAXIMO:setMarginRight(08) | |
| 135 | + | MAXIMO:setSize({width = 55, height = 20}) | |
| 136 | + | ||
| 137 | + | DefName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 138 | + | DefName:setId('DefLabel') | |
| 139 | + | DefName:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 140 | + | DefName:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 141 | + | DefName:setFont('small-9px') | |
| 142 | + | DefName:setTextAlign(AlignCenter) | |
| 143 | + | DefName:setText(tr('DEFESA')) | |
| 144 | + | DefName:setMarginTop(30) | |
| 145 | + | DefName:setMarginLeft(08) | |
| 146 | + | DefName:setSize({width = 50, height = 20}) | |
| 147 | + | ||
| 148 | + | DEF = g_ui.createWidget('UILabel', toolTipLabel) | |
| 149 | + | DEF:setId('DEFValue') | |
| 150 | + | DEF:addAnchor(AnchorTop, 'DefLabel', AnchorBottom) | |
| 151 | + | DEF:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 152 | + | DEF:setFont('sans-bold-16px') | |
| 153 | + | DEF:setTextAlign(AlignCenter) | |
| 154 | + | DEF:setMarginLeft(08) | |
| 155 | + | DEF:setSize({width = 50, height = 20}) | |
| 156 | + | ||
| 157 | + | CompDefName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 158 | + | CompDefName:setId('CompararDef') | |
| 159 | + | CompDefName:addAnchor(AnchorTop, 'DefLabel', AnchorBottom) | |
| 160 | + | CompDefName:addAnchor(AnchorLeft, 'DEFValue', AnchorRight) | |
| 161 | + | CompDefName:setFont('small-9px') | |
| 162 | + | CompDefName:setTextAlign(AlignCenter) | |
| 163 | + | CompDefName:setText('-10') | |
| 164 | + | CompDefName:setMarginTop(10) | |
| 165 | + | CompDefName:setMarginLeft(-15) | |
| 166 | + | CompDefName:setSize({width = 20, height = 20}) | |
| 167 | + | ||
| 168 | + | EsqName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 169 | + | EsqName:setId('EsqLabel') | |
| 170 | + | EsqName:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 171 | + | EsqName:addAnchor(AnchorLeft, 'DefLabel', AnchorRight) | |
| 172 | + | EsqName:setFont('small-9px') | |
| 173 | + | EsqName:setText(tr('ESQUIVA')) | |
| 174 | + | EsqName:setTextAlign(AlignCenter) | |
| 175 | + | EsqName:setMarginTop(30) | |
| 176 | + | EsqName:setMarginLeft(10) | |
| 177 | + | EsqName:setSize({width = 50, height = 20}) | |
| 178 | + | ||
| 179 | + | ESQ = g_ui.createWidget('UILabel', toolTipLabel) | |
| 180 | + | ESQ:setId('ESQValue') | |
| 181 | + | ESQ:addAnchor(AnchorTop, 'EsqLabel', AnchorBottom) | |
| 182 | + | ESQ:addAnchor(AnchorLeft, 'DEFValue', AnchorRight) | |
| 183 | + | ESQ:setFont('sans-bold-16px') | |
| 184 | + | ESQ:setTextAlign(AlignCenter) | |
| 185 | + | ESQ:setMarginLeft(10) | |
| 186 | + | ESQ:setSize({width = 50, height = 20}) | |
| 187 | + | ||
| 188 | + | CompEsqName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 189 | + | CompEsqName:setId('CompararEsq') | |
| 190 | + | CompEsqName:addAnchor(AnchorTop, 'EsqLabel', AnchorBottom) | |
| 191 | + | CompEsqName:addAnchor(AnchorLeft, 'ESQValue', AnchorRight) | |
| 192 | + | CompEsqName:setFont('small-9px') | |
| 193 | + | CompEsqName:setTextAlign(AlignCenter) | |
| 194 | + | CompEsqName:setText('-10') | |
| 195 | + | CompEsqName:setMarginTop(10) | |
| 196 | + | CompEsqName:setMarginLeft(-15) | |
| 197 | + | CompEsqName:setSize({width = 20, height = 20}) | |
| 198 | + | ||
| 199 | + | MagName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 200 | + | MagName:setId('MagLabel') | |
| 201 | + | MagName:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 202 | + | MagName:addAnchor(AnchorLeft, 'EsqLabel', AnchorRight) | |
| 203 | + | MagName:setFont('small-9px') | |
| 204 | + | MagName:setTextAlign(AlignCenter) | |
| 205 | + | MagName:setText(tr('MAGICO')) | |
| 206 | + | MagName:setMarginTop(30) | |
| 207 | + | MagName:setMarginLeft(10) | |
| 208 | + | MagName:setSize({width = 50, height = 20}) | |
| 209 | + | ||
| 210 | + | MAG = g_ui.createWidget('UILabel', toolTipLabel) | |
| 211 | + | MAG:setId('MAGValue') | |
| 212 | + | MAG:addAnchor(AnchorTop, 'MagLabel', AnchorBottom) | |
| 213 | + | MAG:addAnchor(AnchorLeft, 'ESQValue', AnchorRight) | |
| 214 | + | MAG:setFont('sans-bold-16px') | |
| 215 | + | MAG:setTextAlign(AlignCenter) | |
| 216 | + | MAG:setMarginLeft(10) | |
| 217 | + | MAG:setSize({width = 50, height = 20}) | |
| 218 | + | ||
| 219 | + | CompMagName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 220 | + | CompMagName:setId('CompararMag') | |
| 221 | + | CompMagName:addAnchor(AnchorTop, 'MagLabel', AnchorBottom) | |
| 222 | + | CompMagName:addAnchor(AnchorLeft, 'MAGValue', AnchorRight) | |
| 223 | + | CompMagName:setFont('small-9px') | |
| 224 | + | CompMagName:setTextAlign(AlignCenter) | |
| 225 | + | CompMagName:setText('-10') | |
| 226 | + | CompMagName:setMarginTop(10) | |
| 227 | + | CompMagName:setMarginLeft(-15) | |
| 228 | + | CompMagName:setSize({width = 20, height = 20}) | |
| 229 | + | ||
| 230 | + | Desc = g_ui.createWidget('UILabel', toolTipLabel) | |
| 231 | + | Desc:setId('itemDesc') | |
| 232 | + | Desc:addAnchor(AnchorTop, 'itemName', AnchorBottom) | |
| 233 | + | Desc:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 234 | + | Desc:addAnchor(AnchorRight, 'parent', AnchorRight) | |
| 235 | + | Desc:setTextAlign(AlignLeft) | |
| 236 | + | Desc:setFont('small-9px') | |
| 237 | + | Desc:setTextWrap(true) | |
| 238 | + | Desc:setMarginTop(30) | |
| 239 | + | Desc:setMarginRight(15) | |
| 240 | + | Desc:setMarginLeft(15) | |
| 241 | + | Desc:setSize({width = 180, height = 55}) | |
| 242 | + | ||
| 243 | + | Star = g_ui.createWidget('UILabel', toolTipLabel) | |
| 244 | + | Star:setId('itemStar') | |
| 245 | + | Star:addAnchor(AnchorTop, 'itemDesc', AnchorBottom) | |
| 246 | + | Star:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 247 | + | Star:setImageSource("/images/custom/UI/star_0") | |
| 248 | + | Star:setSize({width = 31, height = 10}) | |
| 249 | + | Star:setMarginTop(10) | |
| 250 | + | Star:setMarginLeft(77) | |
| 251 | + | ||
| 252 | + | SKILL01 = g_ui.createWidget('UILabel', toolTipLabel) | |
| 253 | + | SKILL01:setId('SKILL01') | |
| 254 | + | SKILL01:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 255 | + | SKILL01:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 256 | + | SKILL01:setImageSource("/images/custom/UI/insert_skill") | |
| 257 | + | SKILL01:setMarginTop(50) | |
| 258 | + | SKILL01:setMarginLeft(24) | |
| 259 | + | SKILL01:setSize({width = 38, height = 38}) | |
| 260 | + | ||
| 261 | + | SKILL02 = g_ui.createWidget('UILabel', toolTipLabel) | |
| 262 | + | SKILL02:setId('SKILL02') | |
| 263 | + | SKILL02:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 264 | + | SKILL02:addAnchor(AnchorLeft, 'SKILL01', AnchorRight) | |
| 265 | + | SKILL02:setImageSource("/images/custom/UI/insert_skill") | |
| 266 | + | SKILL02:setMarginTop(50) | |
| 267 | + | SKILL02:setMarginLeft(13) | |
| 268 | + | SKILL02:setSize({width = 38, height = 38}) | |
| 269 | + | ||
| 270 | + | SKILL03 = g_ui.createWidget('UILabel', toolTipLabel) | |
| 271 | + | SKILL03:setId('SKILL03') | |
| 272 | + | SKILL03:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 273 | + | SKILL03:addAnchor(AnchorLeft, 'SKILL02', AnchorRight) | |
| 274 | + | SKILL03:setImageSource("/images/custom/UI/insert_skill") | |
| 275 | + | SKILL03:setMarginTop(50) | |
| 276 | + | SKILL03:setMarginLeft(13) | |
| 277 | + | SKILL03:setSize({width = 38, height = 38}) | |
| 278 | + | ||
| 279 | + | ATR1 = g_ui.createWidget('UILabel', toolTipLabel) | |
| 280 | + | ATR1:setId('ATR1') | |
| 281 | + | ATR1:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 282 | + | ATR1:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 283 | + | ATR1:setImageSource("/images/custom/Spells/atr_0") | |
| 284 | + | ATR1:setSize({width = 32, height = 32}) | |
| 285 | + | ATR1:setMarginTop(39) | |
| 286 | + | ATR1:setMarginLeft(15) | |
| 287 | + | ||
| 288 | + | ATR1Name = g_ui.createWidget('UILabel', toolTipLabel) | |
| 289 | + | ATR1Name:setId('ATR1Label') | |
| 290 | + | ATR1Name:setTextAlign(AlignLeft) | |
| 291 | + | ATR1Name:setFont('small-9px') | |
| 292 | + | ATR1Name:setTextWrap(true) | |
| 293 | + | ATR1Name:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 294 | + | ATR1Name:addAnchor(AnchorLeft, 'ATR1', AnchorRight) | |
| 295 | + | ATR1Name:setSize({width = 120, height = 30}) | |
| 296 | + | ATR1Name:setMarginTop(39) | |
| 297 | + | ATR1Name:setMarginLeft(10) | |
| 298 | + | ||
| 299 | + | ATR2 = g_ui.createWidget('UILabel', toolTipLabel) | |
| 300 | + | ATR2:setId('ATR2') | |
| 301 | + | ATR2:addAnchor(AnchorTop, 'ATR1', AnchorBottom) | |
| 302 | + | ATR2:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 303 | + | ATR2:setImageSource("/images/custom/Spells/atr_0") | |
| 304 | + | ATR2:setSize({width = 32, height = 32}) | |
| 305 | + | ATR2:setMarginTop(05) | |
| 306 | + | ATR2:setMarginLeft(15) | |
| 307 | + | ||
| 308 | + | ATR2Name = g_ui.createWidget('UILabel', toolTipLabel) | |
| 309 | + | ATR2Name:setId('ATR2Label') | |
| 310 | + | ATR2Name:setTextAlign(AlignLeft) | |
| 311 | + | ATR2Name:setFont('small-9px') | |
| 312 | + | ATR2Name:setTextWrap(true) | |
| 313 | + | ATR2Name:addAnchor(AnchorTop, 'ATR1Label', AnchorBottom) | |
| 314 | + | ATR2Name:addAnchor(AnchorLeft, 'ATR2', AnchorRight) | |
| 315 | + | ATR2Name:setSize({width = 120, height = 30}) | |
| 316 | + | ATR2Name:setMarginTop(7) | |
| 317 | + | ATR2Name:setMarginLeft(10) | |
| 318 | + | ||
| 319 | + | BonusExtra = g_ui.createWidget('UILabel', toolTipLabel) | |
| 320 | + | BonusExtra:setId('BonusExtra') | |
| 321 | + | BonusExtra:setTextAlign(AlignLeft) | |
| 322 | + | BonusExtra:setFont('small-9px') | |
| 323 | + | BonusExtra:setColor('green') | |
| 324 | + | BonusExtra:setTextWrap(true) | |
| 325 | + | BonusExtra:addAnchor(AnchorTop, 'ATR2Label', AnchorBottom) | |
| 326 | + | BonusExtra:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 327 | + | BonusExtra:setSize({width = 155, height = 50}) | |
| 328 | + | BonusExtra:setMarginTop(15) | |
| 329 | + | BonusExtra:setMarginLeft(15) | |
| 330 | + | ||
| 331 | + | Level = g_ui.createWidget('UILabel', toolTipLabel) | |
| 332 | + | Level:setId('itemLevel') | |
| 333 | + | Level:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 334 | + | Level:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 335 | + | Level:setBackgroundColor('#05AC5E') | |
| 336 | + | Level:setFont('verdana-9px') | |
| 337 | + | Level:setSize({width = 185, height = 15}) | |
| 338 | + | Level:setMarginTop(15) | |
| 339 | + | Level:setMarginLeft(01) | |
| 340 | + | Level:setTextAlign(AlignCenter) | |
| 341 | + | Level:setText("NIVEL REQUERIDO: LV. 12") | |
| 342 | + | ||
| 343 | + | Price = g_ui.createWidget('UILabel', toolTipLabel) | |
| 344 | + | Price:setId('itemPrice') | |
| 345 | + | Price:addAnchor(AnchorBottom, 'parent', AnchorBottom) | |
| 346 | + | Price:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 347 | + | Price:setSize({width = 80, height = 20}) | |
| 348 | + | Price:setMarginTop(5) | |
| 349 | + | Price:setMarginLeft(25) | |
| 350 | + | Price:setTextAlign(AlignLeft) | |
| 351 | + | ||
| 352 | + | Lock = g_ui.createWidget('UILabel', toolTipLabel) | |
| 353 | + | Lock:setId('itemLock') | |
| 354 | + | Lock:setImageSource("/images/custom/UI/backpack_slot_lock") | |
| 355 | + | Lock:addAnchor(AnchorBottom, 'parent', AnchorBottom) | |
| 356 | + | Lock:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 357 | + | Lock:setSize({width = 21, height = 21}) | |
| 358 | + | Lock:setMarginBottom(2) | |
| 359 | + | Lock:setMarginLeft(02) | |
| 360 | + | Lock:setTextAlign(AlignLeft) | |
| 361 | + | ||
| 362 | + | Rary = g_ui.createWidget('UILabel', toolTipLabel) | |
| 363 | + | Rary:setId('itemRary') | |
| 364 | + | Rary:addAnchor(AnchorBottom, 'parent', AnchorBottom) | |
| 365 | + | Rary:addAnchor(AnchorRight, 'parent', AnchorRight) | |
| 366 | + | Rary:setSize({width = 80, height = 20}) | |
| 367 | + | Rary:setMarginBottom(1) | |
| 368 | + | Rary:setMarginRight(10) | |
| 369 | + | Rary:setTextAlign(AlignRight) | |
| 370 | + | ||
| 371 | + | GIF = g_ui.createWidget('UILabel', toolTipLabel) | |
| 372 | + | GIF:setId('skillGIF') | |
| 373 | + | GIF:addAnchor(AnchorTop, 'parent', AnchorTop) | |
| 374 | + | GIF:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 375 | + | GIF:setImageSource("/images/custom/Spells/Animation/Skill_1") | |
| 376 | + | GIF:setMarginTop(1) | |
| 377 | + | GIF:setMarginLeft(1) | |
| 378 | + | GIF:setSize({width = 183, height = 135}) | |
| 379 | + | ||
| 380 | + | ELEM = g_ui.createWidget('UILabel', toolTipLabel) | |
| 381 | + | ELEM:setId('elemSkill') | |
| 382 | + | ELEM:addAnchor(AnchorTop, 'parent', AnchorTop) | |
| 383 | + | ELEM:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 384 | + | ELEM:setImageSource("/images/game/states/burning") | |
| 385 | + | ELEM:setMarginTop(3) | |
| 386 | + | ELEM:setMarginLeft(3) | |
| 387 | + | ELEM:setSize({width = 18, height = 18}) | |
| 388 | + | ||
| 389 | + | SkillName = g_ui.createWidget('UILabel', toolTipLabel) | |
| 390 | + | SkillName:setId('SkillName') | |
| 391 | + | SkillName:addAnchor(AnchorTop, 'skillGIF', AnchorBottom) | |
| 392 | + | SkillName:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 393 | + | SkillName:setColor('#E3BE17') | |
| 394 | + | SkillName:setTextAlign(AlignCenter) | |
| 395 | + | SkillName:setMarginTop(5) | |
| 396 | + | SkillName:setMarginLeft(5) | |
| 397 | + | SkillName:setSize({width = 180, height = 20}) | |
| 398 | + | ||
| 399 | + | SkillDMG = g_ui.createWidget('UILabel', toolTipLabel) | |
| 400 | + | SkillDMG:setId('SkillDMG') | |
| 401 | + | SkillDMG:setTextWrap(true) | |
| 402 | + | SkillDMG:addAnchor(AnchorTop, 'SkillName', AnchorBottom) | |
| 403 | + | SkillDMG:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 404 | + | SkillDMG:setTextAlign(AlignCenter) | |
| 405 | + | SkillDMG:setMarginTop(10) | |
| 406 | + | SkillDMG:setMarginLeft(15) | |
| 407 | + | SkillDMG:setSize({width = 160, height = 20}) | |
| 408 | + | ||
| 409 | + | SkillTarget = g_ui.createWidget('UILabel', toolTipLabel) | |
| 410 | + | SkillTarget:setId('SkillTarget') | |
| 411 | + | SkillTarget:addAnchor(AnchorTop, 'SkillDMG', AnchorBottom) | |
| 412 | + | SkillTarget:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 413 | + | SkillTarget:setTextAlign(AlignCenter) | |
| 414 | + | SkillTarget:setMarginTop(-3) | |
| 415 | + | SkillTarget:setMarginLeft(15) | |
| 416 | + | SkillTarget:setSize({width = 160, height = 20}) | |
| 417 | + | ||
| 418 | + | SkillCooldown = g_ui.createWidget('UILabel', toolTipLabel) | |
| 419 | + | SkillCooldown:setId('SkillCooldown') | |
| 420 | + | SkillCooldown:addAnchor(AnchorTop, 'SkillTarget', AnchorBottom) | |
| 421 | + | SkillCooldown:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 422 | + | SkillCooldown:setTextAlign(AlignCenter) | |
| 423 | + | SkillCooldown:setMarginTop(-3) | |
| 424 | + | SkillCooldown:setMarginLeft(15) | |
| 425 | + | SkillCooldown:setSize({width = 160, height = 20}) | |
| 426 | + | ||
| 427 | + | SkillHotkey = g_ui.createWidget('UILabel', toolTipLabel) | |
| 428 | + | SkillHotkey:setId('SkillHotkey') | |
| 429 | + | SkillHotkey:addAnchor(AnchorBottom, 'parent', AnchorBottom) | |
| 430 | + | SkillHotkey:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 431 | + | SkillHotkey:setTextAlign(AlignCenter) | |
| 432 | + | SkillHotkey:setMarginBottom(3) | |
| 433 | + | SkillHotkey:setMarginLeft(5) | |
| 434 | + | SkillHotkey:setSize({width = 180, height = 20}) | |
| 435 | + | ||
| 436 | + | VipSaldo = g_ui.createWidget('UILabel', toolTipLabel) | |
| 437 | + | VipSaldo:setId('VipSaldo') | |
| 438 | + | VipSaldo:addAnchor(AnchorTop, 'parent', AnchorTop) | |
| 439 | + | VipSaldo:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 440 | + | VipSaldo:setTextAlign(AlignCenter) | |
| 441 | + | VipSaldo:setMarginTop(10) | |
| 442 | + | VipSaldo:setMarginLeft(35) | |
| 443 | + | VipSaldo:setSize({width = 50, height = 20}) | |
| 444 | + | ||
| 445 | + | OnlineSaldo = g_ui.createWidget('UILabel', toolTipLabel) | |
| 446 | + | OnlineSaldo:setId('OnlineSaldo') | |
| 447 | + | OnlineSaldo:addAnchor(AnchorTop, 'VipSaldo', AnchorBottom) | |
| 448 | + | OnlineSaldo:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 449 | + | OnlineSaldo:setTextAlign(AlignCenter) | |
| 450 | + | OnlineSaldo:setMarginTop(04) | |
| 451 | + | OnlineSaldo:setMarginLeft(35) | |
| 452 | + | OnlineSaldo:setSize({width = 50, height = 20}) | |
| 453 | + | ||
| 454 | + | PremiumType = g_ui.createWidget('UILabel', toolTipLabel) | |
| 455 | + | PremiumType:setId('PremiumType') | |
| 456 | + | PremiumType:addAnchor(AnchorTop, 'OnlineSaldo', AnchorBottom) | |
| 457 | + | PremiumType:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 458 | + | PremiumType:setTextAlign(AlignCenter) | |
| 459 | + | PremiumType:setFont('small-9px') | |
| 460 | + | PremiumType:setMarginTop(08) | |
| 461 | + | PremiumType:setMarginLeft(07) | |
| 462 | + | PremiumType:setSize({width = 90, height = 20}) | |
| 463 | + | ||
| 464 | + | toolTipLabel:hide() | |
| 465 | + | end) | |
| 466 | + | ||
| 467 | + | end | |
| 468 | + | ||
| 469 | + | function g_tooltip.terminate() | |
| 470 | + | disconnect(UIWidget, { onStyleApply = onWidgetStyleApply, | |
| 471 | + | onHoverChange = onWidgetHoverChange }) | |
| 472 | + | ||
| 473 | + | currentHoveredWidget = nil | |
| 474 | + | toolTipLabel:destroy() | |
| 475 | + | toolTipLabel = nil | |
| 476 | + | ||
| 477 | + | g_tooltip = nil | |
| 478 | + | end | |
| 479 | + | ||
| 480 | + | function g_tooltip.display(text) | |
| 481 | + | if text == nil or text:len() == 0 then return end | |
| 482 | + | if not toolTipLabel then return end | |
| 483 | + | local t = string.explode(text, " ") | |
| 484 | + | ||
| 485 | + | Nome:hide() Desc:hide() Price:hide() Star:hide() Level:hide() | |
| 486 | + | DefName:hide() DEF:hide() EsqName:hide() ESQ:hide() MagName:hide() | |
| 487 | + | MAG:hide() ATR1:hide() ATR1Name:hide() ATR2:hide() ATR2Name:hide() | |
| 488 | + | MINIMO:hide() MinName:hide() MAXIMO:hide() MaxName:hide() iconType:hide() | |
| 489 | + | TypeDMG:hide() SKILL01:hide() SKILL02:hide() SKILL03:hide() GIF:hide() | |
| 490 | + | ELEM:hide() SkillName:hide() SkillDMG:hide() SkillTarget:hide() SkillCooldown:hide() | |
| 491 | + | SkillHotkey:hide() Rary:hide() VipSaldo:hide() OnlineSaldo:hide() PremiumType:hide() | |
| 492 | + | CompDefName:hide() CompEsqName:hide() CompMagName:hide() Lock:hide() | |
| 493 | + | BonusExtra:hide() | |
| 494 | + | Level:setText('') | |
| 495 | + | ||
| 496 | + | MAG:setColor('white') | |
| 497 | + | toolTipLabel:setText("") | |
| 498 | + | toolTipLabel:setBackgroundColor('#111111cc') | |
| 499 | + | toolTipLabel:setTextAlign(AlignCenter) | |
| 500 | + | toolTipLabel:setImageSource("/images/custom/UI/none") | |
| 501 | + | ||
| 502 | + | if string.find(text, "@JOIAS") then | |
| 503 | + | local t = string.explode(text, " ") | |
| 504 | + | local UID_01 = tonumber(t[02]) or 0 | |
| 505 | + | local UID_02 = tonumber(t[03]) or 0 | |
| 506 | + | local UID_03 = tonumber(t[04]) or 0 | |
| 507 | + | local UID_04 = tonumber(t[05]) or 0 | |
| 508 | + | local UID_05 = tonumber(t[06]) or 0 | |
| 509 | + | local UID_06 = tonumber(t[07]) or 0 | |
| 510 | + | local UID_07 = tonumber(t[08]) or 0 | |
| 511 | + | local UID_08 = tonumber(t[09]) or 0 | |
| 512 | + | local UID_09 = tonumber(t[10]) or 0 | |
| 513 | + | local UID_10 = tonumber(t[11]) or 0 | |
| 514 | + | ||
| 515 | + | local ChanceMode = { | |
| 516 | + | [00] = "Baixa"; | |
| 517 | + | [01] = "Media"; | |
| 518 | + | [02] = "Alta"; | |
| 519 | + | [03] = "Muito Alta"; | |
| 520 | + | [04] = "Altissima"; | |
| 521 | + | } | |
| 522 | + | toolTipLabel:resize(185, 179) | |
| 523 | + | toolTipLabel:setImageSource("/images/custom/UI/itemInfo") | |
| 524 | + | Nome:show() | |
| 525 | + | if UID_05 > 0 then | |
| 526 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1)).. " +" ..UID_05) | |
| 527 | + | else | |
| 528 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1))) | |
| 529 | + | end | |
| 530 | + | Nome:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 531 | + | ||
| 532 | + | Desc:show() | |
| 533 | + | if UID_03 < 0 then UID_03 = 0 end | |
| 534 | + | if UID_02 < 0 then UID_02 = 0 end | |
| 535 | + | if UID_05 < 0 then UID_05 = 0 end | |
| 536 | + | if UID_01 >= 1000 and UID_01 <= 1026 then | |
| 537 | + | if UID_01 == 1009 then | |
| 538 | + | Desc:setText(tr(modules.game_database.getItemInfo(UID_01, 8))) | |
| 539 | + | else | |
| 540 | + | local strTool = tr(modules.game_database.getItemInfo(UID_01, 8)) | |
| 541 | + | strTool = strTool.. "\n\nChance: " | |
| 542 | + | strTool = strTool.. tr(ChanceMode[UID_02]) | |
| 543 | + | strTool = strTool.. " | " ..(UID_05 + (UID_03 * 10) + 5).. " " | |
| 544 | + | strTool = strTool.. tr("seg") | |
| 545 | + | strTool = strTool.. "." | |
| 546 | + | Desc:setText(strTool) | |
| 547 | + | end | |
| 548 | + | else | |
| 549 | + | Desc:setText(tr(modules.game_database.getItemInfo(UID_01, 8))) | |
| 550 | + | end | |
| 551 | + | Price:show() | |
| 552 | + | Price:setText(modules.game_database.getItemInfo(UID_01, 9)) | |
| 553 | + | Rary:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 554 | + | Rary:setText(tr(modules.game_database.getRaridade(00, UID_02))) | |
| 555 | + | ||
| 556 | + | Level:show() | |
| 557 | + | Level:setSize({width = 185, height = 15}) | |
| 558 | + | Level:addAnchor(AnchorTop, 'itemStar', AnchorBottom) | |
| 559 | + | Level:addAnchor(AnchorLeft, 'parent', AnchorRight) | |
| 560 | + | Level:setMarginTop(15) | |
| 561 | + | Level:setMarginLeft(1) | |
| 562 | + | ||
| 563 | + | Star:show() | |
| 564 | + | Star:addAnchor(AnchorTop, 'itemDesc', AnchorBottom) | |
| 565 | + | Star:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 566 | + | Star:setMarginTop(10) | |
| 567 | + | Star:setMarginLeft(77) | |
| 568 | + | if UID_03 > 0 then | |
| 569 | + | Star:setImageSource("/images/custom/UI/star_" ..UID_03) | |
| 570 | + | else | |
| 571 | + | Star:setImageSource("/images/custom/UI/star_0") | |
| 572 | + | end | |
| 573 | + | ||
| 574 | + | if UID_09 > 0 then | |
| 575 | + | Lock:show() | |
| 576 | + | end | |
| 577 | + | ||
| 578 | + | Rary:show() | |
| 579 | + | toolTipLabel:show() | |
| 580 | + | toolTipLabel:raise() | |
| 581 | + | toolTipLabel:enable() | |
| 582 | + | ||
| 583 | + | ||
| 584 | + | elseif string.find(text, "@KARD") then | |
| 585 | + | local t = string.explode(text, "#") | |
| 586 | + | local Class = tonumber(t[02]) | |
| 587 | + | local Pos = tonumber(t[03]) | |
| 588 | + | local RareItem = tonumber(t[04]) | |
| 589 | + | local Effectype = t[05] | |
| 590 | + | ||
| 591 | + | toolTipLabel:resize(185, 179) | |
| 592 | + | toolTipLabel:setImageSource("/images/custom/UI/itemInfo") | |
| 593 | + | Nome:show() | |
| 594 | + | Nome:setColor(modules.game_database.getRaridade(01, RareItem)) | |
| 595 | + | Nome:setText(modules.game_database.onKard(01, Class, Pos)) | |
| 596 | + | Desc:show() | |
| 597 | + | Desc:setText(tr(modules.game_database.onKard(08, Class, Pos, 04))) | |
| 598 | + | Level:setText(tr(Effectype)) | |
| 599 | + | Level:setSize({width = 185, height = 30}) | |
| 600 | + | Level:show() | |
| 601 | + | Level:setBackgroundColor('#05AC5E') | |
| 602 | + | Level:addAnchor(AnchorTop, 'parent', AnchorTop) | |
| 603 | + | Level:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 604 | + | Level:setMarginTop(155) | |
| 605 | + | Level:setMarginLeft(-0,5) | |
| 606 | + | Price:hide() | |
| 607 | + | Rary:hide() | |
| 608 | + | ||
| 609 | + | toolTipLabel:show() | |
| 610 | + | toolTipLabel:raise() | |
| 611 | + | toolTipLabel:enable() | |
| 612 | + | ||
| 613 | + | ||
| 614 | + | elseif string.find(text, "@SKILL") then | |
| 615 | + | local t = string.explode(text, " ") | |
| 616 | + | local idSkill = tonumber(t[02]) | |
| 617 | + | local HotKey = t[03] | |
| 618 | + | toolTipLabel:resize(185, 270) | |
| 619 | + | toolTipLabel:setImageSource("/images/custom/UI/spell_tooltip") | |
| 620 | + | ||
| 621 | + | Rary:hide() | |
| 622 | + | Price:hide() | |
| 623 | + | GIF:show() | |
| 624 | + | GIF:setImageSource("/images/custom/Spells/Animation/Skill_" ..idSkill) | |
| 625 | + | ELEM:show() | |
| 626 | + | if modules.game_database.getSpellInfo(idSkill, 03) == "ICE" then | |
| 627 | + | ELEM:setImageSource("/images/game/states/freezing") | |
| 628 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "FIRE" then | |
| 629 | + | ELEM:setImageSource("/images/game/states/burning") | |
| 630 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "DEATH" then | |
| 631 | + | ELEM:setImageSource("/images/game/states/cursed") | |
| 632 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "PHYSICAL" then | |
| 633 | + | ELEM:setImageSource("/images/game/states/physical") | |
| 634 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "HOLY" then | |
| 635 | + | ELEM:setImageSource("/images/game/states/dazzled") | |
| 636 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "EARTH" then | |
| 637 | + | ELEM:setImageSource("/images/game/states/poisoned") | |
| 638 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "ENERGY" then | |
| 639 | + | ELEM:setImageSource("/images/game/states/electrified") | |
| 640 | + | elseif modules.game_database.getSpellInfo(idSkill, 03) == "SUPORTE" then | |
| 641 | + | ELEM:setImageSource("/images/game/states/protection_zone") | |
| 642 | + | end | |
| 643 | + | SkillName:show() | |
| 644 | + | SkillName:setText(modules.game_database.getSpellInfo(idSkill, 00)) | |
| 645 | + | SkillDMG:show() | |
| 646 | + | if modules.game_database.getSpellInfo(idSkill, 03) == "SUPORTE" then | |
| 647 | + | SkillDMG:setSize({width = 160, height = 150}) | |
| 648 | + | SkillDMG:setMarginTop(-40) | |
| 649 | + | SkillDMG:setText(modules.game_database.getSpellInfo(idSkill, 06)) | |
| 650 | + | else | |
| 651 | + | SkillDMG:setMarginTop(10) | |
| 652 | + | SkillDMG:setSize({width = 160, height = 20}) | |
| 653 | + | SkillDMG:setText("Damage: " ..modules.game_database.getSpellInfo(idSkill, 04).. "%") | |
| 654 | + | SkillTarget:show() | |
| 655 | + | if modules.game_database.getSpellInfo(idSkill, 02) == 0 then | |
| 656 | + | SkillTarget:setText("Target: false") | |
| 657 | + | else | |
| 658 | + | SkillTarget:setText("Target: true") | |
| 659 | + | end | |
| 660 | + | SkillCooldown:show() | |
| 661 | + | SkillCooldown:setText("Cooldown: " ..modules.game_database.getSpellInfo(idSkill, 05).. " seg.") | |
| 662 | + | end | |
| 663 | + | SkillHotkey:show() | |
| 664 | + | SkillHotkey:setText(HotKey) | |
| 665 | + | ||
| 666 | + | if t[04] then | |
| 667 | + | if tonumber(t[04]) > 0 then | |
| 668 | + | Lock:show() | |
| 669 | + | end | |
| 670 | + | end | |
| 671 | + | ||
| 672 | + | toolTipLabel:show() | |
| 673 | + | toolTipLabel:raise() | |
| 674 | + | toolTipLabel:enable() | |
| 675 | + | ||
| 676 | + | ||
| 677 | + | elseif string.find(text, "@GUN") or string.find(text, "@INVGUN") then | |
| 678 | + | local t = string.explode(text, " ") | |
| 679 | + | local UID_01 = tonumber(t[02]) or 0 | |
| 680 | + | local UID_02 = tonumber(t[03]) or 0 | |
| 681 | + | local UID_03 = tonumber(t[04]) or 0 | |
| 682 | + | local UID_04 = tonumber(t[05]) or 0 | |
| 683 | + | local UID_05 = tonumber(t[06]) or 0 | |
| 684 | + | local UID_06 = tonumber(t[07]) or 0 | |
| 685 | + | local UID_07 = tonumber(t[08]) or 0 | |
| 686 | + | local UID_08 = tonumber(t[09]) or 0 | |
| 687 | + | local UID_09 = tonumber(t[10]) or 0 | |
| 688 | + | local UID_10 = tonumber(t[11]) or 0 | |
| 689 | + | ||
| 690 | + | toolTipLabel:resize(185, 320) | |
| 691 | + | toolTipLabel:setImageSource("/images/custom/UI/equipInfo") | |
| 692 | + | Nome:show() | |
| 693 | + | Nome:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 694 | + | if UID_07 > 0 then | |
| 695 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1)).. " +" ..UID_07) | |
| 696 | + | else | |
| 697 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1))) | |
| 698 | + | end | |
| 699 | + | local DanoMinimoValue = modules.game_database.onDamage(UID_01, UID_07, UID_03, "Min", UID_02) | |
| 700 | + | local DanoMaximoValue = modules.game_database.onDamage(UID_01, UID_07, UID_03, "Max", UID_02) | |
| 701 | + | MINIMO:show() | |
| 702 | + | MINIMO:setText(DanoMinimoValue) | |
| 703 | + | MAXIMO:show() | |
| 704 | + | MAXIMO:setText(DanoMaximoValue) | |
| 705 | + | SKILL01:show() | |
| 706 | + | SKILL02:show() | |
| 707 | + | SKILL03:show() | |
| 708 | + | ||
| 709 | + | local Bullet = 0 | |
| 710 | + | if string.find(text, "@GUN") then | |
| 711 | + | local AMMO = UID_09 | |
| 712 | + | Bullet = AMMO | |
| 713 | + | elseif string.find(text, "@INVGUN") then | |
| 714 | + | Bullet = modules.game_database.getInventory(04, 10) | |
| 715 | + | end | |
| 716 | + | if Bullet == nil or Bullet < 0 then Bullet = 0 end | |
| 717 | + | if Bullet < 10 then | |
| 718 | + | TypeDMG:setText('00' ..Bullet) | |
| 719 | + | elseif Bullet >= 10 and Bullet <= 99 then | |
| 720 | + | TypeDMG:setText('0' ..Bullet) | |
| 721 | + | else | |
| 722 | + | TypeDMG:setText(Bullet) | |
| 723 | + | end | |
| 724 | + | ||
| 725 | + | if Bullet < 01 then | |
| 726 | + | TypeDMG:setColor('red') | |
| 727 | + | TypeDMG:setText('EMPTY') | |
| 728 | + | else | |
| 729 | + | TypeDMG:setColor('white') | |
| 730 | + | end | |
| 731 | + | if UID_04 ~= nil then | |
| 732 | + | if UID_04 > 0 then | |
| 733 | + | SKILL01:setImageSource("/images/custom/Spells/skill_" ..UID_04) | |
| 734 | + | SKILL01:setOpacity("1.0") | |
| 735 | + | else | |
| 736 | + | if UID_02 > 0 then | |
| 737 | + | SKILL01:setImageSource("/images/custom/UI/insert_skill") | |
| 738 | + | SKILL01:setOpacity("1.0") | |
| 739 | + | else | |
| 740 | + | SKILL01:setImageSource("/images/custom/UI/lock_skill") | |
| 741 | + | SKILL01:setOpacity("0.4") | |
| 742 | + | end | |
| 743 | + | end | |
| 744 | + | else | |
| 745 | + | SKILL01:setImageSource("/images/custom/UI/insert_skill") | |
| 746 | + | end | |
| 747 | + | if UID_05 ~= nil then | |
| 748 | + | if UID_05 > 0 then | |
| 749 | + | SKILL02:setImageSource("/images/custom/Spells/skill_" ..UID_05) | |
| 750 | + | SKILL02:setOpacity("1.0") | |
| 751 | + | else | |
| 752 | + | if UID_02 > 1 then | |
| 753 | + | SKILL02:setImageSource("/images/custom/UI/insert_skill") | |
| 754 | + | SKILL02:setOpacity("1.0") | |
| 755 | + | else | |
| 756 | + | SKILL02:setImageSource("/images/custom/UI/lock_skill") | |
| 757 | + | SKILL02:setOpacity("0.4") | |
| 758 | + | end | |
| 759 | + | end | |
| 760 | + | else | |
| 761 | + | SKILL01:setImageSource("/images/custom/UI/insert_skill") | |
| 762 | + | end | |
| 763 | + | if UID_06 ~= nil then | |
| 764 | + | if UID_06 > 0 then | |
| 765 | + | SKILL03:setImageSource("/images/custom/Spells/skill_" ..UID_06) | |
| 766 | + | SKILL03:setOpacity("1.0") | |
| 767 | + | else | |
| 768 | + | if UID_02 > 2 then | |
| 769 | + | SKILL03:setImageSource("/images/custom/UI/insert_skill") | |
| 770 | + | SKILL03:setOpacity("1.0") | |
| 771 | + | else | |
| 772 | + | SKILL03:setImageSource("/images/custom/UI/lock_skill") | |
| 773 | + | SKILL03:setOpacity("0.4") | |
| 774 | + | end | |
| 775 | + | end | |
| 776 | + | else | |
| 777 | + | SKILL01:setImageSource("/images/custom/UI/insert_skill") | |
| 778 | + | end | |
| 779 | + | ||
| 780 | + | Star:show() | |
| 781 | + | Star:addAnchor(AnchorTop, 'TypeDMG', AnchorBottom) | |
| 782 | + | Star:addAnchor(AnchorLeft, 'MinLabel', AnchorRight) | |
| 783 | + | Star:setMarginTop(02) | |
| 784 | + | Star:setMarginLeft(15) | |
| 785 | + | if UID_03 > 0 then | |
| 786 | + | Star:setImageSource("/images/custom/UI/star_" ..UID_03) | |
| 787 | + | else | |
| 788 | + | Star:setImageSource("/images/custom/UI/star_0") | |
| 789 | + | end | |
| 790 | + | ||
| 791 | + | local localPlayer = g_game.getLocalPlayer() | |
| 792 | + | local GUN_BASE_LEVEL = modules.game_database.getItemInfo(UID_01, 19) | |
| 793 | + | local LEVEL_FOR_RARE = 05 | |
| 794 | + | local LEVEL_FOR_LEVEL = 04 | |
| 795 | + | if UID_02 < 0 then UID_02 = 00 end | |
| 796 | + | if UID_07 < 0 then UID_07 = 00 end | |
| 797 | + | if UID_03 < 0 then UID_03 = 00 end | |
| 798 | + | ||
| 799 | + | REQUISITO_LEVEL = GUN_BASE_LEVEL + (UID_02 * LEVEL_FOR_RARE) + (UID_07 * LEVEL_FOR_LEVEL) + ((UID_03 * 10) * LEVEL_FOR_LEVEL) | |
| 800 | + | if localPlayer:getLevel() >= REQUISITO_LEVEL then | |
| 801 | + | Level:setBackgroundColor('#05AC5E') | |
| 802 | + | else | |
| 803 | + | Level:setBackgroundColor('#AC0505') | |
| 804 | + | end | |
| 805 | + | Level:setText(tr('NIVEL REQUERIDO: LV.').. ' ' ..REQUISITO_LEVEL) | |
| 806 | + | Level:show() | |
| 807 | + | Level:setSize({width = 185, height = 15}) | |
| 808 | + | Level:addAnchor(AnchorTop, 'SKILL02', AnchorBottom) | |
| 809 | + | Level:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 810 | + | Level:setMarginTop(83) | |
| 811 | + | Level:setMarginLeft(-0,5) | |
| 812 | + | ||
| 813 | + | Price:show() | |
| 814 | + | Lock:hide() | |
| 815 | + | Price:setText(modules.game_database.getItemInfo(UID_01, 9)) | |
| 816 | + | if UID_10 > 0 then | |
| 817 | + | Lock:show() | |
| 818 | + | Price:setText(modules.game_database.getItemInfo(UID_01, 9)) | |
| 819 | + | end | |
| 820 | + | ||
| 821 | + | local StrBonus = "" | |
| 822 | + | local DmgMin = 00 | |
| 823 | + | local DmgMax = 00 | |
| 824 | + | if UID_08 > 0 then | |
| 825 | + | local BonusUM = modules.game_database.onBonusExtra(01, tostring(UID_08), 03) | |
| 826 | + | if #BonusUM > 01 then | |
| 827 | + | if modules.game_database.onBonusExtra(01, tostring(UID_08), 04) == 39 then | |
| 828 | + | DmgMin = DmgMin + modules.game_database.onBonusExtra(01, tostring(UID_08), 02) | |
| 829 | + | end | |
| 830 | + | if modules.game_database.onBonusExtra(01, tostring(UID_08), 04) == 41 then | |
| 831 | + | DmgMax = DmgMax + modules.game_database.onBonusExtra(01, tostring(UID_08), 02) | |
| 832 | + | end | |
| 833 | + | StrBonus = BonusUM | |
| 834 | + | ||
| 835 | + | local BonusDois = modules.game_database.onBonusExtra(02, tostring(UID_08), 03) | |
| 836 | + | if #BonusDois > 01 then | |
| 837 | + | if modules.game_database.onBonusExtra(02, tostring(UID_08), 04) == 39 then | |
| 838 | + | DmgMin = DmgMin + modules.game_database.onBonusExtra(02, tostring(UID_08), 02) | |
| 839 | + | end | |
| 840 | + | if modules.game_database.onBonusExtra(02, tostring(UID_08), 04) == 41 then | |
| 841 | + | DmgMax = DmgMax + modules.game_database.onBonusExtra(02, tostring(UID_08), 02) | |
| 842 | + | end | |
| 843 | + | StrBonus = StrBonus.. "\n" ..BonusDois | |
| 844 | + | ||
| 845 | + | local BonusTres = modules.game_database.onBonusExtra(03, tostring(UID_08), 03) | |
| 846 | + | if #BonusTres > 01 then | |
| 847 | + | if modules.game_database.onBonusExtra(03, tostring(UID_08), 04) == 39 then | |
| 848 | + | DmgMin = DmgMin + modules.game_database.onBonusExtra(03, tostring(UID_08), 02) | |
| 849 | + | end | |
| 850 | + | if modules.game_database.onBonusExtra(03, tostring(UID_08), 04) == 41 then | |
| 851 | + | DmgMax = DmgMax + modules.game_database.onBonusExtra(03, tostring(UID_08), 02) | |
| 852 | + | end | |
| 853 | + | StrBonus = StrBonus.. "\n" ..BonusTres | |
| 854 | + | end | |
| 855 | + | end | |
| 856 | + | end | |
| 857 | + | end | |
| 858 | + | ||
| 859 | + | if DmgMin > 00 then | |
| 860 | + | DanoMinimoValue = DanoMinimoValue + DmgMin | |
| 861 | + | MINIMO:setColor('green') | |
| 862 | + | MINIMO:setText(DanoMinimoValue) | |
| 863 | + | else | |
| 864 | + | MINIMO:setColor('white') | |
| 865 | + | end | |
| 866 | + | if DmgMax > 00 then | |
| 867 | + | DanoMaximoValue = DanoMaximoValue + DmgMax | |
| 868 | + | MAXIMO:setColor('green') | |
| 869 | + | MAXIMO:setText(DanoMaximoValue) | |
| 870 | + | else | |
| 871 | + | MAXIMO:setColor('white') | |
| 872 | + | end | |
| 873 | + | ||
| 874 | + | if #StrBonus > 0 then | |
| 875 | + | BonusExtra:setText(StrBonus) | |
| 876 | + | BonusExtra:setMarginTop(05) | |
| 877 | + | BonusExtra:show() | |
| 878 | + | else | |
| 879 | + | BonusExtra:hide() | |
| 880 | + | end | |
| 881 | + | ||
| 882 | + | local SlotItem = modules.game_database.getItemInfo(UID_01, 2) | |
| 883 | + | local InventoryItemID = modules.game_database.getInventory(SlotItem, 1) | |
| 884 | + | if InventoryItemID > 0 then | |
| 885 | + | local INV_MIN = modules.game_database.onDamage(InventoryItemID, modules.game_database.getInventory(SlotItem, 7), modules.game_database.getInventory(SlotItem, 3), "Min", modules.game_database.getInventory(SlotItem, 2)) | |
| 886 | + | local BAG_MIN = DanoMinimoValue | |
| 887 | + | local DIFE_MIN = BAG_MIN - INV_MIN | |
| 888 | + | if DIFE_MIN < 0 then | |
| 889 | + | CompDefName:setColor('#AC0505') | |
| 890 | + | CompDefName:setText(DIFE_MIN) | |
| 891 | + | CompDefName:show() | |
| 892 | + | elseif DIFE_MIN > 0 then | |
| 893 | + | CompDefName:setColor('#05AC5E') | |
| 894 | + | CompDefName:setText("+" ..DIFE_MIN) | |
| 895 | + | CompDefName:show() | |
| 896 | + | end | |
| 897 | + | ||
| 898 | + | local INV_MAX = modules.game_database.onDamage(InventoryItemID, modules.game_database.getInventory(SlotItem, 7), modules.game_database.getInventory(SlotItem, 3), "Max", modules.game_database.getInventory(SlotItem, 2)) | |
| 899 | + | local BAG_MAX = DanoMaximoValue | |
| 900 | + | local DIFE_MAX = BAG_MAX - INV_MAX | |
| 901 | + | if DIFE_MAX < 0 then | |
| 902 | + | CompMagName:setColor('#AC0505') | |
| 903 | + | CompMagName:setText(DIFE_MAX) | |
| 904 | + | CompMagName:show() | |
| 905 | + | elseif DIFE_MAX > 0 then | |
| 906 | + | CompMagName:setColor('#05AC5E') | |
| 907 | + | CompMagName:setText("+" ..DIFE_MAX) | |
| 908 | + | CompMagName:show() | |
| 909 | + | end | |
| 910 | + | end | |
| 911 | + | Rary:show() | |
| 912 | + | iconType:show() | |
| 913 | + | TypeDMG:show() | |
| 914 | + | MinName:show() | |
| 915 | + | MaxName:show() | |
| 916 | + | Rary:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 917 | + | Rary:setText(tr(modules.game_database.getRaridade(00, UID_02))) | |
| 918 | + | ||
| 919 | + | toolTipLabel:show() | |
| 920 | + | toolTipLabel:raise() | |
| 921 | + | toolTipLabel:enable() | |
| 922 | + | ||
| 923 | + | ||
| 924 | + | elseif string.find(text, "@EQUIP") then | |
| 925 | + | local t = string.explode(text, " ") | |
| 926 | + | local UID_01 = tonumber(t[02]) or 0 | |
| 927 | + | local UID_02 = tonumber(t[03]) or 0 | |
| 928 | + | local UID_03 = tonumber(t[04]) or 0 | |
| 929 | + | local UID_04 = tonumber(t[05]) or 0 | |
| 930 | + | local UID_05 = tonumber(t[06]) or 0 | |
| 931 | + | local UID_06 = tonumber(t[07]) or 0 | |
| 932 | + | local UID_07 = tonumber(t[08]) or 0 | |
| 933 | + | local UID_08 = tonumber(t[09]) or 0 | |
| 934 | + | local UID_09 = tonumber(t[10]) or 0 | |
| 935 | + | local UID_10 = tonumber(t[11]) or 0 | |
| 936 | + | local ProtectElement = modules.game_database.getItemInfo(UID_01, 18) | |
| 937 | + | ||
| 938 | + | toolTipLabel:resize(185, 320) | |
| 939 | + | toolTipLabel:setImageSource("/images/custom/UI/equipInfo") | |
| 940 | + | Nome:show() | |
| 941 | + | Nome:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 942 | + | if UID_05 > 0 then | |
| 943 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1)).. " +" ..UID_05) | |
| 944 | + | else | |
| 945 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1))) | |
| 946 | + | end | |
| 947 | + | Price:show() | |
| 948 | + | Price:setText(modules.game_database.getItemInfo(UID_01, 9)) | |
| 949 | + | DEF:show() | |
| 950 | + | DEF:setText(modules.game_database.onArmor(UID_01, UID_05, UID_03, "DEF", UID_02)) | |
| 951 | + | ESQ:show() | |
| 952 | + | ESQ:setText(modules.game_database.onArmor(UID_01, UID_05, UID_03, "ESQ", UID_02)) | |
| 953 | + | MAG:show() | |
| 954 | + | ||
| 955 | + | local ElemColor = { | |
| 956 | + | ["FIRE"] = {COLOR = '#e64747'}; | |
| 957 | + | ["ICE"] = {COLOR = '#55d8f2'}; | |
| 958 | + | ["ENERGY"] = {COLOR = '#d555f2'}; | |
| 959 | + | ["DEATH"] = {COLOR = '#7d7c7d'}; | |
| 960 | + | ["EARTH"] = {COLOR = 'green'}; | |
| 961 | + | } | |
| 962 | + | MagName:setText(ProtectElement) | |
| 963 | + | MagName:setColor(ElemColor[ProtectElement].COLOR) | |
| 964 | + | MAG:setColor(ElemColor[ProtectElement].COLOR) | |
| 965 | + | MAG:setText(modules.game_database.onArmor(UID_01, UID_05, UID_03, "MAG", UID_02)) | |
| 966 | + | Rary:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 967 | + | Rary:setText(tr(modules.game_database.getRaridade(00, UID_02))) | |
| 968 | + | ||
| 969 | + | local SlotItem = modules.game_database.getItemInfo(UID_01, 2) | |
| 970 | + | local InventoryItemID = modules.game_database.getInventory(SlotItem, 1) | |
| 971 | + | if InventoryItemID > 0 then | |
| 972 | + | local INV_DEF = modules.game_database.onArmor(InventoryItemID, modules.game_database.getInventory(SlotItem, 5), modules.game_database.getInventory(SlotItem, 3), "DEF", modules.game_database.getInventory(SlotItem, 2)) | |
| 973 | + | local BAG_DEF = modules.game_database.onArmor(UID_01, UID_05, UID_03, "DEF", UID_02) | |
| 974 | + | local DIFE_DEF = BAG_DEF - INV_DEF | |
| 975 | + | if DIFE_DEF < 0 then | |
| 976 | + | CompDefName:setColor('#AC0505') | |
| 977 | + | CompDefName:setText(DIFE_DEF) | |
| 978 | + | CompDefName:show() | |
| 979 | + | elseif DIFE_DEF > 0 then | |
| 980 | + | CompDefName:setColor('#05AC5E') | |
| 981 | + | CompDefName:setText("+" ..DIFE_DEF) | |
| 982 | + | CompDefName:show() | |
| 983 | + | end | |
| 984 | + | ||
| 985 | + | local INV_ESQ = modules.game_database.onArmor(InventoryItemID, modules.game_database.getInventory(SlotItem, 5), modules.game_database.getInventory(SlotItem, 3), "ESQ", modules.game_database.getInventory(SlotItem, 2)) | |
| 986 | + | local BAG_ESQ = modules.game_database.onArmor(UID_01, UID_05, UID_03, "ESQ", UID_02) | |
| 987 | + | local DIFE_ESQ = BAG_ESQ - INV_ESQ | |
| 988 | + | if DIFE_ESQ < 0 then | |
| 989 | + | CompEsqName:setColor('#AC0505') | |
| 990 | + | CompEsqName:setText(DIFE_ESQ) | |
| 991 | + | CompEsqName:show() | |
| 992 | + | elseif DIFE_ESQ > 0 then | |
| 993 | + | CompEsqName:setColor('#05AC5E') | |
| 994 | + | CompEsqName:setText("+" ..DIFE_ESQ) | |
| 995 | + | CompEsqName:show() | |
| 996 | + | end | |
| 997 | + | ||
| 998 | + | local INV_MAG = modules.game_database.onArmor(InventoryItemID, modules.game_database.getInventory(SlotItem, 5), modules.game_database.getInventory(SlotItem, 3), "MAG", modules.game_database.getInventory(SlotItem, 2)) | |
| 999 | + | local BAG_MAG = modules.game_database.onArmor(UID_01, UID_05, UID_03, "MAG", UID_02) | |
| 1000 | + | local DIFE_MAG = BAG_MAG - INV_MAG | |
| 1001 | + | if DIFE_MAG < 0 then | |
| 1002 | + | CompMagName:setColor('#AC0505') | |
| 1003 | + | CompMagName:setText(DIFE_MAG) | |
| 1004 | + | CompMagName:show() | |
| 1005 | + | elseif DIFE_MAG > 0 then | |
| 1006 | + | CompMagName:setColor('#05AC5E') | |
| 1007 | + | CompMagName:setText("+" ..DIFE_MAG) | |
| 1008 | + | CompMagName:show() | |
| 1009 | + | end | |
| 1010 | + | end | |
| 1011 | + | ||
| 1012 | + | if UID_06 > 0 then | |
| 1013 | + | local desc = modules.game_database.getAtrInfo(UID_06, 07) | |
| 1014 | + | local text = modules.game_database.getAtrInfo(UID_06, 02) | |
| 1015 | + | local percent = modules.game_database.getAtrInfo(UID_06, 01) | |
| 1016 | + | local txtper = modules.game_database.getAtrInfo(UID_06, 08) | |
| 1017 | + | ATR1:setImageSource("/images/custom/Spells/atr_" ..UID_06) | |
| 1018 | + | ATR1Name:setText(tr(desc).. " (" ..tr(text).. " " ..percent.."" ..txtper..")") | |
| 1019 | + | else | |
| 1020 | + | ATR1:setImageSource("/images/custom/Spells/atr_0") | |
| 1021 | + | ATR1Name:setText(tr("<vazio>")) | |
| 1022 | + | end | |
| 1023 | + | if UID_07 > 0 then | |
| 1024 | + | local desc = modules.game_database.getAtrInfo(UID_07, 07) | |
| 1025 | + | local text = modules.game_database.getAtrInfo(UID_07, 02) | |
| 1026 | + | local percent = modules.game_database.getAtrInfo(UID_07, 01) | |
| 1027 | + | local txtper = modules.game_database.getAtrInfo(UID_07, 08) | |
| 1028 | + | ATR2:setImageSource("/images/custom/Spells/atr_" ..UID_07) | |
| 1029 | + | ATR2Name:setText(tr(desc).. " (" ..tr(text).. " " ..percent.."" ..txtper..")") | |
| 1030 | + | else | |
| 1031 | + | ATR2:setImageSource("/images/custom/Spells/atr_0") | |
| 1032 | + | ATR2Name:setText(tr("<vazio>")) | |
| 1033 | + | end | |
| 1034 | + | ||
| 1035 | + | local StrBonus = "" | |
| 1036 | + | if UID_08 > 0 then | |
| 1037 | + | local BonusUM = modules.game_database.onBonusExtra(01, tostring(UID_08), 03) | |
| 1038 | + | if #BonusUM > 01 then | |
| 1039 | + | StrBonus = BonusUM | |
| 1040 | + | ||
| 1041 | + | local BonusDois = modules.game_database.onBonusExtra(02, tostring(UID_08), 03) | |
| 1042 | + | if #BonusDois > 01 then | |
| 1043 | + | StrBonus = StrBonus.. "\n" ..BonusDois | |
| 1044 | + | ||
| 1045 | + | local BonusTres = modules.game_database.onBonusExtra(03, tostring(UID_08), 03) | |
| 1046 | + | if #BonusTres > 01 then | |
| 1047 | + | StrBonus = StrBonus.. "\n" ..BonusTres | |
| 1048 | + | end | |
| 1049 | + | end | |
| 1050 | + | end | |
| 1051 | + | end | |
| 1052 | + | if #StrBonus > 0 then | |
| 1053 | + | BonusExtra:setText(StrBonus) | |
| 1054 | + | BonusExtra:setMarginTop(15) | |
| 1055 | + | BonusExtra:show() | |
| 1056 | + | else | |
| 1057 | + | BonusExtra:hide() | |
| 1058 | + | end | |
| 1059 | + | Rary:show() | |
| 1060 | + | Desc:hide() | |
| 1061 | + | DefName:show() | |
| 1062 | + | EsqName:show() | |
| 1063 | + | MagName:show() | |
| 1064 | + | ATR1:show() | |
| 1065 | + | ATR1Name:show() | |
| 1066 | + | ATR2:show() | |
| 1067 | + | ATR2Name:show() | |
| 1068 | + | ||
| 1069 | + | Star:show() | |
| 1070 | + | Star:addAnchor(AnchorTop, 'ESQValue', AnchorBottom) | |
| 1071 | + | Star:addAnchor(AnchorLeft, 'DEFValue', AnchorRight) | |
| 1072 | + | Star:setMarginTop(10) | |
| 1073 | + | Star:setMarginLeft(20) | |
| 1074 | + | if UID_03 > 0 then | |
| 1075 | + | Star:setImageSource("/images/custom/UI/star_" ..UID_03) | |
| 1076 | + | else | |
| 1077 | + | Star:setImageSource("/images/custom/UI/star_0") | |
| 1078 | + | end | |
| 1079 | + | ||
| 1080 | + | local localPlayer = g_game.getLocalPlayer() | |
| 1081 | + | if UID_05 < 0 then UID_05 = 0 end | |
| 1082 | + | if UID_03 < 0 then UID_03 = 0 end | |
| 1083 | + | local itemRecLevel = (modules.game_database.getItemInfo(UID_01, 3) + UID_05 + (UID_03 * 10)) * 2 | |
| 1084 | + | ||
| 1085 | + | if localPlayer:getLevel() >= itemRecLevel then | |
| 1086 | + | Level:setBackgroundColor('#05AC5E') | |
| 1087 | + | else | |
| 1088 | + | Level:setBackgroundColor('#AC0505') | |
| 1089 | + | end | |
| 1090 | + | Level:setText(tr('NIVEL REQUERIDO: LV.').. ' ' ..itemRecLevel) | |
| 1091 | + | Level:show() | |
| 1092 | + | Level:setSize({width = 185, height = 15}) | |
| 1093 | + | Level:addAnchor(AnchorTop, 'ATR2Label', AnchorBottom) | |
| 1094 | + | Level:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 1095 | + | Level:setMarginTop(67) | |
| 1096 | + | Level:setMarginLeft(0) | |
| 1097 | + | if UID_09 > 0 then | |
| 1098 | + | Lock:show() | |
| 1099 | + | end | |
| 1100 | + | ||
| 1101 | + | toolTipLabel:show() | |
| 1102 | + | toolTipLabel:raise() | |
| 1103 | + | toolTipLabel:enable() | |
| 1104 | + | ||
| 1105 | + | ||
| 1106 | + | elseif string.find(text, "@BAG") then | |
| 1107 | + | local t = string.explode(text, " ") | |
| 1108 | + | local UID_01 = tonumber(t[02]) or 0 | |
| 1109 | + | local UID_02 = tonumber(t[03]) or 0 | |
| 1110 | + | local UID_03 = tonumber(t[04]) or 0 | |
| 1111 | + | local UID_04 = tonumber(t[05]) or 0 | |
| 1112 | + | local UID_05 = tonumber(t[06]) or 0 | |
| 1113 | + | local UID_06 = tonumber(t[07]) or 0 | |
| 1114 | + | local UID_07 = tonumber(t[08]) or 0 | |
| 1115 | + | local UID_08 = tonumber(t[09]) or 0 | |
| 1116 | + | local UID_09 = tonumber(t[10]) or 0 | |
| 1117 | + | local UID_10 = tonumber(t[11]) or 0 | |
| 1118 | + | ||
| 1119 | + | toolTipLabel:resize(185, 179) | |
| 1120 | + | toolTipLabel:setImageSource("/images/custom/UI/itemInfo") | |
| 1121 | + | Nome:show() | |
| 1122 | + | Nome:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 1123 | + | Nome:setText(tr(modules.game_database.getItemInfo(UID_01, 1))) | |
| 1124 | + | Desc:show() | |
| 1125 | + | Desc:setText(tr(modules.game_database.getItemInfo(UID_01, 8))) | |
| 1126 | + | Price:show() | |
| 1127 | + | if UID_04 ~= nil and UID_04 > 1 then | |
| 1128 | + | Price:setText(mask_number(modules.game_database.getItemInfo(UID_01, 9)).. " (" ..mask_number((UID_04 * modules.game_database.getItemInfo(UID_01, 9))).. ")") | |
| 1129 | + | else | |
| 1130 | + | Price:setText(mask_number(modules.game_database.getItemInfo(UID_01, 9))) | |
| 1131 | + | end | |
| 1132 | + | Level:hide() | |
| 1133 | + | Rary:setColor(modules.game_database.getRaridade(01, UID_02)) | |
| 1134 | + | Rary:setText(tr(modules.game_database.getRaridade(00, UID_02))) | |
| 1135 | + | ||
| 1136 | + | Rary:show() | |
| 1137 | + | Star:show() | |
| 1138 | + | Star:addAnchor(AnchorTop, 'itemDesc', AnchorBottom) | |
| 1139 | + | Star:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 1140 | + | Star:setMarginTop(10) | |
| 1141 | + | Star:setMarginLeft(77) | |
| 1142 | + | if UID_03 > 0 then | |
| 1143 | + | Star:setImageSource("/images/custom/UI/star_" ..UID_03) | |
| 1144 | + | else | |
| 1145 | + | Star:setImageSource("/images/custom/UI/star_0") | |
| 1146 | + | end | |
| 1147 | + | if UID_09 > 0 then | |
| 1148 | + | Lock:show() | |
| 1149 | + | end | |
| 1150 | + | ||
| 1151 | + | toolTipLabel:show() | |
| 1152 | + | toolTipLabel:raise() | |
| 1153 | + | toolTipLabel:enable() | |
| 1154 | + | ||
| 1155 | + | ||
| 1156 | + | else | |
| 1157 | + | toolTipLabel:setText(text) | |
| 1158 | + | toolTipLabel:resizeToText() | |
| 1159 | + | toolTipLabel:resize(toolTipLabel:getWidth() + 4, toolTipLabel:getHeight() + 4) | |
| 1160 | + | toolTipLabel:show() | |
| 1161 | + | toolTipLabel:raise() | |
| 1162 | + | toolTipLabel:enable() | |
| 1163 | + | end | |
| 1164 | + | ||
| 1165 | + | g_effects.fadeIn(toolTipLabel, 100) | |
| 1166 | + | moveToolTip(true) | |
| 1167 | + | connect(rootWidget, { | |
| 1168 | + | onMouseMove = moveToolTip, | |
| 1169 | + | }) | |
| 1170 | + | end | |
| 1171 | + | ||
| 1172 | + | function g_tooltip.hide() | |
| 1173 | + | g_effects.fadeOut(toolTipLabel, 100) | |
| 1174 | + | ||
| 1175 | + | disconnect(rootWidget, { | |
| 1176 | + | onMouseMove = moveToolTip, | |
| 1177 | + | }) | |
| 1178 | + | end | |
| 1179 | + | ||
| 1180 | + | ||
| 1181 | + | -- @docclass UIWidget @{ | |
| 1182 | + | ||
| 1183 | + | -- UIWidget extensions | |
| 1184 | + | function UIWidget:setTooltip(text) | |
| 1185 | + | self.tooltip = text | |
| 1186 | + | end | |
| 1187 | + | ||
| 1188 | + | function UIWidget:removeTooltip() | |
| 1189 | + | self.tooltip = nil | |
| 1190 | + | end | |
| 1191 | + | ||
| 1192 | + | function UIWidget:getTooltip() | |
| 1193 | + | return self.tooltip | |
| 1194 | + | end | |
| 1195 | + | ||
| 1196 | + | -- @} | |
| 1197 | + | ||
| 1198 | + | g_tooltip.init() | |
| 1199 | + | connect(g_app, { onTerminate = g_tooltip.terminate }) |
| @@ -0,0 +1,12 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | UIButton = extends(UIWidget, "UIButton") | |
| 3 | + | ||
| 4 | + | function UIButton.create() | |
| 5 | + | local button = UIButton.internalCreate() | |
| 6 | + | button:setFocusable(false) | |
| 7 | + | return button | |
| 8 | + | end | |
| 9 | + | ||
| 10 | + | function UIButton:onMouseRelease(pos, button) | |
| 11 | + | return self:isPressed() | |
| 12 | + | end |
| @@ -0,0 +1,13 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | UICheckBox = extends(UIWidget, "UICheckBox") | |
| 3 | + | ||
| 4 | + | function UICheckBox.create() | |
| 5 | + | local checkbox = UICheckBox.internalCreate() | |
| 6 | + | checkbox:setFocusable(false) | |
| 7 | + | checkbox:setTextAlign(AlignLeft) | |
| 8 | + | return checkbox | |
| 9 | + | end | |
| 10 | + | ||
| 11 | + | function UICheckBox:onClick() | |
| 12 | + | self:setChecked(not self:isChecked()) | |
| 13 | + | end |
| @@ -0,0 +1,184 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | UIComboBox = extends(UIWidget, "UIComboBox") | |
| 3 | + | ||
| 4 | + | function UIComboBox.create() | |
| 5 | + | local combobox = UIComboBox.internalCreate() | |
| 6 | + | combobox:setFocusable(false) | |
| 7 | + | combobox.options = {} | |
| 8 | + | combobox.currentIndex = -1 | |
| 9 | + | combobox.mouseScroll = true | |
| 10 | + | combobox.menuScroll = false | |
| 11 | + | combobox.menuHeight = 100 | |
| 12 | + | combobox.menuScrollStep = 0 | |
| 13 | + | return combobox | |
| 14 | + | end | |
| 15 | + | ||
| 16 | + | function UIComboBox:clearOptions() | |
| 17 | + | self.options = {} | |
| 18 | + | self.currentIndex = -1 | |
| 19 | + | self:clearText() | |
| 20 | + | end | |
| 21 | + | ||
| 22 | + | function UIComboBox:clear() | |
| 23 | + | return self:clearOptions() | |
| 24 | + | end | |
| 25 | + | ||
| 26 | + | function UIComboBox:getOptionsCount() | |
| 27 | + | return #self.options | |
| 28 | + | end | |
| 29 | + | ||
| 30 | + | function UIComboBox:isOption(text) | |
| 31 | + | if not self.options then return false end | |
| 32 | + | for i,v in ipairs(self.options) do | |
| 33 | + | if v.text == text then | |
| 34 | + | return true | |
| 35 | + | end | |
| 36 | + | end | |
| 37 | + | return false | |
| 38 | + | end | |
| 39 | + | ||
| 40 | + | function UIComboBox:setOption(text, dontSignal) | |
| 41 | + | self:setCurrentOption(text, dontSignal) | |
| 42 | + | end | |
| 43 | + | ||
| 44 | + | function UIComboBox:setCurrentOption(text, dontSignal) | |
| 45 | + | if not self.options then return end | |
| 46 | + | for i,v in ipairs(self.options) do | |
| 47 | + | if v.text == text and self.currentIndex ~= i then | |
| 48 | + | self.currentIndex = i | |
| 49 | + | self:setText(text) | |
| 50 | + | if not dontSignal then | |
| 51 | + | signalcall(self.onOptionChange, self, text, v.data) | |
| 52 | + | end | |
| 53 | + | return | |
| 54 | + | end | |
| 55 | + | end | |
| 56 | + | end | |
| 57 | + | ||
| 58 | + | function UIComboBox:updateCurrentOption(newText) | |
| 59 | + | self.options[self.currentIndex].text = newText | |
| 60 | + | self:setText(newText) | |
| 61 | + | end | |
| 62 | + | ||
| 63 | + | function UIComboBox:setCurrentOptionByData(data, dontSignal) | |
| 64 | + | if not self.options then return end | |
| 65 | + | for i,v in ipairs(self.options) do | |
| 66 | + | if v.data == data and self.currentIndex ~= i then | |
| 67 | + | self.currentIndex = i | |
| 68 | + | self:setText(v.text) | |
| 69 | + | if not dontSignal then | |
| 70 | + | signalcall(self.onOptionChange, self, v.text, v.data) | |
| 71 | + | end | |
| 72 | + | return | |
| 73 | + | end | |
| 74 | + | end | |
| 75 | + | end | |
| 76 | + | ||
| 77 | + | function UIComboBox:setCurrentIndex(index, dontSignal) | |
| 78 | + | if index >= 1 and index <= #self.options then | |
| 79 | + | local v = self.options[index] | |
| 80 | + | self.currentIndex = index | |
| 81 | + | self:setText(v.text) | |
| 82 | + | if not dontSignal then | |
| 83 | + | signalcall(self.onOptionChange, self, v.text, v.data) | |
| 84 | + | end | |
| 85 | + | end | |
| 86 | + | end | |
| 87 | + | ||
| 88 | + | function UIComboBox:getCurrentOption() | |
| 89 | + | if table.haskey(self.options, self.currentIndex) then | |
| 90 | + | return self.options[self.currentIndex] | |
| 91 | + | end | |
| 92 | + | end | |
| 93 | + | ||
| 94 | + | function UIComboBox:addOption(text, data) | |
| 95 | + | table.insert(self.options, { text = text, data = data }) | |
| 96 | + | local index = #self.options | |
| 97 | + | if index == 1 then self:setCurrentOption(text) end | |
| 98 | + | return index | |
| 99 | + | end | |
| 100 | + | ||
| 101 | + | function UIComboBox:removeOption(text) | |
| 102 | + | for i,v in ipairs(self.options) do | |
| 103 | + | if v.text == text then | |
| 104 | + | table.remove(self.options, i) | |
| 105 | + | if self.currentIndex == i then | |
| 106 | + | self:setCurrentIndex(1) | |
| 107 | + | elseif self.currentIndex > i then | |
| 108 | + | self.currentIndex = self.currentIndex - 1 | |
| 109 | + | end | |
| 110 | + | return | |
| 111 | + | end | |
| 112 | + | end | |
| 113 | + | end | |
| 114 | + | ||
| 115 | + | function UIComboBox:onMousePress(mousePos, mouseButton) | |
| 116 | + | local menu | |
| 117 | + | if self.menuScroll then | |
| 118 | + | menu = g_ui.createWidget(self:getStyleName() .. 'PopupScrollMenu') | |
| 119 | + | menu:setHeight(self.menuHeight) | |
| 120 | + | if self.menuScrollStep > 0 then | |
| 121 | + | menu:setScrollbarStep(self.menuScrollStep) | |
| 122 | + | end | |
| 123 | + | else | |
| 124 | + | menu = g_ui.createWidget(self:getStyleName() .. 'PopupMenu') | |
| 125 | + | end | |
| 126 | + | menu:setId(self:getId() .. 'PopupMenu') | |
| 127 | + | for i,v in ipairs(self.options) do | |
| 128 | + | menu:addOption(v.text, function() self:setCurrentOption(v.text) end) | |
| 129 | + | end | |
| 130 | + | menu:setWidth(self:getWidth()) | |
| 131 | + | menu:display({ x = self:getX(), y = self:getY() + self:getHeight() }) | |
| 132 | + | connect(menu, { onDestroy = function() self:setOn(false) end }) | |
| 133 | + | self:setOn(true) | |
| 134 | + | return true | |
| 135 | + | end | |
| 136 | + | ||
| 137 | + | function UIComboBox:onMouseWheel(mousePos, direction) | |
| 138 | + | if not self.mouseScroll or self.disableScroll then | |
| 139 | + | return false | |
| 140 | + | end | |
| 141 | + | if direction == MouseWheelUp and self.currentIndex > 1 then | |
| 142 | + | self:setCurrentIndex(self.currentIndex - 1) | |
| 143 | + | elseif direction == MouseWheelDown and self.currentIndex < #self.options then | |
| 144 | + | self:setCurrentIndex(self.currentIndex + 1) | |
| 145 | + | end | |
| 146 | + | return true | |
| 147 | + | end | |
| 148 | + | ||
| 149 | + | function UIComboBox:onStyleApply(styleName, styleNode) | |
| 150 | + | if styleNode.options then | |
| 151 | + | for k,option in pairs(styleNode.options) do | |
| 152 | + | self:addOption(option) | |
| 153 | + | end | |
| 154 | + | end | |
| 155 | + | ||
| 156 | + | if styleNode.data then | |
| 157 | + | for k,data in pairs(styleNode.data) do | |
| 158 | + | local option = self.options[k] | |
| 159 | + | if option then | |
| 160 | + | option.data = data | |
| 161 | + | end | |
| 162 | + | end | |
| 163 | + | end | |
| 164 | + | ||
| 165 | + | for name,value in pairs(styleNode) do | |
| 166 | + | if name == 'mouse-scroll' then | |
| 167 | + | self.mouseScroll = value | |
| 168 | + | elseif name == 'menu-scroll' then | |
| 169 | + | self.menuScroll = value | |
| 170 | + | elseif name == 'menu-height' then | |
| 171 | + | self.menuHeight = value | |
| 172 | + | elseif name == 'menu-scroll-step' then | |
| 173 | + | self.menuScrollStep = value | |
| 174 | + | end | |
| 175 | + | end | |
| 176 | + | end | |
| 177 | + | ||
| 178 | + | function UIComboBox:setMouseScroll(scroll) | |
| 179 | + | self.mouseScroll = scroll | |
| 180 | + | end | |
| 181 | + | ||
| 182 | + | function UIComboBox:canMouseScroll() | |
| 183 | + | return self.mouseScroll | |
| 184 | + | end |
| @@ -0,0 +1,99 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | UIImageView = extends(UIWidget, "UIImageView") | |
| 3 | + | ||
| 4 | + | function UIImageView.create() | |
| 5 | + | local imageView = UIImageView.internalCreate() | |
| 6 | + | imageView.zoom = 1 | |
| 7 | + | imageView.minZoom = math.pow(10, -2) | |
| 8 | + | imageView.maxZoom = math.pow(10, 2) | |
| 9 | + | imageView:setClipping(true) | |
| 10 | + | return imageView | |
| 11 | + | end | |
| 12 | + | ||
| 13 | + | function UIImageView:getDefaultZoom() | |
| 14 | + | local width = self:getWidth() | |
| 15 | + | local height = self:getHeight() | |
| 16 | + | local textureWidth = self:getImageTextureWidth() | |
| 17 | + | local textureHeight = self:getImageTextureHeight() | |
| 18 | + | local zoomX = width / textureWidth | |
| 19 | + | local zoomY = height / textureHeight | |
| 20 | + | return math.min(zoomX, zoomY) | |
| 21 | + | end | |
| 22 | + | ||
| 23 | + | function UIImageView:getImagePosition(x, y) | |
| 24 | + | x = x or self:getWidth() / 2 | |
| 25 | + | y = y or self:getHeight() / 2 | |
| 26 | + | local offsetX = self:getImageOffsetX() | |
| 27 | + | local offsetY = self:getImageOffsetY() | |
| 28 | + | local posX = (x - offsetX) / self.zoom | |
| 29 | + | local posY = (y - offsetY) / self.zoom | |
| 30 | + | return posX, posY | |
| 31 | + | end | |
| 32 | + | ||
| 33 | + | function UIImageView:setImage(image) | |
| 34 | + | self:setImageSource(image) | |
| 35 | + | local zoom = self:getDefaultZoom() | |
| 36 | + | self:setZoom(zoom) | |
| 37 | + | self:center() | |
| 38 | + | end | |
| 39 | + | ||
| 40 | + | function UIImageView:setZoom(zoom, x, y) | |
| 41 | + | zoom = math.max(math.min(zoom, self.maxZoom), self.minZoom) | |
| 42 | + | local posX, posY = self:getImagePosition(x, y) | |
| 43 | + | local textureWidth = self:getImageTextureWidth() | |
| 44 | + | local textureHeight = self:getImageTextureHeight() | |
| 45 | + | local imageWidth = textureWidth * zoom | |
| 46 | + | local imageHeight = textureHeight * zoom | |
| 47 | + | self:setImageWidth(imageWidth) | |
| 48 | + | self:setImageHeight(imageHeight) | |
| 49 | + | self.zoom = zoom | |
| 50 | + | self:move(posX, posY, x, y) | |
| 51 | + | end | |
| 52 | + | ||
| 53 | + | function UIImageView:zoomIn(x, y) | |
| 54 | + | local zoom = self.zoom * 1.1 | |
| 55 | + | self:setZoom(zoom, x, y) | |
| 56 | + | end | |
| 57 | + | ||
| 58 | + | function UIImageView:zoomOut(x, y) | |
| 59 | + | local zoom = self.zoom / 1.1 | |
| 60 | + | self:setZoom(zoom, x, y) | |
| 61 | + | end | |
| 62 | + | ||
| 63 | + | function UIImageView:center() | |
| 64 | + | self:move(self:getImageTextureWidth() / 2, self:getImageTextureHeight() / 2) | |
| 65 | + | end | |
| 66 | + | ||
| 67 | + | function UIImageView:move(x, y, centerX, centerY) | |
| 68 | + | x = math.max(math.min(x, self:getImageTextureWidth()), 0) | |
| 69 | + | y = math.max(math.min(y, self:getImageTextureHeight()), 0) | |
| 70 | + | local centerX = centerX or self:getWidth() / 2 | |
| 71 | + | local centerY = centerY or self:getHeight() / 2 | |
| 72 | + | local offsetX = centerX - x * self.zoom | |
| 73 | + | local offsetY = centerY - y * self.zoom | |
| 74 | + | self:setImageOffset({x=offsetX, y=offsetY}) | |
| 75 | + | end | |
| 76 | + | ||
| 77 | + | function UIImageView:onDragEnter(pos) | |
| 78 | + | return true | |
| 79 | + | end | |
| 80 | + | ||
| 81 | + | function UIImageView:onDragMove(pos, moved) | |
| 82 | + | local posX, posY = self:getImagePosition() | |
| 83 | + | self:move(posX - moved.x / self.zoom, posY - moved.y / self.zoom) | |
| 84 | + | return true | |
| 85 | + | end | |
| 86 | + | ||
| 87 | + | function UIImageView:onDragLeave(widget, pos) | |
| 88 | + | return true | |
| 89 | + | end | |
| 90 | + | ||
| 91 | + | function UIImageView:onMouseWheel(mousePos, direction) | |
| 92 | + | local x = mousePos.x - self:getX() | |
| 93 | + | local y = mousePos.y - self:getY() | |
| 94 | + | if direction == MouseWheelUp then | |
| 95 | + | self:zoomIn(x, y) | |
| 96 | + | elseif direction == MouseWheelDown then | |
| 97 | + | self:zoomOut(x, y) | |
| 98 | + | end | |
| 99 | + | end |
| @@ -0,0 +1,114 @@ | |||
| 1 | + | if not UIWindow then dofile 'uiwindow' end | |
| 2 | + | ||
| 3 | + | -- @docclass | |
| 4 | + | UIInputBox = extends(UIWindow, "UIInputBox") | |
| 5 | + | ||
| 6 | + | function UIInputBox.create(title, okCallback, cancelCallback) | |
| 7 | + | local inputBox = UIInputBox.internalCreate() | |
| 8 | + | ||
| 9 | + | inputBox:setText(title) | |
| 10 | + | inputBox.inputs = {} | |
| 11 | + | inputBox.onEnter = function() | |
| 12 | + | local results = {} | |
| 13 | + | for _,func in pairs(inputBox.inputs) do | |
| 14 | + | table.insert(results, func()) | |
| 15 | + | end | |
| 16 | + | okCallback(unpack(results)) | |
| 17 | + | inputBox:destroy() | |
| 18 | + | end | |
| 19 | + | inputBox.onEscape = function() | |
| 20 | + | if cancelCallback then | |
| 21 | + | cancelCallback() | |
| 22 | + | end | |
| 23 | + | inputBox:destroy() | |
| 24 | + | end | |
| 25 | + | ||
| 26 | + | return inputBox | |
| 27 | + | end | |
| 28 | + | ||
| 29 | + | function UIInputBox:addLabel(text) | |
| 30 | + | local label = g_ui.createWidget('InputBoxLabel', self) | |
| 31 | + | label:setText(text) | |
| 32 | + | return label | |
| 33 | + | end | |
| 34 | + | ||
| 35 | + | function UIInputBox:addLineEdit(labelText, defaultText, maxLength) | |
| 36 | + | if labelText then self:addLabel(labelText) end | |
| 37 | + | local lineEdit = g_ui.createWidget('InputBoxLineEdit', self) | |
| 38 | + | if defaultText then lineEdit:setText(defaultText) end | |
| 39 | + | if maxLength then lineEdit:setMaxLength(maxLength) end | |
| 40 | + | table.insert(self.inputs, function() return lineEdit:getText() end) | |
| 41 | + | return lineEdit | |
| 42 | + | end | |
| 43 | + | ||
| 44 | + | function UIInputBox:addTextEdit(labelText, defaultText, maxLength, visibleLines) | |
| 45 | + | if labelText then self:addLabel(labelText) end | |
| 46 | + | local textEdit = g_ui.createWidget('InputBoxTextEdit', self) | |
| 47 | + | if defaultText then textEdit:setText(defaultText) end | |
| 48 | + | if maxLength then textEdit:setMaxLength(maxLength) end | |
| 49 | + | visibleLines = visibleLines or 1 | |
| 50 | + | textEdit:setHeight(textEdit:getHeight() * visibleLines) | |
| 51 | + | table.insert(self.inputs, function() return textEdit:getText() end) | |
| 52 | + | return textEdit | |
| 53 | + | end | |
| 54 | + | ||
| 55 | + | function UIInputBox:addCheckBox(text, checked) | |
| 56 | + | local checkBox = g_ui.createWidget('InputBoxCheckBox', self) | |
| 57 | + | checkBox:setText(text) | |
| 58 | + | checkBox:setChecked(checked) | |
| 59 | + | table.insert(self.inputs, function() return checkBox:isChecked() end) | |
| 60 | + | return checkBox | |
| 61 | + | end | |
| 62 | + | ||
| 63 | + | function UIInputBox:addComboBox(labelText, ...) | |
| 64 | + | if labelText then self:addLabel(labelText) end | |
| 65 | + | local comboBox = g_ui.createWidget('InputBoxComboBox', self) | |
| 66 | + | local options = {...} | |
| 67 | + | for i=1,#options do | |
| 68 | + | comboBox:addOption(options[i]) | |
| 69 | + | end | |
| 70 | + | table.insert(self.inputs, function() return comboBox:getCurrentOption() end) | |
| 71 | + | return comboBox | |
| 72 | + | end | |
| 73 | + | ||
| 74 | + | function UIInputBox:addSpinBox(labelText, minimum, maximum, value, step) | |
| 75 | + | if labelText then self:addLabel(labelText) end | |
| 76 | + | local spinBox = g_ui.createWidget('InputBoxSpinBox', self) | |
| 77 | + | spinBox:setMinimum(minimum) | |
| 78 | + | spinBox:setMaximum(maximum) | |
| 79 | + | spinBox:setValue(value) | |
| 80 | + | spinBox:setStep(step) | |
| 81 | + | table.insert(self.inputs, function() return spinBox:getValue() end) | |
| 82 | + | return spinBox | |
| 83 | + | end | |
| 84 | + | ||
| 85 | + | function UIInputBox:display(okButtonText, cancelButtonText) | |
| 86 | + | okButtonText = okButtonText or tr('Ok') | |
| 87 | + | cancelButtonText = cancelButtonText or tr('Cancel') | |
| 88 | + | ||
| 89 | + | local buttonsWidget = g_ui.createWidget('InputBoxButtonsPanel', self) | |
| 90 | + | local okButton = g_ui.createWidget('InputBoxButton', buttonsWidget) | |
| 91 | + | okButton:setText(okButtonText) | |
| 92 | + | okButton.onClick = self.onEnter | |
| 93 | + | ||
| 94 | + | local cancelButton = g_ui.createWidget('InputBoxButton', buttonsWidget) | |
| 95 | + | cancelButton:setText(cancelButtonText) | |
| 96 | + | cancelButton.onClick = self.onEscape | |
| 97 | + | ||
| 98 | + | buttonsWidget:setHeight(okButton:getHeight()) | |
| 99 | + | ||
| 100 | + | rootWidget:addChild(self) | |
| 101 | + | self:setStyle('InputBoxWindow') | |
| 102 | + | end | |
| 103 | + | ||
| 104 | + | function displayTextInputBox(title, label, okCallback, cancelCallback) | |
| 105 | + | local inputBox = UIInputBox.create(title, okCallback, cancelCallback) | |
| 106 | + | inputBox:addLineEdit(label) | |
| 107 | + | inputBox:display() | |
| 108 | + | end | |
| 109 | + | ||
| 110 | + | function displayNumberInputBox(title, label, okCallback, cancelCallback, min, max, value, step) | |
| 111 | + | local inputBox = UIInputBox.create(title, okCallback, cancelCallback) | |
| 112 | + | inputBox:addSpinBox(label, min, max, value, step) | |
| 113 | + | inputBox:display() | |
| 114 | + | end |
| @@ -0,0 +1,10 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | UILabel = extends(UIWidget, "UILabel") | |
| 3 | + | ||
| 4 | + | function UILabel.create() | |
| 5 | + | local label = UILabel.internalCreate() | |
| 6 | + | label:setPhantom(true) | |
| 7 | + | label:setFocusable(false) | |
| 8 | + | label:setTextAlign(AlignLeft) | |
| 9 | + | return label | |
| 10 | + | end |
| @@ -0,0 +1,96 @@ | |||
| 1 | + | if not UIWindow then dofile 'uiwindow' end | |
| 2 | + | ||
| 3 | + | -- @docclass | |
| 4 | + | UIMessageBox = extends(UIWindow, "UIMessageBox") | |
| 5 | + | ||
| 6 | + | -- messagebox cannot be created from otui files | |
| 7 | + | UIMessageBox.create = nil | |
| 8 | + | ||
| 9 | + | function UIMessageBox.display(title, message, buttons, onEnterCallback, onEscapeCallback) | |
| 10 | + | local messageBox = UIMessageBox.internalCreate() | |
| 11 | + | rootWidget:addChild(messageBox) | |
| 12 | + | ||
| 13 | + | messageBox:setStyle('MainWindow') | |
| 14 | + | messageBox:setText(title) | |
| 15 | + | ||
| 16 | + | local messageLabel = g_ui.createWidget('MessageBoxLabel', messageBox) | |
| 17 | + | messageLabel:setText(message) | |
| 18 | + | ||
| 19 | + | local buttonsWidth = 0 | |
| 20 | + | local buttonsHeight = 0 | |
| 21 | + | ||
| 22 | + | local anchor = AnchorRight | |
| 23 | + | if buttons.anchor then anchor = buttons.anchor end | |
| 24 | + | ||
| 25 | + | local buttonHolder = g_ui.createWidget('MessageBoxButtonHolder', messageBox) | |
| 26 | + | buttonHolder:addAnchor(anchor, 'parent', anchor) | |
| 27 | + | ||
| 28 | + | for i=1,#buttons do | |
| 29 | + | local button = messageBox:addButton(buttons[i].text, buttons[i].callback) | |
| 30 | + | if i == 1 then | |
| 31 | + | button:setMarginLeft(0) | |
| 32 | + | button:addAnchor(AnchorBottom, 'parent', AnchorBottom) | |
| 33 | + | button:addAnchor(AnchorLeft, 'parent', AnchorLeft) | |
| 34 | + | buttonsHeight = button:getHeight() | |
| 35 | + | else | |
| 36 | + | button:addAnchor(AnchorBottom, 'prev', AnchorBottom) | |
| 37 | + | button:addAnchor(AnchorLeft, 'prev', AnchorRight) | |
| 38 | + | end | |
| 39 | + | buttonsWidth = buttonsWidth + button:getWidth() + button:getMarginLeft() | |
| 40 | + | end | |
| 41 | + | ||
| 42 | + | buttonHolder:setWidth(buttonsWidth) | |
| 43 | + | buttonHolder:setHeight(buttonsHeight) | |
| 44 | + | ||
| 45 | + | if onEnterCallback then connect(messageBox, { onEnter = onEnterCallback }) end | |
| 46 | + | if onEscapeCallback then connect(messageBox, { onEscape = onEscapeCallback }) end | |
| 47 | + | ||
| 48 | + | messageBox:setWidth(math.max(messageLabel:getWidth(), messageBox:getTextSize().width, buttonHolder:getWidth()) + messageBox:getPaddingLeft() + messageBox:getPaddingRight()) | |
| 49 | + | messageBox:setHeight(messageLabel:getHeight() + messageBox:getPaddingTop() + messageBox:getPaddingBottom() + buttonHolder:getHeight() + buttonHolder:getMarginTop()) | |
| 50 | + | return messageBox | |
| 51 | + | end | |
| 52 | + | ||
| 53 | + | function displayInfoBox(title, message) | |
| 54 | + | local messageBox | |
| 55 | + | local defaultCallback = function() messageBox:ok() end | |
| 56 | + | messageBox = UIMessageBox.display(title, message, {{text='Ok', callback=defaultCallback}}, defaultCallback, defaultCallback) | |
| 57 | + | return messageBox | |
| 58 | + | end | |
| 59 | + | ||
| 60 | + | function displayErrorBox(title, message) | |
| 61 | + | local messageBox | |
| 62 | + | local defaultCallback = function() messageBox:ok() end | |
| 63 | + | messageBox = UIMessageBox.display(title, message, {{text='Ok', callback=defaultCallback}}, defaultCallback, defaultCallback) | |
| 64 | + | return messageBox | |
| 65 | + | end | |
| 66 | + | ||
| 67 | + | function displayCancelBox(title, message) | |
| 68 | + | local messageBox | |
| 69 | + | local defaultCallback = function() messageBox:cancel() end | |
| 70 | + | messageBox = UIMessageBox.display(title, message, {{text='Cancel', callback=defaultCallback}}, defaultCallback, defaultCallback) | |
| 71 | + | return messageBox | |
| 72 | + | end | |
| 73 | + | ||
| 74 | + | function displayGeneralBox(title, message, buttons, onEnterCallback, onEscapeCallback) | |
| 75 | + | return UIMessageBox.display(title, message, buttons, onEnterCallback, onEscapeCallback) | |
| 76 | + | end | |
| 77 | + | ||
| 78 | + | function UIMessageBox:addButton(text, callback) | |
| 79 | + | local buttonHolder = self:getChildById('buttonHolder') | |
| 80 | + | local button = g_ui.createWidget('MessageBoxButton', buttonHolder) | |
| 81 | + | button:setText(text) | |
| 82 | + | connect(button, { onClick = callback }) | |
| 83 | + | return button | |
| 84 | + | end | |
| 85 | + | ||
| 86 | + | function UIMessageBox:ok() | |
| 87 | + | signalcall(self.onOk, self) | |
| 88 | + | self.onOk = nil | |
| 89 | + | self:destroy() | |
| 90 | + | end | |
| 91 | + | ||
| 92 | + | function UIMessageBox:cancel() | |
| 93 | + | signalcall(self.onCancel, self) | |
| 94 | + | self.onCancel = nil | |
| 95 | + | self:destroy() | |
| 96 | + | end |
| @@ -0,0 +1,444 @@ | |||
| 1 | + | -- @docclass | |
| 2 | + | UIMiniWindow = extends(UIWindow, "UIMiniWindow") | |
| 3 | + | ||
| 4 | + | function UIMiniWindow.create() | |
| 5 | + | local miniwindow = UIMiniWindow.internalCreate() | |
| 6 | + | miniwindow.UIMiniWindowContainer = true | |
| 7 | + | return miniwindow | |
| 8 | + | end | |
| 9 | + | ||
| 10 | + | function UIMiniWindow:open(dontSave) | |
| 11 | + | self:setVisible(true) | |
| 12 | + | ||
| 13 | + | if not dontSave then | |
| 14 | + | self:setSettings({closed = false}) | |
| 15 | + | end | |
| 16 | + | ||
| 17 | + | signalcall(self.onOpen, self) | |
| 18 | + | end | |
| 19 | + | ||
| 20 | + | function UIMiniWindow:close(dontSave) | |
| 21 | + | if not self:isExplicitlyVisible() then return end | |
| 22 | + | if self.forceOpen then return end | |
| 23 | + | self:setVisible(false) | |
| 24 | + | ||
| 25 | + | if not dontSave then | |
| 26 | + | self:setSettings({closed = true}) | |
| 27 | + | end | |
| 28 | + | ||
| 29 | + | signalcall(self.onClose, self) | |
| 30 | + | end | |
| 31 | + | ||
| 32 | + | function UIMiniWindow:minimize(dontSave) | |
| 33 | + | self:setOn(true) | |
| 34 | + | self:getChildById('contentsPanel'):hide() | |
| 35 | + | self:getChildById('miniwindowScrollBar'):hide() | |
| 36 | + | self:getChildById('bottomResizeBorder'):hide() | |
| 37 | + | if self.minimizeButton then | |
| 38 | + | self.minimizeButton:setOn(true) | |
| 39 | + | end | |
| 40 | + | self.maximizedHeight = self:getHeight() | |
| 41 | + | self:setHeight(self.minimizedHeight) | |
| 42 | + | ||
| 43 | + | if not dontSave then | |
| 44 | + | self:setSettings({minimized = true}) | |
| 45 | + | end | |
| 46 | + | ||
| 47 | + | signalcall(self.onMinimize, self) | |
| 48 | + | end | |
| 49 | + | ||
| 50 | + | function UIMiniWindow:maximize(dontSave) | |
| 51 | + | self:setOn(false) | |
| 52 | + | self:getChildById('contentsPanel'):show() | |
| 53 | + | self:getChildById('miniwindowScrollBar'):show() | |
| 54 | + | self:getChildById('bottomResizeBorder'):show() | |
| 55 | + | if self.minimizeButton then | |
| 56 | + | self.minimizeButton:setOn(false) | |
| 57 | + | end | |
| 58 | + | self:setHeight(self:getSettings('height') or self.maximizedHeight) | |
| 59 | + | ||
| 60 | + | if not dontSave then | |
| 61 | + | self:setSettings({minimized = false}) | |
| 62 | + | end | |
| 63 | + | ||
| 64 | + | local parent = self:getParent() | |
| 65 | + | if parent and parent:getClassName() == 'UIMiniWindowContainer' then | |
| 66 | + | parent:fitAll(self) | |
| 67 | + | end | |
| 68 | + | ||
| 69 | + | signalcall(self.onMaximize, self) | |
| 70 | + | end | |
| 71 | + | ||
| 72 | + | function UIMiniWindow:lock(dontSave) | |
| 73 | + | local lockButton = self:getChildById('lockButton') | |
| 74 | + | if lockButton then | |
| 75 | + | lockButton:setOn(true) | |
| 76 | + | end | |
| 77 | + | self:setDraggable(false) | |
| 78 | + | if not dontsave then | |
| 79 | + | self:setSettings({locked = true}) | |
| 80 | + | end | |
| 81 | + | ||
| 82 | + | signalcall(self.onLockChange, self) | |
| 83 | + | end | |
| 84 | + | ||
| 85 | + | function UIMiniWindow:unlock(dontSave) | |
| 86 | + | local lockButton = self:getChildById('lockButton') | |
| 87 | + | if lockButton then | |
| 88 | + | lockButton:setOn(false) | |
| 89 | + | end | |
| 90 | + | self:setDraggable(true) | |
| 91 | + | if not dontsave then | |
| 92 | + | self:setSettings({locked = false}) | |
| 93 | + | end | |
| 94 | + | signalcall(self.onLockChange, self) | |
| 95 | + | end | |
| 96 | + | ||
| 97 | + | function UIMiniWindow:setup() | |
| 98 | + | self:getChildById('closeButton').onClick = | |
| 99 | + | function() | |
| 100 | + | self:close() | |
| 101 | + | end | |
| 102 | + | if self.forceOpen then | |
| 103 | + | if self.closeButton then | |
| 104 | + | self.closeButton:hide() | |
| 105 | + | end | |
| 106 | + | end | |
| 107 | + | ||
| 108 | + | if(self.minimizeButton) then | |
| 109 | + | self.minimizeButton.onClick = | |
| 110 | + | function() | |
| 111 | + | if self:isOn() then | |
| 112 | + | self:maximize() | |
| 113 | + | else | |
| 114 | + | self:minimize() | |
| 115 | + | end | |
| 116 | + | end | |
| 117 | + | end | |
| 118 | + | ||
| 119 | + | local lockButton = self:getChildById('lockButton') | |
| 120 | + | if lockButton then | |
| 121 | + | lockButton.onClick = | |
| 122 | + | function () | |
| 123 | + | if self:isDraggable() then | |
| 124 | + | self:lock() | |
| 125 | + | else | |
| 126 | + | self:unlock() | |
| 127 | + | end | |
| 128 | + | end | |
| 129 | + | end | |
| 130 | + | ||
| 131 | + | self:getChildById('miniwindowTopBar').onDoubleClick = | |
| 132 | + | function() | |
| 133 | + | if self:isOn() then | |
| 134 | + | self:maximize() | |
| 135 | + | else | |
| 136 | + | self:minimize() | |
| 137 | + | end | |
| 138 | + | end | |
| 139 | + | ||
| 140 | + | local oldParent = self:getParent() | |
| 141 | + | ||
| 142 | + | local settings = g_settings.getNode('MiniWindows') | |
| 143 | + | if settings then | |
| 144 | + | local selfSettings = settings[self:getId()] | |
| 145 | + | if selfSettings then | |
| 146 | + | if selfSettings.parentId then | |
| 147 | + | local parent = rootWidget:recursiveGetChildById(selfSettings.parentId) | |
| 148 | + | if parent then | |
| 149 | + | if parent:getClassName() == 'UIMiniWindowContainer' and selfSettings.index and parent:isOn() then | |
| 150 | + | self.miniIndex = selfSettings.index | |
| 151 | + | parent:scheduleInsert(self, selfSettings.index) | |
| 152 | + | elseif selfSettings.position then | |
| 153 | + | self:setParent(parent, true) | |
| 154 | + | self:setPosition(topoint(selfSettings.position)) | |
| 155 | + | end | |
| 156 | + | end | |
| 157 | + | end | |
| 158 | + | ||
| 159 | + | if selfSettings.minimized then | |
| 160 | + | self:minimize(true) | |
| 161 | + | else | |
| 162 | + | if selfSettings.height and self:isResizeable() then | |
| 163 | + | self:setHeight(selfSettings.height) | |
| 164 | + | elseif selfSettings.height and not self:isResizeable() then | |
| 165 | + | self:eraseSettings({height = true}) | |
| 166 | + | end | |
| 167 | + | end | |
| 168 | + | ||
| 169 | + | if selfSettings.closed and not self.forceOpen then | |
| 170 | + | self:close(true) | |
| 171 | + | end | |
| 172 | + | ||
| 173 | + | if selfSettings.locked then | |
| 174 | + | self:lock(true) | |
| 175 | + | end | |
| 176 | + | else | |
| 177 | + | if not self.forceOpen and self.autoOpen ~= nil and (self.autoOpen == 0 or self.autoOpen == false) then | |
| 178 | + | self:close(true) | |
| 179 | + | end | |
| 180 | + | end | |
| 181 | + | end | |
| 182 | + | ||
| 183 | + | local newParent = self:getParent() | |
| 184 | + | ||
| 185 | + | self.miniLoaded = true | |
| 186 | + | ||
| 187 | + | if self.save then | |
| 188 | + | if oldParent and oldParent:getClassName() == 'UIMiniWindowContainer' then | |
| 189 | + | addEvent(function() oldParent:order() end) | |
| 190 | + | end | |
| 191 | + | if newParent and newParent:getClassName() == 'UIMiniWindowContainer' and newParent ~= oldParent then | |
| 192 | + | addEvent(function() newParent:order() end) | |
| 193 | + | end | |
| 194 | + | end | |
| 195 | + | ||
| 196 | + | self:fitOnParent() | |
| 197 | + | end | |
| 198 | + | ||
| 199 | + | function UIMiniWindow:onVisibilityChange(visible) | |
| 200 | + | self:fitOnParent() | |
| 201 | + | end | |
| 202 | + | ||
| 203 | + | function UIMiniWindow:onDragEnter(mousePos) | |
| 204 | + | local parent = self:getParent() | |
| 205 | + | if not parent then return false end | |
| 206 | + | ||
| 207 | + | if parent:getClassName() == 'UIMiniWindowContainer' then | |
| 208 | + | local containerParent = parent:getParent():getParent() | |
| 209 | + | parent:removeChild(self) | |
| 210 | + | containerParent:addChild(self) | |
| 211 | + | parent:saveChildren() | |
| 212 | + | end | |
| 213 | + | ||
| 214 | + | local oldPos = self:getPosition() | |
| 215 | + | self.movingReference = { x = mousePos.x - oldPos.x, y = mousePos.y - oldPos.y } | |
| 216 | + | self:setPosition(oldPos) | |
| 217 | + | self.free = true | |
| 218 | + | return true | |
| 219 | + | end | |
| 220 | + | ||
| 221 | + | function UIMiniWindow:onDragLeave(droppedWidget, mousePos) | |
| 222 | + | if self.movedWidget then | |
| 223 | + | self.setMovedChildMargin(self.movedOldMargin or 0) | |
| 224 | + | self.movedWidget = nil | |
| 225 | + | self.setMovedChildMargin = nil | |
| 226 | + | self.movedOldMargin = nil | |
| 227 | + | self.movedIndex = nil | |
| 228 | + | end | |
| 229 | + | ||
| 230 | + | UIWindow:onDragLeave(self, droppedWidget, mousePos) | |
| 231 | + | self:saveParent(self:getParent()) | |
| 232 | + | end | |
| 233 | + | ||
| 234 | + | function UIMiniWindow:onDragMove(mousePos, mouseMoved) | |
| 235 | + | local oldMousePosY = mousePos.y - mouseMoved.y | |
| 236 | + | local children = rootWidget:recursiveGetChildrenByMarginPos(mousePos) | |
| 237 | + | local overAnyWidget = false | |
| 238 | + | for i=1,#children do | |
| 239 | + | local child = children[i] | |
| 240 | + | if child:getParent():getClassName() == 'UIMiniWindowContainer' then | |
| 241 | + | overAnyWidget = true | |
| 242 | + | ||
| 243 | + | local childCenterY = child:getY() + child:getHeight() / 2 | |
| 244 | + | if child == self.movedWidget and mousePos.y < childCenterY and oldMousePosY < childCenterY then | |
| 245 | + | break | |
| 246 | + | end | |
| 247 | + | ||
| 248 | + | if self.movedWidget then | |
| 249 | + | self.setMovedChildMargin(self.movedOldMargin or 0) | |
| 250 | + | self.setMovedChildMargin = nil | |
| 251 | + | end | |
| 252 | + | ||
| 253 | + | if mousePos.y < childCenterY then | |
| 254 | + | self.movedOldMargin = child:getMarginTop() | |
| 255 | + | self.setMovedChildMargin = function(v) child:setMarginTop(v) end | |
| 256 | + | self.movedIndex = 0 | |
| 257 | + | else | |
| 258 | + | self.movedOldMargin = child:getMarginBottom() | |
| 259 | + | self.setMovedChildMargin = function(v) child:setMarginBottom(v) end | |
| 260 | + | self.movedIndex = 1 | |
| 261 | + | end | |
| 262 | + | ||
| 263 | + | self.movedWidget = child | |
| 264 | + | self.setMovedChildMargin(self:getHeight()) | |
| 265 | + | break | |
| 266 | + | end | |
| 267 | + | end | |
| 268 | + | ||
| 269 | + | if not overAnyWidget and self.movedWidget then | |
| 270 | + | self.setMovedChildMargin(self.movedOldMargin or 0) | |
| 271 | + | self.movedWidget = nil | |
| 272 | + | end | |
| 273 | + | ||
| 274 | + | return UIWindow.onDragMove(self, mousePos, mouseMoved) | |
| 275 | + | end | |
| 276 | + | ||
| 277 | + | function UIMiniWindow:onMousePress() | |
| 278 | + | local parent = self:getParent() | |
| 279 | + | if not parent then return false end | |
| 280 | + | if parent:getClassName() ~= 'UIMiniWindowContainer' then | |
| 281 | + | self:raise() | |
| 282 | + | return true | |
| 283 | + | end | |
| 284 | + | end | |
| 285 | + | ||
| 286 | + | function UIMiniWindow:onFocusChange(focused) | |
| 287 | + | if not focused then return end | |
| 288 | + | local parent = self:getParent() | |
| 289 | + | if parent and parent:getClassName() ~= 'UIMiniWindowContainer' then | |
| 290 | + | self:raise() | |
| 291 | + | end | |
| 292 | + | end | |
| 293 | + | ||
| 294 | + | function UIMiniWindow:onHeightChange(height) | |
| 295 | + | if not self:isOn() then | |
| 296 | + | self:setSettings({height = height}) | |
| 297 | + | end | |
| 298 | + | self:fitOnParent() | |
| 299 | + | end | |
| 300 | + | ||
| 301 | + | function UIMiniWindow:getSettings(name) | |
| 302 | + | if not self.save then return nil end | |
| 303 | + | local settings = g_settings.getNode('MiniWindows') | |
| 304 | + | if settings then | |
| 305 | + | local selfSettings = settings[self:getId()] | |
| 306 | + | if selfSettings then | |
| 307 | + | return selfSettings[name] | |
| 308 | + | end | |
| 309 | + | end | |
| 310 | + | return nil | |
| 311 | + | end | |
| 312 | + | ||
| 313 | + | function UIMiniWindow:setSettings(data) | |
| 314 | + | if not self.save then return end | |
| 315 | + | ||
| 316 | + | local settings = g_settings.getNode('MiniWindows') | |
| 317 | + | if not settings then | |
| 318 | + | settings = {} | |
| 319 | + | end | |
| 320 | + | ||
| 321 | + | local id = self:getId() | |
| 322 | + | if not settings[id] then | |
| 323 | + | settings[id] = {} | |
| 324 | + | end | |
| 325 | + | ||
| 326 | + | for key,value in pairs(data) do | |
| 327 | + | settings[id][key] = value | |
| 328 | + | end | |
| 329 | + | ||
| 330 | + | g_settings.setNode('MiniWindows', settings) | |
| 331 | + | end | |
| 332 | + | ||
| 333 | + | function UIMiniWindow:eraseSettings(data) | |
| 334 | + | if not self.save then return end | |
| 335 | + | ||
| 336 | + | local settings = g_settings.getNode('MiniWindows') | |
| 337 | + | if not settings then | |
| 338 | + | settings = {} | |
| 339 | + | end | |
| 340 | + | ||
| 341 | + | local id = self:getId() | |
| 342 | + | if not settings[id] then | |
| 343 | + | settings[id] = {} | |
| 344 | + | end | |
| 345 | + | ||
| 346 | + | for key,value in pairs(data) do | |
| 347 | + | settings[id][key] = nil | |
| 348 | + | end | |
| 349 | + | ||
| 350 | + | g_settings.setNode('MiniWindows', settings) | |
| 351 | + | end | |
| 352 | + | ||
| 353 | + | function UIMiniWindow:saveParent(parent) | |
| 354 | + | local parent = self:getParent() | |
| 355 | + | if parent then | |
| 356 | + | if parent:getClassName() == 'UIMiniWindowContainer' then | |
| 357 | + | parent:saveChildren() | |
| 358 | + | else | |
| 359 | + | self:saveParentPosition(parent:getId(), self:getPosition()) | |
| 360 | + | end | |
| 361 | + | end | |
| 362 | + | end | |
| 363 | + | ||
| 364 | + | function UIMiniWindow:saveParentPosition(parentId, position) | |
| 365 | + | local selfSettings = {} | |
| 366 | + | selfSettings.parentId = parentId | |
| 367 | + | selfSettings.position = pointtostring(position) | |
| 368 | + | self:setSettings(selfSettings) | |
| 369 | + | end | |
| 370 | + | ||
| 371 | + | function UIMiniWindow:saveParentIndex(parentId, index) | |
| 372 | + | local selfSettings = {} | |
| 373 | + | selfSettings.parentId = parentId | |
| 374 | + | selfSettings.index = index | |
| 375 | + | self:setSettings(selfSettings) | |
| 376 | + | self.miniIndex = index | |
| 377 | + | end | |
| 378 | + | ||
| 379 | + | function UIMiniWindow:disableResize() | |
| 380 | + | self:getChildById('bottomResizeBorder'):disable() | |
| 381 | + | end | |
| 382 | + | ||
| 383 | + | function UIMiniWindow:enableResize() | |
| 384 | + | self:getChildById('bottomResizeBorder'):enable() | |
| 385 | + | end | |
| 386 | + | ||
| 387 | + | function UIMiniWindow:fitOnParent() | |
| 388 | + | local parent = self:getParent() | |
| 389 | + | if self:isVisible() and parent and parent:getClassName() == 'UIMiniWindowContainer' then | |
| 390 | + | parent:fitAll(self) | |
| 391 | + | end | |
| 392 | + | end | |
| 393 | + | ||
| 394 | + | function UIMiniWindow:setParent(parent, dontsave) | |
| 395 | + | UIWidget.setParent(self, parent) | |
| 396 | + | if not dontsave then | |
| 397 | + | self:saveParent(parent) | |
| 398 | + | end | |
| 399 | + | self:fitOnParent() | |
| 400 | + | end | |
| 401 | + | ||
| 402 | + | function UIMiniWindow:setHeight(height) | |
| 403 | + | UIWidget.setHeight(self, height) | |
| 404 | + | signalcall(self.onHeightChange, self, height) | |
| 405 | + | end | |
| 406 | + | ||
| 407 | + | function UIMiniWindow:setContentHeight(height) | |
| 408 | + | local contentsPanel = self:getChildById('contentsPanel') | |
| 409 | + | local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() | |
| 410 | + | ||
| 411 | + | local resizeBorder = self:getChildById('bottomResizeBorder') | |
| 412 | + | resizeBorder:setParentSize(minHeight + height) | |
| 413 | + | end | |
| 414 | + | ||
| 415 | + | function UIMiniWindow:setContentMinimumHeight(height) | |
| 416 | + | local contentsPanel = self:getChildById('contentsPanel') | |
| 417 | + | local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() | |
| 418 | + | ||
| 419 | + | local resizeBorder = self:getChildById('bottomResizeBorder') | |
| 420 | + | resizeBorder:setMinimum(minHeight + height) | |
| 421 | + | end | |
| 422 | + | ||
| 423 | + | function UIMiniWindow:setContentMaximumHeight(height) | |
| 424 | + | local contentsPanel = self:getChildById('contentsPanel') | |
| 425 | + | local minHeight = contentsPanel:getMarginTop() + contentsPanel:getMarginBottom() + contentsPanel:getPaddingTop() + contentsPanel:getPaddingBottom() | |
| 426 | + | ||
| 427 | + | local resizeBorder = self:getChildById('bottomResizeBorder') | |
| 428 | + | resizeBorder:setMaximum(minHeight + height) | |
| 429 | + | end | |
| 430 | + | ||
| 431 | + | function UIMiniWindow:getMinimumHeight() | |
| 432 | + | local resizeBorder = self:getChildById('bottomResizeBorder') | |
| 433 | + | return resizeBorder:getMinimum() | |
| 434 | + | end | |
| 435 | + | ||
| 436 | + | function UIMiniWindow:getMaximumHeight() | |
| 437 | + | local resizeBorder = self:getChildById('bottomResizeBorder') | |
| 438 | + | return resizeBorder:getMaximum() | |
| 439 | + | end | |
| 440 | + | ||
| 441 | + | function UIMiniWindow:isResizeable() | |
| 442 | + | local resizeBorder = self:getChildById('bottomResizeBorder') | |
| 443 | + | return resizeBorder:isExplicitlyVisible() and resizeBorder:isEnabled() | |
| 444 | + | end |