YAPOG  0.0.1
Yet Another Pokemon Online Game
ChatDisplayer.cpp
Go to the documentation of this file.
3 
4 namespace yap
5 {
6  void InitTab (bool** tab, size_t size, bool value)
7  {
8  for (size_t i = 0; i < size; i++)
9  (*tab)[i] = false;
10  }
11 
13  : name_ ("Systeme")
14  , offset_ (0)
15  , buff_ ()
16  , chans_ ()
17  , output_ ()
18  //, chanbooltab_ (NBCHAN, false)
19  , chanbooltab_ (new bool[NBCHAN])
20  {
21  chans_.Add (new CMType ()); // System, Red
22  chans_.Add (new CMType ("Global", "Black", 1));
23  chans_.Add (new CMType ("Group", "Green", 2));
24  chans_.Add (new CMType ("Business", "Blue", 3));
25  chans_.Add (new CMType ("Info", "Yellow", 4));
26  chans_.Add (new CMType ("MP", "Purple", 5));
27 
28  InitTab (&chanbooltab_, NBCHAN, false);
29  output_ = std::make_pair (chans_[0], "");
30  }
31 
33  : name_ (name)
34  , offset_ (0)
35  , buff_ ()
36  , chans_ ()
37  , output_ ()
38  , chanbooltab_ (new bool[NBCHAN])
39  {
40  chans_.Add (new CMType ()); // System, Red
41  chans_.Add (new CMType ("Global", "Black", 1));
42  chans_.Add (new CMType ("Group", "Green", 2));
43  chans_.Add (new CMType ("Business", "Blue", 3));
44  chans_.Add (new CMType ("Info", "Yellow", 4));
45  chans_.Add (new CMType ("MP", "Purple", 5));
46 
47  output_ = std::make_pair (chans_[0], "");
48  chanbooltab_[c] = true;
49  }
50 
51  ChatDisplayer::ChatDisplayer (String name, bool* chanbooltab)
52  : name_ (name)
53  , offset_ (0)
54  , buff_ ()
55  , chans_ ()
56  , output_ ()
57  , chanbooltab_ (new bool[NBCHAN])
58  {
59  chans_.Add (new CMType ()); // System, Red
60  chans_.Add (new CMType ("Global", "Black", 1));
61  chans_.Add (new CMType ("Group", "Green", 2));
62  chans_.Add (new CMType ("Business", "Blue", 3));
63  chans_.Add (new CMType ("Info", "Yellow", 4));
64  chans_.Add (new CMType ("MP", "Purple", 5));
65 
66  output_ = std::make_pair (chans_[0], "");
67  for (size_t i = 0; i < NBCHAN; i++)
68  chanbooltab_[i] = chanbooltab[i];
69  }
70 
72  {
74  ChansType::ItType ite (chans_.End ());
75 
76  for (; it < ite; it++)
77  {
78  delete (*it);
79  *it = nullptr;
80  }
81 
82  delete chanbooltab_;
83  chanbooltab_ = nullptr;
84  }
85 
87  {
88  return chans_.Count ();
89  }
90 
92  {
93  if (buff_.Count () == 0)
94  return "";
95 
96  size_t size = buff_.Count ();
97  CMType* cmt = buff_[size - 1].first;
98  String* str = &buff_[size - 1].second;
99 
100  return (cmt->Name
101  + " (" + cmt->Color
102  + ") :: "
103  + *str);
104  }
105 
107  {
108  if (c >= 0 && c <= NBCHAN)
109  chanbooltab_[c] = true;
110  }
111 
113  {
114  if (c >= 0 && c <= NBCHAN)
115  chanbooltab_[c] = false;
116  }
117 
119  {
120  for (int i = 0; i < NBCHAN; i++)
121  DISPLAYS ("Chan " + StringHelper::ToString (i)
122  + " is "
123  + (chanbooltab_[i] ? "ON" : "OFF"));
124  }
125 
127  {
128  output_ = std::make_pair (chans_[0], "");
129  if (chanbooltab_[c] == true)
130  {
131  CMType* mychan = chans_[c];
132  String strtoadd = "";
133 
134  for (size_t i = 0; i < b.Count (); i++)
135  {
136  String s = b[i];
137 
138  strtoadd += + ((i == 0) ? "" : " ") + s;
139 
140  if (buff_.Count () < CHANMAXBUF)
141  {
142  buff_.Add (std::make_pair (mychan, s));
143  offset_++;
144  }
145  else
146  buff_[offset_++] = std::make_pair (mychan, s);
147  if (offset_ == CHANMAXBUF)
148  offset_ = 0;
149  }
150  output_ = std::make_pair (mychan, strtoadd);
151  }
152  }
153 
154  void ChatDisplayer::MyDisplay (size_t index, size_t last)
155  {
156  for (size_t i = index; i < last ; i++)
157  DISPLAYS (buff_[i].first->Name
158  + " (" + buff_[i].first->Color
159  + ") :: " + buff_[i].second);
160  }
161 
162 
163  void ChatDisplayer::MyDisplayAdder (size_t index,
164  size_t last,
165  ResponseType* rt)
166  {
167  MyDisplay (index, last);
168  for (size_t i = index; i < last ; i++)
169  {
170  rt->Channb.Add (buff_[i].first->ChanNb);
171  rt->Message.Add (buff_[i].second);
172  }
173  }
174 
176  {
177  size_t size = buff_.Count ();
178  size_t i = 0;
179  ResponseType rt;
180 
181  rt.Message.Clear ();
182  rt.Channb.Clear ();
183  if (size < CHANMAXBUF)
184  MyDisplayAdder (i, size, &rt);
185  else
186  {
187  size_t index = offset_ + 1;
188  MyDisplayAdder (index, size, &rt);
189  MyDisplayAdder (i, index, &rt);
190  }
191  rt.Clean = true;
192 
193  return rt;
194  }
195 
197  {
198  ResponseType rt;
199 
200  rt.Message.Clear ();
201  rt.Channb.Clear ();
202  if (!output_.second.empty ())
203  {
204  DISPLAYS (output_.first->Name
205  + " (" + output_.first->Color
206  + ") :: " + output_.second);
207  rt.Channb.Add (output_.first->ChanNb);
208  rt.Message.Add (output_.second);
209  }
210 
211  return rt;
212  }
213 
215  {
216  return name_;
217  }
218 
220  {
221  return buff_;
222  }
223 } // namespace yap