Add refresh button for skins, closes #2979

This commit is contained in:
Irisk 2020-10-06 16:00:18 +02:00
parent 79b5852e17
commit fb0372b97f
4 changed files with 45 additions and 18 deletions

View file

@ -422,7 +422,7 @@ void CMenus::RenderSettingsPlayer(CUIRect MainView)
void CMenus::RenderSettingsTee(CUIRect MainView)
{
CUIRect Button, Label, Button2, Dummy, DummyLabel, SkinList, QuickSearch, QuickSearchClearButton, SkinDB, SkinPrefix, SkinPrefixLabel;
CUIRect Button, Label, Button2, Dummy, DummyLabel, SkinList, QuickSearch, QuickSearchClearButton, SkinDB, SkinPrefix, SkinPrefixLabel, DirectoryButton, RefreshButton;
static float s_ClSkinPrefix = 0.0f;
@ -674,7 +674,6 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
s_InitSkinlist = true;
}
CUIRect DirectoryButton;
SkinDB.VSplitLeft(150.0f, &SkinDB, &DirectoryButton);
SkinDB.HSplitTop(5.0f, 0, &SkinDB);
if(DoButton_Menu(&SkinDB, Localize("Skin Database"), 0, &SkinDB))
@ -687,6 +686,8 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
DirectoryButton.HSplitTop(5.0f, 0, &DirectoryButton);
DirectoryButton.VSplitRight(175.0f, 0, &DirectoryButton);
DirectoryButton.VSplitRight(25.0f, &DirectoryButton, &RefreshButton);
DirectoryButton.VSplitRight(10.0f, &DirectoryButton, 0);
if(DoButton_Menu(&DirectoryButton, Localize("Skins directory"), 0, &DirectoryButton))
{
char aBuf[MAX_PATH_LENGTH];
@ -699,6 +700,16 @@ void CMenus::RenderSettingsTee(CUIRect MainView)
dbg_msg("menus", "couldn't open link");
}
}
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
if(DoButton_Menu(&RefreshButton, "\xEE\x97\x95", 0, &RefreshButton))
{
m_pClient->m_pSkins->Refresh();
s_InitSkinlist = true;
}
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);
}
typedef void (*pfnAssignFuncCallback)(CConfiguration *pConfig, int Value);

View file

@ -302,7 +302,7 @@ int InitSearchList(sorted_array<const TName *> &SearchList, sorted_array<TName>
void CMenus::RenderSettingsCustom(CUIRect MainView)
{
CUIRect Label, CustomList, QuickSearch, QuickSearchClearButton, SkinDB, Page1Tab, Page2Tab, Page3Tab, Page4Tab;
CUIRect Label, CustomList, QuickSearch, QuickSearchClearButton, DirectoryButton, Page1Tab, Page2Tab, Page3Tab, Page4Tab, ReloadButton;
MainView.HSplitTop(20, &Label, &MainView);
float TabsW = Label.w;
@ -493,7 +493,7 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
// render quick search
{
MainView.HSplitBottom(ms_ButtonHeight, &MainView, &QuickSearch);
QuickSearch.VSplitLeft(240.0f, &QuickSearch, &SkinDB);
QuickSearch.VSplitLeft(240.0f, &QuickSearch, &DirectoryButton);
QuickSearch.HSplitTop(5.0f, 0, &QuickSearch);
const char *pSearchLabel = "\xEE\xA2\xB6";
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
@ -513,20 +513,11 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
s_InitCustomList[s_CurCustomTab] = true;
}
CUIRect ReloadButton;
SkinDB.VSplitRight(310.0f, 0, &SkinDB);
SkinDB.VSplitRight(200.0f, &ReloadButton, &SkinDB);
ReloadButton.HSplitTop(5.0f, 0, &ReloadButton);
ReloadButton.VSplitRight(10.0f, &ReloadButton, NULL);
if(DoButton_Menu(&ReloadButton, Localize("Refresh"), 0, &ReloadButton))
{
ClearCustomItems(s_CurCustomTab);
}
SkinDB.HSplitTop(5.0f, 0, &SkinDB);
if(DoButton_Menu(&SkinDB, Localize("Assets directory"), 0, &SkinDB))
DirectoryButton.HSplitTop(5.0f, 0, &DirectoryButton);
DirectoryButton.VSplitRight(175.0f, 0, &DirectoryButton);
DirectoryButton.VSplitRight(25.0f, &DirectoryButton, &ReloadButton);
DirectoryButton.VSplitRight(10.0f, &DirectoryButton, 0);
if(DoButton_Menu(&DirectoryButton, Localize("Assets directory"), 0, &DirectoryButton))
{
char aBuf[MAX_PATH_LENGTH];
char aBufFull[MAX_PATH_LENGTH + 7];
@ -547,4 +538,13 @@ void CMenus::RenderSettingsCustom(CUIRect MainView)
dbg_msg("menus", "couldn't open link");
}
}
TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT));
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_OVERSIZE);
if(DoButton_Menu(&ReloadButton, "\xEE\x97\x95", 0, &ReloadButton))
{
ClearCustomItems(s_CurCustomTab);
}
TextRender()->SetRenderFlags(0);
TextRender()->SetCurFont(NULL);
}

View file

@ -171,6 +171,21 @@ void CSkins::OnInit()
}
// load skins
Refresh();
}
void CSkins::Refresh()
{
for(int i = 0; i < m_aSkins.size(); ++i)
{
if(m_aSkins[i].m_OrgTexture != -1)
Graphics()->UnloadTexture(m_aSkins[i].m_OrgTexture);
m_aSkins[i].m_OrgTexture = IGraphics::CTextureHandle();
if(m_aSkins[i].m_ColorTexture != -1)
Graphics()->UnloadTexture(m_aSkins[i].m_ColorTexture);
m_aSkins[i].m_ColorTexture = IGraphics::CTextureHandle();
}
m_aSkins.clear();
Storage()->ListDirectory(IStorage::TYPE_ALL, "skins", SkinScan, this);
if(!m_aSkins.size())

View file

@ -39,6 +39,7 @@ public:
void OnInit();
void Refresh();
int Num();
const CSkin *Get(int Index);
int Find(const char *pName);