2026-02-14 02:14:19 -05:00
|
|
|
////////////////////////////////////////////////////////////
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
2026-02-14 02:14:19 -05:00
|
|
|
// ConsoleOutput.h
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
2026-02-14 02:14:19 -05:00
|
|
|
// Optional helper for the console window. The
|
|
|
|
|
// GameMode blueprint can use this class to store
|
|
|
|
|
// console text as one big string with newlines.
|
2026-02-14 01:25:04 -05:00
|
|
|
//
|
2026-02-14 02:14:19 -05:00
|
|
|
// A dirty bit is set whenever text is appended,
|
|
|
|
|
// so the blueprint only needs to update the widget
|
|
|
|
|
// when the text has actually changed.
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
2026-02-14 02:14:19 -05:00
|
|
|
////////////////////////////////////////////////////////////
|
2025-03-28 23:31:44 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-06-18 16:25:46 -04:00
|
|
|
#include "Containers/UnrealString.h"
|
2025-12-09 02:42:13 -05:00
|
|
|
#include "ConsoleOutput.generated.h"
|
|
|
|
|
|
2026-02-14 02:14:19 -05:00
|
|
|
////////////////////////////////////////////////////////////
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
2026-02-14 02:14:19 -05:00
|
|
|
// UlxConsoleOutput
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
2026-02-09 16:07:15 -05:00
|
|
|
// When the lua code executes a print statement, the text
|
|
|
|
|
// eventually gets passed to the GameMode blueprint: see
|
|
|
|
|
// Docs/Print-Statement-Handling.md for more information.
|
|
|
|
|
//
|
|
|
|
|
// The GameMode blueprint is expected to create a virtual
|
|
|
|
|
// console of some sort to display the print statements.
|
|
|
|
|
// This class, ConsoleOutput, is a class that the GameMode
|
|
|
|
|
// can optionally use to help implement that virtual console.
|
|
|
|
|
//
|
|
|
|
|
// This class just collects the print statements and keeps
|
|
|
|
|
// a record of what text is in the virtual console. The
|
|
|
|
|
// text is stored as one big string.
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
|
|
|
|
// This class also contains a 'dirty' bit. Each time somebody
|
|
|
|
|
// appends a line of text to the console, the dirty bit is
|
|
|
|
|
// automatically set. The bit can be checked using 'IsDirty'
|
2026-02-09 16:07:15 -05:00
|
|
|
// and cleared using 'ClearDirty'. Assuming that the GameMode
|
|
|
|
|
// is maintaining a text widget of some sort, the GameMode
|
|
|
|
|
// can transfer the contents of this buffer into the text
|
|
|
|
|
// widget only when the dirty bit is set.
|
|
|
|
|
//
|
|
|
|
|
// Note that the GameMode is not obligated to use this class.
|
|
|
|
|
// If the GameMode wants to use some other framework to
|
|
|
|
|
// implement the virtual console, that's perfectly fine.
|
2025-03-28 23:31:44 -04:00
|
|
|
//
|
2026-02-14 02:14:19 -05:00
|
|
|
////////////////////////////////////////////////////////////
|
2025-03-28 23:31:44 -04:00
|
|
|
|
2025-12-09 02:42:13 -05:00
|
|
|
UCLASS(BlueprintType)
|
|
|
|
|
class UlxConsoleOutput : public UObject
|
|
|
|
|
{
|
|
|
|
|
GENERATED_BODY()
|
|
|
|
|
|
2025-03-28 23:31:44 -04:00
|
|
|
private:
|
|
|
|
|
FString Content;
|
|
|
|
|
bool Dirty;
|
|
|
|
|
|
2025-12-09 02:42:13 -05:00
|
|
|
private:
|
2026-02-14 02:14:19 -05:00
|
|
|
// Truncate the console to a reasonable number of lines.
|
|
|
|
|
// The length is hardwired.
|
|
|
|
|
//
|
2025-03-28 23:31:44 -04:00
|
|
|
void Truncate();
|
|
|
|
|
|
2026-02-14 02:14:19 -05:00
|
|
|
// Add a newline if there isn't one.
|
|
|
|
|
//
|
|
|
|
|
// Returns true if it changed anything.
|
|
|
|
|
//
|
2025-03-28 23:31:44 -04:00
|
|
|
bool MaybeAppendNewline();
|
|
|
|
|
|
2026-02-14 02:14:19 -05:00
|
|
|
// Append text.
|
|
|
|
|
//
|
|
|
|
|
// Returns true if it changed anything.
|
|
|
|
|
//
|
2025-03-28 23:31:44 -04:00
|
|
|
bool MaybeAppendText(const FString& text);
|
|
|
|
|
|
|
|
|
|
public:
|
2026-02-14 02:14:19 -05:00
|
|
|
// Append text to the console.
|
|
|
|
|
//
|
2025-12-09 02:42:13 -05:00
|
|
|
UFUNCTION(BlueprintCallable)
|
2025-03-28 23:31:44 -04:00
|
|
|
void Append(const FString& text);
|
|
|
|
|
|
2026-02-14 02:14:19 -05:00
|
|
|
// Append text on a line by itself.
|
|
|
|
|
//
|
2025-12-09 02:42:13 -05:00
|
|
|
UFUNCTION(BlueprintCallable)
|
2025-03-28 23:31:44 -04:00
|
|
|
void AppendLine(const FString& text);
|
|
|
|
|
|
|
|
|
|
// Get the console text as a string.
|
2026-02-14 02:14:19 -05:00
|
|
|
//
|
2025-12-09 02:42:13 -05:00
|
|
|
UFUNCTION(BlueprintCallable)
|
2025-03-28 23:31:44 -04:00
|
|
|
const FString& Get() const { return Content; }
|
2026-02-14 02:14:19 -05:00
|
|
|
|
2025-03-28 23:31:44 -04:00
|
|
|
// Return if the dirty flag is set.
|
2026-02-14 02:14:19 -05:00
|
|
|
//
|
2025-12-09 02:42:13 -05:00
|
|
|
UFUNCTION(BlueprintCallable)
|
2025-03-28 23:31:44 -04:00
|
|
|
bool IsDirty() const { return Dirty; }
|
|
|
|
|
|
|
|
|
|
// Clear the dirty flag.
|
2026-02-14 02:14:19 -05:00
|
|
|
//
|
2025-12-09 02:42:13 -05:00
|
|
|
UFUNCTION(BlueprintCallable)
|
2025-03-28 23:31:44 -04:00
|
|
|
void ClearDirty() { Dirty = false; }
|
|
|
|
|
};
|