Esempio n. 1
0
void CHudIcons::Init()
{
	if (m_bHudTexturesLoaded)
		return;

	m_bHudTexturesLoaded = true;
	CUtlDict< CHudTexture *, int >	textureList;

	// check to see if we have sprites for this res; if not, step down
	LoadHudTextures(textureList, "scripts/hud_textures", NULL);
	LoadHudTextures(textureList, "scripts/mod_textures", NULL);

	LoadHudTextures(textureList, "scripts/instructor_textures", NULL);
	LoadHudTextures(textureList, "scripts/instructor_modtextures", NULL);

	int c = textureList.Count();
	for (int index = 0; index < c; index++)
	{
		CHudTexture* tex = textureList[index];
		AddSearchableHudIconToList(*tex);
	}

	FreeHudTextureList(textureList);
}
Esempio n. 2
0
File: hud.cpp Progetto: Yosam02/game
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CHud::RefreshHudTextures()
{
    if (!m_bHudTexturesLoaded)
    {
        Assert(0);
        return;
    }

    CUtlDict< CHudTexture *, int >	textureList;

    // check to see if we have sprites for this res; if not, step down
    LoadHudTextures(textureList, "scripts/hud_textures", NULL);
    LoadHudTextures(textureList, "scripts/mod_textures", NULL);

    // fix up all the texture icons first
    int c = textureList.Count();
    for (int index = 0; index < c; index++)
    {
        CHudTexture *tex = textureList[index];
        Assert(tex);

        CHudTexture *icon = GetIcon(tex->szShortName);
        if (!icon)
            continue;

        // Update file
        Q_strncpy(icon->szTextureFile, tex->szTextureFile, sizeof(icon->szTextureFile));

        if (!icon->bRenderUsingFont)
        {
            // Update subrect
            icon->rc = tex->rc;

            // Keep existing texture id, but now update texture file and texture coordinates
            vgui::surface()->DrawSetTextureFile(icon->textureId, icon->szTextureFile, false, false);

            // Get new texture dimensions in case it changed
            int wide, tall;
            vgui::surface()->DrawGetTextureSize(icon->textureId, wide, tall);

            // Assign coords
            icon->texCoords[0] = (float) (icon->rc.left + 0.5f) / (float) wide;
            icon->texCoords[1] = (float) (icon->rc.top + 0.5f) / (float) tall;
            icon->texCoords[2] = (float) (icon->rc.right - 0.5f) / (float) wide;
            icon->texCoords[3] = (float) (icon->rc.bottom - 0.5f) / (float) tall;
        }
    }

    FreeHudTextureList(textureList);

    // fixup all the font icons
    vgui::HScheme scheme = vgui::scheme()->GetScheme("ClientScheme");
    for (int i = m_Icons.First(); m_Icons.IsValidIndex(i); i = m_Icons.Next(i))
    {
        CHudTexture *icon = m_Icons[i];
        if (!icon)
            continue;

        // Update file
        if (icon->bRenderUsingFont)
        {
            icon->hFont = vgui::scheme()->GetIScheme(scheme)->GetFont(icon->szTextureFile, true);
            icon->rc.top = 0;
            icon->rc.left = 0;
            icon->rc.right = vgui::surface()->GetCharacterWidth(icon->hFont, icon->cCharacterInFont);
            icon->rc.bottom = vgui::surface()->GetFontTall(icon->hFont);
        }
    }
}
Esempio n. 3
0
File: hud.cpp Progetto: Yosam02/game
//-----------------------------------------------------------------------------
// Purpose: This is called every time the DLL is loaded
//-----------------------------------------------------------------------------
void CHud::Init(void)
{
    HOOK_HUD_MESSAGE(gHUD, ResetHUD);

#ifdef CSTRIKE_DLL
    HOOK_HUD_MESSAGE( gHUD, SendAudio );
#endif

    InitFonts();

    // Create all the Hud elements
    CHudElementHelper::CreateAllElements();

    gLCD.Init();

    // Initialize all created elements
    for (int i = 0; i < m_HudList.Size(); i++)
    {
        m_HudList[i]->Init();
    }

    m_bHudTexturesLoaded = false;

    KeyValues *kv = new KeyValues("layout");
    if (kv)
    {
        if (kv->LoadFromFile(filesystem, "scripts/HudLayout.res"))
        {
            int numelements = m_HudList.Size();

            for (int i = 0; i < numelements; i++)
            {
                CHudElement *element = m_HudList[i];

                vgui::Panel *pPanel = dynamic_cast<vgui::Panel*>(element);
                if (!pPanel)
                {
                    Msg("Non-vgui hud element %s\n", m_HudList[i]->GetName());
                    continue;
                }

                KeyValues *key = kv->FindKey(pPanel->GetName(), false);
                if (!key)
                {
                    Msg("Hud element '%s' doesn't have an entry '%s' in scripts/HudLayout.res\n", m_HudList[i]->GetName(), pPanel->GetName());
                }

                // Note:  When a panel is parented to the module root, it's "parent" is returned as NULL.
                if (!element->IsParentedToClientDLLRootPanel() &&
                    !pPanel->GetParent())
                {
                    DevMsg("Hud element '%s'/'%s' doesn't have a parent\n", m_HudList[i]->GetName(), pPanel->GetName());
                }
            }
        }

        kv->deleteThis();
    }

    if (m_bHudTexturesLoaded)
        return;

    m_bHudTexturesLoaded = true;
    CUtlDict< CHudTexture *, int >	textureList;

    // check to see if we have sprites for this res; if not, step down
    LoadHudTextures(textureList, "scripts/hud_textures", NULL);
    LoadHudTextures(textureList, "scripts/mod_textures", NULL);

    int c = textureList.Count();
    for (int index = 0; index < c; index++)
    {
        CHudTexture* tex = textureList[index];
        AddSearchableHudIconToList(*tex);
    }

    FreeHudTextureList(textureList);
}