OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4Scoreboard Class Reference

#include <C4Scoreboard.h>

Collaboration diagram for C4Scoreboard:
[legend]

Public Types

enum  { TitleKey = -1 }
 

Public Member Functions

 C4Scoreboard ()
 
 ~C4Scoreboard ()
 
void Clear ()
 
void SetCell (int32_t iColKey, int32_t iRowKey, const char *szValue, int32_t iValue)
 
const char * GetCellString (int32_t iColKey, int32_t iRowKey)
 
int32_t GetCellData (int32_t iColKey, int32_t iRowKey)
 
void RemoveCol (int32_t iColKey)
 
void RemoveRow (int32_t iRowKey)
 
bool SortBy (int32_t iColKey, bool fReverse)
 
void DoDlgShow (int32_t iChange, bool fUserToggle)
 
void HideDlg ()
 
bool ShouldBeShown ()
 
bool CanBeShown ()
 
bool KeyUserShow ()
 
void CompileFunc (StdCompiler *pComp)
 

Protected Member Functions

Entry * GetCell (int32_t iCol, int32_t iRow) const
 

Protected Attributes

class C4ScoreboardDlgpDlg
 
int32_t iDlgShow
 

Friends

class C4ScoreboardDlg
 

Detailed Description

Definition at line 21 of file C4Scoreboard.h.

Member Enumeration Documentation

anonymous enum
Enumerator
TitleKey 

Definition at line 24 of file C4Scoreboard.h.

24 { TitleKey = -1 }; // value used to index the title bars

Constructor & Destructor Documentation

C4Scoreboard::C4Scoreboard ( )
inline

Definition at line 69 of file C4Scoreboard.h.

69 : iRows(0), iCols(0), pEntries(nullptr), pDlg(nullptr), iDlgShow(0) { }
int32_t iDlgShow
Definition: C4Scoreboard.h:61
class C4ScoreboardDlg * pDlg
Definition: C4Scoreboard.h:60
C4Scoreboard::~C4Scoreboard ( )
inline

Definition at line 70 of file C4Scoreboard.h.

References Clear().

70 { Clear(); }

Here is the call graph for this function:

Member Function Documentation

bool C4Scoreboard::CanBeShown ( )
inline

Definition at line 84 of file C4Scoreboard.h.

Referenced by DoDlgShow().

84 { return iDlgShow>=0 && iRows && iCols; }
int32_t iDlgShow
Definition: C4Scoreboard.h:61

Here is the caller graph for this function:

void C4Scoreboard::Clear ( )

Definition at line 64 of file C4Scoreboard.cpp.

References iDlgShow, and pDlg.

Referenced by C4Game::Clear(), CompileFunc(), and ~C4Scoreboard().

65 {
66  // del all cells
67  delete [] pEntries;
68  pEntries = nullptr; iRows=iCols=0;
69  // del dialog
70  iDlgShow = 0;
71  if (pDlg) { delete pDlg; pDlg = nullptr; }
72 }
int32_t iDlgShow
Definition: C4Scoreboard.h:61
class C4ScoreboardDlg * pDlg
Definition: C4Scoreboard.h:60

Here is the caller graph for this function:

void C4Scoreboard::CompileFunc ( StdCompiler pComp)

Definition at line 315 of file C4Scoreboard.cpp.

References Clear(), DoDlgShow(), FormatString(), GetCell(), iDlgShow, StdCompiler::isDeserializer(), mkNamingAdapt(), and StdCompiler::Value().

316 {
317  bool deserializing = pComp->isDeserializer();
318  if (deserializing) Clear();
319  pComp->Value(mkNamingAdapt(iRows, "Rows", 0));
320  pComp->Value(mkNamingAdapt(iCols, "Cols", 0));
321  pComp->Value(mkNamingAdapt(iDlgShow, "DlgShow", 0));
322  if (iRows * iCols)
323  {
324  if (deserializing) pEntries = new Entry[iRows * iCols];
325  for (int32_t iRow = 0; iRow < iRows; ++iRow)
326  for (int32_t iCol = 0; iCol < iCols; ++iCol)
327  {
328  Entry *pEnt = GetCell(iCol, iRow);
329  pComp->Value(mkNamingAdapt(pEnt->Text, FormatString("Cell%i_%iString", iCol, iRow).getData()));
330  pComp->Value(mkNamingAdapt(pEnt->iVal, FormatString("Cell%i_%iValue", iCol, iRow).getData()));
331  }
332  // recheck dlg show in read mode
333  // will usually not do anything, because reading is done before enetering shared mode
334  if (pComp->isDeserializer()) DoDlgShow(0, false);
335  }
336 }
int32_t iDlgShow
Definition: C4Scoreboard.h:61
void DoDlgShow(int32_t iChange, bool fUserToggle)
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:93
void Value(const T &rStruct)
Definition: StdCompiler.h:171
virtual bool isDeserializer()
Definition: StdCompiler.h:63
Entry * GetCell(int32_t iCol, int32_t iRow) const
Definition: C4Scoreboard.h:64
StdStrBuf FormatString(const char *szFmt,...)
Definition: StdBuf.cpp:277

Here is the call graph for this function:

void C4Scoreboard::DoDlgShow ( int32_t  iChange,
bool  fUserToggle 
)

Definition at line 285 of file C4Scoreboard.cpp.

References CanBeShown(), C4GUI::Dialog::Close(), iDlgShow, C4GUI::Screen::IsExclusive(), C4GameOverDlg::IsShown(), pDlg, pGUI, ShouldBeShown(), and C4GUI::Screen::ShowRemoveDlg().

Referenced by CompileFunc(), C4Game::Init(), and KeyUserShow().

286 {
287  if (::pGUI->IsExclusive()) return;
288  // update dlg show
289  iDlgShow += iChange;
290  if (!fUserToggle)
291  // script update: Dlg on off if iDlgShow variable passed zero
292  fUserToggle = (ShouldBeShown() == !pDlg);
293  else
294  // user pressed Tab: Always toggle except if the scoreboard cannot be shown at all
295  if (!CanBeShown() && !pDlg) fUserToggle = false;
296  if (fUserToggle)
297  {
298  if (!pDlg)
299  {
300  if (!C4GameOverDlg::IsShown()) // never show during game over dlg
301  ::pGUI->ShowRemoveDlg(pDlg = new C4ScoreboardDlg(this));
302  }
303  else
304  pDlg->Close(false);
305  }
306 }
int32_t iDlgShow
Definition: C4Scoreboard.h:61
void Close(bool fOK)
bool ShowRemoveDlg(Dialog *pDlg)
bool ShouldBeShown()
Definition: C4Scoreboard.h:83
bool IsExclusive()
Definition: C4Gui.h:2667
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
static bool IsShown()
Definition: C4GameOverDlg.h:92
class C4ScoreboardDlg * pDlg
Definition: C4Scoreboard.h:60
bool CanBeShown()
Definition: C4Scoreboard.h:84

Here is the call graph for this function:

Here is the caller graph for this function:

Entry* C4Scoreboard::GetCell ( int32_t  iCol,
int32_t  iRow 
) const
inlineprotected

Definition at line 64 of file C4Scoreboard.h.

Referenced by CompileFunc(), C4ScoreboardDlg::DrawElement(), GetCellData(), GetCellString(), SetCell(), SortBy(), and C4ScoreboardDlg::Update().

64 { return pEntries+iRow*iCols+iCol; }

Here is the caller graph for this function:

int32_t C4Scoreboard::GetCellData ( int32_t  iColKey,
int32_t  iRowKey 
)

Definition at line 225 of file C4Scoreboard.cpp.

References GetCell().

226 {
227  // get row/col
228  int32_t iCol = GetColByKey(iColKey);
229  int32_t iRow = GetRowByKey(iRowKey);
230  if (iCol<0 || iRow<0) return 0;
231  // now get value
232  Entry *pCell = GetCell(iCol, iRow);
233  return pCell->iVal;
234 }
Entry * GetCell(int32_t iCol, int32_t iRow) const
Definition: C4Scoreboard.h:64

Here is the call graph for this function:

const char * C4Scoreboard::GetCellString ( int32_t  iColKey,
int32_t  iRowKey 
)

Definition at line 214 of file C4Scoreboard.cpp.

References GetCell().

215 {
216  // get row/col
217  int32_t iCol = GetColByKey(iColKey);
218  int32_t iRow = GetRowByKey(iRowKey);
219  if (iCol<0 || iRow<0) return nullptr;
220  // now get value
221  Entry *pCell = GetCell(iCol, iRow);
222  return pCell->Text.getData();
223 }
Entry * GetCell(int32_t iCol, int32_t iRow) const
Definition: C4Scoreboard.h:64

Here is the call graph for this function:

void C4Scoreboard::HideDlg ( )

Definition at line 308 of file C4Scoreboard.cpp.

References C4GUI::Dialog::Close(), C4GUI::Screen::IsExclusive(), pDlg, and pGUI.

Referenced by C4GameOverDlg::OnShown().

309 {
310  if (::pGUI->IsExclusive()) return;
311  // hide scoreboard if it was active
312  if (pDlg) pDlg->Close(false);
313 }
void Close(bool fOK)
bool IsExclusive()
Definition: C4Gui.h:2667
C4GUIScreen * pGUI
Definition: C4Gui.cpp:1194
class C4ScoreboardDlg * pDlg
Definition: C4Scoreboard.h:60

Here is the call graph for this function:

Here is the caller graph for this function:

bool C4Scoreboard::KeyUserShow ( )
inline

Definition at line 86 of file C4Scoreboard.h.

References DoDlgShow().

Referenced by C4Game::InitKeyboard().

86 { DoDlgShow(0, true); return true; }
void DoDlgShow(int32_t iChange, bool fUserToggle)

Here is the call graph for this function:

Here is the caller graph for this function:

void C4Scoreboard::RemoveCol ( int32_t  iColKey)

Definition at line 236 of file C4Scoreboard.cpp.

237 {
238  int32_t iCol = GetColByKey(iColKey);
239  if (iCol>=0) DelCol(iCol);
240  InvalidateRows(); // recalc row widths in display
241 }
void C4Scoreboard::RemoveRow ( int32_t  iRowKey)

Definition at line 243 of file C4Scoreboard.cpp.

244 {
245  int32_t iRow = GetRowByKey(iRowKey);
246  if (iRow>=0) DelRow(iRow);
247  InvalidateRows(); // recalc row widths in display
248 }
void C4Scoreboard::SetCell ( int32_t  iColKey,
int32_t  iRowKey,
const char *  szValue,
int32_t  iValue 
)

Definition at line 171 of file C4Scoreboard.cpp.

References GetCell(), and TitleKey.

172 {
173  // ensure primary row/col exists
174  if (!iCols || !iRows)
175  {
176  if (!iCols) AddCol(0);
177  if (!iRows) AddRow(0);
178  GetCell(0, 0)->iVal = TitleKey;
179  }
180  // get row/col; create new if not yet existing
181  int32_t iCol = GetColByKey(iColKey);
182  if (iCol<0) { AddCol(iCol=iCols); GetCell(iCol, 0)->iVal = iColKey; }
183  int32_t iRow = GetRowByKey(iRowKey);
184  if (iRow<0) { AddRow(iRow=iRows); GetCell(0, iRow)->iVal = iRowKey; }
185  // now set values
186  Entry *pCell = GetCell(iCol, iRow);
187  pCell->Text.Copy(szValue);
188  if (iCol && iRow) pCell->iVal = iValue; // do NOT overwrite index keys!
189  // if an empty value was set, prune empty
190  if (!szValue || !*szValue)
191  {
192  // prune empty row (not label row)
193  int32_t i;
194  if (iRow)
195  {
196  for (i=1; i<iCols; ++i) if (GetCell(i, iRow)->Text) break;
197  if (i == iCols) DelRow(iRow);
198  }
199  // prune empty col (not label col)
200  if (iCol)
201  {
202  for (i=1; i<iRows; ++i) if (GetCell(iCol, i)->Text) break;
203  if (i == iRows) DelCol(iCol);
204  }
205  }
206  /* // prune empty board? but this would prevent boards that just sort
207  if (iRows == 1 && iCols == 1)
208  Clear(); // must not do this, because it will del pDlg
209  else*/
210  // recalc row widths in display (else done by clear)
211  InvalidateRows();
212 }
Entry * GetCell(int32_t iCol, int32_t iRow) const
Definition: C4Scoreboard.h:64

Here is the call graph for this function:

bool C4Scoreboard::ShouldBeShown ( )
inline

Definition at line 83 of file C4Scoreboard.h.

Referenced by DoDlgShow().

83 { return iDlgShow>0 && iRows && iCols; }
int32_t iDlgShow
Definition: C4Scoreboard.h:61

Here is the caller graph for this function:

bool C4Scoreboard::SortBy ( int32_t  iColKey,
bool  fReverse 
)

Definition at line 250 of file C4Scoreboard.cpp.

References GetCell().

251 {
252  // get sort col
253  int32_t iCol = GetColByKey(iColKey);
254  if (iCol<0) return false;
255  // sort
256  int32_t iSortDir = fReverse ? -1 : +1;
257  int32_t iSortBegin=1, iSortEnd=iRows-1;
258  while (iSortBegin < iSortEnd)
259  {
260  int32_t iNewBorder = iSortBegin; int32_t i;
261  for (i = iSortBegin; i < iSortEnd; ++i)
262  if (GetCell(iCol, i)->iVal * iSortDir > GetCell(iCol, i+1)->iVal * iSortDir)
263  {
264  SwapRows(i, i+1);
265  iNewBorder = i;
266  }
267  iSortEnd = iNewBorder;
268  for (i = iSortEnd; i > iSortBegin; --i)
269  if (GetCell(iCol, i-1)->iVal * iSortDir > GetCell(iCol, i)->iVal * iSortDir)
270  {
271  SwapRows(i-1, i);
272  iNewBorder = i;
273  }
274  iSortBegin = iNewBorder;
275  }
276  return true;
277 }
Entry * GetCell(int32_t iCol, int32_t iRow) const
Definition: C4Scoreboard.h:64

Here is the call graph for this function:

Friends And Related Function Documentation

friend class C4ScoreboardDlg
friend

Definition at line 66 of file C4Scoreboard.h.

Member Data Documentation

int32_t C4Scoreboard::iDlgShow
protected

Definition at line 61 of file C4Scoreboard.h.

Referenced by Clear(), CompileFunc(), and DoDlgShow().

class C4ScoreboardDlg* C4Scoreboard::pDlg
protected

Definition at line 60 of file C4Scoreboard.h.

Referenced by Clear(), DoDlgShow(), HideDlg(), and C4ScoreboardDlg::~C4ScoreboardDlg().


The documentation for this class was generated from the following files: