Class: TonMessage

ADVゲームのようなメッセージウィンドウ機能を提供します。スクリプトテキスト内のタグにより演出を制御できます。

Methods

void LoadScript(string filePath, string scriptName = null)

スクリプトファイルを読み込み、再生を開始します。

注意: MGCB Editorでスクリプトファイルを追加する際は、Build ActionCopy に設定してください。多分UTF-8(BOM無し)がいいです。

void SetWindowRect(int x, int y, int width, int height)

メッセージウィンドウの表示位置とサイズを設定します。

void Show(string scriptText)

テキストを表示キューに追加し、ウィンドウを表示します。

void Next()

メッセージを送り、次のページへ進むか、表示を終了します。

void Close()

ウィンドウを閉じます。

bool IsBusy()

テキスト送り中、または入力待ち状態かどうかを返します。

void SetTextStyle(float scale, float lineSpacing, float kerningOffset = 0f)

文字の基本サイズ、行間の高さ(px)、文字間隔のオフセット(px)を設定します。

void Update(GameTime gameTime, bool isInput = false)

メッセージの文字送り処理や待機時間の更新を行います。毎フレーム呼び出してください。

void SetTextSpeed(float speedMs)

デフォルトの文字送り速度(1文字あたりの表示時間ms)を設定します(初期値=50ms)。

string GetEvent()

[event:xxx]タグでキューイングされたイベントIDを取得します。

Supported Tags

使用可能なタグ一覧

テキスト中に以下のタグを埋め込むことで、表示を制御できます。

Sample Code

// In Initialize()
// Set position and size
Ton.Msg.SetWindowRect(20, 400, 600, 150);

// Show Message Script
string script = 
    "Hello.[wait:500] This is [color:Red]Red Text[reset].\n" +
    "Welcome to [icon:icon_star] Mononotonka.[next]" +
    "Select an option:\n" +
    "[event:opt1] Option 1 (Yes)\n" +
    "[event:opt2] Option 2 (No)";
Ton.Msg.Show(script);


// In Update()
// Advance text on input ("A" button or B button)
bool isInput = Ton.Input.IsJustPressed("A") || Ton.Input.IsJustPressed("B");
Ton.Msg.Update(gameTime, isInput); // Don't forget to pass gameTime!

// Check for Event (Selection)
string eventId = Ton.Msg.GetEvent();
if (eventId != null)
{
    if (eventId == "opt1") { /* Selected Yes */ }
    else if (eventId == "opt2") { /* Selected No */ }
}

// Check if busy
if (Ton.Msg.IsBusy())
{
    // Pause game logic while message is showing?
}

Script Format

スクリプトファイル内では、行頭に # を付けることで複数のスクリプトを記述できます。

また、行頭に ; を付けるとコメント行となり、表示されません。

#Opening
; これはコメントです
[icon:Hero] こんにちは!
これはオープニングです。[next]

#Ending
[icon:Hero] ありがとう!
また会いましょう。[next]

Sample Code

// Initialize
Ton.msg.Initialize();

// Load script from file (Play "Opening" section)
Ton.msg.LoadScript("script/scenario.txt", "Opening");

// Manual Control
if (Ton.input.IsJustPressed("A"))
{
    Ton.msg.Next();
}