1 #ifndef TEXT_HEADER_FILE__ 2 #define TEXT_HEADER_FILE__ 3 4 /* This file contains functions for reading text from files and 5 * storing it in the game. The entire text file will be kept in memory. 6 * Each text object will have the ability to return a line, 7 * track its position in the text or return a random line. 8 * This should allow for better multi-language handling, faster 9 * access to tank speech and remove the need to rely on the lineseq 10 * class. 11 * -- Jesse 12 */ 13 14 #include <cstdint> 15 16 #define MAX_LINE_LENGTH 512 17 #define MAX_LINES_IN_FILE 1024 18 19 struct BOX; 20 21 /// @brief alignment of texts 22 enum alignType { 23 CENTRE = 0, 24 LEFT, 25 RIGHT 26 }; 27 28 29 class TEXTBLOCK 30 { 31 public: 32 33 /* ----------------------------------- 34 * --- Constructors and destructor --- 35 * ----------------------------------- 36 */ 37 38 TEXTBLOCK (); 39 TEXTBLOCK (const char* filename); 40 ~TEXTBLOCK(); 41 42 43 /* ---------------------- 44 * --- Public methods --- 45 * ---------------------- 46 */ 47 48 int32_t Display_All (bool show_line_numbers); // display all text 49 const char* Get_Current_Line() const; // return current line 50 const char* Get_Line (int32_t index) const; // return a specific line 51 const char* Get_Random_Line () const; // give us a random line 52 bool Load_File (const char *filename); // load lines from a file 53 int32_t Lines () const; // Return number of total lines 54 bool Next_Line (); // advance the current line 55 bool Previous_Line (); // move the current line back 56 void Render_Lines (int32_t scrollOffset, 57 int32_t spacing, 58 int32_t top, 59 int32_t bottom); // Render to global.canvas 60 61 62 private: 63 64 /* ----------------------- 65 * --- Private methods --- 66 * ----------------------- 67 */ 68 69 void destroy(); 70 71 72 /* ----------------------- 73 * --- Private members --- 74 * ----------------------- 75 */ 76 77 int32_t total_lines = 0; 78 int32_t current_line = 0; 79 char** complete_text = nullptr; 80 }; 81 82 83 84 85 // Functions we can use anywhere 86 87 // This function returns a string with 88 // comma characters between thousands positions 89 // You *MUST* *NOT* free the returned string. 90 const char* Add_Comma(int32_t number); 91 92 void draw_text_in_box(BOX* region, const char* text, bool with_box); 93 94 // hack the newline off a string 95 void Trim_Newline(char *line); 96 97 #endif 98 99