Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando-A-Rocha committed Oct 28, 2024
1 parent 7e21ff0 commit a59eab7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
19 changes: 8 additions & 11 deletions Client/core/CSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,8 @@ void CSettings::CreateGUI()
m_pRadarMapImageCombo = reinterpret_cast<CGUIComboBox*>(pManager->CreateComboBox(pTabAdvanced, ""));
m_pRadarMapImageCombo->SetPosition(CVector2D(vecTemp.fX + fIndentX, vecTemp.fY - 1.0f));
m_pRadarMapImageCombo->SetSize(CVector2D(fComboWidth, 95.0f));
m_pRadarMapImageCombo->AddItem(_("1024 x 1024 (Default)"));
m_pRadarMapImageCombo->AddItem(_("2048 x 2048"));
m_pRadarMapImageCombo->AddItem(_("1024 x 1024 (Default)")); // index 0
m_pRadarMapImageCombo->AddItem(_("2048 x 2048")); // index 1
m_pRadarMapImageCombo->SetReadOnly(true);
vecTemp.fY += fLineHeight;

Expand Down Expand Up @@ -3169,10 +3169,8 @@ void CSettings::LoadData()

// Radar map image
CVARS_GET("radar_map_image", iVar);
if (iVar == 0)
m_pRadarMapImageCombo->SetText(_("1024 x 1024 (Default)"));
else if (iVar == 1)
m_pRadarMapImageCombo->SetText(_("2048 x 2048"));
if (iVar >= 0 && iVar <= 1)
m_pRadarMapImageCombo->SetSelectedItemByIndex(iVar);

// Fast clothes loading
CVARS_GET("fast_clothes_loading", iVar);
Expand Down Expand Up @@ -3561,11 +3559,10 @@ void CSettings::SaveData()
gameSettings->SetDynamicPedShadowsEnabled(bDynamicPedShadows);

// Radar map image
if (CGUIListItem* pSelected = m_pRadarMapImageCombo->GetSelectedItem())
int selectedComboIndex = m_pRadarMapImageCombo->GetSelectedItemIndex();
if (selectedComboIndex != -1)
{
int iSelected = (int)pSelected->GetData();
CVARS_SET("radar_map_image", iSelected);
// TODO: Update the map image if radar map exists
CVARS_SET("radar_map_image", selectedComboIndex);
}

// Fast clothes loading
Expand Down Expand Up @@ -4845,7 +4842,7 @@ bool CSettings::OnShowAdvancedSettingDescription(CGUIElement* pElement)
if (pLabel && pLabel == m_pPriorityLabel || pComboBox && pComboBox == m_pPriorityCombo)
strText = std::string(_("Process priority:")) + " " + std::string(_("Very experimental feature."));
else if (pLabel && pLabel == m_pRadarMapImageLabel || pComboBox && pComboBox == m_pRadarMapImageCombo)
strText = std::string(_("Radar map image:")) + " " + std::string(_("Select the San Andreas radar map image size."));
strText = std::string(_("Radar map image:")) + " " + std::string(_("Select the size of the full San Andreas map."));
else if (pLabel && pLabel == m_pFastClothesLabel || pComboBox && pComboBox == m_pFastClothesCombo)
strText = std::string(_("Fast CJ clothes loading:")) + " " + std::string(_("Stops stalls with CJ variations (Uses 65MB more RAM)"));
else if (pLabel && pLabel == m_pBrowserSpeedLabel || pComboBox && pComboBox == m_pBrowserSpeedCombo)
Expand Down
42 changes: 34 additions & 8 deletions Client/mods/deathmatch/logic/CRadarMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ CRadarMap::CRadarMap(CClientManager* pManager)

// Create the radar map image
m_pRadarImage = nullptr;
SetMapImage(g_pCore->GetCVars()->GetValue<std::uint32_t>("radar_map_image", 0));
g_pCore->GetCVars()->Get("radar_map_image", m_radarImageIndex);
SetMapImage(m_radarImageIndex);

// Create the marker textures
CreateMarkerTextures();
Expand Down Expand Up @@ -99,6 +100,8 @@ CRadarMap::CRadarMap(CClientManager* pManager)

// Default to attached to player
SetAttachedToLocalPlayer(true);

SetupMapVariables();
}

CRadarMap::~CRadarMap()
Expand All @@ -115,17 +118,31 @@ CRadarMap::~CRadarMap()
// Don't need to delete the help texts as those are destroyed by the display manager
}

// If invalid presetIndex is passed, it will use the first preset
void CRadarMap::SetMapImage(const std::uint32_t presetIndex)
void CRadarMap::SetMapImage(std::uint32_t imageIndex)
{
if (imageIndex < 0 || imageIndex > 1)
imageIndex = 0;

SString fileName;
std::uint32_t width, height;
if (imageIndex == 0)
{
width = 1024;
height = 1024;
}
else
{
width = 2048;
height = 2048;
}
fileName.Format("MTA\\cgui\\images\\radar_%d.png", width);

if (m_pRadarImage != nullptr)
SAFE_RELEASE(m_pRadarImage);

auto [fileName, width, height] = GetRadarImagePreset(presetIndex);
m_pRadarImage = g_pCore->GetGraphics()->GetRenderItemManager()->CreateTexture(CalcMTASAPath("MTA\\cgui\\images\\" + fileName), nullptr, false, width, height,
RFORMAT_DXT1);
g_pCore->GetConsole()->Printf("Radar map image preset id loaded: [%d] %d x %d", presetIndex, width, height);
SetupMapVariables();
m_pRadarImage = g_pCore->GetGraphics()->GetRenderItemManager()->CreateTexture(CalcMTASAPath(fileName), nullptr, false, width, height, RFORMAT_DXT1);

g_pCore->GetConsole()->Printf("Radar map image id %d loaded: %s", imageIndex, fileName);
}

void CRadarMap::DoPulse()
Expand Down Expand Up @@ -251,6 +268,15 @@ void CRadarMap::DoRender()
int iRadarAlpha;
g_pCore->GetCVars()->Get("mapalpha", iRadarAlpha);

// Update the image if the user changed it via a setting
std::uint32_t radarImageIndex;
g_pCore->GetCVars()->Get("radar_map_image", radarImageIndex);
if (radarImageIndex != m_radarImageIndex)
{
m_radarImageIndex = radarImageIndex;
SetMapImage(m_radarImageIndex);
}

g_pCore->GetGraphics()->DrawTexture(m_pRadarImage, static_cast<float>(m_iMapMinX), static_cast<float>(m_iMapMinY),
m_fMapSize / m_pRadarImage->m_uiSizeX, m_fMapSize / m_pRadarImage->m_uiSizeY, 0.0f, 0.0f, 0.0f,
SColorARGB(iRadarAlpha, 255, 255, 255));
Expand Down
17 changes: 3 additions & 14 deletions Client/mods/deathmatch/logic/CRadarMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@ class CRadarMap
void ZoomIn();
void ZoomOut();

void SetMapImage(const std::uint32_t presetIndex);
void SetMapImage(std::uint32_t imageIndex);

SString GetBoundKeyName(const SString& strCommand);

std::tuple<std::string, std::uint32_t, std::uint32_t> GetRadarImagePreset(std::uint32_t index) const
{
if (index < 0 || index >= m_radarImagePresets.size())
index = 0;
assert(index < m_radarImagePresets.size()); // Vector should never be empty
return m_radarImagePresets[index];
}

private:
bool CalculateEntityOnScreenPosition(class CClientEntity* pEntity, CVector2D& vecLocalPos);
bool CalculateEntityOnScreenPosition(CVector vecPosition, CVector2D& vecLocalPos);
Expand All @@ -89,15 +81,12 @@ class CRadarMap
class CClientRadarMarkerManager* m_pRadarMarkerManager;
class CClientRadarAreaManager* m_pRadarAreaManager;

std::uint32_t m_radarImageIndex;

CTextureItem* m_pRadarImage;
CTextureItem* m_pLocalPlayerBlip;
std::vector<CTextureItem*> m_MarkerTextureList;

const std::vector<std::tuple<std::string, std::uint32_t, std::uint32_t>> m_radarImagePresets = {
{"radar_1024.png", 1024, 1024},
{"radar_2048.png", 2048, 2048},
};

unsigned int m_uiHeight;
unsigned int m_uiWidth;

Expand Down

0 comments on commit a59eab7

Please sign in to comment.