Small dialogue polish

- Slide in from top
- Fix chaining multiple dialogues with the same speaker not working
- Unset when changing level
- Sped up punctuation pause a bit
This commit is contained in:
Sally Coolatta 2023-08-25 06:50:12 -04:00
parent ffda097421
commit 3009f1c106
6 changed files with 123 additions and 83 deletions

View file

@ -676,6 +676,8 @@ bool CallFunc_DialogueWaitDismiss(ACSVM::Thread *thread, const ACSVM::Word *argV
(void)argV; (void)argV;
(void)argC; (void)argC;
g_dialogue.SetDismissable(true);
thread->state = { thread->state = {
ACSVM::ThreadState::WaitTag, ACSVM::ThreadState::WaitTag,
0, 0,
@ -696,6 +698,8 @@ bool CallFunc_DialogueWaitText(ACSVM::Thread *thread, const ACSVM::Word *argV, A
(void)argV; (void)argV;
(void)argC; (void)argC;
g_dialogue.SetDismissable(false);
thread->state = { thread->state = {
ACSVM::ThreadState::WaitTag, ACSVM::ThreadState::WaitTag,
1, 1,

View file

@ -84,6 +84,7 @@
#include "k_vote.h" #include "k_vote.h"
#include "k_serverstats.h" #include "k_serverstats.h"
#include "music.h" #include "music.h"
#include "k_dialogue.h"
#ifdef HWRENDER #ifdef HWRENDER
#include "hardware/hw_main.h" // 3D View Rendering #include "hardware/hw_main.h" // 3D View Rendering
@ -1012,6 +1013,8 @@ void D_ClearState(void)
if (gamedata && gamedata->deferredsave) if (gamedata && gamedata->deferredsave)
G_SaveGameData(); G_SaveGameData();
K_UnsetDialogue();
G_SetGamestate(GS_NULL); G_SetGamestate(GS_NULL);
wipegamestate = GS_NULL; wipegamestate = GS_NULL;
} }

View file

@ -21,13 +21,22 @@
#include "g_game.h" #include "g_game.h"
#include "v_video.h" #include "v_video.h"
#include "r_draw.h" #include "r_draw.h"
#include "m_easing.h"
#include "r_skins.h" #include "r_skins.h"
#include "z_zone.h" #include "z_zone.h"
#include "v_draw.hpp"
#include "acs/interface.h" #include "acs/interface.h"
using srb2::Dialogue; using srb2::Dialogue;
void Dialogue::Init(void)
{
active = true;
dismissable = false;
}
void Dialogue::SetSpeaker(void) void Dialogue::SetSpeaker(void)
{ {
// Unset speaker // Unset speaker
@ -38,9 +47,10 @@ void Dialogue::SetSpeaker(void)
void Dialogue::SetSpeaker(std::string skinName, int portraitID) void Dialogue::SetSpeaker(std::string skinName, int portraitID)
{ {
Init();
// Set speaker based on a skin // Set speaker based on a skin
int skinID = -1; int skinID = -1;
if (!skinName.empty()) if (!skinName.empty())
{ {
skinID = R_SkinAvailable(skinName.c_str()); skinID = R_SkinAvailable(skinName.c_str());
@ -70,6 +80,8 @@ void Dialogue::SetSpeaker(std::string skinName, int portraitID)
void Dialogue::SetSpeaker(std::string customName, std::string customPatch, UINT8 *customColormap) void Dialogue::SetSpeaker(std::string customName, std::string customPatch, UINT8 *customColormap)
{ {
Init();
// Set custom speaker // Set custom speaker
speaker = customName; speaker = customName;
@ -86,6 +98,15 @@ void Dialogue::SetSpeaker(std::string customName, std::string customPatch, UINT8
void Dialogue::NewText(std::string newText) void Dialogue::NewText(std::string newText)
{ {
Init();
newText = V_ScaledWordWrap(
290 << FRACBITS,
FRACUNIT, FRACUNIT, FRACUNIT,
0, HU_FONT,
newText.c_str()
);
text.clear(); text.clear();
textDest = newText; textDest = newText;
@ -98,7 +119,7 @@ void Dialogue::NewText(std::string newText)
bool Dialogue::Active(void) bool Dialogue::Active(void)
{ {
return (!speaker.empty()); return active;
} }
bool Dialogue::TextDone(void) bool Dialogue::TextDone(void)
@ -106,6 +127,16 @@ bool Dialogue::TextDone(void)
return textDone; return textDone;
} }
bool Dialogue::Dismissable(void)
{
return dismissable;
}
void Dialogue::SetDismissable(bool value)
{
dismissable = value;
}
void Dialogue::WriteText(void) void Dialogue::WriteText(void)
{ {
textTimer -= textSpeed; textTimer -= textSpeed;
@ -145,114 +176,109 @@ void Dialogue::CompleteText(void)
void Dialogue::Tick(void) void Dialogue::Tick(void)
{ {
if (Active() == false) if (Active())
{
if (slide < FRACUNIT)
{
slide += kSlideSpeed;
}
}
else
{
if (slide > 0)
{
slide -= kSlideSpeed;
if (slide <= 0)
{
Unset();
}
}
}
slide = std::clamp(slide, 0, FRACUNIT);
if (slide != FRACUNIT)
{ {
return; return;
} }
WriteText(); WriteText();
bool pressed = ( if (Dismissable() == true)
((players[serverplayer].cmd.buttons & BT_VOTE) == BT_VOTE) &&
((players[serverplayer].oldcmd.buttons & BT_VOTE) == 0)
);
if (pressed == true)
{ {
if (textDone) bool pressed = (
((players[serverplayer].cmd.buttons & BT_VOTE) == BT_VOTE) &&
((players[serverplayer].oldcmd.buttons & BT_VOTE) == 0)
);
if (pressed == true)
{ {
SetSpeaker(); if (TextDone())
{
Dismiss();
}
else
{
CompleteText();
}
} }
else
{
CompleteText();
}
}
}
void Dialogue::UpdatePatches(void)
{
if (bgPatch == nullptr)
{
bgPatch = static_cast<patch_t *>(W_CachePatchName("TUTDIAG1", PU_HUDGFX) );
}
if (confirmPatch == nullptr)
{
confirmPatch = static_cast<patch_t *>(W_CachePatchName("TUTDIAG2", PU_HUDGFX) );
} }
} }
void Dialogue::Draw(void) void Dialogue::Draw(void)
{ {
if (Active() == false) if (slide == 0)
{ {
return; return;
} }
UpdatePatches(); srb2::Draw drawer =
srb2::Draw(
0, FixedToFloat(Easing_OutCubic(slide, -78 * FRACUNIT, 0))
).flags(V_SNAPTOTOP);
V_DrawFixedPatch( drawer.patch("TUTDIAG1");
0, 0,
FRACUNIT,
V_SNAPTOTOP,
bgPatch,
nullptr
);
if (portrait != nullptr) if (portrait != nullptr)
{ {
V_DrawFixedPatch( drawer
10 * FRACUNIT, 41 * FRACUNIT, .xy(10, 41)
FRACUNIT, .colormap(portraitColormap)
V_SNAPTOTOP, .patch(portrait);
portrait,
portraitColormap
);
} }
V_DrawString( drawer
45, 39, .xy(45, 39)
V_SNAPTOTOP, .font(srb2::Draw::Font::kConsole)
speaker.c_str() .text( speaker.c_str() );
);
V_DrawString( drawer
10, 3, .xy(10, 3)
V_SNAPTOTOP, .font(srb2::Draw::Font::kConsole)
text.c_str() .text( text.c_str() );
);
if (textDone) if (Dismissable() && TextDone() && Active())
{ {
V_DrawFixedPatch( drawer
304 * FRACUNIT, 7 * FRACUNIT, .xy(304, 7)
FRACUNIT, .patch("TUTDIAG2");
V_SNAPTOTOP,
confirmPatch,
nullptr
);
} }
} }
void Dialogue::Dismiss(void) void Dialogue::Dismiss(void)
{ {
if (Active() == false) active = false;
{ dismissable = false;
return;
}
SetSpeaker();
text.clear(); text.clear();
textDest.clear(); textDest.clear();
}
if (G_GamestateUsesLevel() == true && !script.empty()) void Dialogue::Unset(void)
{ {
ACS_Execute(script.c_str(), nullptr, 0, nullptr); Dismiss();
} SetSpeaker();
script.clear();
} }
/* /*
@ -264,9 +290,9 @@ void Dialogue::Dismiss(void)
Dialogue g_dialogue; Dialogue g_dialogue;
void K_DismissDialogue(void) void K_UnsetDialogue(void)
{ {
g_dialogue.Dismiss(); g_dialogue.Unset();
} }
void K_DrawDialogue(void) void K_DrawDialogue(void)

View file

@ -21,7 +21,7 @@
extern "C" { extern "C" {
#endif #endif
void K_DismissDialogue(void); void K_UnsetDialogue(void);
void K_DrawDialogue(void); void K_DrawDialogue(void);
void K_TickDialogue(void); void K_TickDialogue(void);

View file

@ -30,8 +30,6 @@ private:
patch_t *bgPatch; patch_t *bgPatch;
patch_t *confirmPatch; patch_t *confirmPatch;
bool active;
std::string speaker; std::string speaker;
patch_t *portrait; patch_t *portrait;
UINT8 *portraitColormap; UINT8 *portraitColormap;
@ -39,21 +37,25 @@ private:
std::string text; std::string text;
std::string textDest; std::string textDest;
bool active;
fixed_t slide;
fixed_t textTimer; fixed_t textTimer;
fixed_t textSpeed; fixed_t textSpeed;
bool textDone; bool textDone;
bool freeze; bool dismissable;
std::string script;
void UpdatePatches(void); void Init(void);
//void Unset(void);
void WriteText(void); void WriteText(void);
void CompleteText(void); void CompleteText(void);
public: public:
static constexpr fixed_t kTextSpeedDefault = FRACUNIT; static constexpr fixed_t kTextSpeedDefault = FRACUNIT;
static constexpr fixed_t kTextPunctPause = FRACUNIT * TICRATE * 3 / 5; static constexpr fixed_t kTextPunctPause = (FRACUNIT * TICRATE * 2) / 5;
static constexpr fixed_t kSlideSpeed = FRACUNIT / (TICRATE / 5);
void SetSpeaker(void); void SetSpeaker(void);
void SetSpeaker(std::string skinName, int portraitID); void SetSpeaker(std::string skinName, int portraitID);
@ -63,11 +65,14 @@ public:
bool Active(void); bool Active(void);
bool TextDone(void); bool TextDone(void);
bool Dismissable(void);
void SetDismissable(bool value);
void Tick(void); void Tick(void);
void Draw(void); void Draw(void);
void Dismiss(void); void Dismiss(void);
void Unset(void);
}; };
}; // namespace srb2 }; // namespace srb2

View file

@ -8299,6 +8299,8 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
// Close text prompt before freeing the old level // Close text prompt before freeing the old level
F_EndTextPrompt(false, true); F_EndTextPrompt(false, true);
K_UnsetDialogue();
LUA_InvalidateLevel(); LUA_InvalidateLevel();
for (ss = sectors; sectors+numsectors != ss; ss++) for (ss = sectors; sectors+numsectors != ss; ss++)