diff --git a/game/engines/default/engine/PlayerProfile.lua b/game/engines/default/engine/PlayerProfile.lua index 782974397962e3b64b753cd3d1c77eb6f4e0c035..4d17ca1038461972666c07943049c666531f3db2 100644 --- a/game/engines/default/engine/PlayerProfile.lua +++ b/game/engines/default/engine/PlayerProfile.lua @@ -76,6 +76,7 @@ function _M:init() self.chat = UserChat.new() self.dlc_files = {classes={}, files={}} self.saved_events = {} + self.temporary_event_handlers = {} self.generic = {} self.modules = {} self.evt_cbs = {} @@ -628,11 +629,20 @@ function _M:eventFunFacts(e) end end +function _M:registerTemporaryEventHandler(name, fct) + self.temporary_event_handlers[name] = self.temporary_event_handlers[name] or {} + table.insert(self.temporary_event_handlers[name], fct) +end + --- Got an event from the profile thread function _M:handleEvent(e) if type(e) == "string" then e = e:unserialize() end if not e then return end - if self["event"..e.e] then self["event"..e.e](self, e) end + if self["event"..e.e] then self["event"..e.e](self, e) + elseif self.temporary_event_handlers[e.e] then + for _, fct in ipairs(self.temporary_event_handlers[e.e]) do print("[PROFILE] temporary_event_handlers", e.e, pcall(fct, e)) end + self.temporary_event_handlers[e.e] = nil + end return e end diff --git a/game/engines/default/engine/dialogs/microtxn/ShowPurchasable.lua b/game/engines/default/engine/dialogs/microtxn/ShowPurchasable.lua index 6a576451a507e2b352af2f25703195407d63b00e..20fb610319efa7b6ff690b647d6e35e1039b6de5 100644 --- a/game/engines/default/engine/dialogs/microtxn/ShowPurchasable.lua +++ b/game/engines/default/engine/dialogs/microtxn/ShowPurchasable.lua @@ -34,6 +34,7 @@ function _M:init(mode) self:generateList() + self.c_waiter = Textzone.new{auto_width=1, auto_height=1, text="#YELLOW#-- connecting to server... --"} self.c_list = ListColumns.new{width=self.iw, height=self.ih, item_height=132, hide_columns=true, scrollbar=true, sortable=true, columns={ {name="", width=100, display_prop="", direct_draw=function(item, x, y) item.img:toScreen(nil, x+2, y+2, 128, 128) @@ -43,9 +44,11 @@ function _M:init(mode) self:loadUI{ + {vcenter=0, hcenter=0, ui=self.c_waiter}, {left=0, top=0, ui=self.c_list}, } self:setupUI(false, false) + self:toggleDisplay(self.c_list, false) self.key:addBinds{ ACCEPT = "EXIT", @@ -57,16 +60,23 @@ function _M:init(mode) end function _M:generateList() - local list = {} - for file in fs.iterate("/data/microtxn/", "%.lua$") do - local f, err = loadfile("/data/microtxn/"..file) - setfenv(f, {mode=self.mode}) - local ok, res = pcall(f) - if ok and res then + self.list = {} + + profile:registerTemporaryEventHandler("MicroTxnListPurchasables", function(e) + if not e.data then return end + e.data = e.data:unserialize() + local list = {} + for _, res in ipairs(e.data.list) do res.img = Entity.new{image=res.image} res.txt = Textzone.new{width=self.iw - 10 - 132, auto_height=true, text=("%s\n#SLATE##{italic}#%s#{normal}#"):format(res.name, res.desc)} list[#list+1] = res end - end - self.list = list + self.list = list + self.c_list:setList(list) + self:toggleDisplay(self.c_list, true) + self:toggleDisplay(self.c_waiter, false) + self:setFocus(self.c_list) + game.log("===balance: %s", tostring(e.data.balance)) + end) + core.profile.pushOrder(string.format("o='MicroTxn' suborder='list_purchasables' module=%q", game.__mod_info.short_name)) end diff --git a/game/modules/tome/data/microtxn/poosh.lua b/game/modules/tome/data/microtxn/poosh.lua index 6649b34e8969f701fd672d60def51144f1b1d4a9..fe31f5a00aab6b0b86a673e90443786c8dacc865 100644 --- a/game/modules/tome/data/microtxn/poosh.lua +++ b/game/modules/tome/data/microtxn/poosh.lua @@ -22,7 +22,7 @@ return { name = "Lost Land of Poosh (server-wide)", image = "/data/gfx/achievements/land_poosh.png", desc = [[The Bearscape is a level 15+ zone that spawns on the worldmap. -Poosh has gone missing! But what is push? Who stole it? And most importantly, what deliciously terrible deaths will it give your character? +Poosh has gone missing! But what is poosh? Who stole it? And most importantly, what deliciously terrible deaths will it give your character? Will you survive and claim your rewards? Or will you die forever lost in a lost land? #GREEN#Server-wide:#LAST# This event will trigger for your character and every other player currently playing.]], diff --git a/game/profile-thread/Client.lua b/game/profile-thread/Client.lua index c3ab20f1b1bd923ee511475e1075850d6d367c92..a5e8d7015cb5e307662bcbd8d7d0a7bef8722a84 100644 --- a/game/profile-thread/Client.lua +++ b/game/profile-thread/Client.lua @@ -23,7 +23,7 @@ local UserChat = require "profile-thread.UserChat" module(..., package.seeall, class.make) -local debug = false +local debug = true local metaport = 2240 local profilehost = "profiles.te4.org" @@ -744,6 +744,25 @@ function _M:orderAddonAuthoring(o) end end end + +function _M:orderMicroTxn(o) + if o.suborder == "list_purchasables" then + self:command("MTXN LIST_PURCHASABLE", o.module) + if self:read("200") then + local _, _, size = self.last_line:find("^([0-9]+)") + size = tonumber(size) + local body = {} + if size and size > 1 then + body = self:receive(size) + if body then body = zlib.decompress(body) end + end + + cprofile.pushEvent(("e='MicroTxnListPurchasables' data=%q"):format(body)) + return + end + end +end + -------------------------------------------------------------------- -- Pushes comming from the push socket --------------------------------------------------------------------