add logic show emoji for typingPreview and file md

This commit is contained in:
CuongNV
2026-04-25 11:37:57 +07:00
parent 0c6f73b4db
commit 99cb7d0fc0
4 changed files with 481 additions and 27 deletions
+4 -4
View File
@@ -13,7 +13,7 @@ namespace BrewMonster.Scripts.ChatUI
[Tooltip("Root của box xem trước nội dung đang gõ.")]
[SerializeField] private GameObject typingPreviewRoot;
[Tooltip("Text hiển thị nội dung đang gõ realtime.")]
[SerializeField] private TextMeshProUGUI typingPreviewText;
[SerializeField] private TMP_InputField typingPreviewText;
[Tooltip("Rect của preview box để neo theo keyboard.")]
[SerializeField] private RectTransform typingPreviewRect;
[Tooltip("Khoảng cách dọc cộng thêm cho preview box.")]
@@ -49,12 +49,12 @@ namespace BrewMonster.Scripts.ChatUI
if (typingPreviewRoot == null || typingPreviewText == null)
return;
string trimmedBody = (body ?? string.Empty).Trim();
string previewBody = body ?? string.Empty;
bool keyboardVisible = IsMobileKeyboardVisible();
bool shouldShow = keyboardVisible && isInputFocused && !string.IsNullOrEmpty(trimmedBody);
bool shouldShow = keyboardVisible && isInputFocused;
typingPreviewRoot.SetActive(shouldShow);
if (shouldShow)
typingPreviewText.text = trimmedBody;
typingPreviewText.text = previewBody;
}
bool IsMobileKeyboardVisible()
+60
View File
@@ -0,0 +1,60 @@
# Typing Preview - Summary
## Muc tieu da thuc hien
- Tach logic `typingPreview` ra class rieng de de tai su dung.
- Lien ket lai logic giua `ChatInputHandler` va `TypingPreviewController`.
- Dieu chinh co che hien/an theo yeu cau mobile keyboard.
## Cac file da cap nhat
- `Assets/Scripts/TypingPreviewController.cs`
- `Assets/Scripts/ChatInputHandler.cs`
## Noi dung da lam
### 1) Tach typing preview thanh class rieng
- Tao class `TypingPreviewController` de quan ly:
- Hien/an preview (`typingPreviewRoot`)
- Cap nhat text preview realtime (`typingPreviewText`)
- Dinh vi preview theo offset keyboard (`typingPreviewRect`, `previewVerticalOffset`)
### 2) Lien ket voi ChatInputHandler
- `ChatInputHandler` giu `SerializeField`:
- `TypingPreviewController typingPreview`
- Moi khi input thay doi text, `ChatInputHandler` lay message body (bo prefix kenh/whisper) roi day sang controller de cap nhat preview.
- Khi clear input, preview duoc cap nhat lai ngay de an dung trang thai.
### 3) Co che mobile keyboard (cap nhat moi nhat)
- Da chuyen logic check keyboard vao thang `TypingPreviewController`:
- `IsMobileKeyboardVisible()`
- `GetVisibleKeyboardHeight()`
- `ChatInputHandler` da bo cac ham keyboard-check khong con dung.
- `ChatInputHandler` chi can goi `typingPreview.UpdatePreview(isFocused, body)`.
- `ChatInputHandler.Update()` van refresh moi frame de bat kip luc keyboard mo/dong.
- Rule hien moi nhat:
- Keyboard mobile vua mo la preview show ngay (neu input dang focus), khong can cho co ky tu.
## Hanh vi hien tai
- Preview chi hien khi:
- Dang o mobile
- Keyboard dang mo
- Input dang focus
- Khong con yeu cau body phai khong rong (show ngay khi keyboard mo).
- Khi tat keyboard, preview an ngay.
- Khi mo lai keyboard, noi dung da go truoc do van con trong input va preview hien lai dung noi dung.
## Emoji tren preview
- Hien tai preview duoc set text truc tiep tu `body`, nen neu `body` co TMP sprite tag thi co the hien emoji.
- Luu y cau hinh component:
- `typingPreviewText` dang de kieu `TMP_InputField` trong `TypingPreviewController`.
- Neu muon on dinh cho muc dich "preview display", nen doi sang `TMP_Text` hoac `TextMeshProUGUI`.
## Ghi chu
- Da kiem tra lint sau cac lan sua, khong phat hien loi lint moi tren cac file da chinh.
@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 85a85257c23e84e41ba29cbc51455178
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: