|
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 |
...
|
...
|
|