1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#include "menus.h"
4
5#include <base/str.h>
6
7#include <engine/font_icons.h>
8#include <engine/graphics.h>
9#include <engine/shared/config.h>
10#include <engine/storage.h>
11#include <engine/textrender.h>
12
13#include <game/client/animstate.h>
14#include <game/client/components/console.h>
15#include <game/client/components/emoticon.h>
16#include <game/client/components/skins.h>
17#include <game/client/gameclient.h>
18#include <game/client/skin.h>
19#include <game/client/ui.h>
20#include <game/client/ui_listbox.h>
21#include <game/localization.h>
22
23#include <algorithm>
24#include <vector>
25
26void CMenus::RenderSettingsTee(CUIRect MainView)
27{
28 CUIRect TabBar, PlayerTab, DummyTab, ChangeInfo;
29 MainView.HSplitTop(Cut: 20.0f, pTop: &TabBar, pBottom: &MainView);
30 TabBar.VSplitMid(pLeft: &TabBar, pRight: &ChangeInfo, Spacing: 20.f);
31 TabBar.VSplitMid(pLeft: &PlayerTab, pRight: &DummyTab);
32 MainView.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &MainView);
33
34 static CButtonContainer s_PlayerTabButton;
35 if(DoButton_MenuTab(pButtonContainer: &s_PlayerTabButton, pText: Localize(pStr: "Player"), Checked: !m_Dummy, pRect: &PlayerTab, Corners: IGraphics::CORNER_L, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
36 {
37 m_Dummy = false;
38 m_SkinListScrollToSelected = true;
39 }
40
41 static CButtonContainer s_DummyTabButton;
42 if(DoButton_MenuTab(pButtonContainer: &s_DummyTabButton, pText: Localize(pStr: "Dummy"), Checked: m_Dummy, pRect: &DummyTab, Corners: IGraphics::CORNER_R, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
43 {
44 m_Dummy = true;
45 m_SkinListScrollToSelected = true;
46 }
47
48 if(Client()->State() == IClient::STATE_ONLINE &&
49 GameClient()->m_aNextChangeInfo[m_Dummy] > Client()->GameTick(Conn: m_Dummy))
50 {
51 char aChangeInfo[128], aTimeLeft[32];
52 str_format(buffer: aTimeLeft, buffer_size: sizeof(aTimeLeft), format: Localize(pStr: "%ds left"), (GameClient()->m_aNextChangeInfo[m_Dummy] - Client()->GameTick(Conn: m_Dummy) + Client()->GameTickSpeed() - 1) / Client()->GameTickSpeed());
53 str_format(buffer: aChangeInfo, buffer_size: sizeof(aChangeInfo), format: "%s: %s", Localize(pStr: "Player info change cooldown"), aTimeLeft);
54 Ui()->DoLabel(pRect: &ChangeInfo, pText: aChangeInfo, Size: 10.f, Align: TEXTALIGN_ML);
55 }
56
57 if(g_Config.m_Debug)
58 {
59 const CSkins::CSkinLoadingStats Stats = GameClient()->m_Skins.LoadingStats();
60 char aStats[256];
61 str_format(buffer: aStats, buffer_size: sizeof(aStats), format: "unloaded: %" PRIzu ", pending: %" PRIzu ", loading: %" PRIzu ",\nloaded: %" PRIzu ", error: %" PRIzu ", notfound: %" PRIzu,
62 Stats.m_NumUnloaded, Stats.m_NumPending, Stats.m_NumLoading, Stats.m_NumLoaded, Stats.m_NumError, Stats.m_NumNotFound);
63 Ui()->DoLabel(pRect: &ChangeInfo, pText: aStats, Size: 9.0f, Align: TEXTALIGN_MR);
64 }
65
66 char *pSkinName;
67 size_t SkinNameSize;
68 int *pUseCustomColor;
69 unsigned *pColorBody;
70 unsigned *pColorFeet;
71 int *pEmote;
72 if(!m_Dummy)
73 {
74 pSkinName = g_Config.m_ClPlayerSkin;
75 SkinNameSize = sizeof(g_Config.m_ClPlayerSkin);
76 pUseCustomColor = &g_Config.m_ClPlayerUseCustomColor;
77 pColorBody = &g_Config.m_ClPlayerColorBody;
78 pColorFeet = &g_Config.m_ClPlayerColorFeet;
79 pEmote = &g_Config.m_ClPlayerDefaultEyes;
80 }
81 else
82 {
83 pSkinName = g_Config.m_ClDummySkin;
84 SkinNameSize = sizeof(g_Config.m_ClDummySkin);
85 pUseCustomColor = &g_Config.m_ClDummyUseCustomColor;
86 pColorBody = &g_Config.m_ClDummyColorBody;
87 pColorFeet = &g_Config.m_ClDummyColorFeet;
88 pEmote = &g_Config.m_ClDummyDefaultEyes;
89 }
90
91 const float EyeButtonSize = 40.0f;
92 const bool RenderEyesBelow = MainView.w < 750.0f;
93 CUIRect YourSkin, Checkboxes, SkinPrefix, Eyes, Button, Label;
94 MainView.HSplitTop(Cut: 90.0f, pTop: &YourSkin, pBottom: &MainView);
95 if(RenderEyesBelow)
96 {
97 YourSkin.VSplitLeft(Cut: MainView.w * 0.45f, pLeft: &YourSkin, pRight: &Checkboxes);
98 Checkboxes.VSplitLeft(Cut: MainView.w * 0.35f, pLeft: &Checkboxes, pRight: &SkinPrefix);
99 MainView.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &MainView);
100 MainView.HSplitTop(Cut: EyeButtonSize, pTop: &Eyes, pBottom: &MainView);
101 Eyes.VSplitRight(Cut: EyeButtonSize * (float)NUM_EMOTES + 5.0f * (float)(NUM_EMOTES - 1), pLeft: nullptr, pRight: &Eyes);
102 }
103 else
104 {
105 YourSkin.VSplitRight(Cut: 3 * EyeButtonSize + 2 * 5.0f, pLeft: &YourSkin, pRight: &Eyes);
106 const float RemainderWidth = YourSkin.w;
107 YourSkin.VSplitLeft(Cut: RemainderWidth * 0.4f, pLeft: &YourSkin, pRight: &Checkboxes);
108 Checkboxes.VSplitLeft(Cut: RemainderWidth * 0.35f, pLeft: &Checkboxes, pRight: &SkinPrefix);
109 SkinPrefix.VSplitRight(Cut: 20.0f, pLeft: &SkinPrefix, pRight: nullptr);
110 }
111 YourSkin.VSplitRight(Cut: 20.0f, pLeft: &YourSkin, pRight: nullptr);
112 Checkboxes.VSplitRight(Cut: 20.0f, pLeft: &Checkboxes, pRight: nullptr);
113
114 // Checkboxes
115 bool ShouldRefresh = false;
116 Checkboxes.HSplitTop(Cut: 20.0f, pTop: &Button, pBottom: &Checkboxes);
117 if(DoButton_CheckBox(pId: &g_Config.m_ClDownloadSkins, pText: Localize(pStr: "Download skins"), Checked: g_Config.m_ClDownloadSkins, pRect: &Button))
118 {
119 g_Config.m_ClDownloadSkins ^= 1;
120 ShouldRefresh = true;
121 }
122
123 Checkboxes.HSplitTop(Cut: 20.0f, pTop: &Button, pBottom: &Checkboxes);
124 if(DoButton_CheckBox(pId: &g_Config.m_ClDownloadCommunitySkins, pText: Localize(pStr: "Download community skins"), Checked: g_Config.m_ClDownloadCommunitySkins, pRect: &Button))
125 {
126 g_Config.m_ClDownloadCommunitySkins ^= 1;
127 ShouldRefresh = true;
128 }
129
130 Checkboxes.HSplitTop(Cut: 20.0f, pTop: &Button, pBottom: &Checkboxes);
131 if(DoButton_CheckBox(pId: &g_Config.m_ClVanillaSkinsOnly, pText: Localize(pStr: "Vanilla skins only"), Checked: g_Config.m_ClVanillaSkinsOnly, pRect: &Button))
132 {
133 g_Config.m_ClVanillaSkinsOnly ^= 1;
134 ShouldRefresh = true;
135 }
136
137 Checkboxes.HSplitTop(Cut: 20.0f, pTop: &Button, pBottom: &Checkboxes);
138 if(DoButton_CheckBox(pId: &g_Config.m_ClFatSkins, pText: Localize(pStr: "Fat skins (DDFat)"), Checked: g_Config.m_ClFatSkins, pRect: &Button))
139 {
140 g_Config.m_ClFatSkins ^= 1;
141 }
142
143 // Skin prefix
144 {
145 SkinPrefix.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &SkinPrefix);
146 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Skin prefix"), Size: 14.0f, Align: TEXTALIGN_ML);
147
148 SkinPrefix.HSplitTop(Cut: 20.0f, pTop: &Button, pBottom: &SkinPrefix);
149 static CLineInput s_SkinPrefixInput(g_Config.m_ClSkinPrefix, sizeof(g_Config.m_ClSkinPrefix));
150 if(Ui()->DoClearableEditBox(pLineInput: &s_SkinPrefixInput, pRect: &Button, FontSize: 14.0f))
151 {
152 ShouldRefresh = true;
153 }
154
155 SkinPrefix.HSplitTop(Cut: 2.0f, pTop: nullptr, pBottom: &SkinPrefix);
156
157 static const char *s_apSkinPrefixes[] = {"kitty", "santa"};
158 static CButtonContainer s_aPrefixButtons[std::size(s_apSkinPrefixes)];
159 for(size_t i = 0; i < std::size(s_apSkinPrefixes); i++)
160 {
161 SkinPrefix.HSplitTop(Cut: 20.0f, pTop: &Button, pBottom: &SkinPrefix);
162 Button.HMargin(Cut: 2.0f, pOtherRect: &Button);
163 if(DoButton_Menu(pButtonContainer: &s_aPrefixButtons[i], pText: s_apSkinPrefixes[i], Checked: 0, pRect: &Button))
164 {
165 str_copy(dst&: g_Config.m_ClSkinPrefix, src: s_apSkinPrefixes[i]);
166 ShouldRefresh = true;
167 }
168 }
169 }
170
171 // Player skin area
172 CUIRect CustomColorsButton, RandomSkinButton;
173 YourSkin.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &YourSkin);
174 YourSkin.HSplitBottom(Cut: 20.0f, pTop: &YourSkin, pBottom: &CustomColorsButton);
175 CustomColorsButton.VSplitRight(Cut: 30.0f, pLeft: &CustomColorsButton, pRight: &RandomSkinButton);
176 CustomColorsButton.VSplitRight(Cut: 20.0f, pLeft: &CustomColorsButton, pRight: nullptr);
177 YourSkin.VSplitLeft(Cut: 65.0f, pLeft: &YourSkin, pRight: &Button);
178 Button.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Button);
179 Button.HMargin(Cut: (Button.h - 20.0f) / 2.0f, pOtherRect: &Button);
180
181 char aBuf[128 + IO_MAX_PATH_LENGTH];
182 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s:", Localize(pStr: "Your skin"));
183 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: 14.0f, Align: TEXTALIGN_ML);
184
185 CSkins::CSkinList &SkinList = GameClient()->m_Skins.SkinList();
186 const CSkin *pDefaultSkin = GameClient()->m_Skins.Find(pName: "default");
187 const CSkins::CSkinContainer *pOwnSkinContainer = GameClient()->m_Skins.FindContainerOrNullptr(pName: pSkinName[0] == '\0' ? "default" : pSkinName);
188 if(pOwnSkinContainer != nullptr && pOwnSkinContainer->IsSpecial())
189 {
190 pOwnSkinContainer = nullptr; // Special skins cannot be selected, show as missing due to invalid name
191 }
192
193 CTeeRenderInfo OwnSkinInfo;
194 OwnSkinInfo.Apply(pSkin: pOwnSkinContainer == nullptr || pOwnSkinContainer->Skin() == nullptr ? pDefaultSkin : pOwnSkinContainer->Skin().get());
195 OwnSkinInfo.ApplyColors(CustomColoredSkin: *pUseCustomColor, ColorBody: *pColorBody, ColorFeet: *pColorFeet);
196 OwnSkinInfo.m_Size = 50.0f;
197
198 // Tee
199 {
200 vec2 OffsetToMid;
201 CRenderTools::GetRenderTeeOffsetToRenderedTee(pAnim: CAnimState::GetIdle(), pInfo: &OwnSkinInfo, TeeOffsetToMid&: OffsetToMid);
202 const vec2 TeeRenderPos = vec2(YourSkin.x + YourSkin.w / 2.0f, YourSkin.y + YourSkin.h / 2.0f + OffsetToMid.y);
203 // tee looking towards cursor, and it is happy when you touch it
204 const vec2 DeltaPosition = Ui()->MousePos() - TeeRenderPos;
205 const float Distance = length(a: DeltaPosition);
206 const float InteractionDistance = 20.0f;
207 const vec2 TeeDirection = Distance < InteractionDistance ? normalize(v: vec2(DeltaPosition.x, std::max(a: DeltaPosition.y, b: 0.5f))) : normalize(v: DeltaPosition);
208 const int TeeEmote = Distance < InteractionDistance ? EMOTE_HAPPY : *pEmote;
209 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &OwnSkinInfo, Emote: TeeEmote, Dir: TeeDirection, Pos: TeeRenderPos);
210 }
211
212 // Skin loading status
213 const auto &&RenderSkinStatus = [&](CUIRect Parent, const CSkins::CSkinContainer *pSkinContainer, const void *pStatusTooltipId) {
214 if(pSkinContainer != nullptr && pSkinContainer->State() == CSkins::CSkinContainer::EState::LOADED)
215 {
216 return;
217 }
218
219 CUIRect StatusIcon;
220 Parent.HSplitTop(Cut: 20.0f, pTop: &StatusIcon, pBottom: nullptr);
221 StatusIcon.VSplitLeft(Cut: 20.0f, pLeft: &StatusIcon, pRight: nullptr);
222
223 if(pSkinContainer != nullptr &&
224 (pSkinContainer->State() == CSkins::CSkinContainer::EState::UNLOADED ||
225 pSkinContainer->State() == CSkins::CSkinContainer::EState::PENDING ||
226 pSkinContainer->State() == CSkins::CSkinContainer::EState::LOADING))
227 {
228 Ui()->RenderProgressSpinner(Center: StatusIcon.Center(), OuterRadius: 5.0f);
229 }
230 else
231 {
232 TextRender()->TextColor(Color: ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
233 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
234 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
235 Ui()->DoLabel(pRect: &StatusIcon, pText: pSkinContainer == nullptr || pSkinContainer->State() == CSkins::CSkinContainer::EState::ERROR ? FontIcon::TRIANGLE_EXCLAMATION : FontIcon::QUESTION, Size: 12.0f, Align: TEXTALIGN_MC);
236 TextRender()->SetRenderFlags(0);
237 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
238 TextRender()->TextColor(Color: TextRender()->DefaultTextColor());
239 Ui()->DoButtonLogic(pId: pStatusTooltipId, Checked: 0, pRect: &StatusIcon, Flags: BUTTONFLAG_NONE);
240 const char *pErrorTooltip;
241 if(pSkinContainer == nullptr)
242 {
243 pErrorTooltip = Localize(pStr: "This skin name cannot be used.");
244 }
245 else if(pSkinContainer->State() == CSkins::CSkinContainer::EState::ERROR)
246 {
247 pErrorTooltip = Localize(pStr: "Skin could not be loaded due to an error. Check the local console for details.");
248 }
249 else
250 {
251 pErrorTooltip = Localize(pStr: "Skin could not be found.");
252 }
253 Ui()->DoToolTip(pId: pStatusTooltipId, pNearRect: &StatusIcon, pText: pErrorTooltip);
254 }
255 };
256 static char s_StatusTooltipId;
257 RenderSkinStatus(YourSkin, pOwnSkinContainer, &s_StatusTooltipId);
258
259 // Skin name
260 static CLineInput s_SkinInput;
261 s_SkinInput.SetBuffer(pStr: pSkinName, MaxSize: SkinNameSize);
262 s_SkinInput.SetEmptyText("default");
263 if(Ui()->DoClearableEditBox(pLineInput: &s_SkinInput, pRect: &Button, FontSize: 14.0f))
264 {
265 SetNeedSendInfo();
266 m_SkinListScrollToSelected = true;
267 SkinList.ForceRefresh();
268 }
269
270 // Random skin button
271 static CButtonContainer s_RandomSkinButton;
272 static const char *s_apDice[] = {FontIcon::DICE_ONE, FontIcon::DICE_TWO, FontIcon::DICE_THREE, FontIcon::DICE_FOUR, FontIcon::DICE_FIVE, FontIcon::DICE_SIX};
273 static int s_CurrentDie = rand() % std::size(s_apDice);
274 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
275 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
276 if(DoButton_Menu(pButtonContainer: &s_RandomSkinButton, pText: s_apDice[s_CurrentDie], Checked: 0, pRect: &RandomSkinButton, Flags: BUTTONFLAG_LEFT, pImageName: nullptr, Corners: IGraphics::CORNER_ALL, Rounding: 5.0f, FontFactor: -0.2f))
277 {
278 GameClient()->m_Skins.RandomizeSkin(Dummy: m_Dummy);
279 SetNeedSendInfo();
280 m_SkinListScrollToSelected = true;
281 s_CurrentDie = rand() % std::size(s_apDice);
282 }
283 TextRender()->SetRenderFlags(0);
284 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
285 Ui()->DoToolTip(pId: &s_RandomSkinButton, pNearRect: &RandomSkinButton, pText: Localize(pStr: "Create a random skin"));
286
287 // Custom colors button
288 if(DoButton_CheckBox(pId: pUseCustomColor, pText: Localize(pStr: "Custom colors"), Checked: *pUseCustomColor, pRect: &CustomColorsButton))
289 {
290 *pUseCustomColor = *pUseCustomColor ? 0 : 1;
291 SetNeedSendInfo();
292 }
293
294 // Default eyes
295 {
296 CTeeRenderInfo EyeSkinInfo = OwnSkinInfo;
297 EyeSkinInfo.m_Size = EyeButtonSize;
298 vec2 OffsetToMid;
299 CRenderTools::GetRenderTeeOffsetToRenderedTee(pAnim: CAnimState::GetIdle(), pInfo: &EyeSkinInfo, TeeOffsetToMid&: OffsetToMid);
300
301 CUIRect EyesRow;
302 Eyes.HSplitTop(Cut: EyeButtonSize, pTop: &EyesRow, pBottom: &Eyes);
303 static CButtonContainer s_aEyeButtons[NUM_EMOTES];
304 for(int CurrentEyeEmote = 0; CurrentEyeEmote < NUM_EMOTES; CurrentEyeEmote++)
305 {
306 EyesRow.VSplitLeft(Cut: EyeButtonSize, pLeft: &Button, pRight: &EyesRow);
307 EyesRow.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &EyesRow);
308 if(!RenderEyesBelow && (CurrentEyeEmote + 1) % 3 == 0)
309 {
310 Eyes.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &Eyes);
311 Eyes.HSplitTop(Cut: EyeButtonSize, pTop: &EyesRow, pBottom: &Eyes);
312 }
313
314 const ColorRGBA EyeButtonColor = ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f + (*pEmote == CurrentEyeEmote ? 0.25f : 0.0f));
315 if(DoButton_Menu(pButtonContainer: &s_aEyeButtons[CurrentEyeEmote], pText: "", Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT, pImageName: nullptr, Corners: IGraphics::CORNER_ALL, Rounding: 5.0f, FontFactor: 0.0f, Color: EyeButtonColor))
316 {
317 *pEmote = CurrentEyeEmote;
318 if(GameClient()->m_GameInfo.m_AllowEyeWheel && (int)m_Dummy == g_Config.m_ClDummy)
319 GameClient()->m_Emoticon.EyeEmote(EyeEmote: CurrentEyeEmote);
320 }
321 Ui()->DoToolTip(pId: &s_aEyeButtons[CurrentEyeEmote], pNearRect: &Button, pText: Localize(pStr: "Choose default eyes when joining a server"));
322 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &EyeSkinInfo, Emote: CurrentEyeEmote, Dir: vec2(1.0f, 0.0f), Pos: vec2(Button.x + Button.w / 2.0f, Button.y + Button.h / 2.0f + OffsetToMid.y));
323 }
324 }
325
326 // Custom color pickers
327 MainView.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &MainView);
328 if(*pUseCustomColor)
329 {
330 CUIRect CustomColors;
331 MainView.HSplitTop(Cut: 95.0f, pTop: &CustomColors, pBottom: &MainView);
332 CUIRect aRects[2];
333 CustomColors.VSplitMid(pLeft: &aRects[0], pRight: &aRects[1], Spacing: 20.0f);
334
335 unsigned *apColors[] = {pColorBody, pColorFeet};
336 const char *apParts[] = {Localize(pStr: "Body"), Localize(pStr: "Feet")};
337
338 for(int i = 0; i < 2; i++)
339 {
340 aRects[i].HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &aRects[i]);
341 Ui()->DoLabel(pRect: &Label, pText: apParts[i], Size: 14.0f, Align: TEXTALIGN_ML);
342 if(RenderHslaScrollbars(pRect: &aRects[i], pColor: apColors[i], Alpha: false, DarkestLight: ColorHSLA::DARKEST_LGT))
343 {
344 SetNeedSendInfo();
345 }
346 }
347 }
348 MainView.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &MainView);
349
350 // Layout bottom controls and use remainder for skin selector
351 CUIRect QuickSearch, DatabaseButton, DirectoryButton, RefreshButton;
352 MainView.HSplitBottom(Cut: 20.0f, pTop: &MainView, pBottom: &QuickSearch);
353 MainView.HSplitBottom(Cut: 5.0f, pTop: &MainView, pBottom: nullptr);
354 QuickSearch.VSplitLeft(Cut: 220.0f, pLeft: &QuickSearch, pRight: &DatabaseButton);
355 DatabaseButton.VSplitLeft(Cut: 10.0f, pLeft: nullptr, pRight: &DatabaseButton);
356 DatabaseButton.VSplitLeft(Cut: 150.0f, pLeft: &DatabaseButton, pRight: &DirectoryButton);
357 DirectoryButton.VSplitRight(Cut: 175.0f, pLeft: nullptr, pRight: &DirectoryButton);
358 DirectoryButton.VSplitRight(Cut: 25.0f, pLeft: &DirectoryButton, pRight: &RefreshButton);
359 DirectoryButton.VSplitRight(Cut: 10.0f, pLeft: &DirectoryButton, pRight: nullptr);
360
361 // Skin selector
362 static CListBox s_ListBox;
363 std::vector<CSkins::CSkinListEntry> &vSkinList = SkinList.Skins();
364 int OldSelected = -1;
365 s_ListBox.DoStart(RowHeight: 50.0f, NumItems: vSkinList.size(), ItemsPerRow: 4, RowsPerScroll: 2, SelectedIndex: OldSelected, pRect: &MainView);
366 for(size_t i = 0; i < vSkinList.size(); ++i)
367 {
368 CSkins::CSkinListEntry &SkinListEntry = vSkinList[i];
369 const CSkins::CSkinContainer *pSkinContainer = vSkinList[i].SkinContainer();
370
371 if(!m_Dummy ? SkinListEntry.IsSelectedMain() : SkinListEntry.IsSelectedDummy())
372 {
373 OldSelected = i;
374 if(m_SkinListScrollToSelected)
375 {
376 s_ListBox.ScrollToSelected();
377 m_SkinListScrollToSelected = false;
378 }
379 }
380
381 const CListboxItem Item = s_ListBox.DoNextItem(pId: SkinListEntry.ListItemId(), Selected: OldSelected >= 0 && (size_t)OldSelected == i);
382 if(!Item.m_Visible)
383 {
384 continue;
385 }
386
387 SkinListEntry.RequestLoad();
388 const CSkin *pSkin = pSkinContainer->State() == CSkins::CSkinContainer::EState::LOADED ? pSkinContainer->Skin().get() : pDefaultSkin;
389
390 Item.m_Rect.VSplitLeft(Cut: 60.0f, pLeft: &Button, pRight: &Label);
391
392 {
393 CTeeRenderInfo Info = OwnSkinInfo;
394 Info.Apply(pSkin);
395 RenderTools()->RenderIdleTeeAtCenter(pInfo: &Info, Center: vec2(Button.x + Button.w / 2.0f, Button.y + Button.h / 2), Emote: *pEmote);
396 }
397
398 {
399 SLabelProperties Props;
400 Props.m_MaxWidth = Label.w - 5.0f;
401 const auto &NameMatch = SkinListEntry.NameMatch();
402 if(NameMatch.has_value())
403 {
404 const auto [MatchStart, MatchLength] = NameMatch.value();
405 Props.m_vColorSplits.emplace_back(args: MatchStart, args: MatchLength, args: ColorRGBA(0.4f, 0.4f, 1.0f, 1.0f));
406 }
407 Ui()->DoLabel(pRect: &Label, pText: pSkinContainer->Name(), Size: 12.0f, Align: TEXTALIGN_ML, LabelProps: Props);
408 }
409
410 if(g_Config.m_Debug)
411 {
412 Graphics()->TextureClear();
413 Graphics()->QuadsBegin();
414 Graphics()->SetColor(*pUseCustomColor ? color_cast<ColorRGBA>(hsl: ColorHSLA(*pColorBody).UnclampLighting(Darkest: ColorHSLA::DARKEST_LGT)) : pSkin->m_BloodColor);
415 IGraphics::CQuadItem QuadItem(Label.x, Label.y, 12.0f, 12.0f);
416 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
417 Graphics()->QuadsEnd();
418 }
419
420 // render skin favorite icon
421 {
422 CUIRect FavIcon;
423 Item.m_Rect.HSplitTop(Cut: 20.0f, pTop: &FavIcon, pBottom: nullptr);
424 FavIcon.VSplitRight(Cut: 20.0f, pLeft: nullptr, pRight: &FavIcon);
425 if(DoButton_Favorite(pButtonId: SkinListEntry.FavoriteButtonId(), pParentId: SkinListEntry.ListItemId(), Checked: SkinListEntry.IsFavorite(), pRect: &FavIcon))
426 {
427 if(SkinListEntry.IsFavorite())
428 {
429 GameClient()->m_Skins.RemoveFavorite(pName: pSkinContainer->Name());
430 }
431 else
432 {
433 GameClient()->m_Skins.AddFavorite(pName: pSkinContainer->Name());
434 }
435 }
436 }
437
438 RenderSkinStatus(Item.m_Rect, pSkinContainer, SkinListEntry.ErrorTooltipId());
439 }
440
441 const int NewSelected = s_ListBox.DoEnd();
442 if(OldSelected != NewSelected)
443 {
444 str_copy(dst: pSkinName, src: vSkinList[NewSelected].SkinContainer()->Name(), dst_size: SkinNameSize);
445 SkinList.ForceRefresh();
446 SetNeedSendInfo();
447 }
448
449 static CLineInput s_SkinFilterInput(g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString));
450 if(SkinList.UnfilteredCount() > 0 && vSkinList.empty())
451 {
452 CUIRect FilterLabel, ResetButton;
453 MainView.HMargin(Cut: (MainView.h - (16.0f + 18.0f + 8.0f)) / 2.0f, pOtherRect: &FilterLabel);
454 FilterLabel.HSplitTop(Cut: 16.0f, pTop: &FilterLabel, pBottom: &ResetButton);
455 ResetButton.HSplitTop(Cut: 8.0f, pTop: nullptr, pBottom: &ResetButton);
456 ResetButton.VMargin(Cut: (ResetButton.w - 200.0f) / 2.0f, pOtherRect: &ResetButton);
457 Ui()->DoLabel(pRect: &FilterLabel, pText: Localize(pStr: "No skins match your filter criteria"), Size: 16.0f, Align: TEXTALIGN_MC);
458 static CButtonContainer s_ResetButton;
459 if(DoButton_Menu(pButtonContainer: &s_ResetButton, pText: Localize(pStr: "Reset filter"), Checked: 0, pRect: &ResetButton))
460 {
461 s_SkinFilterInput.Clear();
462 SkinList.ForceRefresh();
463 }
464 }
465
466 if(Ui()->DoEditBox_Search(pLineInput: &s_SkinFilterInput, pRect: &QuickSearch, FontSize: 14.0f, HotkeyEnabled: !Ui()->IsPopupOpen() && !GameClient()->m_GameConsole.IsActive()))
467 {
468 SkinList.ForceRefresh();
469 }
470
471 static CButtonContainer s_SkinDatabaseButton;
472 if(DoButton_Menu(pButtonContainer: &s_SkinDatabaseButton, pText: Localize(pStr: "Skin Database"), Checked: 0, pRect: &DatabaseButton))
473 {
474 Client()->ViewLink(pLink: "https://ddnet.org/skins/");
475 }
476
477 static CButtonContainer s_DirectoryButton;
478 if(DoButton_Menu(pButtonContainer: &s_DirectoryButton, pText: Localize(pStr: "Skins directory"), Checked: 0, pRect: &DirectoryButton))
479 {
480 Storage()->GetCompletePath(Type: IStorage::TYPE_SAVE, pDir: "skins", pBuffer: aBuf, BufferSize: sizeof(aBuf));
481 Storage()->CreateFolder(pFoldername: "skins", Type: IStorage::TYPE_SAVE);
482 Client()->ViewFile(pFilename: aBuf);
483 }
484 Ui()->DoToolTip(pId: &s_DirectoryButton, pNearRect: &DirectoryButton, pText: Localize(pStr: "Open the directory to add custom skins"));
485
486 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
487 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
488 static CButtonContainer s_SkinRefreshButton;
489 if(DoButton_Menu(pButtonContainer: &s_SkinRefreshButton, pText: FontIcon::ARROW_ROTATE_RIGHT, Checked: 0, pRect: &RefreshButton) || Input()->KeyPress(Key: KEY_F5) || (Input()->KeyPress(Key: KEY_R) && Input()->ModifierIsPressed()))
490 {
491 ShouldRefresh = true;
492 }
493 TextRender()->SetRenderFlags(0);
494 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
495
496 if(ShouldRefresh)
497 {
498 GameClient()->RefreshSkins(SkinDescriptorFlags: CSkinDescriptor::FLAG_SIX);
499 }
500}
501