njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
njin_dialog.h
1#pragma once
2#include "_math.h"
3#include "_types.h"
4#include "njin_json.h"
5#include "njin_ui.h"
6#include <functional>
7#include <string>
8#include <vector>
9
10namespace njin {
11struct context;
12
15
18 std::string text;
19 std::string next;
20 std::string event;
21 std::string cond;
22};
23
26 std::string id;
27 std::string speaker;
28 std::string text;
29 std::string portrait;
30 std::string next;
31 std::string event;
32 std::string cond;
33 std::vector<dialog_choice> choices;
34};
35
50 std::vector<dialog_node> nodes;
51 std::string start;
52};
53
58bool dialog_parse(const json_value &json, dialog_script &out);
59
64bool dialog_load(const char *path, dialog_script &out);
65
91
95
97void dialog_set_style(context &ctx, const dialog_style &style);
98
100dialog_style dialog_get_style(const context &ctx);
101
107void dialog_portrait(context &ctx, const char *name, texture_handle texture, rect source = {});
108
114void dialog_set_condition(context &ctx, std::function<bool(context &, const std::string &)> fn);
115
125void dialog_start(context &ctx, const dialog_script &script, const char *start = nullptr);
126
132void dialog_say(context &ctx, const char *speaker, const char *text, const char *portrait = nullptr);
133
135bool dialog_active(const context &ctx);
136
138void dialog_stop(context &ctx);
139
142 std::string name;
143 std::string node;
144};
145
148 std::string last_node;
149};
150
151} // namespace njin
bool dialog_parse(const json_value &json, dialog_script &out)
Đọc một đoạn hội thoại từ JSON (dạng ở njin::dialog_script).
bool dialog_load(const char *path, dialog_script &out)
Nạp một đoạn hội thoại từ file JSON.
void dialog_portrait(context &ctx, const char *name, texture_handle texture, rect source={})
Đăng ký một chân dung để các câu thoại gọi tên ("portrait": "oldman").
void dialog_start(context &ctx, const dialog_script &script, const char *start=nullptr)
Bắt đầu một đoạn hội thoại.
void dialog_stop(context &ctx)
Đóng hộp thoại ngay (gửi njin::dialog_ended).
void dialog_set_style(context &ctx, const dialog_style &style)
Đặt giao diện cho hộp thoại.
dialog_style dialog_default_style()
Giao diện mặc định: hộp tối ở dưới, cùng tông với UI mặc định.
void dialog_say(context &ctx, const char *speaker, const char *text, const char *portrait=nullptr)
Nói một câu lẻ, không cần kịch bản: biển báo, đồ vật.
dialog_style dialog_get_style(const context &ctx)
Giao diện hiện tại.
void dialog_set_condition(context &ctx, std::function< bool(context &, const std::string &)> fn)
Hàm kiểm tra điều kiện cond của câu thoại và lựa chọn: nhận chuỗi điều kiện, trả về đúng hay sai.
bool dialog_active(const context &ctx)
Hộp thoại có đang mở không.
std::int32_t i32
Số nguyên có dấu 32 bit.
Definition _types.h:14
float f32
Số thực 32 bit.
Definition _types.h:28
Định danh của một action nhập liệu, tạo bởi action_register().
Definition _types.h:85
Một lựa chọn trả lời trong hộp thoại.
Definition njin_dialog.h:17
std::string text
Chữ hiện. Bắt đầu bằng @ là khóa dịch (xem tr()).
Definition njin_dialog.h:18
std::string next
Nút đi tới khi chọn. Rỗng là kết thúc hội thoại.
Definition njin_dialog.h:19
std::string cond
Chỉ hiện khi điều kiện này đúng (xem dialog_set_condition()).
Definition njin_dialog.h:21
std::string event
Tên event gửi khi chọn (njin::dialog_event). Có thể rỗng.
Definition njin_dialog.h:20
Event: hội thoại vừa kết thúc.
Definition njin_dialog.h:147
std::string last_node
Nút cuối cùng đã hiện.
Definition njin_dialog.h:148
Event: một câu thoại hoặc lựa chọn có event vừa được kích hoạt.
Definition njin_dialog.h:141
std::string node
Nút phát ra nó.
Definition njin_dialog.h:143
std::string name
Tên event trong kịch bản.
Definition njin_dialog.h:142
Một câu thoại: ai nói, nói gì, rồi đi đâu.
Definition njin_dialog.h:25
std::vector< dialog_choice > choices
Các lựa chọn, hiện sau khi chữ chạy xong.
Definition njin_dialog.h:33
std::string id
Tên nút, để next trỏ tới.
Definition njin_dialog.h:26
std::string portrait
Tên chân dung đã đăng ký bằng dialog_portrait(). Có thể rỗng.
Definition njin_dialog.h:29
std::string cond
Bỏ qua câu này (đi thẳng tới next) khi điều kiện sai.
Definition njin_dialog.h:32
std::string speaker
Tên người nói. Rỗng là lời dẫn. @ là khóa dịch.
Definition njin_dialog.h:27
std::string text
Nội dung. @ là khóa dịch. Tự xuống dòng.
Definition njin_dialog.h:28
std::string next
Nút kế tiếp khi không có lựa chọn. Rỗng là hết.
Definition njin_dialog.h:30
std::string event
Event gửi khi câu này hiện ra. Có thể rỗng.
Definition njin_dialog.h:31
Một đoạn hội thoại: nhiều nút nối với nhau.
Definition njin_dialog.h:49
std::string start
Nút bắt đầu. Rỗng là nút đầu tiên.
Definition njin_dialog.h:51
std::vector< dialog_node > nodes
Các nút.
Definition njin_dialog.h:50
Giao diện của hộp thoại.
Definition njin_dialog.h:70
f32 max_width
Chiều rộng tối đa của hộp.
Definition njin_dialog.h:77
f32 chars_per_second
Tốc độ chữ chạy. 0 là hiện ngay cả câu.
Definition njin_dialog.h:79
f32 margin
Khoảng từ mép màn hình.
Definition njin_dialog.h:75
f32 scale
Nhân mọi kích thước.
Definition njin_dialog.h:73
ui_look choice
Lựa chọn: normal, focused và màu chữ tương ứng.
Definition njin_dialog.h:82
bool pause_game
Dừng thời gian của game (time_set_paused()) khi hộp thoại đang mở.
Definition njin_dialog.h:87
i32 lines
Số dòng chữ của hộp.
Definition njin_dialog.h:74
ui_look box
Nền hộp (normal) và màu chữ (text).
Definition njin_dialog.h:80
action_handle advance
Action cũng dùng để sang câu, ngoài Enter, Space, nút A và chuột trái.
Definition njin_dialog.h:89
bool top
Đặt hộp ở trên màn hình thay vì dưới.
Definition njin_dialog.h:78
f32 font_size
Cỡ chữ, pixel.
Definition njin_dialog.h:72
f32 padding
Khoảng từ mép hộp vào chữ.
Definition njin_dialog.h:76
sound_handle sound_blip
Phát khi chữ chạy (mỗi vài ký tự). Có thể để trống.
Definition njin_dialog.h:84
sound_handle sound_next
Phát khi sang câu hoặc chọn.
Definition njin_dialog.h:85
vec2 portrait_size
Kích thước chân dung. 0 là vừa chiều cao chữ.
Definition njin_dialog.h:83
font_handle font
Phông chữ. Mặc định là phông của UI.
Definition njin_dialog.h:71
ui_look name
Thẻ tên người nói: nền (normal) và màu chữ (text).
Definition njin_dialog.h:81
Định danh của một font, tạo bởi font_load().
Definition _types.h:131
Một giá trị JSON: null, bool, số, chuỗi, mảng hoặc object.
Definition njin_json.h:33
Hình chữ nhật thẳng trục: pos là góc trên trái, size là rộng và cao.
Definition _math.h:13
Định danh của một âm thanh ngắn (sound), tạo bởi sound_load().
Definition _types.h:116
Định danh của một texture, tạo bởi texture_load().
Definition _types.h:146
Diện mạo của một loại widget ở từng trạng thái.
Definition njin_ui.h:41
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39