-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechBubble.ms
More file actions
65 lines (54 loc) · 2.05 KB
/
Copy pathspeechBubble.ms
File metadata and controls
65 lines (54 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import "utils"
ensureImport "math"
SpeechBubble = {}
SpeechBubble.init = function(tileDisplayLayer, pixelDisplayLayer, width, height)
self.td = tileDisplayLayer
self.pd = pixelDisplayLayer
self.maxCol = width - 1
self.maxRow = height - 1
self.loadTileSet("/sys/pics/TwoCornerTiles.png", 64, 16)
self.td.extent = [width, height] // columns, rows on screen
end function
SpeechBubble.loadTileSet = function(path, tileSize, wangOffset)
self.td.tileSet = file.loadImage("/sys/pics/TwoCornerTiles.png")
self.td.tileSetTileSize = 64 // size of each tile in the image
self.SW = 1 + wangOffset
self.NW = 2 + wangOffset
self.W = 3 + wangOffset
self.NE = 4 + wangOffset
self.N = 6 + wangOffset
self.SE = 8 + wangOffset
self.S = 9 + wangOffset
self.E = 12 + wangOffset
self.SOLID = 15 + wangOffset
end function
SpeechBubble.draw = function(pos, firstLine = "", secondLine = "", textLimit = 1.0)
td = self.td
td.clear self.SOLID
td.scrollX = -pos.x
td.scrollY = -pos.y
for col in range(1, self.maxCol - 1)
td.setCell col, 0, self.S
td.setCell col, self.maxRow, self.N
end for
for row in range(1, self.maxRow - 1)
td.setCell 0, row, self.W
td.setCell self.maxCol, row, self.E
end for
td.setCell 0, 0, self.SW
td.setCell 0, self.maxRow, self.NW
td.setCell self.maxCol, 0, self.SE
td.setCell self.maxCol, self.maxRow, self.NE
fontSize = 24
tileSize = self.td.tileSetTileSize
textX = pos.x + (1 * tileSize)
textY = pos.y + ((self.maxRow) * tileSize) - fontSize
textLimit1 = 2.0 * math.clamp(textLimit, 0.0, 0.5)
textLimit2 = 2.0 * math.clamp(textLimit - 0.5, 0.0, 0.5)
textLength1 = ceil(textLimit1 * firstLine.len)
textLength2 = ceil(textLimit2 * secondLine.len)
firstLine = firstLine[0:textLength1]
secondLine = secondLine[0:textLength2]
self.pd.print(firstLine, textX, textY)
self.pd.print(secondLine, textX, textY - fontSize)
end function