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

Loading screen of ToME will display a random "fun fact" in the top right...

Loading screen of ToME will display a random "fun fact" in the top right corner: number of total deaths, playtime, ten killers, ... taken from the vault


git-svn-id: http://svn.net-core.org/repos/t-engine4@5999 51575b47-30f0-44d4-a5cc-537603b46e54
parent 4577d3dd
No related branches found
No related tags found
No related merge requests found
......@@ -391,6 +391,29 @@ function _M:loadAddons(mod, saveuse)
-- os.exit()
end
-- Grab some fun facts!
function _M:selectFunFact(ffdata)
local l = {}
print("Computing fun facts")
print(pcall(function()
if ffdata.total_time then l[#l+1] = "Total playtime of all registered players:\n"..ffdata.total_time end
if ffdata.top_five_races then l[#l+1] = ("#LIGHT_BLUE#%s#WHITE# is one of the top five played races"):format(rng.table(ffdata.top_five_races).name) end
if ffdata.top_five_classes then l[#l+1] = ("#LIGHT_BLUE#%s#WHITE# is one of the top five played classes"):format(rng.table(ffdata.top_five_classes).name) end
if ffdata.top_ten_killer then l[#l+1] = ("#CRIMSON#%s#WHITE# is one of the top ten killer"):format(rng.table(ffdata.top_ten_killer).name:capitalize()) end
if ffdata.top_ten_raceclass then l[#l+1] = ("#LIGHT_BLUE#%s#WHITE# is one of the top ten race/class combo"):format(rng.table(ffdata.top_ten_raceclass).name:capitalize()) end
if ffdata.nb_players then l[#l+1] = ("There is currently %d people playing online"):format(ffdata.nb_players) end
if ffdata.total_deaths then l[#l+1] = ("The character's vault has registered a total of #RED#%d#WHITE# character's deaths"):format(ffdata.total_deaths) end
if ffdata.wins_this_version then l[#l+1] = ("The character's vault has registered a total of #LIGHT_BLUE#%d#WHITE# winners for the current version"):format(ffdata.wins_this_version) end
if ffdata.latest_donator then l[#l+1] = ("The latest donator is #LIGHT_GREEN#%s#WHITE#. Many thanks to all donators, you are keepign this game alive!"):format(ffdata.latest_donator) end
end))
table.print(l)
return #l > 0 and rng.table(l) or false
end
--- Make a module loadscreen
function _M:loadScreen(mod)
core.display.forceRedraw()
......@@ -418,6 +441,16 @@ function _M:loadScreen(mod)
local dw, dh = math.floor(sw / 2), left[7]
local dx, dy = math.floor((sw - dw) / 2), sh - dh
-- Check profile thread events
local evt = core.profile.popEvent()
while evt do
profile:handleEvent(evt)
evt = core.profile.popEvent()
end
local funfacts = nil
local ffdata = profile.funfacts
local tip = nil
if mod.load_tips then
local l = rng.table(mod.load_tips)
......@@ -455,6 +488,35 @@ function _M:loadScreen(mod)
end
end
local ffw = math.ceil(sw / 4)
if ffdata then
local str = self:selectFunFact(ffdata)
if str then
local text, _, tw = font:draw(str, ffw, 255, 255, 255)
local text_h = #text * text[1].h
ffw = math.min(ffw, tw)
local Base = require "engine.ui.Base"
local frame = Base:makeFrame("ui/tooltip/", ffw + 30, text_h + 30)
funfacts = function(x, y)
x = x - ffw - 30
Base:drawFrame(frame, x+1, y+1, 0, 0, 0, 0.3)
Base:drawFrame(frame, x-3, y-3, 1, 1, 1, 0.5)
x = x + 10
y = y + 10
y = y - 10 + math.floor((frame.h - text_h) / 2)
for i = 1, #text do
local item = text[i]
if not item then break end
item._tex:toScreenFull(x+2, y+2, item.w, item.h, item._tex_w, item._tex_h, 0, 0, 0, 0.5)
item._tex:toScreenFull(x, y, item.w, item.h, item._tex_w, item._tex_h, 1, 1, 1, 0.85)
y = y + item.h
end
end
end
end
return function()
-- Background
local x, y = 0, 0
......@@ -505,6 +567,7 @@ function _M:loadScreen(mod)
end
if tip then tip(dw / 2, dy) end
if funfacts then funfacts(sw, 10) end
end
end)
core.display.forceRedraw()
......
......@@ -86,6 +86,8 @@ function _M:init()
["^achievements$"] = { invalid = { read={offline=true,online=true}, write="offline" }, valid = { read={online=true}, write="online" } },
}
self:funFactsGrab()
self.auth = false
self:loadGenericProfile()
......@@ -376,7 +378,7 @@ function _M:waitEvent(name, cb, wait_max)
local tries = 0
while not stop do
if not first then
core.display.forceRedraw()
if not self.waiting_event_no_redraw then core.display.forceRedraw() end
core.game.sleep(50)
end
local evt = core.profile.popEvent()
......@@ -482,6 +484,12 @@ function _M:eventDisconnected(e)
if game and type(game) == "table" and game.log then game.log("#YELLOW#Connection to online server lost, trying to reconnect.") end
end
function _M:eventFunFacts(e)
if e.data then
self.funfacts = zlib.decompress(e.data):unserialize()
end
end
--- Got an event from the profile thread
function _M:handleEvent(e)
e = e:unserialize()
......@@ -780,6 +788,11 @@ function _M:entityVaultInfos(module, kind)
print("[ONLINE PROFILE] list entity vault", module, kind)
end
function _M:funFactsGrab(module)
core.profile.pushOrder(table.serialize{o="FunFactsGrab", module=module})
print("[ONLINE PROFILE] fun facts", module)
end
function _M:isDonator(s)
s = s or 1
if not self.auth or not tonumber(self.auth.donated) or tonumber(self.auth.donated) <= s then return false else return true end
......
......@@ -42,6 +42,7 @@ function _M:connected()
self:login()
self.chat:reconnect()
cprofile.pushEvent("e='Connected'")
self:orderFunFactsGrab{module="tome"}
return true
end
......@@ -512,6 +513,24 @@ function _M:orderPing(o)
self.server_latency = lat
end
function _M:orderFunFactsGrab(o)
if self.funfacts then
cprofile.pushEvent(string.format("e='FunFacts' data=%q", self.funfacts))
return
end
if self.funfacts_wait then return end
self.funfacts_wait = true
self:command("FACT", o.module)
if self:read("200") then
local _, _, size = self.last_line:find("^([0-9]+)")
size = tonumber(size)
if not size or size < 1 then return end
self.funfacts = self:receive(size)
cprofile.pushEvent(string.format("e='FunFacts' data=%q", self.funfacts))
end
end
--------------------------------------------------------------------
-- Pushes comming from the push socket
--------------------------------------------------------------------
......
* RSS feed of events in a character's life, exportable to FB
* auto-leveling for beginners/lazy
* sleep => replace all talents with spcial dream talents, freeze all tmp effects
* daze => ???
after v1:
* donator's fight club
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment