mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
-added images to startmenu -changed way to load menu image
This commit is contained in:
parent
1f76649bd1
commit
1d480f34bd
|
@ -247,8 +247,6 @@ container.images.Add(image_demobuttons)
|
|||
container.images.Add(image_fileicons)
|
||||
container.images.Add(image_guibuttons)
|
||||
container.images.Add(image_guiicons)
|
||||
container.images.Add(Image("button_play_game", "gui_button_play_game.png"))
|
||||
container.images.Add(Image("button_editor", "gui_button_editor.png"))
|
||||
|
||||
container.pickups.Add(Pickup("health"))
|
||||
container.pickups.Add(Pickup("armor"))
|
||||
|
|
|
@ -117,15 +117,41 @@ int CMenus::DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect,
|
|||
return Active ? UI()->DoButtonLogic(pID, "", Checked, pRect) : 0;
|
||||
}
|
||||
|
||||
int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
|
||||
int CMenus::DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, float r, float FontFactor)
|
||||
{
|
||||
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f);
|
||||
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, r);
|
||||
CUIRect Temp;
|
||||
pRect->HMargin(pRect->h>=20.0f?2.0f:1.0f, &Temp);
|
||||
Temp.HMargin((Temp.h*FontFactor)/2.0f, &Temp);
|
||||
UI()->DoLabel(&Temp, pText, Temp.h*ms_FontmodHeight, 0);
|
||||
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
|
||||
}
|
||||
|
||||
int CMenus::DoButton_MenuImage(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName, float r, float FontFactor)
|
||||
{
|
||||
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, r);
|
||||
CUIRect Text, Image;
|
||||
pRect->VSplitMid(&Text, &Image);
|
||||
|
||||
// render image
|
||||
const CMenuImage *pImage = FindMenuImage(pImageName);
|
||||
if(pImage)
|
||||
{
|
||||
Graphics()->TextureSet(UI()->HotItem() == pID ? pImage->m_OrgTexture : pImage->m_GreyTexture);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1,1,1,1);
|
||||
IGraphics::CQuadItem QuadItem(Image.x, Image.y, Image.w, Image.h);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
|
||||
pRect->HMargin(pRect->h>=20.0f?2.0f:1.0f, &Text);
|
||||
Text.HMargin((Text.h*FontFactor)/2.0f, &Text);
|
||||
Text.VSplitLeft(r, 0, &Text);
|
||||
UI()->DoLabel(&Text, pText, Text.h*ms_FontmodHeight, -1);
|
||||
return UI()->DoButtonLogic(pID, pText, Checked, pRect);
|
||||
}
|
||||
|
||||
void CMenus::DoButton_KeySelect(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
|
||||
{
|
||||
RenderTools()->DrawUIRect(pRect, vec4(1,1,1,0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f);
|
||||
|
@ -698,8 +724,103 @@ void CMenus::RenderNews(CUIRect MainView)
|
|||
RenderTools()->DrawUIRect(&MainView, ms_ColorTabbarActive, CUI::CORNER_ALL, 10.0f);
|
||||
}
|
||||
|
||||
int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser)
|
||||
{
|
||||
CMenus *pSelf = (CMenus *)pUser;
|
||||
int l = str_length(pName);
|
||||
if(l < 4 || IsDir || str_comp(pName+l-4, ".png") != 0)
|
||||
return 0;
|
||||
|
||||
char aBuf[512];
|
||||
str_format(aBuf, sizeof(aBuf), "menuimages/%s", pName);
|
||||
CImageInfo Info;
|
||||
if(!pSelf->Graphics()->LoadPNG(&Info, aBuf, DirType))
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "failed to load menu image from %s", pName);
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CMenuImage MenuImage;
|
||||
MenuImage.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
|
||||
|
||||
unsigned char *d = (unsigned char *)Info.m_pData;
|
||||
int Pitch = Info.m_Width*4;
|
||||
|
||||
// create colorless version
|
||||
int Step = Info.m_Format == CImageInfo::FORMAT_RGBA ? 4 : 3;
|
||||
|
||||
// make the texture gray scale
|
||||
for(int i = 0; i < Info.m_Width*Info.m_Height; i++)
|
||||
{
|
||||
int v = (d[i*Step]+d[i*Step+1]+d[i*Step+2])/3;
|
||||
d[i*Step] = v;
|
||||
d[i*Step+1] = v;
|
||||
d[i*Step+2] = v;
|
||||
}
|
||||
|
||||
|
||||
int Freq[256] = {0};
|
||||
int OrgWeight = 0;
|
||||
int NewWeight = 192;
|
||||
|
||||
// find most common frequence
|
||||
for(int y = 0; y < Info.m_Height; y++)
|
||||
for(int x = 0; x < Info.m_Width; x++)
|
||||
{
|
||||
if(d[y*Pitch+x*4+3] > 128)
|
||||
Freq[d[y*Pitch+x*4]]++;
|
||||
}
|
||||
|
||||
for(int i = 1; i < 256; i++)
|
||||
{
|
||||
if(Freq[OrgWeight] < Freq[i])
|
||||
OrgWeight = i;
|
||||
}
|
||||
|
||||
// reorder
|
||||
int InvOrgWeight = 255-OrgWeight;
|
||||
int InvNewWeight = 255-NewWeight;
|
||||
for(int y = 0; y < Info.m_Height; y++)
|
||||
for(int x = 0; x < Info.m_Width; x++)
|
||||
{
|
||||
int v = d[y*Pitch+x*4];
|
||||
if(v <= OrgWeight)
|
||||
v = (int)(((v/(float)OrgWeight) * NewWeight));
|
||||
else
|
||||
v = (int)(((v-OrgWeight)/(float)InvOrgWeight)*InvNewWeight + NewWeight);
|
||||
d[y*Pitch+x*4] = v;
|
||||
d[y*Pitch+x*4+1] = v;
|
||||
d[y*Pitch+x*4+2] = v;
|
||||
}
|
||||
|
||||
MenuImage.m_GreyTexture = pSelf->Graphics()->LoadTextureRaw(Info.m_Width, Info.m_Height, Info.m_Format, Info.m_pData, Info.m_Format, 0);
|
||||
mem_free(Info.m_pData);
|
||||
|
||||
// set menu image data
|
||||
str_copy(MenuImage.m_aName, pName, min((int)sizeof(MenuImage.m_aName),l-3));
|
||||
str_format(aBuf, sizeof(aBuf), "load menu image %s", MenuImage.m_aName);
|
||||
pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "game", aBuf);
|
||||
pSelf->m_lMenuImages.add(MenuImage);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
const CMenus::CMenuImage *CMenus::FindMenuImage(const char *pName)
|
||||
{
|
||||
for(int i = 0; i < m_lMenuImages.size(); i++)
|
||||
{
|
||||
if(str_comp(m_lMenuImages[i].m_aName, pName) == 0)
|
||||
return &m_lMenuImages[i];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CMenus::OnInit()
|
||||
{
|
||||
// load menu images
|
||||
m_lMenuImages.clear();
|
||||
Storage()->ListDirectory(IStorage::TYPE_ALL, "menuimages", MenuImageScan, this);
|
||||
|
||||
/*
|
||||
array<string> my_strings;
|
||||
|
|
|
@ -41,7 +41,8 @@ class CMenus : public CComponent
|
|||
int DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
|
||||
int DoButton_Sprite(const void *pID, int ImageID, int SpriteID, int Checked, const CUIRect *pRect, int Corners);
|
||||
int DoButton_Toggle(const void *pID, int Checked, const CUIRect *pRect, bool Active);
|
||||
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect);
|
||||
int DoButton_Menu(const void *pID, const char *pText, int Checked, const CUIRect *pRect, float r=5.0f, float FontFactor=0.0f);
|
||||
int DoButton_MenuImage(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pImageName, float r=5.0f, float FontFactor=0.0f);
|
||||
int DoButton_MenuTab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Corners);
|
||||
|
||||
int DoButton_CheckBox_Common(const void *pID, const char *pText, const char *pBoxText, const CUIRect *pRect);
|
||||
|
@ -136,6 +137,19 @@ class CMenus : public CComponent
|
|||
bool m_UseMouseButtons;
|
||||
vec2 m_MousePos;
|
||||
|
||||
// images
|
||||
struct CMenuImage
|
||||
{
|
||||
char m_aName[64];
|
||||
int m_OrgTexture;
|
||||
int m_GreyTexture;
|
||||
};
|
||||
array<CMenuImage> m_lMenuImages;
|
||||
|
||||
static int MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser);
|
||||
|
||||
const CMenuImage *FindMenuImage(const char* pName);
|
||||
|
||||
int64 m_LastInput;
|
||||
|
||||
// loading
|
||||
|
|
|
@ -14,28 +14,53 @@
|
|||
|
||||
void CMenus::RenderStartMenu(CUIRect MainView)
|
||||
{
|
||||
MainView.VMargin(200.0f, &MainView);
|
||||
MainView.HMargin(137.0f, &MainView);
|
||||
MainView.VMargin(160.0f, &MainView);
|
||||
MainView.HMargin(145.0f, &MainView);
|
||||
RenderTools()->DrawUIRect(&MainView, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
|
||||
|
||||
MainView.Margin(5.0f, &MainView);
|
||||
|
||||
CUIRect Button;
|
||||
|
||||
MainView.HSplitTop(70.0f, &Button, &MainView);
|
||||
RenderTools()->DrawUIRect(&Button, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
|
||||
MainView.HSplitTop(40.0f, &Button, &MainView);
|
||||
static int s_PlayButton = 0;
|
||||
if(DoButton_MenuImage(&s_PlayButton, Localize("Play Game"), 0, &Button, "play_game", 15.0f, 0.5f))
|
||||
m_MenuPage = MENU_PAGE;
|
||||
|
||||
MainView.HSplitTop(5.0f, 0, &MainView); // little space
|
||||
MainView.HSplitTop(70.0f, &Button, &MainView);
|
||||
RenderTools()->DrawUIRect(&Button, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
|
||||
MainView.HSplitTop(40.0f, &Button, &MainView);
|
||||
static int s_MapEditorButton = 0;
|
||||
if(DoButton_MenuImage(&s_MapEditorButton, Localize("Map Editor"), 0, &Button, "editor2", 15.0f, 0.5f))
|
||||
{
|
||||
g_Config.m_ClEditor = 1;
|
||||
Input()->MouseModeRelative();
|
||||
}
|
||||
|
||||
MainView.HSplitTop(5.0f, 0, &MainView); // little space
|
||||
MainView.HSplitTop(70.0f, &Button, &MainView);
|
||||
RenderTools()->DrawUIRect(&Button, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
|
||||
MainView.HSplitTop(40.0f, &Button, &MainView);
|
||||
static int s_DemoButton = 0;
|
||||
if(DoButton_MenuImage(&s_DemoButton, Localize("Demos"), 0, &Button, "play_game", 15.0f, 0.5f))
|
||||
{
|
||||
}
|
||||
|
||||
MainView.HSplitTop(5.0f, 0, &MainView); // little space
|
||||
MainView.HSplitTop(70.0f, &Button, &MainView);
|
||||
RenderTools()->DrawUIRect(&Button, vec4(0,0,0,0.5f), CUI::CORNER_ALL, 15.0f);
|
||||
MainView.HSplitTop(40.0f, &Button, &MainView);
|
||||
static int s_LocalServerButton = 0;
|
||||
if(DoButton_MenuImage(&s_LocalServerButton, Localize("Create Local Server"), 0, &Button, "play_game", 15.0f, 0.5f))
|
||||
{
|
||||
}
|
||||
|
||||
MainView.HSplitTop(5.0f, 0, &MainView); // little space
|
||||
MainView.HSplitTop(40.0f, &Button, &MainView);
|
||||
static int s_SettingsButton = 0;
|
||||
if(DoButton_MenuImage(&s_SettingsButton, Localize("Settings"), 0, &Button, "play_game", 15.0f, 0.5f))
|
||||
{
|
||||
}
|
||||
|
||||
MainView.HSplitBottom(45.0f, &MainView, &Button);
|
||||
static int s_QuitButton = 0;
|
||||
if(DoButton_Menu(&s_QuitButton, Localize("Quit Game"), 0, &Button, 15.0f, 0.5f))
|
||||
m_Popup = POPUP_QUIT;
|
||||
}
|
||||
|
||||
void CMenus::RenderLogo(CUIRect MainView)
|
||||
|
@ -44,7 +69,7 @@ void CMenus::RenderLogo(CUIRect MainView)
|
|||
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_BANNER].m_Id);
|
||||
Graphics()->QuadsBegin();
|
||||
Graphics()->SetColor(1,1,1,1);
|
||||
IGraphics::CQuadItem QuadItem(MainView.w/2-170, 80, 330, 50);
|
||||
IGraphics::CQuadItem QuadItem(MainView.w/2-170, 70, 330, 50);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
Loading…
Reference in a new issue