MSGLIST.H 11 KB

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