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/dbg.h>
6#include <base/str.h>
7
8#include <engine/font_icons.h>
9#include <engine/graphics.h>
10#include <engine/shared/config.h>
11#include <engine/storage.h>
12#include <engine/textrender.h>
13
14#include <game/client/animstate.h>
15#include <game/client/components/console.h>
16#include <game/client/components/skins7.h>
17#include <game/client/components/sounds.h>
18#include <game/client/gameclient.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::RenderSettingsTee7(CUIRect MainView)
27{
28 CUIRect SkinPreview, NormalSkinPreview, RedTeamSkinPreview, BlueTeamSkinPreview, Buttons, QuickSearch, DirectoryButton, RefreshButton, SaveDeleteButton, TabBars, TabBar, LeftTab, RightTab;
29 MainView.HSplitBottom(Cut: 20.0f, pTop: &MainView, pBottom: &Buttons);
30 MainView.HSplitBottom(Cut: 5.0f, pTop: &MainView, pBottom: nullptr);
31 Buttons.VSplitRight(Cut: 25.0f, pLeft: &Buttons, pRight: &RefreshButton);
32 Buttons.VSplitRight(Cut: 10.0f, pLeft: &Buttons, pRight: nullptr);
33 Buttons.VSplitRight(Cut: 140.0f, pLeft: &Buttons, pRight: &DirectoryButton);
34 Buttons.VSplitLeft(Cut: 220.0f, pLeft: &QuickSearch, pRight: &Buttons);
35 Buttons.VSplitLeft(Cut: 10.0f, pLeft: nullptr, pRight: &Buttons);
36 Buttons.VSplitLeft(Cut: 120.0f, pLeft: &SaveDeleteButton, pRight: &Buttons);
37 MainView.HSplitTop(Cut: 50.0f, pTop: &TabBars, pBottom: &MainView);
38 MainView.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &MainView);
39 TabBars.VSplitMid(pLeft: &TabBars, pRight: &SkinPreview, Spacing: 20.0f);
40
41 TabBars.HSplitTop(Cut: 20.0f, pTop: &TabBar, pBottom: &TabBars);
42 TabBar.VSplitMid(pLeft: &LeftTab, pRight: &RightTab);
43 TabBars.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &TabBars);
44
45 SkinPreview.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: 5.0f);
46 SkinPreview.VMargin(Cut: 10.0f, pOtherRect: &SkinPreview);
47 SkinPreview.VSplitRight(Cut: 50.0f, pLeft: &SkinPreview, pRight: &BlueTeamSkinPreview);
48 SkinPreview.VSplitRight(Cut: 10.0f, pLeft: &SkinPreview, pRight: nullptr);
49 SkinPreview.VSplitRight(Cut: 50.0f, pLeft: &SkinPreview, pRight: &RedTeamSkinPreview);
50 SkinPreview.VSplitRight(Cut: 10.0f, pLeft: &SkinPreview, pRight: nullptr);
51 SkinPreview.VSplitRight(Cut: 50.0f, pLeft: &SkinPreview, pRight: &NormalSkinPreview);
52 SkinPreview.VSplitRight(Cut: 10.0f, pLeft: &SkinPreview, pRight: nullptr);
53
54 static CButtonContainer s_PlayerTabButton;
55 if(DoButton_MenuTab(pButtonContainer: &s_PlayerTabButton, pText: Localize(pStr: "Player"), Checked: !m_Dummy, pRect: &LeftTab, Corners: IGraphics::CORNER_L, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
56 {
57 m_Dummy = false;
58 }
59
60 static CButtonContainer s_DummyTabButton;
61 if(DoButton_MenuTab(pButtonContainer: &s_DummyTabButton, pText: Localize(pStr: "Dummy"), Checked: m_Dummy, pRect: &RightTab, Corners: IGraphics::CORNER_R, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
62 {
63 m_Dummy = true;
64 }
65
66 TabBars.HSplitTop(Cut: 20.0f, pTop: &TabBar, pBottom: &TabBars);
67 TabBar.VSplitMid(pLeft: &LeftTab, pRight: &RightTab);
68
69 static CButtonContainer s_BasicTabButton;
70 if(DoButton_MenuTab(pButtonContainer: &s_BasicTabButton, pText: Localize(pStr: "Basic"), Checked: !m_CustomSkinMenu, pRect: &LeftTab, Corners: IGraphics::CORNER_L, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
71 {
72 m_CustomSkinMenu = false;
73 }
74
75 static CButtonContainer s_CustomTabButton;
76 if(DoButton_MenuTab(pButtonContainer: &s_CustomTabButton, pText: Localize(pStr: "Custom"), Checked: m_CustomSkinMenu, pRect: &RightTab, Corners: IGraphics::CORNER_R, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
77 {
78 m_CustomSkinMenu = true;
79 if(m_CustomSkinMenu && m_pSelectedSkin)
80 {
81 if(m_pSelectedSkin->m_Flags & CSkins7::SKINFLAG_STANDARD)
82 {
83 m_SkinNameInput.Set("copy_");
84 m_SkinNameInput.Append(pString: m_pSelectedSkin->m_aName);
85 }
86 else
87 m_SkinNameInput.Set(m_pSelectedSkin->m_aName);
88 }
89 }
90
91 // validate skin parts for solo mode
92 char aSkinParts[protocol7::NUM_SKINPARTS][protocol7::MAX_SKIN_ARRAY_SIZE];
93 char *apSkinPartsPtr[protocol7::NUM_SKINPARTS];
94 int aUCCVars[protocol7::NUM_SKINPARTS];
95 int aColorVars[protocol7::NUM_SKINPARTS];
96 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
97 {
98 str_copy(dst: aSkinParts[Part], src: CSkins7::ms_apSkinVariables[(int)m_Dummy][Part], dst_size: protocol7::MAX_SKIN_ARRAY_SIZE);
99 apSkinPartsPtr[Part] = aSkinParts[Part];
100 aUCCVars[Part] = *CSkins7::ms_apUCCVariables[(int)m_Dummy][Part];
101 aColorVars[Part] = *CSkins7::ms_apColorVariables[(int)m_Dummy][Part];
102 }
103 GameClient()->m_Skins7.ValidateSkinParts(apPartNames: apSkinPartsPtr, pUseCustomColors: aUCCVars, pPartColors: aColorVars, GameFlags: 0);
104
105 CTeeRenderInfo OwnSkinInfo;
106 OwnSkinInfo.m_Size = 50.0f;
107 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
108 {
109 GameClient()->m_Skins7.FindSkinPart(Part, pName: apSkinPartsPtr[Part], AllowSpecialPart: false)->ApplyTo(SixupRenderInfo&: OwnSkinInfo.m_aSixup[g_Config.m_ClDummy]);
110 GameClient()->m_Skins7.ApplyColorTo(SixupRenderInfo&: OwnSkinInfo.m_aSixup[g_Config.m_ClDummy], UseCustomColors: aUCCVars[Part], Value: aColorVars[Part], Part);
111 }
112
113 char aBuf[128 + IO_MAX_PATH_LENGTH];
114 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s:", Localize(pStr: "Your skin"));
115 Ui()->DoLabel(pRect: &SkinPreview, pText: aBuf, Size: 14.0f, Align: TEXTALIGN_ML);
116
117 vec2 OffsetToMid;
118 CRenderTools::GetRenderTeeOffsetToRenderedTee(pAnim: CAnimState::GetIdle(), pInfo: &OwnSkinInfo, TeeOffsetToMid&: OffsetToMid);
119 {
120 // interactive tee: tee looking towards cursor, and it is happy when you touch it
121 const vec2 TeePosition = NormalSkinPreview.Center() + OffsetToMid;
122 const vec2 DeltaPosition = Ui()->MousePos() - TeePosition;
123 const float Distance = length(a: DeltaPosition);
124 const float InteractionDistance = 20.0f;
125 const vec2 TeeDirection = Distance < InteractionDistance ? normalize(v: vec2(DeltaPosition.x, std::max(a: DeltaPosition.y, b: 0.5f))) : normalize(v: DeltaPosition);
126 const int TeeEmote = Distance < InteractionDistance ? EMOTE_HAPPY : EMOTE_NORMAL;
127 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &OwnSkinInfo, Emote: TeeEmote, Dir: TeeDirection, Pos: TeePosition);
128 static char s_InteractiveTeeButtonId;
129 if(Distance < InteractionDistance && Ui()->DoButtonLogic(pId: &s_InteractiveTeeButtonId, Checked: 0, pRect: &NormalSkinPreview, Flags: BUTTONFLAG_LEFT))
130 {
131 GameClient()->m_Sounds.Play(Channel: CSounds::CHN_GUI, SetId: SOUND_PLAYER_SPAWN, Volume: 1.0f);
132 }
133 }
134
135 // validate skin parts for team game mode
136 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
137 {
138 str_copy(dst: aSkinParts[Part], src: CSkins7::ms_apSkinVariables[(int)m_Dummy][Part], dst_size: protocol7::MAX_SKIN_ARRAY_SIZE);
139 apSkinPartsPtr[Part] = aSkinParts[Part];
140 aUCCVars[Part] = *CSkins7::ms_apUCCVariables[(int)m_Dummy][Part];
141 aColorVars[Part] = *CSkins7::ms_apColorVariables[(int)m_Dummy][Part];
142 }
143 GameClient()->m_Skins7.ValidateSkinParts(apPartNames: apSkinPartsPtr, pUseCustomColors: aUCCVars, pPartColors: aColorVars, GameFlags: GAMEFLAG_TEAMS);
144
145 CTeeRenderInfo TeamSkinInfo;
146 TeamSkinInfo.m_Size = OwnSkinInfo.m_Size;
147 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
148 {
149 GameClient()->m_Skins7.FindSkinPart(Part, pName: apSkinPartsPtr[Part], AllowSpecialPart: false)->ApplyTo(SixupRenderInfo&: TeamSkinInfo.m_aSixup[g_Config.m_ClDummy]);
150 TeamSkinInfo.m_aSixup[g_Config.m_ClDummy].m_aUseCustomColors[Part] = aUCCVars[Part];
151 }
152
153 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
154 {
155 TeamSkinInfo.m_aSixup[g_Config.m_ClDummy].m_aColors[Part] = GameClient()->m_Skins7.GetTeamColor(UseCustomColors: aUCCVars[Part], PartColor: aColorVars[Part], Team: TEAM_RED, Part);
156 }
157 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &TeamSkinInfo, Emote: 0, Dir: vec2(1, 0), Pos: RedTeamSkinPreview.Center() + OffsetToMid);
158
159 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
160 {
161 TeamSkinInfo.m_aSixup[g_Config.m_ClDummy].m_aColors[Part] = GameClient()->m_Skins7.GetTeamColor(UseCustomColors: aUCCVars[Part], PartColor: aColorVars[Part], Team: TEAM_BLUE, Part);
162 }
163 RenderTools()->RenderTee(pAnim: CAnimState::GetIdle(), pInfo: &TeamSkinInfo, Emote: 0, Dir: vec2(-1, 0), Pos: BlueTeamSkinPreview.Center() + OffsetToMid);
164
165 if(m_CustomSkinMenu)
166 RenderSettingsTeeCustom7(MainView);
167 else
168 RenderSkinSelection7(MainView);
169
170 if(m_CustomSkinMenu)
171 {
172 static CButtonContainer s_CustomSkinSaveButton;
173 if(DoButton_Menu(pButtonContainer: &s_CustomSkinSaveButton, pText: Localize(pStr: "Save"), Checked: 0, pRect: &SaveDeleteButton))
174 {
175 m_Popup = POPUP_SAVE_SKIN;
176 m_SkinNameInput.SelectAll();
177 Ui()->SetActiveItem(&m_SkinNameInput);
178 }
179 }
180 else if(m_pSelectedSkin && (m_pSelectedSkin->m_Flags & CSkins7::SKINFLAG_STANDARD) == 0)
181 {
182 static CButtonContainer s_CustomSkinDeleteButton;
183 if(DoButton_Menu(pButtonContainer: &s_CustomSkinDeleteButton, pText: Localize(pStr: "Delete"), Checked: 0, pRect: &SaveDeleteButton) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_DELETE))
184 {
185 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Are you sure that you want to delete '%s'?"), m_pSelectedSkin->m_aName);
186 PopupConfirm(pTitle: Localize(pStr: "Delete skin"), pMessage: aBuf, pConfirmButtonLabel: Localize(pStr: "Yes"), pCancelButtonLabel: Localize(pStr: "No"), pfnConfirmButtonCallback: &CMenus::PopupConfirmDeleteSkin7);
187 }
188 }
189
190 static CLineInput s_SkinFilterInput(g_Config.m_ClSkinFilterString, sizeof(g_Config.m_ClSkinFilterString));
191 if(Ui()->DoEditBox_Search(pLineInput: &s_SkinFilterInput, pRect: &QuickSearch, FontSize: 14.0f, HotkeyEnabled: !Ui()->IsPopupOpen() && !GameClient()->m_GameConsole.IsActive()))
192 {
193 m_SkinList7LastRefreshTime = std::nullopt;
194 m_SkinPartsList7LastRefreshTime = std::nullopt;
195 }
196
197 static CButtonContainer s_DirectoryButton;
198 if(DoButton_Menu(pButtonContainer: &s_DirectoryButton, pText: Localize(pStr: "Skins directory"), Checked: 0, pRect: &DirectoryButton))
199 {
200 Storage()->GetCompletePath(Type: IStorage::TYPE_SAVE, pDir: "skins7", pBuffer: aBuf, BufferSize: sizeof(aBuf));
201 Storage()->CreateFolder(pFoldername: "skins7", Type: IStorage::TYPE_SAVE);
202 Client()->ViewFile(pFilename: aBuf);
203 }
204 Ui()->DoToolTip(pId: &s_DirectoryButton, pNearRect: &DirectoryButton, pText: Localize(pStr: "Open the directory to add custom skins"));
205
206 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
207 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);
208 static CButtonContainer s_SkinRefreshButton;
209 if(DoButton_Menu(pButtonContainer: &s_SkinRefreshButton, pText: FontIcon::ARROW_ROTATE_RIGHT, Checked: 0, pRect: &RefreshButton) ||
210 (!Ui()->IsPopupOpen() && !GameClient()->m_GameConsole.IsActive() && (Input()->KeyPress(Key: KEY_F5) || (Input()->ModifierIsPressed() && Input()->KeyPress(Key: KEY_R)))))
211 {
212 // reset render flags for possible loading screen
213 TextRender()->SetRenderFlags(0);
214 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
215 GameClient()->RefreshSkins(SkinDescriptorFlags: CSkinDescriptor::FLAG_SEVEN);
216 }
217 TextRender()->SetRenderFlags(0);
218 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
219}
220
221void CMenus::PopupConfirmDeleteSkin7()
222{
223 dbg_assert(m_pSelectedSkin, "no skin selected for deletion");
224
225 if(!GameClient()->m_Skins7.RemoveSkin(pSkin: m_pSelectedSkin))
226 {
227 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "Unable to delete skin"), pButtonLabel: Localize(pStr: "Ok"));
228 return;
229 }
230 m_pSelectedSkin = nullptr;
231 m_DeletedSkinIndex7 = m_SelectedSkinIndex7;
232}
233
234void CMenus::RenderSettingsTeeCustom7(CUIRect MainView)
235{
236 CUIRect ButtonBar, SkinPartSelection, CustomColors;
237
238 MainView.HSplitTop(Cut: 20.0f, pTop: &ButtonBar, pBottom: &MainView);
239 MainView.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f), Corners: IGraphics::CORNER_B, Rounding: 5.0f);
240 MainView.VSplitMid(pLeft: &SkinPartSelection, pRight: &CustomColors, Spacing: 10.0f);
241 CustomColors.Margin(Cut: 5.0f, pOtherRect: &CustomColors);
242 CUIRect CustomColorsButton, RandomSkinButton;
243 CustomColors.HSplitTop(Cut: 20.0f, pTop: &CustomColorsButton, pBottom: &CustomColors);
244 CustomColorsButton.VSplitRight(Cut: 30.0f, pLeft: &CustomColorsButton, pRight: &RandomSkinButton);
245 CustomColorsButton.VSplitRight(Cut: 20.0f, pLeft: &CustomColorsButton, pRight: nullptr);
246
247 const float ButtonWidth = ButtonBar.w / (float)protocol7::NUM_SKINPARTS;
248
249 static CButtonContainer s_aSkinPartButtons[protocol7::NUM_SKINPARTS];
250 for(int i = 0; i < protocol7::NUM_SKINPARTS; i++)
251 {
252 CUIRect Button;
253 ButtonBar.VSplitLeft(Cut: ButtonWidth, pLeft: &Button, pRight: &ButtonBar);
254 const int Corners = i == 0 ? IGraphics::CORNER_TL : (i == (protocol7::NUM_SKINPARTS - 1) ? IGraphics::CORNER_TR : IGraphics::CORNER_NONE);
255 if(DoButton_MenuTab(pButtonContainer: &s_aSkinPartButtons[i], pText: Localize(pStr: CSkins7::ms_apSkinPartNamesLocalized[i], pContext: "skins"), Checked: m_TeePartSelected == i, pRect: &Button, Corners, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 4.0f))
256 {
257 m_TeePartSelected = i;
258 }
259 }
260
261 RenderSkinPartSelection7(MainView: SkinPartSelection);
262
263 int *pUseCustomColor = CSkins7::ms_apUCCVariables[(int)m_Dummy][m_TeePartSelected];
264 if(DoButton_CheckBox(pId: pUseCustomColor, pText: Localize(pStr: "Custom colors"), Checked: *pUseCustomColor, pRect: &CustomColorsButton))
265 {
266 *pUseCustomColor = !*pUseCustomColor;
267 SetNeedSendInfo();
268 }
269
270 if(*pUseCustomColor)
271 {
272 CUIRect CustomColorScrollbars;
273 CustomColors.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &CustomColors);
274 CustomColors.HSplitTop(Cut: 95.0f, pTop: &CustomColorScrollbars, pBottom: &CustomColors);
275
276 if(RenderHslaScrollbars(pRect: &CustomColorScrollbars, pColor: CSkins7::ms_apColorVariables[(int)m_Dummy][m_TeePartSelected], Alpha: m_TeePartSelected == protocol7::SKINPART_MARKING, DarkestLight: ColorHSLA::DARKEST_LGT7))
277 {
278 SetNeedSendInfo();
279 }
280 }
281
282 // Random skin button
283 static CButtonContainer s_RandomSkinButton;
284 static const char *s_apDice[] = {FontIcon::DICE_ONE, FontIcon::DICE_TWO, FontIcon::DICE_THREE, FontIcon::DICE_FOUR, FontIcon::DICE_FIVE, FontIcon::DICE_SIX};
285 static int s_CurrentDie = rand() % std::size(s_apDice);
286 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
287 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);
288 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))
289 {
290 GameClient()->m_Skins7.RandomizeSkin(Dummy: m_Dummy);
291 SetNeedSendInfo();
292 s_CurrentDie = rand() % std::size(s_apDice);
293 }
294 TextRender()->SetRenderFlags(0);
295 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
296 Ui()->DoToolTip(pId: &s_RandomSkinButton, pNearRect: &RandomSkinButton, pText: Localize(pStr: "Create a random skin"));
297}
298
299void CMenus::RenderSkinSelection7(CUIRect MainView)
300{
301 static float s_LastSelectionTime = -10.0f;
302 static std::vector<const CSkins7::CSkin *> s_vpSkinList;
303 static CListBox s_ListBox;
304
305 if(!m_SkinList7LastRefreshTime.has_value() || m_SkinList7LastRefreshTime.value() != m_SkinList7LastRefreshTime)
306 {
307 s_vpSkinList.clear();
308 for(const CSkins7::CSkin &Skin : GameClient()->m_Skins7.GetSkins())
309 {
310 if((Skin.m_Flags & CSkins7::SKINFLAG_SPECIAL) != 0)
311 continue;
312 if(g_Config.m_ClSkinFilterString[0] != '\0' && !str_utf8_find_nocase(haystack: Skin.m_aName, needle: g_Config.m_ClSkinFilterString))
313 continue;
314
315 s_vpSkinList.emplace_back(args: &Skin);
316 }
317 }
318
319 m_pSelectedSkin = nullptr;
320 m_SelectedSkinIndex7 = -1;
321 for(int i = 0; i < (int)s_vpSkinList.size(); ++i)
322 {
323 const CSkins7::CSkin *pSkin = s_vpSkinList[i];
324 if(!str_comp(a: pSkin->m_aName, b: CSkins7::ms_apSkinNameVariables[m_Dummy]))
325 {
326 m_pSelectedSkin = pSkin;
327 m_SelectedSkinIndex7 = i;
328 break;
329 }
330 }
331 s_ListBox.DoStart(RowHeight: 50.0f, NumItems: s_vpSkinList.size(), ItemsPerRow: 4, RowsPerScroll: 1, SelectedIndex: m_SelectedSkinIndex7, pRect: &MainView);
332
333 for(const CSkins7::CSkin *pSkin : s_vpSkinList)
334 {
335 const CListboxItem Item = s_ListBox.DoNextItem(pId: pSkin);
336 if(!Item.m_Visible)
337 continue;
338
339 CUIRect TeePreview, Label;
340 Item.m_Rect.VSplitLeft(Cut: 60.0f, pLeft: &TeePreview, pRight: &Label);
341
342 CTeeRenderInfo Info;
343 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
344 {
345 pSkin->m_apParts[Part]->ApplyTo(SixupRenderInfo&: Info.m_aSixup[g_Config.m_ClDummy]);
346 GameClient()->m_Skins7.ApplyColorTo(SixupRenderInfo&: Info.m_aSixup[g_Config.m_ClDummy], UseCustomColors: pSkin->m_aUseCustomColors[Part], Value: pSkin->m_aPartColors[Part], Part);
347 }
348 Info.m_Size = 50.0f;
349
350 {
351 // interactive tee: tee is happy to be selected
352 int TeeEmote = (Item.m_Selected && s_LastSelectionTime + 0.75f > Client()->GlobalTime()) ? EMOTE_HAPPY : EMOTE_NORMAL;
353 RenderTools()->RenderIdleTeeAtCenter(pInfo: &Info, Center: TeePreview.Center(), Emote: TeeEmote);
354 }
355
356 SLabelProperties Props;
357 Props.m_MaxWidth = Label.w - 5.0f;
358 Ui()->DoLabel(pRect: &Label, pText: pSkin->m_aName, Size: 12.0f, Align: TEXTALIGN_ML, LabelProps: Props);
359 }
360
361 int NewSelected = s_ListBox.DoEnd();
362 if(m_DeletedSkinIndex7 >= 0)
363 {
364 // Select the skin which took the place of the deleted skin, or the last skin
365 NewSelected = std::min(a: m_DeletedSkinIndex7, b: (int)s_vpSkinList.size() - 1);
366 m_DeletedSkinIndex7 = -1;
367 }
368 if(NewSelected != -1 && NewSelected != m_SelectedSkinIndex7)
369 {
370 s_LastSelectionTime = Client()->GlobalTime();
371 m_pSelectedSkin = s_vpSkinList[NewSelected];
372 str_copy(dst: CSkins7::ms_apSkinNameVariables[m_Dummy], src: m_pSelectedSkin->m_aName, dst_size: protocol7::MAX_SKIN_ARRAY_SIZE);
373 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
374 {
375 str_copy(dst: CSkins7::ms_apSkinVariables[(int)m_Dummy][Part], src: m_pSelectedSkin->m_apParts[Part]->m_aName, dst_size: protocol7::MAX_SKIN_ARRAY_SIZE);
376 *CSkins7::ms_apUCCVariables[(int)m_Dummy][Part] = m_pSelectedSkin->m_aUseCustomColors[Part];
377 *CSkins7::ms_apColorVariables[(int)m_Dummy][Part] = m_pSelectedSkin->m_aPartColors[Part];
378 }
379 SetNeedSendInfo();
380 }
381}
382
383void CMenus::RenderSkinPartSelection7(CUIRect MainView)
384{
385 static std::vector<const CSkins7::CSkinPart *> s_avpList[protocol7::NUM_SKINPARTS];
386 static CListBox s_ListBox;
387 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
388 {
389 if(!m_SkinList7LastRefreshTime.has_value() || m_SkinList7LastRefreshTime.value() != GameClient()->m_Skins7.LastRefreshTime())
390 {
391 s_avpList[Part].clear();
392 for(const CSkins7::CSkinPart &SkinPart : GameClient()->m_Skins7.GetSkinParts(Part))
393 {
394 if((SkinPart.m_Flags & CSkins7::SKINFLAG_SPECIAL) != 0)
395 continue;
396
397 if(g_Config.m_ClSkinFilterString[0] != '\0' && !str_utf8_find_nocase(haystack: SkinPart.m_aName, needle: g_Config.m_ClSkinFilterString))
398 continue;
399
400 s_avpList[Part].emplace_back(args: &SkinPart);
401 }
402 }
403 }
404
405 int OldSelected = -1;
406 for(int i = 0; i < (int)s_avpList[m_TeePartSelected].size(); ++i)
407 {
408 const CSkins7::CSkinPart *pPart = s_avpList[m_TeePartSelected][i];
409 if(!str_comp(a: pPart->m_aName, b: CSkins7::ms_apSkinVariables[(int)m_Dummy][m_TeePartSelected]))
410 {
411 OldSelected = i;
412 break;
413 }
414 }
415 s_ListBox.DoStart(RowHeight: 72.0f, NumItems: s_avpList[m_TeePartSelected].size(), ItemsPerRow: 4, RowsPerScroll: 1, SelectedIndex: OldSelected, pRect: &MainView, Background: false, BackgroundCorners: IGraphics::CORNER_NONE, ForceShowScrollbar: true);
416
417 for(const CSkins7::CSkinPart *pPart : s_avpList[m_TeePartSelected])
418 {
419 CListboxItem Item = s_ListBox.DoNextItem(pId: pPart);
420 if(!Item.m_Visible)
421 continue;
422
423 CUIRect Label;
424 Item.m_Rect.Margin(Cut: 5.0f, pOtherRect: &Item.m_Rect);
425 Item.m_Rect.HSplitBottom(Cut: 12.0f, pTop: &Item.m_Rect, pBottom: &Label);
426
427 CTeeRenderInfo Info;
428 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
429 {
430 const CSkins7::CSkinPart *pPreviewPart = (m_TeePartSelected == Part ? pPart : GameClient()->m_Skins7.FindSkinPart(Part, pName: CSkins7::ms_apSkinVariables[(int)m_Dummy][Part], AllowSpecialPart: false));
431 pPreviewPart->ApplyTo(SixupRenderInfo&: Info.m_aSixup[g_Config.m_ClDummy]);
432 GameClient()->m_Skins7.ApplyColorTo(SixupRenderInfo&: Info.m_aSixup[g_Config.m_ClDummy], UseCustomColors: *CSkins7::ms_apUCCVariables[(int)m_Dummy][Part], Value: *CSkins7::ms_apColorVariables[(int)m_Dummy][Part], Part);
433 }
434 Info.m_Size = 50.0f;
435
436 if(m_TeePartSelected == protocol7::SKINPART_HANDS)
437 {
438 // RenderTools()->RenderTeeHand(&Info, Item.m_Rect.Center(), vec2(1.0f, 0.0f), -pi*0.5f, vec2(18, 0));
439 }
440 int TeePartEmote = EMOTE_NORMAL;
441 if(m_TeePartSelected == protocol7::SKINPART_EYES)
442 {
443 TeePartEmote = (int)(Client()->GlobalTime() * 0.5f) % NUM_EMOTES;
444 }
445 RenderTools()->RenderIdleTeeAtCenter(pInfo: &Info, Center: Item.m_Rect.Center(), Emote: TeePartEmote);
446
447 Ui()->DoLabel(pRect: &Label, pText: pPart->m_aName, Size: 12.0f, Align: TEXTALIGN_MC);
448 }
449
450 const int NewSelected = s_ListBox.DoEnd();
451 if(NewSelected != -1 && NewSelected != OldSelected)
452 {
453 str_copy(dst: CSkins7::ms_apSkinVariables[(int)m_Dummy][m_TeePartSelected], src: s_avpList[m_TeePartSelected][NewSelected]->m_aName, dst_size: protocol7::MAX_SKIN_ARRAY_SIZE);
454 CSkins7::ms_apSkinNameVariables[m_Dummy][0] = '\0';
455 SetNeedSendInfo();
456 }
457}
458