~jadedctrl/gem-xwx-moe
~jadedctrl/gem-xwx-moe/gemujo_ludo/mods.niaj/fasado/subtitles/ClassicSubtitleDisplay.lua
~jadedctrl/gem-xwx-moe/gemujo_ludo/mods.niaj/fasado/subtitles/ClassicSubtitleDisplay.lua
0 | --[[ |
1 | Subtitles — adds subtitles to Minetest. |
2 |
|
3 | Copyright © 2022‒2023, Silver Sandstone <@SilverSandstone@craftodon.social> |
4 |
|
5 | Permission is hereby granted, free of charge, to any person obtaining a |
6 | copy of this software and associated documentation files (the "Software"), |
7 | to deal in the Software without restriction, including without limitation |
8 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
9 | and/or sell copies of the Software, and to permit persons to whom the |
10 | Software is furnished to do so, subject to the following conditions: |
11 |
|
12 | The above copyright notice and this permission notice shall be included |
13 | in all copies or substantial portions of the Software. |
14 |
|
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21 | DEALINGS IN THE SOFTWARE. |
22 | ]] |
23 |
|
24 |
|
25 | --- Provides the ClassicSubtitleDisplay class, which displays subtitles at the bottom of the screen. |
26 |
|
27 |
|
28 | local S = subtitles.S; |
29 |
|
30 |
|
31 | --- Displays subtitles at the bottom of the screen. |
32 | -- @type ClassicSubtitleDisplay |
33 | subtitles.ClassicSubtitleDisplay = subtitles.BaseTextSubtitleDisplay:extend(); |
34 |
|
35 | subtitles.ClassicSubtitleDisplay.NAME = 'classic'; |
36 | subtitles.ClassicSubtitleDisplay.ICON = 'subtitles_mode_classic.png'; |
37 | subtitles.ClassicSubtitleDisplay.TITLE = S('Classic subtitles'); |
38 | subtitles.ClassicSubtitleDisplay.DESCRIPTION = S('Displays outlined subtitles at the bottom of the screen.'); |
39 |
|
40 | function subtitles.ClassicSubtitleDisplay:init() |
41 | self.super.init(self); |
42 |
|
43 | self.margin = 85; |
44 | self.font_size = 1.0; |
45 | self.size = {x = 640, y = 30}; |
46 | self.offset = {x = 0, y = -self.margin}; |
47 | self.position = {x = 0.5, y = 1.0}; |
48 |
|
49 | self.pan_amount = 0.0; |
50 | end; |
51 |
|
52 | function subtitles.ClassicSubtitleDisplay:get_huds(entry) |
53 | local offset = entry:get_offset(); |
54 | local huds = {}; |
55 | local radius = 3; |
56 | local shade = entry:get_distance_shade(); |
57 | --local border_colour = subtitles.util.rgb_to_number(0, shade * 64, shade * 255); -- Disabled because the rapid HUD updates lag too much. |
58 | local border_colour = 0x003FCF; |
59 | local description = entry.sound:get_description(); |
60 | local pan = entry:get_pan() * self.pan_amount; |
61 |
|
62 | local z_index = self.z_index; |
63 | for x = -radius, radius do |
64 | for y = -radius, radius do |
65 | if (x == 0 and y == 0) or math.floor(math.sqrt(x ^ 2 + y ^ 2)) == radius then |
66 | huds[x .. ',' .. y] = |
67 | { |
68 | hud_elem_type = 'text'; |
69 | name = S('Subtitle'); |
70 | text = description; |
71 | offset = {x = offset.x + x + pan, y = offset.y + y - 2}; |
72 | scale = self.size; |
73 | number = border_colour; |
74 | size = {x = self.font_size, y = self.font_size}; |
75 | z_index = z_index; |
76 | style = self.style; |
77 | }; |
78 | z_index = z_index + 1; |
79 | end; |
80 | end; |
81 | end; |
82 |
|
83 | local text_hud = huds['0,0']; |
84 | text_hud.number = 0xFFFFFF; |
85 | text_hud.z_index = z_index; |
86 |
|
87 | return huds; |
88 | end; |
89 |
|
90 | subtitles.ClassicSubtitleDisplay:register(); |