summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/CmpSceneDlg.cpp
blob: 866eb4314f7d35cb0cc5ab9a6ddee3aa9c0a71b1 (plain)
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
/*  Starshatter: The Open Source Project
    Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
    Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
    Copyright (c) 1997-2006, Destroyer Studios LLC.

    AUTHOR:       John DiCamillo


    OVERVIEW
    ========
*/

#include "CmpSceneDlg.h"
#include "CmpnScreen.h"
#include "GameScreen.h"
#include "Campaign.h"
#include "CombatEvent.h"
#include "Starshatter.h"
#include "Sim.h"
#include "CameraDirector.h"
#include "Mission.h"
#include "MissionEvent.h"

#include "Clock.h"
#include "DataLoader.h"
#include "Video.h"
#include "Keyboard.h"
#include "Mouse.h"
#include "ImageBox.h"
#include "RichTextBox.h"
#include "Button.h"
#include "FormatUtil.h"

// +--------------------------------------------------------------------+
// DECLARE MAPPING FUNCTIONS:

// +--------------------------------------------------------------------+

CmpSceneDlg::CmpSceneDlg(Screen* s, FormDef& def, CmpnScreen* mgr)
: FormWindow(s, 0, 0, s->Width(), s->Height()), manager(mgr),
mov_scene(0), subtitles_box(0), cam_view(0), disp_view(0), old_disp_win(0),
flare1(0), flare2(0), flare3(0), flare4(0), subtitles_delay(0), subtitles_time(0)
{
    Init(def);

    DataLoader* loader = DataLoader::GetLoader();
    const char* oldpath = loader->GetDataPath();

    loader->SetDataPath(0);
    loader->LoadTexture("flare0+.pcx", flare1, Bitmap::BMP_TRANSLUCENT);
    loader->LoadTexture("flare2.pcx",  flare2, Bitmap::BMP_TRANSLUCENT);
    loader->LoadTexture("flare3.pcx",  flare3, Bitmap::BMP_TRANSLUCENT);
    loader->LoadTexture("flare4.pcx",  flare4, Bitmap::BMP_TRANSLUCENT);
    loader->SetDataPath(oldpath);
}

CmpSceneDlg::~CmpSceneDlg()
{
}

void
CmpSceneDlg::RegisterControls()
{
    mov_scene      =                 FindControl(101);
    subtitles_box  = (RichTextBox*)  FindControl(102);

    if (mov_scene) {
        CameraDirector* cam_dir = CameraDirector::GetInstance();
        cam_view = new CameraView(mov_scene, cam_dir->GetCamera(), 0);
        if (cam_view)
        mov_scene->AddView(cam_view);

        disp_view = DisplayView::GetInstance();
    }
}

void
CmpSceneDlg::Show()
{
    FormWindow::Show();

    Starshatter* stars = Starshatter::GetInstance();

    if (stars->InCutscene()) {
        Sim* sim = Sim::GetSim();

        if (sim) {
            cam_view->UseCamera(CameraDirector::GetInstance()->GetCamera());
            cam_view->UseScene(sim->GetScene());
        }

        // initialize lens flare bitmaps:
        if (stars->LensFlare()) {
            cam_view->LensFlareElements(flare1, flare4, flare2, flare3);
            cam_view->LensFlare(true);
        }

        // if lens flare disabled, just create the corona:
        else if (stars->Corona()) {
            cam_view->LensFlareElements(flare1, 0, 0, 0);
            cam_view->LensFlare(true);
        }

        if (disp_view) {
            old_disp_win = disp_view->GetWindow();

            disp_view->SetWindow(mov_scene);
            mov_scene->AddView(disp_view);
        }

        if (subtitles_box) {
            subtitles_box->SetText(stars->GetSubtitles());
            subtitles_delay = 0;
            subtitles_time  = 0;
        }
    }
}

void
CmpSceneDlg::Hide()
{
    FormWindow::Hide();

    if (disp_view && mov_scene && old_disp_win) {
        mov_scene->DelView(disp_view);
        disp_view->SetWindow(old_disp_win);
    }
}

// +--------------------------------------------------------------------+

CameraView*
CmpSceneDlg::GetCameraView()
{
    return cam_view;
}

DisplayView*
CmpSceneDlg::GetDisplayView()
{
    return disp_view;
}

// +--------------------------------------------------------------------+

void
CmpSceneDlg::ExecFrame()
{
    Starshatter*   stars             = Starshatter::GetInstance();
    Mission*       cutscene_mission  = stars->GetCutsceneMission();

    if (cutscene_mission && disp_view) {
        disp_view->ExecFrame();

        if (subtitles_box && subtitles_box->GetLineCount() > 0) {
            if (subtitles_delay == 0) {
                int nlines = subtitles_box->GetLineCount();

                MissionEvent* begin_scene = cutscene_mission->FindEvent(MissionEvent::BEGIN_SCENE);
                MissionEvent* end_scene   = cutscene_mission->FindEvent(MissionEvent::END_SCENE);

                if (begin_scene && end_scene) {
                    double total_time = end_scene->Time() - begin_scene->Time();
                    subtitles_delay   = total_time / nlines;
                    subtitles_time    = Clock::GetInstance()->RealTime() / 1000.0 + subtitles_delay;
                }
                else {
                    subtitles_delay = -1;
                }
            }

            if (subtitles_delay > 0) {
                double seconds = Clock::GetInstance()->RealTime() / 1000.0;

                if (subtitles_time <= seconds) {
                    subtitles_time = seconds + subtitles_delay;
                    subtitles_box->Scroll(ScrollWindow::SCROLL_DOWN);
                }
            }
        }
    }
    else {
        manager->ShowCmdDlg();
    }
}