From 59161b0212ed28c00ce1c04c9e430d1ed6f436e9 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Tue, 6 Sep 2016 01:47:25 +0200 Subject: [PATCH] backup --- aux-addon.lua | 2 +- control.lua | 6 +++--- gui/core.lua | 19 +++++++++++------- libs/inspect.lua | 48 ++++++++++++++++++++++++++++++--------------- libs/module.lua | 6 +++--- tabs/post/core.lua | 4 ++-- tabs/post/frame.lua | 10 ++++++---- 7 files changed, 59 insertions(+), 36 deletions(-) diff --git a/aux-addon.lua b/aux-addon.lua index 0b90613..92bf298 100644 --- a/aux-addon.lua +++ b/aux-addon.lua @@ -9,7 +9,7 @@ do local modules = {} modules[name] = module and M import (green_t) private.aux = setmetatable(t, mt) - private.p.set = inspect + private.p.set = function(v) inspect(nil, v) end end)() end modules[name].import (modules.core.I) diff --git a/control.lua b/control.lua index 29b2a98..8f9565a 100644 --- a/control.lua +++ b/control.lua @@ -45,7 +45,7 @@ do end do local id = 0 - function private.id.get() id = id + 1; return id end + function private.unique_id.get() id = id + 1; return id end end function public.kill_listener(listener_id) @@ -57,7 +57,7 @@ function public.kill_thread(thread_id) end function public.event_listener(event, cb) - local listener_id = id + local listener_id = unique_id listeners[listener_id] = {event=event, cb=cb, kill=function(...) temp=arg if arg.n == 0 or arg[1] then kill_listener(listener_id) end end} event_frame:RegisterEvent(event) return listener_id @@ -68,7 +68,7 @@ function public.on_next_event(event, callback) end function public.thread(k, ...) temp=arg - local thread_id = id + local thread_id = unique_id threads[thread_id] = T('k', L(k, unpack(arg))) return thread_id end diff --git a/gui/core.lua b/gui/core.lua index 0c73b34..10fb81f 100644 --- a/gui/core.lua +++ b/gui/core.lua @@ -302,10 +302,10 @@ function public.editbox(parent) editbox:SetTextInsets(1.5, 1.5, 3, 3) editbox:SetMaxLetters(nil) editbox:SetHeight(24) - editbox:SetTextColor(0, 0, 0, 0) +-- editbox:SetTextColor(0, 0, 0, 0) set_content_style(editbox) - local function colorize() this.display:SetText((this.colorizer or nop)(this:GetText()) or this:GetText()) end - local function format() this.display:SetText((this.formatter or this.colorizer or nop)(this:GetText()) or this:GetText()) end + local function colorize() end -- this.display:SetText((this.colorizer or id)(this:GetText())) end + local function format() end-- this.display:SetText((this.formatter or this.colorizer or id)(this:GetText())) end editbox:SetScript('OnEscapePressed', function() this:ClearFocus() ;(this.escape or nop)() @@ -316,7 +316,7 @@ function public.editbox(parent) this.focused = true this:HighlightText() this:SetScript('OnUpdate', function() - this.cursor:SetAlpha(mod(floor((GetTime()-this.cursor.last_change) * 2 + 1), 2)) + this.cursor:SetAlpha(mod(floor((GetTime() - this.cursor.last_change) * 2 + 1), 2)) end) ;(this.focus_gain or nop)() end) @@ -338,16 +338,21 @@ function public.editbox(parent) end) editbox:SetScript('OnChar', function() (this.char or nop)() end) do - local last_click + local last_click = T('t', 0) editbox:SetScript('OnMouseDown', function() local x, y = GetCursorPosition() -- local offset = x - editbox:GetLeft()*editbox:GetEffectiveScale() TODO use a fontstring to measure getstringwidth for structural highlighting -- editbox:Insert'' TODO use insert with special tags to determine cursor position -- or use an overlay with itemlinks - if last_click and GetTime() - last_click.t < .5 and x == last_click.x and y == last_click.y then + if GetTime() - last_click.t < .5 and x == last_click.x and y == last_click.y then thread(function() editbox:HighlightText() end) end - last_click = {t=GetTime(), x=x, y=y} + wipe(last_click) + last_click.t = GetTime() + last_click.x = x + last_click.y = y + -- __(last_click) :t(GetTime()) :x(x) :y(y) TODO + end) end function editbox:Enable() diff --git a/libs/inspect.lua b/libs/inspect.lua index efb5ea3..267ddb6 100644 --- a/libs/inspect.lua +++ b/libs/inspect.lua @@ -1,31 +1,47 @@ local function print(msg) - DEFAULT_CHAT_FRAME:AddMessage(RED_FONT_COLOR_CODE .. msg) + DEFAULT_CHAT_FRAME:AddMessage(msg, 1, 0, 0) end local function format_key(k) return type(k) == 'string' and k or '[' .. tostring(k) .. ']' end + local function format_value(v) return type(v) == 'string' and '"' .. v .. '"' or tostring(v) end -function inspect(...) - for i = 1, arg.n do - print('arg' .. i..' = ' .. format_value(arg[i])) - if type(arg[i]) == 'table' and next(arg[i]) then - print('{') - for k, v in arg[i] do - print(' ' .. format_key(k) .. ' = ' .. format_value(v)) - end - print('}') +local function print_table(t, max_depth, depth) + local indent = strrep(' ', depth * 4) + for k, v in t do + print(indent .. format_key(k) .. ' = ' .. format_value(v)) + if type(v) == 'table' and next(v) and depth < max_depth then + print(indent .. '{') + print_table(v, max_depth, depth + 1) + print(indent .. '}') end end +end + +local depth + +function inspect(_, ...) + arg.n = nil + print_table(arg, depth or 2, 0) + depth = nil return unpack(arg) end -p = setmetatable({}, { - __metatable = false, - __pow = function(self, v) self(v); return v end, - __sub = function(self, v) self(v); return v end, - __call = function(_, ...) return inspect(unpack(arg)) end, -}) \ No newline at end of file +local mt = { __metatable=false, __call=inspect, __div=inspect } + +function mt:__index(key) + if type(key) == 'number' then + depth = key + elseif type(key) == 'function' then + print('#' .. key()) + else + print('#' .. key) + end + return self +end + +p = setmetatable({}, mt) \ No newline at end of file diff --git a/libs/module.lua b/libs/module.lua index 047f19d..0086542 100644 --- a/libs/module.lua +++ b/libs/module.lua @@ -10,7 +10,7 @@ local function declaration_error() error('Declaration error.') end local function collision_error(key) error('"%s" already exists.', key) end local function nil_error(key) if key then error('"%s" is nil.', key) else error('Callee is nil') end end -local nop = function() end +local nop, id = function() end, function(v) return v end local function prototype() local eq = function() return true end return setmetatable({__metatable=false, __eq=eq}, {__metatable=false, __eq=eq, __call=function(self, t) return setmetatable(t, self) end}) @@ -85,8 +85,8 @@ function mt:__index(key) if key ~= 'module' then return nil end local interface, environment, declarator = INTERFACE {}, ENVIRONMENT {}, DECLARATOR {} self = { - access = {_G=PRIVATE, I=PRIVATE, M=PRIVATE, public=PRIVATE, private=PRIVATE, import=PRIVATE, _=PRIVATE, error=PRIVATE, nop=PRIVATE}, - [CALL] = {_G=_G, I=interface, M=environment, import=function(interface) import(self, interface) end, error=error, nop=nop}, + access = {_G=PRIVATE, I=PRIVATE, M=PRIVATE, public=PRIVATE, private=PRIVATE, import=PRIVATE, _=PRIVATE, error=PRIVATE, nop=PRIVATE, id=PRIVATE}, + [CALL] = {_G=_G, I=interface, M=environment, import=function(interface) import(self, interface) end, error=error, nop=nop, id=id}, [INDEX] = {public=function() return declarator.public end, private=function() return declarator.private end}, [NEWINDEX] = {_=nop}, declarator = declarator, diff --git a/tabs/post/core.lua b/tabs/post/core.lua index 14e0acf..9a53977 100644 --- a/tabs/post/core.lua +++ b/tabs/post/core.lua @@ -75,8 +75,8 @@ function set_unit_start_price(amount) end function get_unit_buyout_price() - local money_text = unit_buyout_price:GetText() - return aux.money.from_string(money_text) or 0 + local money_text = p/unit_buyout_price:GetText() + return p/aux.money.from_string(money_text) or 0 end function set_unit_buyout_price(amount) diff --git a/tabs/post/frame.lua b/tabs/post/frame.lua index fbe29f7..3c41112 100644 --- a/tabs/post/frame.lua +++ b/tabs/post/frame.lua @@ -203,13 +203,10 @@ function create_frames() label:SetPoint('LEFT', checkbox, 'RIGHT', 4, 1) label:SetText('Hide this item') hide_checkbox = checkbox - end - local function money_input() - - end do local editbox = gui.editbox(frame.parameters) + editbox.name = 'start' editbox:SetPoint('TOPRIGHT', -71, -60) editbox:SetWidth(180) editbox:SetHeight(22) @@ -227,6 +224,7 @@ function create_frames() editbox.change = function() refresh = true end editbox.enter = function() this:ClearFocus() end editbox.focus_loss = function() + p = this.SetText this:SetText(money.to_string(get_unit_start_price(), true, nil, 3, nil, true)) end do @@ -245,6 +243,7 @@ function create_frames() end do local editbox = gui.editbox(frame.parameters) + editbox.name = 'buy' editbox:SetPoint('TOPRIGHT', unit_start_price, 'BOTTOMRIGHT', 0, -19) editbox:SetWidth(180) editbox:SetHeight(22) @@ -262,6 +261,7 @@ function create_frames() editbox.change = function() refresh = true end editbox.enter = function() this:ClearFocus() end editbox.focus_loss = function() + p(this.SetText) this:SetText(money.to_string(get_unit_buyout_price(), true, nil, 3, nil, true)) end do @@ -277,6 +277,8 @@ function create_frames() buyout_price_percentage = label end unit_buyout_price = editbox + local o = editbox.SetText + function editbox:SetText(v) p(v) o(self, v) end end do local btn = gui.button(frame.parameters, 14)