Commit aae521968f3306b5dfd4969fd0bc897a167c754d

Authored by dg
1 parent e91d329d

Added a message log dialog which supports page up/down, home/end, up/down and mo…

…use wheel. Activate it by clicking on the log or pressing ctrl+m


git-svn-id: http://svn.net-core.org/repos/t-engine4@3374 51575b47-30f0-44d4-a5cc-537603b46e54
... ... @@ -23,3 +23,10 @@ defineAction{
23 23 group = "actions",
24 24 name = "Toggle list of seen creatures",
25 25 }
  26 +
  27 +defineAction{
  28 + default = { "sym:109:true:false:false:false" },
  29 + type = "SHOW_MESSAGE_LOG",
  30 + group = "actions",
  31 + name = "Show message log",
  32 +}
... ...
... ... @@ -72,6 +72,12 @@ function _M:resize(x, y, w, h)
72 72 self.scrollbar = Slider.new{size=self.h - 20, max=1, inverse=true}
73 73 end
74 74
  75 +--- Make a dialog popup with the full log
  76 +function _M:showLogDialog(title, shadow)
  77 + local d = require("engine.dialogs.ShowLog").new(title or "Message Log", shadow, self)
  78 + game:registerDialog(d)
  79 +end
  80 +
75 81 --- Appends text to the log
76 82 -- This method is set as the call methamethod too, this means it is usable like this:<br/>
77 83 -- log = LogDisplay.new(...)<br/>
... ...
  1 +-- TE4 - T-Engine 4
  2 +-- Copyright (C) 2009, 2010, 2011 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +require "engine.class"
  21 +local Dialog = require "engine.ui.Dialog"
  22 +local Slider = require "engine.ui.Slider"
  23 +
  24 +module(..., package.seeall, class.inherit(Dialog))
  25 +
  26 +function _M:init(title, shadow, log)
  27 + local w = math.floor(game.w * 0.9)
  28 + local h = math.floor(game.h * 0.9)
  29 + Dialog.init(self, title, w, h)
  30 + if shadow then self.shadow = shadow end
  31 +
  32 + self:loadUI{}
  33 + self:setupUI()
  34 +
  35 + self.lines = {}
  36 + for i = #log.log, 1, -1 do
  37 + self.lines[#self.lines+1] = log.log[i]
  38 + end
  39 +
  40 + self.max_h = self.ih - self.iy
  41 + self.max = #log.log
  42 + self.max_display = math.floor(self.max_h / self.font_h)
  43 +
  44 + -- Add UI controls
  45 + self.mouse:registerZone(0, 0, self.w, self.h, function(button, x, y, xrel, yrel, bx, by, event)
  46 + if button == "wheelup" and event == "button" then self.key:triggerVirtual("MOVE_UP")
  47 + elseif button == "wheeldown" and event == "button" then self.key:triggerVirtual("MOVE_DOWN")
  48 + end
  49 + end)
  50 + self.key:addBinds{
  51 + MOVE_UP = function() self:setScroll(self.scroll - 1) end,
  52 + MOVE_DOWN = function() self:setScroll(self.scroll + 1) end,
  53 + ACCEPT = "EXIT",
  54 + EXIT = function() game:unregisterDialog(self) end,
  55 + }
  56 + self.key:addCommands{
  57 + _HOME = function() self:setScroll(1) end,
  58 + _END = function() self:setScroll(self.max) end,
  59 + _PAGEUP = function() self:setScroll(self.scroll - self.max_display) end,
  60 + _PAGEDOWN = function() self:setScroll(self.scroll + self.max_display) end,
  61 + }
  62 +
  63 + self.scrollbar = Slider.new{size=self.h - 20, max=1, inverse=true}
  64 + self.scrollbar.max = self.max - self.max_display + 1
  65 +
  66 + self:setScroll(self.max - self.max_display + 1)
  67 +end
  68 +
  69 +function _M:setScroll(i)
  70 + local old = self.scroll
  71 + self.scroll = util.bound(i, 1, math.max(1, self.max - self.max_display + 1))
  72 + if self.scroll == old then return end
  73 +
  74 + self.dlist = {}
  75 + local nb = 0
  76 + local old_style = self.font:getStyle()
  77 + for z = 1 + self.scroll, #self.lines do
  78 + local stop = false
  79 + local tstr = self.lines[z]
  80 + if not tstr then break end
  81 + local gen = self.font:draw(tstr, self.iw - 10, 255, 255, 255)
  82 + for i = #gen, 1, -1 do
  83 + self.dlist[#self.dlist+1] = gen[i]
  84 + nb = nb + 1
  85 + if nb >= self.max_display then stop = true break end
  86 + end
  87 + if stop then break end
  88 + end
  89 + self.font:setStyle(old_style)
  90 +end
  91 +
  92 +function _M:innerDisplay(x, y, nb_keyframes)
  93 + local h = y + self.iy
  94 + for i = 1, #self.dlist do
  95 + local item = self.dlist[i]
  96 + if self.shadow then item._tex:toScreenFull(x+2, h+2, item.w, item.h, item._tex_w, item._tex_h, 0,0,0, self.shadow) end
  97 + item._tex:toScreenFull(x, h, item.w, item.h, item._tex_w, item._tex_h)
  98 + h = h + self.font_h
  99 + end
  100 +
  101 + self.scrollbar.pos = self.scrollbar.max - self.scroll + 1
  102 + self.scrollbar:display(x + self.iw - self.scrollbar.w, y)
  103 +end
... ...
... ... @@ -418,6 +418,9 @@ function _M:drawFrame(x, y, r, g, b, a)
418 418 end
419 419 end
420 420
  421 +function _M:innerDisplay(x, y, nb_keyframes)
  422 +end
  423 +
421 424 function _M:toScreen(x, y, nb_keyframes)
422 425 if self.__hidden then return end
423 426 x = util.bound(x, 0, game.w - (self.w+self.frame.ox2))
... ... @@ -463,6 +466,8 @@ function _M:toScreen(x, y, nb_keyframes)
463 466 ui.ui:display(x + ui.x, y + ui.y, nb_keyframes, ox + ui.x, oy + ui.y)
464 467 end
465 468
  469 + self:innerDisplay(x, y, nb_keyframes)
  470 +
466 471 -- Restiore normal opengl matrix
467 472 if zoom < 1 then core.display.glScale() end
468 473 core.display.glTranslate(-tx, -ty, 0)
... ...
... ... @@ -1106,6 +1106,10 @@ function _M:setupCommands()
1106 1106 self:registerDialog(require("mod.dialogs.CharacterSheet").new(self.party:findMember{main=true}))
1107 1107 end,
1108 1108
  1109 + SHOW_MESSAGE_LOG = function()
  1110 + self.logdisplay:showLogDialog(nil, 0.6)
  1111 + end,
  1112 +
1109 1113 -- Show time
1110 1114 SHOW_TIME = function()
1111 1115 self.log(self.calendar:getTimeDate(self.turn))
... ... @@ -1197,6 +1201,7 @@ function _M:setupMouse(reset)
1197 1201 else
1198 1202 if button == "wheelup" then self.logdisplay:scrollUp(1) end
1199 1203 if button == "wheeldown" then self.logdisplay:scrollUp(-1) end
  1204 + if button == "left" then self.logdisplay:showLogDialog(nil, 0.6) end
1200 1205 end
1201 1206 end)
1202 1207 -- Use hotkeys with mouse
... ...