2020-06-20 07:46:41 +00:00
|
|
|
#pragma once
|
|
|
|
#include <functional>
|
2020-06-27 09:48:55 +00:00
|
|
|
#include "dobject.h"
|
2020-07-29 21:18:08 +00:00
|
|
|
#include "v_2ddrawer.h"
|
2021-04-15 22:50:13 +00:00
|
|
|
#include "d_eventbase.h"
|
2020-06-20 07:46:41 +00:00
|
|
|
|
2020-06-28 08:14:42 +00:00
|
|
|
using CompletionFunc = std::function<void(bool)>;
|
2020-07-01 10:55:32 +00:00
|
|
|
struct JobDesc;
|
2020-07-19 09:57:00 +00:00
|
|
|
class ScreenJobRunner;
|
2020-06-27 09:48:55 +00:00
|
|
|
|
|
|
|
class DScreenJob : public DObject
|
|
|
|
{
|
|
|
|
DECLARE_CLASS(DScreenJob, DObject)
|
2020-07-01 10:55:32 +00:00
|
|
|
const int fadestyle;
|
|
|
|
const float fadetime; // in milliseconds
|
2020-07-03 07:59:24 +00:00
|
|
|
int fadestate = fadein;
|
2020-07-01 10:55:32 +00:00
|
|
|
|
2020-07-19 09:57:00 +00:00
|
|
|
friend class ScreenJobRunner;
|
2021-04-15 22:50:13 +00:00
|
|
|
protected:
|
|
|
|
int ticks = 0;
|
|
|
|
int state = running;
|
2021-04-15 22:11:02 +00:00
|
|
|
bool pausable = true;
|
2020-07-01 10:55:32 +00:00
|
|
|
|
2020-06-27 09:48:55 +00:00
|
|
|
public:
|
2021-04-15 22:50:13 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
running = 1, // normal operation
|
|
|
|
skipped = 2, // finished by user skipping
|
|
|
|
finished = 3, // finished by completing its sequence
|
|
|
|
stopping = 4, // running ending animations / fadeout, etc. Will not accept more input.
|
|
|
|
stopped = 5, // we're done here.
|
|
|
|
};
|
2020-07-01 10:55:32 +00:00
|
|
|
enum
|
|
|
|
{
|
2020-07-03 07:59:24 +00:00
|
|
|
visible = 0,
|
2020-07-01 10:55:32 +00:00
|
|
|
fadein = 1,
|
|
|
|
fadeout = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
DScreenJob(int fade = 0, float fadet = 250.f) : fadestyle(fade), fadetime(fadet) {}
|
2020-08-21 20:30:51 +00:00
|
|
|
|
|
|
|
virtual bool ProcessInput()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2020-07-01 10:55:32 +00:00
|
|
|
|
2021-04-16 21:29:53 +00:00
|
|
|
virtual void Start() {}
|
2021-04-15 22:50:13 +00:00
|
|
|
virtual bool OnEvent(event_t* evt) { return false; }
|
2021-04-15 22:11:02 +00:00
|
|
|
virtual void OnTick() { /*state = finished;*/ }
|
2021-04-15 22:50:13 +00:00
|
|
|
virtual void Draw(double smoothratio) {}
|
|
|
|
|
2021-04-16 19:27:54 +00:00
|
|
|
int DrawFrame(double smoothratio)
|
2021-04-15 22:50:13 +00:00
|
|
|
{
|
2021-04-16 18:08:20 +00:00
|
|
|
if (state != running) smoothratio = 1; // this is necessary because the ticker won't be incremented anymore to avoid having a negative time span.
|
2021-04-15 22:50:13 +00:00
|
|
|
Draw(smoothratio);
|
|
|
|
if (state == skipped) return -1;
|
|
|
|
if (state == finished) return 0;
|
2021-04-16 18:48:40 +00:00
|
|
|
return 1;
|
2021-04-15 22:50:13 +00:00
|
|
|
}
|
|
|
|
|
2020-07-03 07:59:24 +00:00
|
|
|
int GetFadeState() const { return fadestate; }
|
|
|
|
|
2020-06-27 09:48:55 +00:00
|
|
|
};
|
|
|
|
|
2020-06-28 20:17:27 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-04-15 22:02:09 +00:00
|
|
|
class DSkippableScreenJob : public DScreenJob
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
DSkippableScreenJob(int fade = 0, float fadet = 250.f) : DScreenJob(fade, fadet)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool OnEvent(event_t* evt) override;
|
2021-04-16 16:43:59 +00:00
|
|
|
virtual void Skipped() {}
|
2021-04-15 22:02:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2020-07-29 21:18:08 +00:00
|
|
|
class DBlackScreen : public DScreenJob
|
|
|
|
{
|
|
|
|
int wait;
|
2021-04-15 22:11:02 +00:00
|
|
|
bool cleared = false;
|
2020-07-29 21:18:08 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
DBlackScreen(int w) : wait(w) {}
|
2021-04-15 22:11:02 +00:00
|
|
|
void OnTick() override;
|
|
|
|
void Draw(double smooth) override;
|
2020-07-29 21:18:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2021-04-15 22:11:02 +00:00
|
|
|
class DImageScreen : public DSkippableScreenJob
|
2020-06-28 20:17:27 +00:00
|
|
|
{
|
|
|
|
DECLARE_CLASS(DImageScreen, DScreenJob)
|
|
|
|
|
|
|
|
int tilenum = -1;
|
2020-10-13 21:29:12 +00:00
|
|
|
int trans;
|
2020-07-29 21:18:08 +00:00
|
|
|
int waittime; // in ms.
|
2021-04-15 22:11:02 +00:00
|
|
|
bool cleared = false;
|
2020-06-28 20:17:27 +00:00
|
|
|
FGameTexture* tex = nullptr;
|
|
|
|
|
|
|
|
public:
|
2021-04-15 22:11:02 +00:00
|
|
|
DImageScreen(FGameTexture* tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DSkippableScreenJob(fade), waittime(wait)
|
2020-06-28 20:17:27 +00:00
|
|
|
{
|
|
|
|
tex = tile;
|
2020-10-13 21:29:12 +00:00
|
|
|
trans = translation;
|
2020-06-28 20:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 22:11:02 +00:00
|
|
|
DImageScreen(int tile, int fade = DScreenJob::fadein | DScreenJob::fadeout, int wait = 3000, int translation = 0) : DSkippableScreenJob(fade), waittime(wait)
|
2020-06-28 20:17:27 +00:00
|
|
|
{
|
|
|
|
tilenum = tile;
|
2020-10-13 21:29:12 +00:00
|
|
|
trans = translation;
|
2020-06-28 20:17:27 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 22:11:02 +00:00
|
|
|
void OnTick() override;
|
|
|
|
void Draw(double smooth) override;
|
2020-06-28 20:17:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-06-28 19:38:25 +00:00
|
|
|
struct JobDesc
|
|
|
|
{
|
|
|
|
DScreenJob* job;
|
|
|
|
void (*postAction)();
|
|
|
|
bool ignoreifskipped;
|
|
|
|
};
|
|
|
|
|
2020-06-27 09:48:55 +00:00
|
|
|
|
2020-07-21 22:42:50 +00:00
|
|
|
void RunScreenJob(JobDesc *jobs, int count, CompletionFunc completion, bool clearbefore = true, bool blockingui = false);
|
2021-04-15 22:50:13 +00:00
|
|
|
void EndScreenJob();
|
2020-07-19 10:48:31 +00:00
|
|
|
void DeleteScreenJob();
|
2021-04-15 22:50:13 +00:00
|
|
|
bool ScreenJobResponder(event_t* ev);
|
|
|
|
void ScreenJobTick();
|
2021-04-16 20:03:01 +00:00
|
|
|
bool ScreenJobDraw();
|
2020-06-27 09:48:55 +00:00
|
|
|
|
|
|
|
struct AnimSound
|
|
|
|
{
|
|
|
|
int framenum;
|
|
|
|
int soundnum;
|
|
|
|
};
|
|
|
|
|
2020-08-17 22:04:48 +00:00
|
|
|
DScreenJob *PlayVideo(const char *filename, const AnimSound *ans = nullptr, const int *frameticks = nullptr, bool nosoundstop = false);
|