Rise
The Vieneo Province
chat.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../Common/server.h" // MAX_ONLINEPLAYERS
4 
5 #include <vector>
6 
7 #define STORE_CHAT_SIZE 271 // includes 255 plus handle12, brackets2, colon1, space1
8 #define FORMAT_LINES 256 // controls how many we build for display in a vector, could be more because they are multi-line
9 
11 {
12 public:
13  unsigned char seqplayer[MAX_ONLINEPLAYERS]; // sequential list of players
14  bool dndplayer[MAX_ONLINEPLAYERS];
15  short players;
16 
17  void AddPlayer(unsigned char tempplayer)
18  {
19  dndplayer[players] = false; // eventually retrieve this from the people manager persistent data
20  seqplayer[players] = tempplayer;
21  players++;
22  }
23 
24  void RemovePlayer(short tempplayer)
25  {
26  short index = -1;
27  for (short t = 0; t < players; t++)
28  {
29  if (seqplayer[t] == tempplayer)
30  {
31  index = t;
32  break;
33  }
34  }
35  if (index == -1)
36  return;
37 
38  for (short t = index; t < players - 1; t++)
39  {
40  seqplayer[t] = seqplayer[t + 1];
41  dndplayer[t] = dndplayer[t + 1];
42  }
43  players--;
44  }
45 
46  // so we store all the chats as an array, one per element
47  std::vector<std::wstring> chatline;
48  std::vector<std::string> chatlineplayer;
49  // we go through that list to make another array that has chatlinereference or placeholder based on width
50  // ie |
51  // [reskin]: howdy doody fresh and fruity
52  // becomes
53  // [reskin]: howdy doody fresh
54  // BLANK LINE for and fruity
55  std::vector<std::wstring> formatchatline;
56  std::vector<std::string> formatchatlineplayer;
57  unsigned char channel, owner; // which channel does this tab transmit/receive on
58  bool dnd;
59  WCHAR title[MAX_TAB_CHARS - 5] = {0};
60 
61  void RefreshChat(long columnWidth, int fontWidth)
62  {
63  const size_t maxChars = min(columnWidth / fontWidth, HELP_SIZE - 1);
64 
65  formatchatline.clear();
66  formatchatlineplayer.clear();
67 
68  const auto totalLines = chatline.size();
69  const auto start = static_cast<size_t>(max(0, (int)totalLines - FORMAT_LINES));
70  for (auto pos = start; pos < totalLines; pos++) // these are all the chat lines in the backlog
71  {
72  assert(pos < chatlineplayer.size());
73  formatchatlineplayer.emplace_back(chatlineplayer.at(pos));
74 
75  UINT startIndex = 0;
76  do
77  {
78  if (startIndex != 0) formatchatlineplayer.emplace_back("");
79  std::basic_string<wchar_t> substr = chatline.at(pos).substr(startIndex, maxChars);
80  if (substr.at(0) == 32)
81  {
82  startIndex++;
83  substr = chatline.at(pos).substr(startIndex, maxChars);
84  }
85 
86  int backup = 0;
87  const size_t length = substr.length();
88  if (length == maxChars)
89  {
90  size_t space = substr.find_last_of(L' '); // npos
91  size_t hyphen = substr.find_last_of(L'-'); // 63
92  if (space == std::string::npos) space = 0;
93  if (hyphen == std::string::npos) hyphen = 0; else hyphen++;
94  backup = length - max(space, hyphen); // so 128 - 110 = 18 which is within 20
95  if (backup > 20)
96  backup = 0;
97  }
98 
99  formatchatline.emplace_back(substr.substr(0, length - backup));
100  startIndex += maxChars - backup;
101 
102  } while (startIndex < chatline.at(pos).length());
103  }
104  }
105 
107  {
108  channel = 0;
109  owner = 0;
110  players = 0;
111  dnd = false;
112  ZeroMemory(seqplayer, MAX_ONLINEPLAYERS);
113  ZeroMemory(dndplayer, MAX_ONLINEPLAYERS);
114  }
115 };
std::vector< std::wstring > formatchatline
Definition: chat.h:55
std::vector< std::wstring > chatline
Definition: chat.h:47
short players
Definition: chat.h:15
#define FORMAT_LINES
Definition: chat.h:8
std::vector< std::string > formatchatlineplayer
Definition: chat.h:56
unsigned char channel
Definition: chat.h:57
unsigned char owner
Definition: chat.h:57
std::vector< std::string > chatlineplayer
Definition: chat.h:48
bool dndplayer[MAX_ONLINEPLAYERS]
Definition: chat.h:14
void AddPlayer(unsigned char tempplayer)
Definition: chat.h:17
unsigned char seqplayer[MAX_ONLINEPLAYERS]
Definition: chat.h:13
WCHAR title[MAX_TAB_CHARS - 5]
Definition: chat.h:59
void RefreshChat(long columnWidth, int fontWidth)
Definition: chat.h:61
bool dnd
Definition: chat.h:58
#define HELP_SIZE
Definition: gui.h:17
CHATCHANNEL()
Definition: chat.h:106
void RemovePlayer(short tempplayer)
Definition: chat.h:24