File include/vn.h changed (mode: 100644) (index 08ceef6..6c1a55a) |
... |
... |
void vnGo( dialogue::Talk &convo, const std::string &id ); |
20 |
20 |
// Width and height of the VN. Graphics will be scaled from this to screen size. |
// Width and height of the VN. Graphics will be scaled from this to screen size. |
21 |
21 |
double vn_width = 1366.0, vn_height = 768.0; |
double vn_width = 1366.0, vn_height = 768.0; |
22 |
22 |
|
|
|
23 |
|
// UI meshes. |
|
24 |
|
fgl::Mesh vn_mesh_plane; |
|
25 |
|
|
23 |
26 |
// Common VN UI textures. Loaded automatically. |
// Common VN UI textures. Loaded automatically. |
24 |
27 |
fgl::Texture vn_tex_shade = {}, vn_tex_gradient = {}, vn_tex_button_n = {}, vn_tex_button_p = {}, vn_tex_button_s = {}; |
fgl::Texture vn_tex_shade = {}, vn_tex_gradient = {}, vn_tex_button_n = {}, vn_tex_button_p = {}, vn_tex_button_s = {}; |
25 |
28 |
|
|
|
... |
... |
void vnLoadUITextures( |
53 |
56 |
const std::string &buttonN, |
const std::string &buttonN, |
54 |
57 |
const std::string &buttonP, |
const std::string &buttonP, |
55 |
58 |
const std::string &buttonS ){ |
const std::string &buttonS ){ |
|
59 |
|
vn_mesh_plane = fgl::getPlaneMesh(); |
56 |
60 |
vn_tex_gradient = vnLoadImage( dataPath + "/" + gradient, true, true ); |
vn_tex_gradient = vnLoadImage( dataPath + "/" + gradient, true, true ); |
57 |
61 |
vn_tex_button_n = vnLoadImage( dataPath + "/" + buttonN, true, true ); |
vn_tex_button_n = vnLoadImage( dataPath + "/" + buttonN, true, true ); |
58 |
62 |
vn_tex_button_p = vnLoadImage( dataPath + "/" + buttonP, true, true ); |
vn_tex_button_p = vnLoadImage( dataPath + "/" + buttonP, true, true ); |
|
... |
... |
void vnDrawImage( fgl::Texture &tex, float posX, float posY, float angle, float |
65 |
69 |
double textureWidth = tex.width, textureHeight = tex.height; |
double textureWidth = tex.width, textureHeight = tex.height; |
66 |
70 |
fgl::setTexture( tex, 0 ); |
fgl::setTexture( tex, 0 ); |
67 |
71 |
fgl::drawMesh( |
fgl::drawMesh( |
68 |
|
fgl::planeMesh, |
|
|
72 |
|
vn_mesh_plane, |
69 |
73 |
linalg::mul( |
linalg::mul( |
70 |
74 |
linalg::translation_matrix( linalg::vec<double,3>( |
linalg::translation_matrix( linalg::vec<double,3>( |
71 |
75 |
( textureWidth * 0.5 * scaleX + posX ) / screenHeight * 2.0 - screenWidth / screenHeight, |
( textureWidth * 0.5 * scaleX + posX ) / screenHeight * 2.0 - screenWidth / screenHeight, |
|
... |
... |
void vnFreeImages(){ |
115 |
119 |
vn_foregrounds = {}; |
vn_foregrounds = {}; |
116 |
120 |
} |
} |
117 |
121 |
|
|
|
122 |
|
// TODO: ADV auto mode |
|
123 |
|
void vnDrawStats( fgl::Font &font, dialogue::Talk &convo ){ |
|
124 |
|
double sw = fgl::getDisplayWidth(), sh = fgl::getDisplayHeight(); |
|
125 |
|
double aspect = sw / sh; |
|
126 |
|
double vnScale = sw / vn_width; |
|
127 |
|
double vnOffX = 0.0; |
|
128 |
|
double vnMinAspect = 5.0 / 4.0, vnMaxAspect = 1.78; |
|
129 |
|
if( aspect < vnMinAspect ){ |
|
130 |
|
vnScale = sh * vnMinAspect / vn_width; |
|
131 |
|
vnOffX = ( sw - sh * vnMinAspect ) * 0.5; |
|
132 |
|
}else if( aspect > vnMaxAspect ){ |
|
133 |
|
vnScale = sh * vnMaxAspect / vn_width; |
|
134 |
|
vnOffX = ( sw - sh * vnMaxAspect ) * 0.5; |
|
135 |
|
} |
|
136 |
|
|
|
137 |
|
// Assume at least 720p and a maximum of exactly 500 stat points. |
|
138 |
|
float bar_pixels = 227.0f; |
|
139 |
|
float bar_factor = 0.454f; |
|
140 |
|
|
|
141 |
|
// Draw the stats listed in the showstats array. |
|
142 |
|
float tw = 0.0f; |
|
143 |
|
auto showstats_it = convo.arrays.find( "showstats" ); |
|
144 |
|
if( showstats_it != convo.arrays.end() ){ |
|
145 |
|
for( auto &stat : showstats_it->second ){ |
|
146 |
|
tw = std::max(tw, fgl::getTextWidth(convo.strings[stat], font)); |
|
147 |
|
} |
|
148 |
|
} |
|
149 |
|
if( tw > 0.0f ){ |
|
150 |
|
float bw = tw + bar_pixels + font.size * 1.76944f; |
|
151 |
|
float x = vnOffX + ( vn_width - bw - font.size * 1.05) * vnScale; |
|
152 |
|
float y = font.size * 1.333 * vnScale; |
|
153 |
|
float box_h = |
|
154 |
|
showstats_it->second.size() * font.size * 1.333 * vnScale; |
|
155 |
|
vnDrawImage( |
|
156 |
|
vn_tex_shade, |
|
157 |
|
x, |
|
158 |
|
y, |
|
159 |
|
0.0, |
|
160 |
|
bw * vnScale, |
|
161 |
|
box_h |
|
162 |
|
); |
|
163 |
|
for( auto &stat : showstats_it->second ){ |
|
164 |
|
double points = convo.numbers[stat]; |
|
165 |
|
// Draw bar. |
|
166 |
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
|
167 |
|
float bar_x = std::floor( x + ( tw + 5.0 ) * vnScale ); |
|
168 |
|
float bar_y = std::floor( y + font.size * 0.1665 * vnScale ); |
|
169 |
|
float bar_w = |
|
170 |
|
std::ceil( std::max(points * bar_factor, 1.0) * vnScale ) / fgl::blankTexture.width; |
|
171 |
|
float bar_h = std::floor( font.size * vnScale ) / fgl::blankTexture.height; |
|
172 |
|
fgl::setFog( { 0.2f, 0.0f, 0.0f, 1.0f } ); |
|
173 |
|
vnDrawImage( fgl::blankTexture, bar_x, bar_y, 0.0, std::ceil( bar_pixels * vnScale ) / fgl::blankTexture.width, bar_h ); |
|
174 |
|
// Lines. |
|
175 |
|
fgl::setFog( { 0.65f, 0.6f, 0.6f, 1.0f } ); |
|
176 |
|
for( int i = 1; i < 5; i++ ){ |
|
177 |
|
vnDrawImage( |
|
178 |
|
fgl::blankTexture, |
|
179 |
|
std::floor( bar_x + (i * bar_pixels * 0.25 - 2.0) * vnScale ), |
|
180 |
|
bar_y, |
|
181 |
|
0.0, |
|
182 |
|
std::ceil( vnScale ) / fgl::blankTexture.width, |
|
183 |
|
bar_h + std::floor( 2.0 * vnScale ) |
|
184 |
|
); |
|
185 |
|
} |
|
186 |
|
// Bar. |
|
187 |
|
fgl::setFog( { 0.9f, 0.0f, 0.0f, 1.0f } ); |
|
188 |
|
vnDrawImage( fgl::blankTexture, bar_x, bar_y, 0.0, bar_w, bar_h ); |
|
189 |
|
fgl::setFog( { 1.0f, 0.0f, 0.0f, 1.0f } ); |
|
190 |
|
vnDrawImage( fgl::blankTexture, bar_x, bar_y, 0.0, bar_w, bar_h * 0.65 ); |
|
191 |
|
fgl::setFog( { 1.0f, 0.33f, 0.33f, 1.0f } ); |
|
192 |
|
vnDrawImage( fgl::blankTexture, bar_x, bar_y + bar_h * 0.15, 0.0, bar_w, bar_h * 0.15 ); |
|
193 |
|
// Draw text. |
|
194 |
|
glBlendFunc( GL_ONE, GL_ONE ); |
|
195 |
|
fgl::setFog( { 1.0f, 1.0f, 1.0f, 1.0f } ); |
|
196 |
|
fgl::drawText( |
|
197 |
|
convo.strings[stat], |
|
198 |
|
font, |
|
199 |
|
x + 3.0 * vnScale, |
|
200 |
|
y, |
|
201 |
|
vnScale |
|
202 |
|
); |
|
203 |
|
fgl::drawText( |
|
204 |
|
convo.stringifyNumber( points ), |
|
205 |
|
font, |
|
206 |
|
x + ( bw - 3.0 ) * vnScale, |
|
207 |
|
y, |
|
208 |
|
vnScale, |
|
209 |
|
2 |
|
210 |
|
); |
|
211 |
|
y += font.size * 1.333 * vnScale; |
|
212 |
|
} |
|
213 |
|
} |
|
214 |
|
} |
|
215 |
|
|
118 |
216 |
// Draw the VN. Return true if a selection was made. |
// Draw the VN. Return true if a selection was made. |
119 |
217 |
bool vnDraw( |
bool vnDraw( |
120 |
218 |
const std::string &dataPath, |
const std::string &dataPath, |
|
... |
... |
bool vnDraw( |
252 |
350 |
} |
} |
253 |
351 |
} |
} |
254 |
352 |
|
|
|
353 |
|
int mouseX = fgl::getMouseX(), mouseY = fgl::getMouseY(); |
|
354 |
|
|
255 |
355 |
if( convo.screen.lines.empty() ){ |
if( convo.screen.lines.empty() ){ |
256 |
356 |
// Handle button-free screen advance. |
// Handle button-free screen advance. |
257 |
357 |
if( convo.screen.ids.size() > 0 ) choiceIndex = 0; |
if( convo.screen.ids.size() > 0 ) choiceIndex = 0; |
|
... |
... |
bool vnDraw( |
269 |
369 |
float xpos = ( sw - total_width * vnScale ) * 0.5; |
float xpos = ( sw - total_width * vnScale ) * 0.5; |
270 |
370 |
float ypos = vn_height * 0.7409 * vnScale; |
float ypos = vn_height * 0.7409 * vnScale; |
271 |
371 |
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); |
272 |
|
fgl::setPipeline( fgl::unlitPipeline ); |
|
|
372 |
|
fgl::setPipeline( fgl::getUnlitPipeline() ); |
273 |
373 |
for( size_t i = 0; i < img_buttons.size(); i++ ){ |
for( size_t i = 0; i < img_buttons.size(); i++ ){ |
274 |
374 |
auto w = img_buttons[i]->width, h = img_buttons[i]->height; |
auto w = img_buttons[i]->width, h = img_buttons[i]->height; |
275 |
375 |
bool hover = |
bool hover = |
276 |
376 |
useMouse && |
useMouse && |
277 |
|
fgl::mouseY >= ypos && |
|
278 |
|
fgl::mouseY < ypos + ( h + 2.0 ) * vnScale && |
|
279 |
|
fgl::mouseX >= xpos && |
|
280 |
|
fgl::mouseX < xpos + ( w + 2.0 ) * vnScale; |
|
|
377 |
|
mouseY >= ypos && |
|
378 |
|
mouseY < ypos + ( h + 2.0 ) * vnScale && |
|
379 |
|
mouseX >= xpos && |
|
380 |
|
mouseX < xpos + ( w + 2.0 ) * vnScale; |
281 |
381 |
if( hover ){ |
if( hover ){ |
282 |
382 |
choiceIndex = i; |
choiceIndex = i; |
283 |
383 |
} |
} |
|
... |
... |
bool vnDraw( |
314 |
414 |
); |
); |
315 |
415 |
xpos += ( w + 2.0 ) * vnScale; |
xpos += ( w + 2.0 ) * vnScale; |
316 |
416 |
} |
} |
317 |
|
fgl::setPipeline( fgl::colorModPipeline ); |
|
|
417 |
|
fgl::setPipeline( fgl::getColorModPipeline() ); |
318 |
418 |
fgl::setFog( { 1.0f, 1.0f, 1.0f, 1.0f } ); |
fgl::setFog( { 1.0f, 1.0f, 1.0f, 1.0f } ); |
319 |
419 |
}else{ |
}else{ |
320 |
420 |
// Draw text buttons. |
// Draw text buttons. |
|
... |
... |
bool vnDraw( |
331 |
431 |
float ypos = ( vn_height * 0.7409 + buttonHeight * (float)i ) * vnScale; |
float ypos = ( vn_height * 0.7409 + buttonHeight * (float)i ) * vnScale; |
332 |
432 |
bool hover = |
bool hover = |
333 |
433 |
useMouse && |
useMouse && |
334 |
|
fgl::mouseY >= ypos && |
|
335 |
|
fgl::mouseY < ( vn_height * 0.7409 + buttonHeight * (float)( i + 1 ) ) * vnScale && |
|
336 |
|
fgl::mouseX >= vnOffX && |
|
337 |
|
fgl::mouseX < vnOffX + vn_width * vnScale; |
|
|
434 |
|
mouseY >= ypos && |
|
435 |
|
mouseY < ( vn_height * 0.7409 + buttonHeight * (float)( i + 1 ) ) * vnScale && |
|
436 |
|
mouseX >= vnOffX && |
|
437 |
|
mouseX < vnOffX + vn_width * vnScale; |
338 |
438 |
if( hover ){ |
if( hover ){ |
339 |
439 |
choiceIndex = i; |
choiceIndex = i; |
340 |
440 |
} |
} |