OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4StartupPlrSelDlg.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2005-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 // Startup screen for non-parameterized engine start: Player selection dialog
17 // Also contains player creation, editing and crew management
18 
19 #ifndef INC_C4StartupPlrSelDlg
20 #define INC_C4StartupPlrSelDlg
21 
22 #include <utility>
23 #include "gui/C4Startup.h"
24 #include "object/C4InfoCore.h"
25 
26 // startup dialog: Player selection
28 {
29 private:
30  enum Mode { PSDM_Player=0, PSDM_Crew }; // player selection list, or crew editing mode
31  enum { IconLabelSpacing = 2 }; // space between an icon and its text
32 
33 private:
34  // one item in the player or crew list
35  class ListItem : public C4GUI::Control
36  {
37  private:
38  typedef C4GUI::Window BaseClass;
39  // subcomponents
40  protected:
41  C4GUI::CheckBox *pCheck; // check box to mark participation
42  C4GUI::Label *pNameLabel; // item caption
43  class C4StartupPlrSelDlg *pPlrSelDlg;
44  C4GUI::Icon *pIcon; // item icon
45  private:
46  class C4KeyBinding *pKeyCheck; // space activates/deactivates selected player
47  StdStrBuf Filename; // file info was loaded from
48 
49  public:
50  ListItem(C4StartupPlrSelDlg *pForDlg, C4GUI::ListBox *pForListBox, C4GUI::Element *pInsertBeforeElement=nullptr, bool fActivated=false);
51  const C4FacetSurface &GetIconFacet() const { return pIcon->GetFacet(); }
52  virtual ~ListItem();
53 
54  protected:
55  virtual C4GUI::ContextMenu *ContextMenu() = 0;
56  C4GUI::ContextMenu *ContextMenu(C4GUI::Element *pEl, int32_t iX, int32_t iY)
57  { return ContextMenu(); }
58 
59  virtual void UpdateOwnPos(); // recalculate item positioning
60  bool KeyCheck() { pCheck->ToggleCheck(true); return true; }
61  virtual bool IsFocusOnClick() { return false; } // do not focus; keep focus on listbox
62 
63  void SetName(const char *szNewName);
64  void SetIcon(C4GUI::Icons icoNew);
65 
66  void SetFilename(const StdStrBuf &sNewFN);
67 
68  public:
69  C4GUI::CheckBox *GetCheckBox() const { return pCheck; }
70  ListItem *GetNext() const { return static_cast<ListItem *>(BaseClass::GetNext()); }
71  virtual uint32_t GetColorDw() const = 0; // get drawing color for portrait
72  bool IsActivated() const { return pCheck->GetChecked(); }
73  void SetActivated(bool fToVal) { pCheck->SetChecked(fToVal); }
74  const char *GetName() const;
75  virtual void SetSelectionInfo(C4GUI::TextWindow *pSelectionInfo) = 0; // clears text field and writes selection info text into it
76  const StdStrBuf &GetFilename() const { return Filename; }
77  virtual StdStrBuf GetDelWarning() = 0;
78  void GrabIcon(C4FacetSurface &rFromFacet);
79 
80  virtual bool CheckNameHotkey(const char * c); // return whether this item can be selected by entering given char
81 
82  class LoadError : public StdStrBuf
83  {
84  public:
85  LoadError(StdStrBuf &&rTakeFrom) { Take(std::move(rTakeFrom)); }
86  }; // class thrown off load function if load failed
87  };
88 
89 public:
90  // a list item when in player selection mode
91  class PlayerListItem : public ListItem
92  {
93  private:
94  C4PlayerInfoCore Core; // player info core loaded from player file
95  bool fHasCustomIcon; // set for players with a BigIcon.png
96 
97  public:
98  PlayerListItem(C4StartupPlrSelDlg *pForDlg, C4GUI::ListBox *pForListBox, C4GUI::Element *pInsertBeforeElement=nullptr, bool fActivated=false);
100 
101  void Load(const StdStrBuf &rsFilename); // may throw LoadError
102 
103  protected:
104  virtual C4GUI::ContextMenu *ContextMenu();
105 
106  public:
107  const C4PlayerInfoCore &GetCore() const { return Core; }
108  void UpdateCore(C4PlayerInfoCore & NewCore); // Save Core to disk and update this item
109  void GrabCustomIcon(C4FacetSurface &fctGrabFrom);
110  virtual void SetSelectionInfo(C4GUI::TextWindow *pSelectionInfo);
111  virtual uint32_t GetColorDw() const { return Core.PrefColorDw; }
112  virtual StdStrBuf GetDelWarning();
113  bool MoveFilename(const char *szToFilename); // change filename to given
114  };
115 
116 private:
117  // a list item when in crew editing mode
118  class CrewListItem : public ListItem
119  {
120  private:
121  bool fLoaded;
122  C4ObjectInfoCore Core;
123  uint32_t dwPlrClr;
124  C4Group *pParentGrp;
125 
126  public:
127  CrewListItem(C4StartupPlrSelDlg *pForDlg, C4GUI::ListBox *pForListBox, uint32_t dwPlrClr);
128  ~CrewListItem() {}
129 
130  void Load(C4Group &rGrp, const StdStrBuf &rsFilename); // may throw LoadError
131 
132  protected:
133  virtual C4GUI::ContextMenu *ContextMenu();
134 
135  void RewriteCore();
136 
137  struct RenameParams { };
138  void AbortRenaming(RenameParams par);
139  C4GUI::RenameEdit::RenameResult DoRenaming(RenameParams par, const char *szNewName);
140 
141  public:
142  void UpdateClonkEnabled();
143 
144  virtual uint32_t GetColorDw() const { return dwPlrClr; }; // get drawing color for portrait
145  virtual void SetSelectionInfo(C4GUI::TextWindow *pSelectionInfo); // clears text field and writes selection info text into it
146  virtual StdStrBuf GetDelWarning();
147  const C4ObjectInfoCore &GetCore() const { return Core; }
148 
149  CrewListItem *GetNext() const { return static_cast<CrewListItem *>(ListItem::GetNext()); }
150 
151  void CrewRename(); // shows the edit-field to rename a crew member
152  bool SetName(const char *szNewName); // update clonk name and core
153  void OnDeathMessageCtx(C4GUI::Element *el);
154  void OnDeathMessageSet(const StdStrBuf &rsNewMessage);
155  };
156 
157 public:
158  C4StartupPlrSelDlg(); // ctor
159  ~C4StartupPlrSelDlg(); // dtor
160 
161 private:
162  class C4KeyBinding *pKeyBack, *pKeyProperties, *pKeyCrew, *pKeyDelete, *pKeyRename, *pKeyNew;
163  class C4GUI::ListBox *pPlrListBox;
164  C4GUI::TextWindow *pSelectionInfo;
165  Mode eMode;
166 
167  // in crew mode:
168  struct CurrPlayer_t
169  {
170  C4PlayerInfoCore Core; // loaded player main core
171  C4Group Grp; // group to player file; opened when in crew mode
172  }
173  CurrPlayer;
174 
175 private:
176  C4Rect rcBottomButtons; int32_t iBottomButtonWidth;
177  class C4GUI::Button *btnActivatePlr, *btnCrew, *btnProperties, *btnDelete, *btnBack, *btnNew;
178 
179  void UpdateBottomButtons(); // update command button texts and positions
180  void UpdatePlayerList(); // refill pPlrListBox with players in player folder, or with crew in selected player
181  void UpdateSelection();
182  void OnSelChange(class C4GUI::Element *pEl) { UpdateSelection(); }
183  void OnSelDblClick(class C4GUI::Element *pEl) { C4GUI::GUISound("UI::Click"); OnPropertyBtn(nullptr); }
184  void UpdateActivatedPlayers(); // update Config.General.Participants by currently activated players
185  void SelectItem(const StdStrBuf &Filename, bool fActivate); // find item by filename and select (and activate it, if desired)
186 
187  void SetPlayerMode(); // change view to listing players
188  void SetCrewMode(PlayerListItem *pForPlayer); // change view to listing crew of a player
189 
190  static int32_t CrewSortFunc(const C4GUI::Element *pEl1, const C4GUI::Element *pEl2, void *par);
191  void ResortCrew();
192 
193 protected:
194  void OnItemCheckChange(C4GUI::Element *pCheckBox);
195  static bool CheckPlayerName(const StdStrBuf &Playername, StdStrBuf &Filename, const StdStrBuf *pPrevFilename, bool fWarnEmpty);
197  void SetSelection(ListItem *pNewItem);
198 
199  C4GUI::RenameEdit *pRenameEdit; // hack: set by crew list item renaming. Must be cleared when something is done in the dlg
200  void AbortRenaming();
201 
202  friend class ListItem; friend class PlayerListItem; friend class CrewListItem;
204 
205 protected:
206  virtual int32_t GetMarginTop() { return (rcBounds.Hgt/7); }
207  virtual bool HasBackground() { return false; }
208  virtual void DrawElement(C4TargetFacet &cgo);
209 
210  virtual bool OnEnter() { return false; } // Enter ignored
211  virtual bool OnEscape() { DoBack(); return true; }
212  bool KeyBack() { DoBack(); return true; }
213  bool KeyProperties() { OnPropertyBtn(nullptr); return true; }
214  bool KeyCrew() { OnCrewBtn(nullptr); return true; }
215  bool KeyDelete() { OnDelBtn(nullptr); return true; }
216  bool KeyNew() { OnNewBtn(nullptr); return true; }
217 
218  void OnNewBtn(C4GUI::Control *btn);
219  void OnNew(const StdStrBuf &Playername);
220  void OnActivateBtn(C4GUI::Control *btn);
221  void OnPropertyBtn(C4GUI::Control *btn);
223  void OnCrewBtn(C4GUI::Control *btn);
224  void OnDelBtn(C4GUI::Control *btn);
225  void OnDelCtx(C4GUI::Element *el) { OnDelBtn(nullptr); }
226  void OnDelBtnConfirm(ListItem *pSel);
227  void OnBackBtn(C4GUI::Control *btn) { DoBack(); }
228 
229 public:
230  void DoBack(); // back to main menu
231 };
232 
233 // player creation or property editing dialog
235 {
236 protected:
237  C4StartupPlrSelDlg *pMainDlg; // may be nullptr if shown as creation dialog in main menu!
239  C4GUI::Edit *pNameEdit; // player name edit box
240  C4GUI::CheckBox *pAutoStopControl; // wether the player uses AutoStopControl
246  C4PlayerInfoCore C4P; // player info core copy currently being edited
248  C4FacetSurface fctNewBigIcon; // if assigned, save new picture/bigicon
249  bool fClearBigIcon; // if true, delete current picture/bigicon
250  virtual const char *GetID() { return "PlrPropertiesDlg"; }
251 
252  void DrawElement(C4TargetFacet &cgo);
253  virtual int32_t GetMarginTop() { return 16; }
254  virtual int32_t GetMarginLeft() { return 45; }
255  virtual int32_t GetMarginRight() { return 55; }
256  virtual int32_t GetMarginBottom() { return 30; }
257 
258  virtual void UserClose(bool fOK); // OK only with a valid name
259  virtual bool IsComponentOutsideClientArea() { return true; } // OK and close btn
260 
261  void OnClrChangeLeft(C4GUI::Control *pBtn);
262  void OnClrChangeRight(C4GUI::Control *pBtn);
263  void OnClrChangeCustom(C4GUI::Control *pBtn);
264  void OnCtrlChangeLeft(C4GUI::Control *pBtn);
265  void OnCtrlChangeRight(C4GUI::Control *pBtn);
266  void OnSkinChangeLeft(C4GUI::Control *pBtn);
267  void OnSkinChangeRight(C4GUI::Control *pBtn);
268  void OnPictureBtn(C4GUI::Control *pBtn);
269 
270 private:
271  void UpdatePlayerColor(bool fUpdateSliders);
272  void UpdatePlayerControl();
273  void UpdatePlayerSkin();
274  void UpdateBigIcon();
275 
276  bool SetNewPicture(C4Surface &srcSfc, C4FacetSurface *trgFct, int32_t iMaxSize, bool fColorize);
277  void SetNewPicture(const char *szFromFilename); // set new bigicon by loading and scaling if necessary. If szFromFilename==nullptr, clear bigicon
278 
279 public:
282 
283  virtual void OnClosed(bool fOK); // close CB
284 };
285 
286 #endif // INC_C4StartupPlrSelDlg
char * GetFilename(char *szPath)
Definition: StdFile.cpp:55
C4GUI::IconButton * pJumpNRunBtn
virtual uint32_t GetColorDw() const
void OnCtrlChangeRight(C4GUI::Control *pBtn)
virtual int32_t GetMarginTop()
void GUISound(const char *szSound)
Definition: C4Gui.cpp:1178
virtual bool OnEscape()
void OnDelBtnConfirm(ListItem *pSel)
C4StartupPlrPropertiesDlg(C4StartupPlrSelDlg::PlayerListItem *pForPlayer, C4StartupPlrSelDlg *pMainDlg)
C4StartupPlrSelDlg::PlayerListItem * pForPlayer
void OnCrewBtn(C4GUI::Control *btn)
virtual bool OnEnter()
void OnPropertyCtx(C4GUI::Element *el)
void GrabCustomIcon(C4FacetSurface &fctGrabFrom)
Definition: C4Rect.h:29
virtual const char * GetID()
void OnNew(const StdStrBuf &Playername)
virtual int32_t GetMarginRight()
void OnClrChangeCustom(C4GUI::Control *pBtn)
virtual void UserClose(bool fOK)
virtual bool HasBackground()
bool fOK
Definition: C4Gui.h:2082
C4StartupPlrSelDlg * pMainDlg
virtual bool CheckNameHotkey(const char *)
Definition: C4Gui.h:407
void OnSkinChangeRight(C4GUI::Control *pBtn)
void OnDelCtx(C4GUI::Element *el)
virtual void UpdateOwnPos()
C4GUI::IconButton * pMouseBtn
bool MoveFilename(const char *szToFilename)
static bool CheckPlayerName(const StdStrBuf &Playername, StdStrBuf &Filename, const StdStrBuf *pPrevFilename, bool fWarnEmpty)
const StdStrBuf & GetName() const
virtual int32_t GetMarginLeft()
void SetChecked(bool fToVal)
Definition: C4Gui.h:1476
C4GUI::CheckBox * pAutoStopControl
void SetSelection(ListItem *pNewItem)
C4Rect rcBounds
Definition: C4Gui.h:385
void Take(char *pnData)
Definition: StdBuf.h:465
friend class PlayerListItem
void OnClrChangeLeft(C4GUI::Control *pBtn)
C4GUI::RenameEdit * pRenameEdit
PlayerListItem(C4StartupPlrSelDlg *pForDlg, C4GUI::ListBox *pForListBox, C4GUI::Element *pInsertBeforeElement=nullptr, bool fActivated=false)
uint32_t PrefColorDw
Definition: C4InfoCore.h:100
Icons
Definition: C4Gui.h:637
const C4PlayerInfoCore & GetCore() const
void OnPropertyBtn(C4GUI::Control *btn)
Element * GetNext() const
Definition: C4Gui.h:449
bool GetChecked() const
Definition: C4Gui.h:1477
virtual int32_t GetMarginTop()
const C4FacetSurface & GetFacet() const
Definition: C4Gui.h:610
virtual C4GUI::ContextMenu * ContextMenu()
virtual void SetSelectionInfo(C4GUI::TextWindow *pSelectionInfo)
C4GUI::IconButton * pPictureBtn
void Load(const StdStrBuf &rsFilename)
C4GUI::IconButton * pClassicBtn
void UpdateCore(C4PlayerInfoCore &NewCore)
C4GUI::IconButton * pClrPreview
virtual void DrawElement(C4TargetFacet &cgo)
void OnBackBtn(C4GUI::Control *btn)
void OnClrChangeRight(C4GUI::Control *pBtn)
virtual int32_t GetMarginBottom()
void OnNewBtn(C4GUI::Control *btn)
void DrawElement(C4TargetFacet &cgo)
void OnPictureBtn(C4GUI::Control *pBtn)
void OnDelBtn(C4GUI::Control *btn)
int32_t Hgt
Definition: C4Rect.h:32
virtual bool IsComponentOutsideClientArea()
virtual void OnClosed(bool fOK)
void OnActivateBtn(C4GUI::Control *btn)
void OnCtrlChangeLeft(C4GUI::Control *pBtn)
void ToggleCheck(bool fByUser)
void OnItemCheckChange(C4GUI::Element *pCheckBox)
void OnSkinChangeLeft(C4GUI::Control *pBtn)