Commit 5eda539cae3f1b66760a778fff8244e88a77e556

Authored by dg
1 parent 3668b45e

list & cur char


git-svn-id: http://svn.net-core.org/repos/t-engine4@2869 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -19,6 +19,7 @@
19 19
20 20 require "engine.class"
21 21 require "engine.ui.Base"
  22 +local Slider = require "engine.ui.Slider"
22 23
23 24 --- Module that handles message history in a mouse wheel scrollable zone
24 25 module(..., package.seeall, class.inherit(engine.ui.Base))
... ... @@ -62,15 +63,7 @@ function _M:resize(x, y, w, h)
62 63 self.bg_texture, self.bg_texture_w, self.bg_texture_h = self.bg_surface:glTexture()
63 64 end
64 65
65   - local sb, sb_w, sb_h = self:getImage("ui/scrollbar.png")
66   - local ssb, ssb_w, ssb_h = self:getImage("ui/scrollbar-sel.png")
67   -
68   - self.scrollbar = { bar = {}, sel = {} }
69   - self.scrollbar.sel.w, self.scrollbar.sel.h, self.scrollbar.sel.tex, self.scrollbar.sel.texw, self.scrollbar.sel.texh = ssb_w, ssb_h, ssb:glTexture()
70   - local s = core.display.newSurface(sb_w, self.h)
71   - s:erase(200,0,0)
72   - for i = 0, self.h do s:merge(sb, 0, i) end
73   - self.scrollbar.bar.w, self.scrollbar.bar.h, self.scrollbar.bar.tex, self.scrollbar.bar.texw, self.scrollbar.bar.texh = ssb_w, self.h, s:glTexture()
  66 + self.scrollbar = Slider.new{size=self.h - 20, max=1, inverse=true}
74 67 end
75 68
76 69 --- Appends text to the log
... ... @@ -142,10 +135,9 @@ function _M:toScreen()
142 135 end
143 136
144 137 if true then
145   - local pos = self.scroll * (self.h - self.fh) / (self.max - self.max_display + 1)
146   -
147   - self.scrollbar.bar.tex:toScreenFull(self.display_x + self.w - self.scrollbar.bar.w, self.display_y, self.scrollbar.bar.w, self.scrollbar.bar.h, self.scrollbar.bar.texw, self.scrollbar.bar.texh)
148   - self.scrollbar.sel.tex:toScreenFull(self.display_x + self.w - self.scrollbar.sel.w, self.display_y + self.h - self.scrollbar.sel.h - pos, self.scrollbar.sel.w, self.scrollbar.sel.h, self.scrollbar.sel.texw, self.scrollbar.sel.texh)
  138 + self.scrollbar.pos = self.scroll
  139 + self.scrollbar.max = self.max - self.max_display + 1
  140 + self.scrollbar:display(self.display_x + self.w - self.scrollbar.w, self.display_y)
149 141 end
150 142 end
151 143
... ...
... ... @@ -239,6 +239,7 @@ function _M:instanciate(mod, name, new_game, no_reboot)
239 239
240 240 profile:addStatFields(unpack(mod.profile_stats_fields or {}))
241 241 profile:loadModuleProfile(mod.short_name)
  242 + profile:currentCharacter(mod.name, "game did not tell us")
242 243
243 244 -- Init the module code
244 245 local M, W = mod.load("init")
... ...
... ... @@ -523,6 +523,16 @@ function _M:registerSaveChardump(module, uuid, title, tags, data)
523 523 print("[ONLINE PROFILE] saved character ", uuid)
524 524 end
525 525
  526 +function _M:currentCharacter(module, title)
  527 + if not self.auth then return end
  528 + core.profile.pushOrder(table.serialize{o="CurrentCharacter",
  529 + module=module,
  530 + title=title,
  531 + valid=self.hash_valid,
  532 + })
  533 + print("[ONLINE PROFILE] current character ", title)
  534 +end
  535 +
526 536 function _M:newProfile(Login, Name, Password, Email)
527 537 print("[ONLINE PROFILE] profile options ", Login, Email, Name)
528 538
... ...
... ... @@ -21,6 +21,7 @@ require "engine.class"
21 21 require "engine.ui.Base"
22 22 local KeyBind = require "engine.KeyBind"
23 23 local Mouse = require "engine.Mouse"
  24 +local Slider = require "engine.ui.Slider"
24 25
25 26 --- Module that handles multiplayer chats
26 27 module(..., package.seeall, class.inherit(engine.ui.Base))
... ... @@ -83,6 +84,13 @@ function _M:event(e)
83 84 elseif e.se == "UserInfo" then
84 85 local info = e.data:unserialize()
85 86 if not info then return end
  87 + elseif e.se == "ChannelList" then
  88 + local info = zlib.decompress(e.data):unserialize()
  89 + if not info then return end
  90 + for _, user in ipairs(info.users) do
  91 + print(" === ", user.name, user.cur_char and user.cur_char.title, user.cur_char and user.cur_char.valid, user.cur_char and user.cur_char.module)
  92 + end
  93 + self.channels_changed = true
86 94 end
87 95 end
88 96
... ... @@ -93,6 +101,7 @@ function _M:join(channel)
93 101 self.channels[channel] = self.channels[channel] or {users={}, log={}}
94 102 self.channels_changed = true
95 103 self.changed = true
  104 + self:updateChanList(true)
96 105 end
97 106
98 107 function _M:selectChannel(channel)
... ... @@ -100,6 +109,7 @@ function _M:selectChannel(channel)
100 109 self.cur_channel = channel
101 110 self.channels_changed = true
102 111 self.changed = true
  112 + self:updateChanList(true)
103 113 end
104 114
105 115 function _M:talk(msg)
... ... @@ -124,8 +134,17 @@ function _M:talkBox()
124 134 end)
125 135 d.key:addBind("EXIT", function() game:unregisterDialog(d) end)
126 136 game:registerDialog(d)
  137 +
  138 + self:updateChanList()
127 139 end
128 140
  141 +function _M:updateChanList(force)
  142 + local time = core.game.getTime()
  143 + if force or not self.last_chan_update or self.last_chan_update + 60000 < time then
  144 + self.last_chan_update = time
  145 + core.profile.pushOrder(string.format("o='ChatChannelList' channel=%q", self.cur_channel))
  146 + end
  147 +end
129 148
130 149 ----------------------------------------------------------------
131 150 -- UI Section
... ... @@ -162,15 +181,7 @@ function _M:resize(x, y, w, h, fontname, fontsize, color, bgcolor)
162 181 self.bg_texture, self.bg_texture_w, self.bg_texture_h = self.bg_surface:glTexture()
163 182 end
164 183
165   - local sb, sb_w, sb_h = self:getImage("ui/scrollbar.png")
166   - local ssb, ssb_w, ssb_h = self:getImage("ui/scrollbar-sel.png")
167   -
168   - self.scrollbar = { bar = {}, sel = {} }
169   - self.scrollbar.sel.w, self.scrollbar.sel.h, self.scrollbar.sel.tex, self.scrollbar.sel.texw, self.scrollbar.sel.texh = ssb_w, ssb_h, ssb:glTexture()
170   - local s = core.display.newSurface(sb_w, self.h)
171   - s:erase(200,0,0)
172   - for i = 0, self.h do s:merge(sb, 0, i) end
173   - self.scrollbar.bar.w, self.scrollbar.bar.h, self.scrollbar.bar.tex, self.scrollbar.bar.texw, self.scrollbar.bar.texh = ssb_w, self.h, s:glTexture()
  184 + self.scrollbar = Slider.new{size=self.h - 20, max=1, inverse=true}
174 185
175 186 self.mouse = Mouse.new()
176 187 self.mouse.delegate_offset_x = self.display_x
... ... @@ -188,6 +199,8 @@ function _M:resize(x, y, w, h, fontname, fontsize, color, bgcolor)
188 199 if last_ok then self:selectChannel(last_ok.name) end
189 200 end
190 201 end)
  202 +
  203 + self.last_chan_update = 0
191 204 end
192 205
193 206 function _M:display()
... ... @@ -262,10 +275,9 @@ function _M:toScreen()
262 275 end
263 276
264 277 if true then
265   - local pos = self.scroll * (self.h - self.fh) / (self.max - self.max_display + 1)
266   -
267   - self.scrollbar.bar.tex:toScreenFull(self.display_x + self.w - self.scrollbar.bar.w, self.display_y, self.scrollbar.bar.w, self.scrollbar.bar.h, self.scrollbar.bar.texw, self.scrollbar.bar.texh)
268   - self.scrollbar.sel.tex:toScreenFull(self.display_x + self.w - self.scrollbar.sel.w, self.display_y + self.h - self.scrollbar.sel.h - pos, self.scrollbar.sel.w, self.scrollbar.sel.h, self.scrollbar.sel.texw, self.scrollbar.sel.texh)
  278 + self.scrollbar.pos = self.scroll
  279 + self.scrollbar.max = self.max - self.max_display + 1
  280 + self.scrollbar:display(self.display_x + self.w - self.scrollbar.w, self.display_y)
269 281 end
270 282 end
271 283
... ...
... ... @@ -27,6 +27,7 @@ function _M:init(t)
27 27 self.size = assert(t.size, "no slider size")
28 28 self.max = assert(t.max, "no slider max")
29 29 self.pos = t.pos or 0
  30 + self.inverse = t.inverse
30 31
31 32 Base.init(self, t)
32 33 end
... ... @@ -43,5 +44,11 @@ function _M:display(x, y)
43 44 self.top.t:toScreenFull(x, y, self.top.w, self.top.h, self.top.tw, self.top.th)
44 45 self.bottom.t:toScreenFull(x, y + self.h - self.bottom.h, self.bottom.w, self.bottom.h, self.bottom.tw, self.bottom.th)
45 46 self.middle.t:toScreenFull(x, y + self.top.h, self.middle.w, self.h - self.top.h - self.bottom.h, self.middle.tw, self.middle.th)
46   - self.sel.t:toScreenFull(x - (self.sel.w - self.top.w) / 2, y + (self.pos * self.size / self.max) + self.sel.h / 2, self.sel.w, self.sel.h, self.sel.tw, self.sel.th)
  47 + self.pos = util.bound(self.pos, 0, self.max)
  48 + if self.inverse then
  49 + y = y + self.h - (self.pos * self.size / self.max) + self.sel.h / 2
  50 + else
  51 + y = y + (self.pos * self.size / self.max) + self.sel.h / 2
  52 + end
  53 + self.sel.t:toScreenFull(x - (self.sel.w - self.top.w) / 2, y, self.sel.w, self.sel.h, self.sel.tw, self.sel.th)
47 54 end
... ...
... ... @@ -64,6 +64,7 @@ function _M:init()
64 64 end
65 65
66 66 self:loaded()
  67 + profile:currentCharacter("Main Menu", "Main Menu")
67 68 end
68 69
69 70 function _M:loaded()
... ...
... ... @@ -1376,6 +1376,7 @@ function _M:levelup()
1376 1376 self.easy_mode_lifes = (self.easy_mode_lifes or 0) + 1
1377 1377 game.logPlayer(self, "#AQUAMARINE#You have gained one more life (%d remaining).", self.easy_mode_lifes)
1378 1378 end
  1379 + game:updateCurrentChar()
1379 1380 end
1380 1381 end
1381 1382
... ...
... ... @@ -164,6 +164,7 @@ function _M:newGame()
164 164
165 165 -- Register the character online if possible
166 166 self.player:getUUID()
  167 + self:updateCurrentChar()
167 168 end
168 169
169 170 -- Load for quick birth
... ... @@ -313,6 +314,7 @@ function _M:loaded()
313 314
314 315 if self.always_target then Map:setViewerFaction(self.player.faction) end
315 316 if self.player and config.settings.cheat then self.player.__cheated = true end
  317 + self:updateCurrentChar()
316 318 end
317 319
318 320 function _M:setupDisplayMode(reboot, mode)
... ... @@ -384,6 +386,12 @@ function _M:save()
384 386 return class.save(self, self:defaultSavedFields{difficulty=true, to_re_add_actors=true, party=true, _chronoworlds=true}, true)
385 387 end
386 388
  389 +function _M:updateCurrentChar()
  390 + if not self.party then return end
  391 + local player = self.party:findMember{main=true}
  392 + profile:currentCharacter(self.__mod_info.name, ("%s the level %d %s %s"):format(player.name, player.level, player.descriptor.subrace, player.descriptor.subclass))
  393 +end
  394 +
387 395 function _M:getSaveDescription()
388 396 local player = self.party:findMember{main=true}
389 397
... ...
... ... @@ -127,6 +127,7 @@ function _M:login()
127 127 self.auth = self.last_line:unserialize()
128 128 cprofile.pushEvent(string.format("e='Auth' ok=%q", self.last_line))
129 129 self:connectedPull()
  130 + if self.cur_char then self:orderCurrentCharacter(self.cur_char) end
130 131 return true
131 132 else
132 133 print("[PROFILE] could not log in")
... ... @@ -184,7 +185,7 @@ end
184 185
185 186 function _M:handleOrder(o)
186 187 o = o:unserialize()
187   - if not self.sock and o.o ~= "Login" then return end -- Dont do stuff without a connection, unless we try to auth
  188 + if not self.sock and o.o ~= "Login" and o.o ~= "CurrentCharacter" then return end -- Dont do stuff without a connection, unless we try to auth
188 189 if self["order"..o.o] then self["order"..o.o](self, o) end
189 190 end
190 191
... ... @@ -291,6 +292,11 @@ function _M:orderSaveChardump(o)
291 292 cprofile.pushEvent("e='SaveChardump' ok=true")
292 293 end
293 294
  295 +function _M:orderCurrentCharacter(o)
  296 + self:command("CHAR", "CUR", table.serialize(o))
  297 + self.cur_char = o
  298 +end
  299 +
294 300 function _M:orderChatTalk(o)
295 301 self:command("BRDC", o.channel, o.msg)
296 302 self:read("200")
... ... @@ -312,6 +318,17 @@ function _M:orderChatUserInfo(o)
312 318 end
313 319 end
314 320
  321 +function _M:orderChatChannelList(o)
  322 + self:command("CLST", o.channel)
  323 + if self:read("200") then
  324 + local _, _, size = self.last_line:find("^([0-9]+)")
  325 + size = tonumber(size)
  326 + if not size or size < 1 then return end
  327 + local body = self:receive(size)
  328 + cprofile.pushEvent(string.format("e='Chat' se='ChannelList' channel=%q data=%q", o.channel, body))
  329 + end
  330 +end
  331 +
315 332 --------------------------------------------------------------------
316 333 -- Pushes comming from the push socket
317 334 --------------------------------------------------------------------
... ...