Showing
31 changed files
with
47 additions
and
6 deletions
... | ... | @@ -76,6 +76,20 @@ function math.triangle_area(p1, p2, p3) |
76 | 76 | return math.abs(0.5 * lu * lv * math.sin(av - au)) |
77 | 77 | end |
78 | 78 | |
79 | +function math.find_closest_lower(x, list) | |
80 | + table.sort(list) | |
81 | + for i in ripairs_value(list) do | |
82 | + if x >= i then return i end | |
83 | + end | |
84 | +end | |
85 | + | |
86 | +function math.find_closest_higher(x, list) | |
87 | + table.sort(list) | |
88 | + for i in ipairs_value(list) do | |
89 | + if x <= i then return i end | |
90 | + end | |
91 | +end | |
92 | + | |
79 | 93 | function lpeg.anywhere (p) |
80 | 94 | return lpeg.P{ p + 1 * lpeg.V(1) } |
81 | 95 | end |
... | ... | @@ -134,6 +148,16 @@ function ipairs_value(t) |
134 | 148 | end |
135 | 149 | end |
136 | 150 | |
151 | +function ripairs_value(t) | |
152 | + local i = #t | |
153 | + return function() | |
154 | + if i == 0 then return nil end | |
155 | + local oi = i | |
156 | + i = i - 1 | |
157 | + return t[oi], oi | |
158 | + end | |
159 | +end | |
160 | + | |
137 | 161 | function table.weak_keys(t) |
138 | 162 | t = t or {} |
139 | 163 | setmetatable(t, {__mode="k"}) | ... | ... |

7.76 KB

13.7 KB

21.3 KB

24.3 KB

24.5 KB

7.84 KB

13.6 KB

20.5 KB

23.5 KB

21.7 KB
... | ... | @@ -51,7 +51,6 @@ function _M:makeUI() |
51 | 51 | |
52 | 52 | -- Only for size info |
53 | 53 | local back = self:getUITexture("ui/portrait_frame_back.png") |
54 | - local deco_down = self:getUITexture("ui/chat_ui_deco_padding_left_down.png") | |
55 | 54 | |
56 | 55 | self:loadUI(uis) |
57 | 56 | self:setFocus(self.c_list) |
... | ... | @@ -60,7 +59,15 @@ function _M:makeUI() |
60 | 59 | -- Ensure minimal height |
61 | 60 | if h + frameh < back.h then h = back.h - frameh end |
62 | 61 | -- Ensure if it's too big but too small to not have the down deco, to increase it a it |
63 | - if h + frameh > back.h and h + frameh < back.h + deco_down.h / 2 then h = back.h - frameh + deco_down.h / 2 end | |
62 | + if h + frameh > back.h then | |
63 | + if h + frameh < back.h + 16 then h = back.h - frameh + 16 game.log("==adjusting to %d", 16) | |
64 | + elseif h + frameh < back.h + 32 then h = back.h - frameh + 32 game.log("==adjusting to %d", 32) | |
65 | + elseif h + frameh < back.h + 48 then h = back.h - frameh + 48 game.log("==adjusting to %d", 48) | |
66 | + elseif h + frameh < back.h + 64 then h = back.h - frameh + 64 game.log("==adjusting to %d", 64) | |
67 | + elseif h + frameh < back.h + 80 then h = back.h - frameh + 80 game.log("==adjusting to %d", 80) | |
68 | + end | |
69 | + end | |
70 | + | |
64 | 71 | self.force_x = game.w / 2 - w / 2 |
65 | 72 | self.force_y = game.h - h - 20 |
66 | 73 | return w, h | ... | ... |
... | ... | @@ -65,7 +65,11 @@ function _M:generate() |
65 | 65 | |
66 | 66 | self.front = self:getUITexture("ui/portrait_frame_front.png") |
67 | 67 | self.back = self:getUITexture("ui/portrait_frame_back.png") |
68 | - self.deco_down = self:getUITexture("ui/chat_ui_deco_padding_"..self.side.."_down.png") | |
68 | + self.deco_downs = {} | |
69 | + for i in ipairs_value{16, 32, 48, 64, 80} do | |
70 | + self.deco_downs[i] = self:getUITexture("ui/chat_ui_deco_padding_"..self.side.."_down_"..i..".png") | |
71 | + end | |
72 | + self.deco_down = nil | |
69 | 73 | self.deco_up = self:getUITexture("ui/chat_ui_deco_padding_"..self.side.."_up.png") |
70 | 74 | self.w, self.h = self.front.w, self.front.h |
71 | 75 | |
... | ... | @@ -83,20 +87,26 @@ end |
83 | 87 | |
84 | 88 | function _M:adjustHeight(h) |
85 | 89 | self.h_deco = h - self.back.h |
90 | + local ch = math.find_closest_lower(self.h_deco, {16, 32, 48, 64, 80}) | |
91 | + if not ch then | |
92 | + self.deco_down = nil | |
93 | + else | |
94 | + self.deco_down = self.deco_downs[ch] | |
95 | + end | |
86 | 96 | end |
87 | 97 | |
88 | 98 | function _M:display(x, y, nb_keyframes, screen_x, screen_y) |
89 | 99 | local deco_x |
90 | - if self.h_deco >= self.deco_up.h + self.deco_down.h then | |
100 | + if self.deco_down and self.h_deco >= self.deco_up.h + self.deco_down.h then | |
91 | 101 | if self.side == "left" then deco_x = x + self.back.w - self.deco_up.w else deco_x = x end |
92 | 102 | self.deco_up.t:toScreenFull(deco_x, y, self.deco_up.w, self.deco_up.h, self.deco_up.tw, self.deco_up.th) |
93 | 103 | y = y + self.deco_up.h |
94 | 104 | screen_y = screen_y + self.deco_up.h |
95 | 105 | end |
96 | - if self.h_deco >= 1 then | |
106 | + if self.deco_down then | |
97 | 107 | if self.side == "left" then deco_x = x + self.back.w - self.deco_down.w else deco_x = x end |
98 | 108 | local deco_h = math.min(self.deco_down.h, self.h_deco) |
99 | - self.deco_down.t:toScreenFull(deco_x, y + self.back.h, self.deco_down.w, deco_h, self.deco_down.tw, deco_h * self.deco_down.th / self.deco_down.h) | |
109 | + self.deco_down.t:toScreenFull(deco_x, y + self.back.h, self.deco_down.w, deco_h, self.deco_down.tw, self.deco_down.th) | |
100 | 110 | end |
101 | 111 | |
102 | 112 | self.back.t:toScreenFull(x, y, self.back.w, self.back.h, self.back.tw, self.back.th) | ... | ... |
-
Please register or login to post a comment