MSGLIST.H 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /CounterStrike/MSGLIST.H 2 3/04/97 2:53p Joe_bostic $ */
  19. /***************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * File Name : MSGLIST.H *
  25. * *
  26. * Programmer : Bill R. Randolph *
  27. * *
  28. * Start Date : 05/22/95 *
  29. * *
  30. * Last Update : May 22, 1995 [BRR] *
  31. * *
  32. * Initializing: *
  33. * Call Init(), giving it the coords of the upper-left corner to display *
  34. * the messages, the coordinates to display the editable message, max # *
  35. * messages allowed, max # chars per message, and the pixel height of *
  36. * the font. MaxChars should be less than or equal to the define *
  37. * MAX_MESSAGE_LENGTH. *
  38. * *
  39. * Displaying a message: *
  40. * Call Add_Message(); the buffer you pass in is copied into a static *
  41. * buffer in this class. Each message is given a timeout; after this *
  42. * time, the message is removed from the displayed list. *
  43. * Each message also has a 2-byte ID, which can be used to identify the
  44. * sender.
  45. * *
  46. * Editing a message: *
  47. * Call Add_Edit(), giving it the color & style to print in. An *
  48. * optional "To xxx" prefix is allowed. The edit message can appear in *
  49. * the message list itself (it's placed first), or at a separate screen *
  50. * location, depending on the values passed to Init(). *
  51. * *
  52. * Updating messages: *
  53. * The Input() routine passes new keys to the editable message; this *
  54. * routine's return code tells the app whether to redraw the messages, *
  55. * and whether to send it the edit message. As the user types *
  56. * characters into the edit field, if he overflows the max storage *
  57. * for the edit field, the field is parsed & the first few words *
  58. * removed; these words are put into the Overflow buffer, and the app *
  59. * is told so; the app should send this buffer across to the destination.*
  60. * *
  61. * - MessageList is a gadget list of all current messages *
  62. * - MessageX & Y are the upper left corner of the 1st message *
  63. * - MaxMessages is the max # of messages allowed, including the editable *
  64. * message; 0 = no limit. *
  65. * - MaxChars is the max # of chars allowed per message *
  66. * - Height is the pixel height of a single line *
  67. * - EditLabel points to the textmessage gadget for the current editable *
  68. * field. EditBuf points to the char buffer being edited. EditInitPos *
  69. * & EditCurPos define buffer index positions. *
  70. * - EditSendAddress is the IPX Address to send the message to when RETURN *
  71. * is pressed. *
  72. * *
  73. * The low word in the UserData field in the TextLabelClass tells what the *
  74. * timeout for each message is (0 = none); the high byte of the UserData *
  75. * field is used for the text message ID. *
  76. * When a message's timeout expires, it's deleted. When a new message *
  77. * is added, the top message is deleted if MPlayerMaxMessages is exceeded. *
  78. * *
  79. * The Edit-able message is never deleted until ESC or RETURN is pressed. *
  80. * *
  81. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  82. #ifndef MSGLIST_H
  83. #define MSGLIST_H
  84. //***************************************************************************
  85. // Defines
  86. //***************************************************************************
  87. //---------------------------------------------------------------------------
  88. // Max length of inter-player message buffers. Messages.Init() should specify
  89. // a value <= this. For editing messages, the "to" field length is added to
  90. // this length to generate the entire editable message length. For displayed
  91. // messages, a "From" prefix length should be added to this value to generate
  92. // the entire max displayable message length.
  93. //---------------------------------------------------------------------------
  94. #define MAX_MESSAGE_LENGTH 120
  95. //---------------------------------------------------------------------------
  96. // Max # of allowed messages at one time
  97. //---------------------------------------------------------------------------
  98. #define MAX_NUM_MESSAGES 14
  99. //***************************************************************************
  100. // Forward declarations
  101. //***************************************************************************
  102. class TextLabelClass;
  103. //***************************************************************************
  104. // Class declaration
  105. //***************************************************************************
  106. class MessageListClass {
  107. public:
  108. //.....................................................................
  109. // Constructor/Destructor
  110. //.....................................................................
  111. MessageListClass (void);
  112. ~MessageListClass ();
  113. //.....................................................................
  114. // Initialization
  115. //.....................................................................
  116. void Reset(void);
  117. void Init (int x, int y, int max_msg, int maxchars, int height,
  118. int edit_x, int edit_y, int overflow_on, int over_start,
  119. int over_end, int width = 640);
  120. TextLabelClass * Add_Message (char const * name, int id, char const * txt,
  121. PlayerColorType color, TextPrintType style, int timeout);
  122. int Concat_Message (char const * name, int id, char const * txt, int timeout);
  123. //.....................................................................
  124. // Message access utility routines
  125. //.....................................................................
  126. char * Get_Message (int id);
  127. TextLabelClass * Get_Label (int id);
  128. //.....................................................................
  129. // Message-editing support routines
  130. //.....................................................................
  131. TextLabelClass * Add_Edit(PlayerColorType color, TextPrintType style,
  132. char *to, char cursor = 0, int width = 640);
  133. void Remove_Edit (void);
  134. char * Get_Edit_Buf (void);
  135. char * Get_Overflow_Buf (void) {return (OverflowBuf);}
  136. void Clear_Overflow_Buf (void) {OverflowBuf[0] = 0;}
  137. int Is_Edit(void) {return (IsEdit);}
  138. void Set_Edit_Color(PlayerColorType color);
  139. //.....................................................................
  140. // Maintenance routines
  141. //.....................................................................
  142. int Manage (void);
  143. int Input (KeyNumType &input);
  144. void Draw(void);
  145. int Num_Messages(void);
  146. void Set_Width(int width);
  147. void Set_Edit_Focus(void);
  148. bool Has_Edit_Focus(void);
  149. private:
  150. //.....................................................................
  151. // Message parsing
  152. //.....................................................................
  153. int Trim_Message(char *dest, char *src, int min_chars, int max_chars,
  154. int scandir);
  155. //.....................................................................
  156. // Compute the y-coord of the message list
  157. //.....................................................................
  158. void Compute_Y(void);
  159. //.....................................................................
  160. // Private Data
  161. //.....................................................................
  162. TextLabelClass * MessageList; // list of messages
  163. int MessageX; // x-coord of upper-left
  164. int MessageY; // y-coord of upper-left
  165. int MaxMessages; // max messages allowed
  166. int MaxChars; // max allowed chars per message
  167. int Height; // height in pixels
  168. //.....................................................................
  169. // Data for the edit field: the edit field will either appear at
  170. // exact coordinates specified by the application, or it will appear
  171. // vertically above the other messages.
  172. //.....................................................................
  173. unsigned EnableOverflow : 1; // 1 = enable overflow feature
  174. unsigned IsEdit : 1; // 1 = there's an edit field
  175. unsigned AdjustEdit : 1; // 1 = edit field appears over msgs
  176. int EditX; // x-coord of edit field
  177. int EditY; // y-coord of edit field
  178. TextLabelClass *EditLabel; // ptr to current edit label
  179. char EditBuf[MAX_MESSAGE_LENGTH + 30]; // buffer for editable message
  180. char OverflowBuf[MAX_MESSAGE_LENGTH + 30]; // overflow area
  181. int EditCurPos; // current edit position
  182. int EditInitPos; // initial edit position
  183. char CursorChar; // character to use a cursor
  184. int OverflowStart; // 1st index for overflow trimming
  185. int OverflowEnd; // last index for overflow trimming
  186. int Width; // Maximum width in pixels of editable string
  187. //.....................................................................
  188. // Buffers provided for messages. They must be long enough for
  189. // both the message, and for the "To" prefix on edited messages, or
  190. // the "Name:" prefix on received messages.
  191. //.....................................................................
  192. char MessageBuffers[MAX_NUM_MESSAGES][MAX_MESSAGE_LENGTH + 30];
  193. char BufferAvail[MAX_NUM_MESSAGES];
  194. };
  195. #endif
  196. /**************************** end of msglist.h *****************************/