OpenClonk
C4PlayerInfoCore Class Reference

#include <C4InfoCore.h>

Inheritance diagram for C4PlayerInfoCore:
[legend]
Collaboration diagram for C4PlayerInfoCore:
[legend]

Public Member Functions

 C4PlayerInfoCore ()
 
void Default (C4RankSystem *pRanks=nullptr)
 
void Promote (int32_t iRank, C4RankSystem &rRanks)
 
bool Load (C4Group &hGroup)
 
bool Save (C4Group &hGroup)
 
bool CheckPromotion (C4RankSystem &rRanks)
 
void CompileFunc (StdCompiler *pComp)
 

Static Public Member Functions

static DWORD GetPrefColorValue (int32_t iPrefColor)
 

Public Attributes

char PrefName [C4MaxName+1]
 
char Comment [C4MaxComment+1]
 
int32_t Rank
 
char RankName [C4MaxName+1]
 
int32_t TotalScore
 
int32_t Rounds
 
int32_t RoundsWon
 
int32_t RoundsLost
 
int32_t TotalPlayingTime
 
C4RoundResult LastRound
 
C4ValueMapData ExtraData
 
char LeagueName [C4MaxName+1]
 
StdCopyStrBuf PrefControl
 
int32_t PrefMouse
 
int32_t PrefColor
 
uint32_t PrefColorDw
 
uint32_t PrefColor2Dw
 
int32_t PrefClonkSkin
 
int32_t OldPrefControl
 
int32_t OldPrefControlStyle
 
int32_t OldPrefAutoContextMenu
 
C4ScenarioParameters Achievements
 

Detailed Description

Definition at line 79 of file C4InfoCore.h.

Constructor & Destructor Documentation

◆ C4PlayerInfoCore()

C4PlayerInfoCore::C4PlayerInfoCore ( )

Definition at line 35 of file C4InfoCore.cpp.

36 {
37  Default();
38 }
void Default(C4RankSystem *pRanks=nullptr)
Definition: C4InfoCore.cpp:40

References Default().

Here is the call graph for this function:

Member Function Documentation

◆ CheckPromotion()

bool C4PlayerInfoCore::CheckPromotion ( C4RankSystem rRanks)

Definition at line 145 of file C4InfoCore.cpp.

146 {
147  if (TotalScore >= rRanks.Experience(Rank + 1))
148  {
149  Promote(Rank + 1,rRanks);
150  return true;
151  }
152  return false;
153 }
void Promote(int32_t iRank, C4RankSystem &rRanks)
Definition: C4InfoCore.cpp:139
int32_t TotalScore
Definition: C4InfoCore.h:89
int Experience(int iRank)

References C4RankSystem::Experience(), Promote(), Rank, and TotalScore.

Here is the call graph for this function:

◆ CompileFunc()

void C4PlayerInfoCore::CompileFunc ( StdCompiler pComp)

Definition at line 155 of file C4InfoCore.cpp.

156 {
157  C4ValueNumbers numbers;
158  pComp->Name("Player");
159  pComp->Value(mkNamingAdapt(toC4CStr(PrefName), "Name", "Neuling"));
160  pComp->Value(mkNamingAdapt(toC4CStr(Comment), "Comment", ""));
161  pComp->Value(mkNamingAdapt(Rank, "Rank", 0));
162  pComp->Value(mkNamingAdapt(toC4CStr(RankName), "RankName", LoadResStr("IDS_MSG_RANK"))); // TODO: check if this would be desirable
163  pComp->Value(mkNamingAdapt(TotalScore, "Score", 0));
164  pComp->Value(mkNamingAdapt(Rounds, "Rounds", 0));
165  pComp->Value(mkNamingAdapt(RoundsWon, "RoundsWon", 0));
166  pComp->Value(mkNamingAdapt(RoundsLost, "RoundsLost", 0));
167  pComp->Value(mkNamingAdapt(TotalPlayingTime, "TotalPlayingTime", 0));
168  pComp->Value(mkNamingAdapt(mkParAdapt(ExtraData, &numbers), "ExtraData", C4ValueMapData()));
169  pComp->Value(mkNamingAdapt(numbers, "ExtraDataValues"));
170  if (pComp->isDeserializer())
171  {
172  numbers.Denumerate();
173  ExtraData.Denumerate(&numbers);
174  }
175  pComp->Value(mkNamingAdapt(toC4CStr(LeagueName), "LeagueName", ""));
176  pComp->NameEnd();
177 
178  pComp->Name("Preferences");
179  pComp->Value(mkNamingAdapt(PrefColor, "Color", 0));
180  pComp->Value(mkNamingAdapt(PrefColorDw, "ColorDw", 0xffu));
181  pComp->Value(mkNamingAdapt(PrefColor2Dw, "AlternateColorDw", 0u));
182  pComp->Value(mkNamingAdapt(PrefMouse, "Mouse", 1));
183  pComp->Value(mkNamingAdapt(OldPrefControl, "Control", 1));
184  pComp->Value(mkNamingAdapt(OldPrefControlStyle, "AutoStopControl", 0));
185  pComp->Value(mkNamingAdapt(OldPrefAutoContextMenu, "AutoContextMenu", -1)); // Compiling default is -1 (if this is detected, AutoContextMenus will be defaulted by control style)
186  pComp->Value(mkNamingAdapt(PrefControl, "ControlSet", StdStrBuf()));
187  pComp->Value(mkNamingAdapt(PrefClonkSkin, "ClonkSkin", 0));
188  pComp->NameEnd();
189 
190  pComp->Value(mkNamingAdapt(LastRound, "LastRound"));
191  pComp->Value(mkNamingAdapt(Achievements, "Achievements"));
192 }
const char * LoadResStr(const char *id)
Definition: C4Language.h:83
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92
#define toC4CStr(szString)
Definition: StdAdaptors.h:24
char Comment[C4MaxComment+1]
Definition: C4InfoCore.h:86
StdCopyStrBuf PrefControl
Definition: C4InfoCore.h:96
int32_t OldPrefControlStyle
Definition: C4InfoCore.h:104
uint32_t PrefColor2Dw
Definition: C4InfoCore.h:99
int32_t RoundsWon
Definition: C4InfoCore.h:90
int32_t PrefColor
Definition: C4InfoCore.h:98
char LeagueName[C4MaxName+1]
Definition: C4InfoCore.h:94
int32_t TotalPlayingTime
Definition: C4InfoCore.h:91
int32_t Rounds
Definition: C4InfoCore.h:90
int32_t OldPrefAutoContextMenu
Definition: C4InfoCore.h:105
char RankName[C4MaxName+1]
Definition: C4InfoCore.h:88
int32_t RoundsLost
Definition: C4InfoCore.h:90
C4RoundResult LastRound
Definition: C4InfoCore.h:92
char PrefName[C4MaxName+1]
Definition: C4InfoCore.h:85
int32_t PrefClonkSkin
Definition: C4InfoCore.h:100
uint32_t PrefColorDw
Definition: C4InfoCore.h:99
int32_t PrefMouse
Definition: C4InfoCore.h:97
C4ValueMapData ExtraData
Definition: C4InfoCore.h:93
int32_t OldPrefControl
Definition: C4InfoCore.h:103
C4ScenarioParameters Achievements
Definition: C4InfoCore.h:108
void Denumerate(C4ValueNumbers *)
Definition: C4ValueMap.cpp:254
void Denumerate()
Definition: C4Value.cpp:281
void Value(const T &rStruct)
Definition: StdCompiler.h:161
virtual void NameEnd(bool fBreak=false)
Definition: StdCompiler.h:78
virtual bool isDeserializer()
Definition: StdCompiler.h:53
virtual bool Name(const char *szName)
Definition: StdCompiler.h:77

References Achievements, Comment, C4ValueNumbers::Denumerate(), C4ValueMapData::Denumerate(), ExtraData, StdCompiler::isDeserializer(), LastRound, LeagueName, LoadResStr(), mkNamingAdapt(), mkParAdapt(), StdCompiler::Name(), StdCompiler::NameEnd(), OldPrefAutoContextMenu, OldPrefControl, OldPrefControlStyle, PrefClonkSkin, PrefColor, PrefColor2Dw, PrefColorDw, PrefControl, PrefMouse, PrefName, Rank, RankName, Rounds, RoundsLost, RoundsWon, toC4CStr, TotalPlayingTime, TotalScore, and StdCompiler::Value().

Here is the call graph for this function:

◆ Default()

void C4PlayerInfoCore::Default ( C4RankSystem pRanks = nullptr)

Definition at line 40 of file C4InfoCore.cpp.

41 {
42  *Comment = '\0';
43  *RankName = '\0';
44  TotalScore = 0;
45  Rounds = 0;
46  RoundsWon = 0;
47  RoundsLost = 0;
48  TotalPlayingTime = 0;
49  *LeagueName = '\0';
53  Rank = 0;
54  SCopy("Neuling",PrefName);
55  if (pRanks)
56  {
57  SCopy(pRanks->GetRankName(Rank, false).getData(), RankName);
58  }
59  else
60  {
61  SCopy("Rang", RankName);
62  }
63  PrefClonkSkin = 0;
64  PrefColor = 0;
65  PrefColorDw = 0xff;
66  PrefColor2Dw = 0;
67  OldPrefControl = 0;
68  PrefMouse = 1;
72  ExtraData.Reset();
73 }
void SCopy(const char *szSource, char *sTarget, size_t iMaxL)
Definition: Standard.cpp:152
StdStrBuf GetRankName(int iRank, bool fReturnLastIfOver)
const char * getData() const
Definition: StdBuf.h:442
void Clear()
Definition: StdBuf.h:466

References StdStrBuf::Clear(), Comment, C4RoundResult::Default(), ExtraData, StdStrBuf::getData(), C4RankSystem::GetRankName(), LastRound, LeagueName, OldPrefAutoContextMenu, OldPrefControl, OldPrefControlStyle, PrefClonkSkin, PrefColor, PrefColor2Dw, PrefColorDw, PrefControl, PrefMouse, PrefName, Rank, RankName, C4ValueMapData::Reset(), Rounds, RoundsLost, RoundsWon, SCopy(), TotalPlayingTime, and TotalScore.

Referenced by C4PlayerInfoCore(), and C4StartupPlrPropertiesDlg::C4StartupPlrPropertiesDlg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPrefColorValue()

DWORD C4PlayerInfoCore::GetPrefColorValue ( int32_t  iPrefColor)
static

Definition at line 75 of file C4InfoCore.cpp.

76 {
77  DWORD valRGB[12] = { 0xFF0000E8, 0xFFF40000, 0xFF00C800, 0xFFFCF41C,
78  0xFFC48444, 0xFF784830, 0xFFA04400, 0xFFF08050,
79  0xFF848484, 0xFFFFFFFF, 0xFF0094F8, 0xFFBC00C0
80  };
81  if (Inside<int32_t>(iPrefColor, 0, 11))
82  {
83  return valRGB[iPrefColor];
84  }
85  return 0xFFAAAAAA;
86 }
uint32_t DWORD

Referenced by C4StartupPlrPropertiesDlg::C4StartupPlrPropertiesDlg(), Load(), C4StartupPlrPropertiesDlg::OnClrChangeLeft(), and C4StartupPlrPropertiesDlg::OnClrChangeRight().

Here is the caller graph for this function:

◆ Load()

bool C4PlayerInfoCore::Load ( C4Group hGroup)

Definition at line 88 of file C4InfoCore.cpp.

89 {
90  // New version
91  StdStrBuf Source;
92  if (hGroup.LoadEntryString(C4CFN_PlayerInfoCore, &Source))
93  {
94  // Compile
95  StdStrBuf GrpName = hGroup.GetFullName();
97  if (!CompileFromBuf_LogWarn<StdCompilerINIRead>(*this, Source, GrpName.getData()))
98  {
99  return false;
100  }
101  // Pref for AutoContextMenus is still undecided: default by player's control style
102  if (OldPrefAutoContextMenu == -1)
103  {
105  }
106  // Determine true color from indexed pref color
107  if (!PrefColorDw)
108  {
110  }
111  // Validate colors
112  PrefColorDw &= 0xffffff;
113  PrefColor2Dw &= 0xffffff;
114  // Validate name
116  // Success
117  return true;
118  }
119 
120  // Old version no longer supported - sorry
121  return false;
122 }
#define C4CFN_PlayerInfoCore
Definition: C4Components.h:45
#define DirSep
StdStrBuf GetFullName() const
Definition: C4Group.cpp:2638
bool LoadEntryString(const char *entry_name, StdStrBuf *buffer)
Definition: C4Group.cpp:2430
static bool StripMarkup(char *szText)
Definition: C4Markup.cpp:148
static DWORD GetPrefColorValue(int32_t iPrefColor)
Definition: C4InfoCore.cpp:75
void Append(const char *pnData, size_t iChars)
Definition: StdBuf.h:519

References StdStrBuf::Append(), C4CFN_PlayerInfoCore, DirSep, StdStrBuf::getData(), C4Group::GetFullName(), GetPrefColorValue(), C4Group::LoadEntryString(), OldPrefAutoContextMenu, OldPrefControlStyle, PrefColor, PrefColor2Dw, PrefColorDw, PrefName, and C4Markup::StripMarkup().

Referenced by C4MainMenu::ActivateNewPlayer(), C4Player::Load(), C4PlayerInfo::LoadFromLocalFile(), and C4Player::Strip().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Promote()

void C4PlayerInfoCore::Promote ( int32_t  iRank,
C4RankSystem rRanks 
)

Definition at line 139 of file C4InfoCore.cpp.

140 {
141  Rank = iRank;
142  SCopy(rRanks.GetRankName(Rank, true).getData(), RankName, C4MaxName);
143 }
const unsigned int C4MaxName

References C4MaxName, StdStrBuf::getData(), C4RankSystem::GetRankName(), Rank, RankName, and SCopy().

Referenced by CheckPromotion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Save()

bool C4PlayerInfoCore::Save ( C4Group hGroup)

Definition at line 124 of file C4InfoCore.cpp.

125 {
126  StdStrBuf Source, Name = hGroup.GetFullName(); Name.Append(DirSep C4CFN_PlayerInfoCore);
127  if (!DecompileToBuf_Log<StdCompilerINIWrite>(*this, &Source, Name.getData()))
128  {
129  return false;
130  }
131  if (!hGroup.Add(C4CFN_PlayerInfoCore, Source, false, true))
132  {
133  return false;
134  }
135  hGroup.Delete("C4Player.ocb");
136  return true;
137 }
bool Add(const char *filename, const char *entry_name)
Definition: C4Group.cpp:1621
bool Delete(const char *files, bool recursive=false)
Definition: C4Group.cpp:1645

References C4Group::Add(), StdStrBuf::Append(), C4CFN_PlayerInfoCore, C4Group::Delete(), DirSep, StdStrBuf::getData(), and C4Group::GetFullName().

Referenced by C4StartupPlrPropertiesDlg::OnClosed(), C4Player::Save(), C4Player::Strip(), and C4StartupPlrSelDlg::PlayerListItem::UpdateCore().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ Achievements

C4ScenarioParameters C4PlayerInfoCore::Achievements

Definition at line 108 of file C4InfoCore.h.

Referenced by CompileFunc(), and C4Player::GainScenarioAchievement().

◆ Comment

char C4PlayerInfoCore::Comment[C4MaxComment+1]

◆ ExtraData

C4ValueMapData C4PlayerInfoCore::ExtraData

Definition at line 93 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().

◆ LastRound

C4RoundResult C4PlayerInfoCore::LastRound

◆ LeagueName

char C4PlayerInfoCore::LeagueName[C4MaxName+1]

Definition at line 94 of file C4InfoCore.h.

Referenced by CompileFunc(), and Default().

◆ OldPrefAutoContextMenu

int32_t C4PlayerInfoCore::OldPrefAutoContextMenu

◆ OldPrefControl

int32_t C4PlayerInfoCore::OldPrefControl

◆ OldPrefControlStyle

int32_t C4PlayerInfoCore::OldPrefControlStyle

◆ PrefClonkSkin

int32_t C4PlayerInfoCore::PrefClonkSkin

◆ PrefColor

◆ PrefColor2Dw

uint32_t C4PlayerInfoCore::PrefColor2Dw

Definition at line 99 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), Load(), and C4PlayerInfo::LoadFromLocalFile().

◆ PrefColorDw

◆ PrefControl

◆ PrefMouse

int32_t C4PlayerInfoCore::PrefMouse

Definition at line 97 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and C4Player::InitControl().

◆ PrefName

◆ Rank

int32_t C4PlayerInfoCore::Rank

Definition at line 87 of file C4InfoCore.h.

Referenced by CheckPromotion(), CompileFunc(), Default(), and Promote().

◆ RankName

char C4PlayerInfoCore::RankName[C4MaxName+1]

Definition at line 88 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and Promote().

◆ Rounds

int32_t C4PlayerInfoCore::Rounds

Definition at line 90 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and C4Player::Evaluate().

◆ RoundsLost

int32_t C4PlayerInfoCore::RoundsLost

Definition at line 90 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and C4Player::Evaluate().

◆ RoundsWon

int32_t C4PlayerInfoCore::RoundsWon

Definition at line 90 of file C4InfoCore.h.

Referenced by CompileFunc(), Default(), and C4Player::Evaluate().

◆ TotalPlayingTime

int32_t C4PlayerInfoCore::TotalPlayingTime

◆ TotalScore

int32_t C4PlayerInfoCore::TotalScore

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