1 2 #ifndef _TEXTBOX_H 3 #define _TEXTBOX_H 4 #include "ItemImage.h" 5 #include "SaveSelect.h" 6 #include "StageSelect.h" 7 #include "YesNoPrompt.h" 8 9 #include <array> 10 #include <cstdint> 11 #include <string> 12 13 #define MSG_W 244 14 #define MSG_H 64 15 #define MSG_UPPER_Y 24 16 17 #define MSG_NLINES 4 18 #define MSG_LINE_SPACING 16 19 20 enum TBFlags 21 { 22 TB_DEFAULTS = 0x00, 23 24 TB_DRAW_AT_TOP = 0x01, 25 TB_NO_BORDER = 0x02, 26 27 TB_LINE_AT_ONCE = 0x04, 28 TB_VARIABLE_WIDTH_CHARS = 0x08, 29 TB_CURSOR_NEVER_SHOWN = 0x10 30 }; 31 32 class TextBox 33 { 34 public: 35 bool Init(); 36 void Deinit(); 37 38 void SetVisible(bool enable, uint8_t flags = TB_DEFAULTS); 39 void ResetState(); 40 41 void AddText(const std::string &str); 42 void SetText(const std::string &str); 43 void ClearText(); 44 void RecalculateOffsets(); 45 46 void SetFace(int newface); 47 48 void SetFlags(uint8_t flags, bool enable); 49 void SetFlags(uint8_t flags); 50 void ShowCursor(bool enable); 51 52 TB_YNJPrompt YesNoPrompt; 53 TB_ItemImage ItemImage; 54 TB_StageSelect StageSelect; 55 TB_SaveSelect SaveSelect; 56 57 bool IsVisible(); 58 bool IsBusy(); 59 60 void Draw(); 61 void Tick(); 62 static void DrawFrame(int x, int y, int w, int h); 63 GetFlags()64 uint8_t GetFlags() 65 { 66 return fFlags; 67 } 68 void SetCanSpeedUp(bool newstate); 69 70 private: 71 void DrawTextBox(); 72 void TickTextBox(); 73 int GetMaxLineLen(); 74 void AddNextChar(); 75 76 bool fVisible; 77 uint8_t fFlags; 78 79 uint8_t fFace; // current NPC face or 0 if none 80 int fFaceXOffset; // for face slide-in animation 81 uint8_t faceFrame; 82 uint8_t faceStep = 1; 83 uint32_t faceTimer = 0; 84 85 // currently visible lines 86 std::array<std::string, MSG_NLINES> fLines; 87 int fCurLine; 88 int fCurLineLen; 89 90 // handles scrolling lines off 91 bool fScrolling; 92 int fTextYOffset; 93 94 // chars waiting to be added 95 std::string fCharsWaiting; 96 97 int fTextTimer; 98 bool fCanSpeedUp; 99 100 // blinking cursor control 101 bool fCursorVisible; 102 int fCursorTimer; 103 104 struct 105 { 106 int x, y; 107 int w, h; 108 } fCoords; 109 }; 110 111 #endif 112