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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//! This scene encompasses the main menu system

use chrono::Duration;
use na::Vector1;
use nalgebra as na;
use raylib::{
    ffi::{GetMouseX, GetMouseY, IsMouseButtonDown, Texture},
    prelude::*,
};

use crate::{
    asset_manager::load_texture_from_internal_data,
    discord::{DiscordChannel, DiscordRpcSignal},
    global_resource_package::GlobalResources,
    persistent::settings::PersistentGameSettings,
    project_constants::ProjectConstants,
};

use super::main_menu::MenuStateSignal;

const MIWU_WHITE: Color = Color {
    r: 247,
    g: 239,
    b: 231,
    a: 255,
};
const MIWU_WHITE_V2: Color = Color {
    r: 255,
    g: 245,
    b: 228,
    a: 255,
};

#[derive(Debug)]
pub struct CutScenes {
    show_debug_info: bool,
    intro_art: Texture2D,
    melted_art: Texture2D,
}

impl CutScenes {
    /// Construct a new `CutScenes`
    pub fn new(
        raylib_handle: &mut RaylibHandle,
        thread: &RaylibThread,
        constants: &ProjectConstants,
        game_settings: &mut PersistentGameSettings,
    ) -> Self {
        // Load art
        let intro_art = load_texture_from_internal_data(
            raylib_handle,
            thread,
            "assets/cut/cut_intro/cut_intro.png",
        )
        .unwrap();
        let melted_art = load_texture_from_internal_data(
            raylib_handle,
            thread,
            "assets/cut/cut_melty/cut_melty.png",
        )
        .unwrap();

        Self {
            show_debug_info: false,
            intro_art,
            melted_art,
        }
    }

    pub async fn render_bartender_cutscene_frame(
        &mut self,
        raylib: &mut RaylibHandle,
        rl_thread: &RaylibThread,
        discord: &DiscordChannel,
        global_resources: &GlobalResources,
        constants: &ProjectConstants,
        audio_subsystem: &mut RaylibAudio,
    ) -> MenuStateSignal {
        // Get a drawing handle
        let mut draw = raylib.begin_drawing(rl_thread);

        // Clear the screen
        draw.clear_background(MIWU_WHITE);

        //Obtain mouse position
        let mouse_x = draw.get_mouse_x();
        let mouse_y = draw.get_mouse_y();

        // Optionally display debug info
        if draw.is_key_pressed(KeyboardKey::KEY_F3) {
            self.show_debug_info = !self.show_debug_info;
        }
        if self.show_debug_info {
            // Draw FPS and mouse location
            draw.draw_fps(10, 10);
            draw.draw_text(
                format!("Mouse position: ({}, {})", mouse_x, mouse_y).as_str(),
                10,
                30,
                20,
                Color::GREEN,
            );
        }

        // Title
        // draw.draw_text("INTRO CUTSCENE GOES HERE", 100, 90, 60, Color::BLACK);
        // draw.draw_text("Press SPACE to skip", 100, 600, 20, Color::BLACK);

        let screen_height = draw.get_screen_height();
        let screen_width = draw.get_screen_width();

        // Build a rect for the texture
        let tex_rect = Rectangle::new(
            0.0,
            0.0,
            self.intro_art.width as f32,
            self.intro_art.height as f32,
        );

        // Draw the texture to the center of the screen.
        // Keep in mind, textures are drawn from the top left
        // corner, so we need to offset the rect by half the
        // texture's width and height.
        let dest_rect = Rectangle::new(
            (screen_width / 2) as f32 - (tex_rect.width / 2.0),
            (screen_height / 2) as f32 - (tex_rect.height / 2.0),
            tex_rect.width,
            tex_rect.height,
        );

        // Draw the texture
        draw.draw_texture_pro(
            &self.intro_art,
            &tex_rect,
            &dest_rect,
            Vector2::zero(),
            0.0,
            Color::WHITE,
        );

        // Let the user leave this cutscene by pressing space
        if draw.is_key_pressed(KeyboardKey::KEY_SPACE) {
            return MenuStateSignal::StartGame;
        }

        // Return MenuStateSignal::DoMainMenu if you want to return to the main menu
        // Return MenuStateSignal::StartGame if you want the game to start.
        // Otherwise, keep returning MenuStateSignal::DoIntroCutscene
        return MenuStateSignal::DoIntroCutscene;
    }

    pub async fn render_melted_cutscene_frame(
        &mut self,
        raylib: &mut RaylibHandle,
        rl_thread: &RaylibThread,
        discord: &DiscordChannel,
        global_resources: &GlobalResources,
        constants: &ProjectConstants,
        audio_subsystem: &mut RaylibAudio,
        playtime: &Duration,
    ) -> MenuStateSignal {
        // Get a drawing handle
        let mut draw = raylib.begin_drawing(rl_thread);

        // Clear the screen
        draw.clear_background(MIWU_WHITE_V2);

        //Obtain mouse position
        let mouse_x = draw.get_mouse_x();
        let mouse_y = draw.get_mouse_y();

        // Optionally display debug info
        if draw.is_key_pressed(KeyboardKey::KEY_F3) {
            self.show_debug_info = !self.show_debug_info;
        }
        if self.show_debug_info {
            // Draw FPS and mouse location
            draw.draw_fps(10, 10);
            draw.draw_text(
                format!("Mouse position: ({}, {})", mouse_x, mouse_y).as_str(),
                10,
                30,
                20,
                Color::GREEN,
            );
        }

        // // Title
        // draw.draw_text("MELTY CUTSCENE GOES HERE", 100, 90, 60, Color::BLACK);
        // draw.draw_text(
        //     &format!("This took you {} seconds", playtime.num_seconds()),
        //     100,
        //     600,
        //     20,
        //     Color::BLACK,
        // );
        // draw.draw_text("Press SPACE to skip", 100, 680, 20, Color::BLACK);

        let screen_height = draw.get_screen_height();
        let screen_width = draw.get_screen_width();

        // Build a rect for the texture
        let tex_rect = Rectangle::new(
            0.0,
            0.0,
            self.melted_art.width as f32,
            self.melted_art.height as f32,
        );

        // Draw the texture to the center of the screen.
        // Keep in mind, textures are drawn from the top left
        // corner, so we need to offset the rect by half the
        // texture's width and height.
        let dest_rect = Rectangle::new(
            (screen_width / 2) as f32 - (tex_rect.width / 2.0),
            (screen_height / 2) as f32 - (tex_rect.height / 2.0),
            tex_rect.width,
            tex_rect.height,
        );

        // Draw the texture
        draw.draw_texture_pro(
            &self.melted_art,
            &tex_rect,
            &dest_rect,
            Vector2::zero(),
            0.0,
            Color::WHITE,
        );

        // Let the user leave this cutscene by pressing space
        if draw.is_key_pressed(KeyboardKey::KEY_SPACE) {
            return MenuStateSignal::DoMainMenu;
        }

        // Return MenuStateSignal::DoMainMenu if you want to return to the main menu
        // Otherwise, keep returning MenuStateSignal::DoMeltedDeathCutscene
        return MenuStateSignal::DoMeltedDeathCutscene {
            playtime: playtime.clone(),
        };
    }

    pub async fn render_finished_cutscene_frame(
        &mut self,
        raylib: &mut RaylibHandle,
        rl_thread: &RaylibThread,
        discord: &DiscordChannel,
        global_resources: &GlobalResources,
        constants: &ProjectConstants,
        audio_subsystem: &mut RaylibAudio,
        playtime: &Duration,
    ) -> MenuStateSignal {
        // Get a drawing handle
        let mut draw = raylib.begin_drawing(rl_thread);

        // Clear the screen
        draw.clear_background(MIWU_WHITE);

        //Obtain mouse position
        let mouse_x = draw.get_mouse_x();
        let mouse_y = draw.get_mouse_y();

        // Optionally display debug info
        if draw.is_key_pressed(KeyboardKey::KEY_F3) {
            self.show_debug_info = !self.show_debug_info;
        }
        if self.show_debug_info {
            // Draw FPS and mouse location
            draw.draw_fps(10, 10);
            draw.draw_text(
                format!("Mouse position: ({}, {})", mouse_x, mouse_y).as_str(),
                10,
                30,
                20,
                Color::GREEN,
            );
        }

        // Title
        draw.draw_text("END CUTSCENE GOES HERE", 100, 90, 60, Color::BLACK);
        draw.draw_text(
            &format!("This took you {} seconds", playtime.num_seconds()),
            100,
            600,
            20,
            Color::BLACK,
        );
        draw.draw_text("Press SPACE to skip", 100, 680, 20, Color::BLACK);

        // Let the user leave this cutscene by pressing space
        if draw.is_key_pressed(KeyboardKey::KEY_SPACE) {
            return MenuStateSignal::DoMainMenu;
        }

        // Return MenuStateSignal::DoMainMenu if you want to return to the main menu
        // Otherwise, keep returning MenuStateSignal::DoFinishedCutscene
        return MenuStateSignal::DoFinishedCutscene {
            playtime: playtime.clone(),
        };
    }

    pub async fn render_ocean_cutscene_frame(
        &mut self,
        raylib: &mut RaylibHandle,
        rl_thread: &RaylibThread,
        discord: &DiscordChannel,
        global_resources: &GlobalResources,
        constants: &ProjectConstants,
        audio_subsystem: &mut RaylibAudio,
        playtime: &Duration,
    ) -> MenuStateSignal {
        // Get a drawing handle
        let mut draw = raylib.begin_drawing(rl_thread);

        // Clear the screen
        draw.clear_background(MIWU_WHITE);

        //Obtain mouse position
        let mouse_x = draw.get_mouse_x();
        let mouse_y = draw.get_mouse_y();

        // Optionally display debug info
        if draw.is_key_pressed(KeyboardKey::KEY_F3) {
            self.show_debug_info = !self.show_debug_info;
        }
        if self.show_debug_info {
            // Draw FPS and mouse location
            draw.draw_fps(10, 10);
            draw.draw_text(
                format!("Mouse position: ({}, {})", mouse_x, mouse_y).as_str(),
                10,
                30,
                20,
                Color::GREEN,
            );
        }

        // Title
        draw.draw_text("OCEAN CUTSCENE GOES HERE", 100, 90, 60, Color::BLACK);
        draw.draw_text(
            &format!("This took you {} seconds", playtime.num_seconds()),
            100,
            600,
            20,
            Color::BLACK,
        );
        draw.draw_text("Press SPACE to skip", 100, 680, 20, Color::BLACK);

        // Let the user leave this cutscene by pressing space
        if draw.is_key_pressed(KeyboardKey::KEY_SPACE) {
            return MenuStateSignal::DoMainMenu;
        }

        // Return MenuStateSignal::DoMainMenu if you want to return to the main menu
        // Otherwise, keep returning MenuStateSignal::DoOceanCutscene
        return MenuStateSignal::DoOceanCutscene {
            playtime: playtime.clone(),
        };
    }
}