Skip to content

Commit

Permalink
Sprays - Initial commit
Browse files Browse the repository at this point in the history
* Integrate stb_image/stb_image_resize2/stb_dxt.h library
* rought draft
* fixes NeotokyoRebuild#602
  • Loading branch information
nullsystem committed Oct 27, 2024
1 parent 05c54d0 commit ee2234d
Show file tree
Hide file tree
Showing 11 changed files with 19,973 additions and 2 deletions.
11 changes: 11 additions & 0 deletions mp/src/game/client/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ target_include_directories(client
${CMAKE_SOURCE_DIR}/game/shared/neo/weapons
${CMAKE_SOURCE_DIR}/public
${CMAKE_SOURCE_DIR}/thirdparty/sixensesdk/include
${CMAKE_SOURCE_DIR}/vendor
game_controls
hl2
hl2/elements
Expand Down Expand Up @@ -1488,6 +1489,16 @@ target_sources_grouped(
neo/neo_fixup_glshaders.h
)

target_sources_grouped(
TARGET client
NAME "Source Files\\NEO_Vendor"
FILES
neo/vendor_impl.cpp
${CMAKE_SOURCE_DIR}/vendor/stb_image.h
${CMAKE_SOURCE_DIR}/vendor/stb_image_resize2.h
${CMAKE_SOURCE_DIR}/vendor/stb_dxt.h
)

target_sources_grouped(
TARGET client
NAME "Source Files\\NEO\\Game_Controls"
Expand Down
91 changes: 89 additions & 2 deletions mp/src/game/client/neo/ui/neo_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1540,8 +1540,95 @@ void CNeoRoot::ReadNewsFile(CUtlBuffer &buf)

void CNeoRoot::OnFileSelected(const char *szFullpath)
{
((m_ns.crosshair.eFileIOMode == vgui::FOD_OPEN) ?
&ImportCrosshair : &ExportCrosshair)(&m_ns.crosshair.info, szFullpath);
switch (m_eFileIOMode)
{
case FILEIODLGMODE_CROSSHAIR:
((m_ns.crosshair.eFileIOMode == vgui::FOD_OPEN) ?
&ImportCrosshair : &ExportCrosshair)(&m_ns.crosshair.info, szFullpath);
break;
case FILEIODLGMODE_SPRAY:
{
#if 1
if (V_striEndsWith(szFullpath, ".vtf"))
{
CUtlBuffer buf(0, 0, CUtlBuffer::READ_ONLY);
if (filesystem->ReadFile(szFullpath, nullptr, buf))
{
IVTFTexture *pVTFTexture = CreateVTFTexture();
if (pVTFTexture->Unserialize(buf))
{
const auto width = pVTFTexture->Width();
const auto height = pVTFTexture->Height();
const auto depth = pVTFTexture->Depth();
const auto format = pVTFTexture->Format();
const auto flags = pVTFTexture->Flags();
const auto mip = pVTFTexture->MipCount();
const auto face = pVTFTexture->FaceCount();
const auto frame = pVTFTexture->FrameCount();

int foo = 0;
}
//DestroyVTFTexture(pVTFTexture);
//stbi_image_free(data);
}


#if 0
engine->CopyLocalFile(szFullpath, "vgui/logos/testing.vtf");
ConVarRef("cl_logofile").SetValue("vgui/logos/testing.vtf");
if (m_ns.general.iTexIdSpray > 0)
{
vgui::surface()->DeleteTextureByID(m_ns.general.iTexIdSpray);
}
m_ns.general.iTexIdSpray = vgui::surface()->CreateNewTextureID(true);
vgui::surface()->DrawSetTextureFile(m_ns.general.iTexIdSpray, szFullpath, false, false);
#endif
return;
}
#endif

char szRetTexPath[VTF_PATH_MAX] = {};
uint8 *data = NeoUI::ConvertToVTF(&szRetTexPath, szFullpath);

char szRetVtfPath[PATH_MAX];
V_sprintf_safe(szRetVtfPath, "%s.vtf", szRetTexPath);

ConVarRef("cl_logofile").SetValue(szRetVtfPath);
if (m_ns.general.iTexIdSpray > 0)
{
vgui::surface()->DeleteTextureByID(m_ns.general.iTexIdSpray);
}
#if 1
m_ns.general.iTexIdSpray = vgui::surface()->CreateNewTextureID(true);
//vgui::surface()->DrawSetTextureFile(m_ns.general.iTexIdSpray, szRetTexPath, false, false);
vgui::surface()->DrawSetTextureRGBA(m_ns.general.iTexIdSpray, data, 256, 256, false, false);
free(data);
#else
CUtlBuffer buf(0, 0, CUtlBuffer::READ_ONLY);
if (filesystem->ReadFile(szRetFullPath, nullptr, buf))
{
IVTFTexture *pVTFTexture = CreateVTFTexture();
if (pVTFTexture->Unserialize(buf))
{
const auto width = pVTFTexture->Width();
const auto height = pVTFTexture->Height();
const auto depth = pVTFTexture->Depth();
const auto format = pVTFTexture->Format();
const auto flags = pVTFTexture->Flags();
const auto mip = pVTFTexture->MipCount();
const auto face = pVTFTexture->FaceCount();
const auto frame = pVTFTexture->FrameCount();
}
//DestroyVTFTexture(pVTFTexture);
//stbi_image_free(data);
}
#endif
break;
}
default:
break;
}
}

// NEO NOTE (nullsystem): NeoRootCaptureESC is so that ESC keybinds can be recognized by non-root states, but root
Expand Down
8 changes: 8 additions & 0 deletions mp/src/game/client/neo/ui/neo_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ class CNeoRoot : public vgui::EditablePanel, public CGameEventListener
void ReadNewsFile(CUtlBuffer &buf);
bool m_bShowBrowserLabel = false;

enum FileIODialogMode
{
FILEIODLGMODE_CROSSHAIR = 0,
FILEIODLGMODE_SPRAY,

FILEIODLGMODE__TOTAL,
};
FileIODialogMode m_eFileIOMode;
vgui::FileOpenDialog *m_pFileIODialog = nullptr;
MESSAGE_FUNC_CHARPTR(OnFileSelected, "FileSelected", fullpath);

Expand Down
46 changes: 46 additions & 0 deletions mp/src/game/client/neo/ui/neo_root_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ void NeoSettingsRestore(NeoSettings *ns, const NeoSettings::Keys::Flags flagsKey
pGeneral->bStreamerMode = cvr->neo_cl_streamermode.GetBool();
pGeneral->bAutoDetectOBS = cvr->neo_cl_streamermode_autodetect_obs.GetBool();
pGeneral->bEnableRangeFinder = cvr->neo_cl_hud_rangefinder_enabled.GetBool();

if (pGeneral->iTexIdSpray > 0)
{
vgui::surface()->DeleteTextureByID(pGeneral->iTexIdSpray);
}
const char *szLogo = ConVarRef("cl_logofile").GetString();
if (szLogo)
{
pGeneral->iTexIdSpray = vgui::surface()->CreateNewTextureID();
vgui::surface()->DrawSetTextureFile(pGeneral->iTexIdSpray, szLogo, false, false);
}
}
{
NeoSettings::Keys *pKeys = &ns->keys;
Expand Down Expand Up @@ -653,6 +664,40 @@ void NeoSettings_General(NeoSettings *ns)
NeoUI::RingBoxBool(L"Auto streamer mode (requires restart)", &pGeneral->bAutoDetectOBS);
NeoUI::Label(L"OBS detection", g_bOBSDetected ? L"OBS detected on startup" : L"Not detected on startup");
NeoUI::RingBoxBool(L"Show rangefinder", &pGeneral->bEnableRangeFinder);

NeoUI::Pad();
if (NeoUI::Button(L"", L"Import spray").bPressed)
{
if (g_pNeoRoot->m_pFileIODialog)
{
g_pNeoRoot->m_pFileIODialog->MarkForDeletion();
}
g_pNeoRoot->m_pFileIODialog = new vgui::FileOpenDialog(g_pNeoRoot, "Import spray", vgui::FOD_OPEN);
g_pNeoRoot->m_eFileIOMode = CNeoRoot::FILEIODLGMODE_SPRAY;
g_pNeoRoot->m_pFileIODialog->AddFilter("*.jpg;*.jpeg;*.png;*.vtf", "Images (JPEG, PNG, VTF)", true);
g_pNeoRoot->m_pFileIODialog->AddFilter("*.jpg;*.jpeg", "JPEG Image", false);
g_pNeoRoot->m_pFileIODialog->AddFilter("*.png", "PNG Image", false);
g_pNeoRoot->m_pFileIODialog->AddFilter("*.vtf", "VTF Image", false);
g_pNeoRoot->m_pFileIODialog->DoModal();
}

NeoUI::Pad();

if (pGeneral->iTexIdSpray > 0)
{
vgui::surface()->DrawSetTexture(pGeneral->iTexIdSpray);
vgui::surface()->DrawSetColor(COLOR_WHITE);
vgui::surface()->DrawTexturedRect(
g_uiCtx.dPanel.x + g_uiCtx.iLayoutX,
g_uiCtx.dPanel.y + g_uiCtx.iLayoutY,
g_uiCtx.dPanel.x + g_uiCtx.iLayoutX + 256,
g_uiCtx.dPanel.y + g_uiCtx.iLayoutY + 256);
}

for (int i = 0; i < 5; ++i)
{
NeoUI::Pad();
}
}

void NeoSettings_Keys(NeoSettings *ns)
Expand Down Expand Up @@ -811,6 +856,7 @@ void NeoSettings_Crosshair(NeoSettings *ns)
g_pNeoRoot->m_pFileIODialog->MarkForDeletion();
}
pCrosshair->eFileIOMode = bPresImport ? vgui::FOD_OPEN : vgui::FOD_SAVE;
g_pNeoRoot->m_eFileIOMode = CNeoRoot::FILEIODLGMODE_CROSSHAIR;
g_pNeoRoot->m_pFileIODialog = new vgui::FileOpenDialog(g_pNeoRoot,
bPresImport ? "Import crosshair" : "Export crosshair",
pCrosshair->eFileIOMode);
Expand Down
1 change: 1 addition & 0 deletions mp/src/game/client/neo/ui/neo_root_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ struct NeoSettings
bool bStreamerMode;
bool bAutoDetectOBS;
bool bEnableRangeFinder;
int iTexIdSpray;
};

struct Keys
Expand Down
Loading

0 comments on commit ee2234d

Please sign in to comment.