-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayer_prologue.lua
165 lines (148 loc) · 5.76 KB
/
layer_prologue.lua
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
PrologueLayer = Layer:extend()
function PrologueLayer:new(story)
PrologueLayer.super.new(self)
self.story = story
self.layer_name = "PrologueLayer"
self.mode_queue = {"story", "logo"}
self.box_patch = patchy.load("gfx/textbox.9.png")
self.textbox_string = ""
self.currently_shown_length = 0
self.background = nil
self.portrait = nil
self.blinky_icon = love.graphics.newImage("gfx/icon_next.png")
self.blinky_rect = { x = 1280 - 30 - 15, y = 720 - 30 - 30, w = 15, h = 30 }
self.show_blinker = true
self.blinky_counter = 0
end
function PrologueLayer:draw()
-- background layer
local bgc = constants.dark_bg_color
if self.background == nil then
love.graphics.setColor(bgc.r, bgc.g, bgc.b, 1)
love.graphics.rectangle("fill", 0, 0, 1280, 720) -- solid color
else
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(self.background, 0, 0, 0, 4, 4) -- img scaled by 4
end
-- character portrait
if self.portrait ~= nil then
local sw, sh = love.graphics.getDimensions() -- screen width/height
local pw, ph = self.portrait:getDimensions() -- portrait width/height
local x = (sw - pw * 3) / 2
local y = (sh - ph * 3) / 2 - 15
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(self.portrait, x, y, 0, 3, 3)
end
-- boxes
local box_scale = 3
love.graphics.push()
love.graphics.scale(box_scale, box_scale)
love.graphics.setColor(1, 1, 1, 1)
local txt_x, txt_y, txt_w, txt_h = self.box_patch:draw(0, 480 / box_scale, 1280 / box_scale, 240 / box_scale) -- textbox
love.graphics.pop()
txt_x = txt_x * box_scale + box_scale * 12
txt_y = txt_y * box_scale + box_scale * 6
txt_w = txt_w * box_scale - (box_scale * 12) * 2
txt_h = txt_h * box_scale - (box_scale * 6) * 2
-- text and blinker
local txt = constants.system_txt_color
love.graphics.setFont(constants.big_font)
love.graphics.setColor(txt.r, txt.g, txt.b, 1)
local chopped = string.sub(self.textbox_string, 1, self.currently_shown_length)
love.graphics.printf(chopped, txt_x, txt_y, txt_w, "left")
if lume.first(self.mode_queue) == "wait_for_any_input" and self.show_blinker then
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(self.blinky_icon, self.blinky_rect.x, self.blinky_rect.y, 0, 3)
end
love.graphics.setScissor()
end
function PrologueLayer:update(dt)
if lume.first(self.mode_queue) == "logo" then
self.mode_queue = {}
layer_manager:transition(self, MenuLayer())
elseif self.currently_shown_length < #self.textbox_string then
-- dialogue increment
self.currently_shown_length = self.currently_shown_length + 1
elseif lume.first(self.mode_queue) == "wait_for_text" then
self:pop_current_mode()
elseif lume.first(self.mode_queue) == "wait_for_any_input" then
if self.blinky_counter == 20 then
self.blinky_counter = 0
if self.show_blinker then
self.show_blinker = false
else
self.show_blinker = true
end
else
self.blinky_counter = self.blinky_counter + 1
end
elseif lume.first(self.mode_queue) == "story" then
local story = self.story
story:next_line()
if story.complete == true then
self:pop_current_mode()
else
local line = story.lines[story.current_line]
if string_begins_with(line, "#portrait ") then
local path = string.gsub(line, "#portrait ", "")
if path ~= "none" then
local type = self:current_flavor()
self.portrait = love.graphics.newImage(path)
else
self.portrait = nil
end
elseif string_begins_with(line, "#bg ") then
local path = string.gsub(line, "#bg ", "")
if path ~= "none" then
self.background = love.graphics.newImage(path)
else
self.background = nil
end
elseif string_begins_with(line, "#music ") then
local path = string.gsub(line, "#music ", "")
TEsound.stop("music")
TEsound.playLooping(path, 'stream', 'music')
return
else
self:set_textbox_string(line)
end
end
end
end
function PrologueLayer:keypressed(key, scancode, isrepeat)
local current_mode = lume.first(self.mode_queue)
if key == layer_manager.controls["Back"] then
back_sound()
self.mode_queue = { "logo" }
elseif current_mode == "wait_for_text" then
self:wait_for_text_input()
elseif current_mode == "wait_for_any_input" then
self:wait_for_any_input_input()
end
end
function PrologueLayer:mousepressed(x, y, button, istouch, presses)
local current_mode = lume.first(self.mode_queue)
if current_mode == "wait_for_text" then
self:wait_for_text_input()
elseif current_mode == "wait_for_any_input" then
self:wait_for_any_input_input()
end
end
function PrologueLayer:wait_for_text_input()
self.currently_shown_length = #self.textbox_string
end
function PrologueLayer:wait_for_any_input_input()
self:pop_current_mode()
end
function PrologueLayer:set_textbox_string(str)
self.currently_shown_length = 0
self.textbox_string = str
local prepend_modes = { "wait_for_text", "wait_for_any_input" }
self.mode_queue = lume.concat(prepend_modes, self.mode_queue)
end
function PrologueLayer:pop_current_mode()
self.mode_queue = lume.last(self.mode_queue, #self.mode_queue - 1)
if self.mode_queue == nil then
self.mode_queue = {}
end
end