Skip to content

Commit

Permalink
Add settings file, minor code changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gennariarmando committed Apr 29, 2022
1 parent ee616f9 commit 302e320
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
6 changes: 6 additions & 0 deletions resources/MenuMapIII.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MenuMap]
; Set colors for drawing the menu map page.
RadarMapColor = 255 255 255 255
BackgroundColor = 0 0 0 255
CrosshairColor = 234 171 54 155
ZoneNameColor = 255 255 255 255
16 changes: 8 additions & 8 deletions source/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using namespace plugin;
class MenuMap {
public:
MenuMap() {
#ifdef GTA3
const CMenuScreen pauseMenuPage = {
"FET_PAU", 1, -1, -1, 0, 0,
MENUACTION_RESUME, "FEM_RES", 0, MENUPAGE_NONE,
Expand All @@ -21,24 +22,21 @@ class MenuMap {
};

plugin::patch::Set(0x611930 + sizeof(CMenuScreen) * MENUPAGE_PAUSE_MENU, pauseMenuPage);

const CMenuScreen mapMenuPage = {
"", 1, MENUPAGE_PAUSE_MENU, MENUPAGE_PAUSE_MENU, 2, 2,
};

plugin::patch::Set(0x611930 + sizeof(CMenuScreen) * MENUPAGE_MAP, mapMenuPage);
#endif

plugin::Events::initRwEvent += [] {
CMenuManager* m = &FrontEndMenuManager;
if (m) {
MenuNew = std::make_shared<CMenuNew>();
MenuNew->menuManager = m;
}
MenuNew = std::make_shared<CMenuNew>();
};

#ifdef GTA3
ThiscallEvent <AddressList<0x47AB12, H_CALL>, PRIORITY_AFTER, ArgPickN<CMenuManager*, 0>, void(CMenuManager*)> onDrawingMenuManager;
onDrawingMenuManager += [](CMenuManager* menuManager) {
if (!MenuNew)
if (!MenuNew || !MenuNew->menuManager)
return;

switch (MenuNew->menuManager->m_nCurrentMenuScreen) {
Expand All @@ -52,9 +50,11 @@ class MenuMap {
break;
}
};
#else
#endif

plugin::Events::drawBlipsEvent += [] {
if (!MenuNew)
if (!MenuNew || !MenuNew->menuManager)
return;

if (MenuNew->targetBlipIndex) {
Expand Down
21 changes: 15 additions & 6 deletions source/MenuNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ using namespace plugin;
std::shared_ptr<CMenuNew> MenuNew;

CMenuNew::CMenuNew() {
menuManager = NULL;
menuManager = &FrontEndMenuManager;
m_fMapZoom = MAP_ZOOM_MIN;
m_vMapBase = {};
m_vCrosshair = {};
targetBlipIndex = 0;
targetBlipWorldPos = {};
clearInput = false;
settings.Read();
}

CMenuNew::~CMenuNew() {
menuManager = NULL;
}

void CMenuNew::DrawMap() {
if (!menuManager)
return;

RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(FALSE));
RwRenderStateSet(rwRENDERSTATESRCBLEND, reinterpret_cast<void*>(rwBLENDSRCALPHA));
RwRenderStateSet(rwRENDERSTATEDESTBLEND, reinterpret_cast<void*>(rwBLENDINVSRCALPHA));
Expand All @@ -39,10 +43,11 @@ void CMenuNew::DrawMap() {
RwRenderStateSet(rwRENDERSTATEZTESTENABLE, reinterpret_cast<void*>(FALSE));

CSprite2d::DrawRect(CRect(-5.0f, -5.0f, SCREEN_WIDTH + 5.0f, SCREEN_HEIGHT + 5.0f), CRGBA(0, 0, 0, 255));
CSprite2d::DrawRect(CRect(-5.0f, -5.0f, SCREEN_WIDTH + 5.0f, SCREEN_HEIGHT + 5.0f), CRGBA(settings.backgroundColor.r, settings.backgroundColor.g, settings.backgroundColor.b, settings.backgroundColor.a));

const float mapHalfSize = GetMenuMapWholeSize() / 2;
CRect rect;
CRGBA col = { 255, 255, 255, static_cast<unsigned char>(menuManager->FadeIn(255)) };
CRGBA col = { settings.radarMapColor.r, settings.radarMapColor.g, settings.radarMapColor.b, static_cast<unsigned char>(menuManager->FadeIn(settings.radarMapColor.a)) };

float mapZoom = GetMenuMapTileSize() * m_fMapZoom;
rect.left = m_vMapBase.x;
Expand Down Expand Up @@ -74,7 +79,7 @@ void CMenuNew::DrawMap() {

void CMenuNew::DrawCrosshair(float x, float y) {
float lineSize = ScaleY(2.0f);
CRGBA lineCol = CRGBA(234, 171, 54, menuManager->FadeIn(155));
CRGBA lineCol = CRGBA(settings.crosshairColor.r, settings.crosshairColor.g, settings.crosshairColor.b, menuManager->FadeIn(settings.crosshairColor.a));

RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));

Expand All @@ -88,7 +93,7 @@ void CMenuNew::DrawCrosshair(float x, float y) {
void CMenuNew::DrawZone() {
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(FALSE));

CSprite2d::DrawRect(CRect(-5.0f, SCREEN_HEIGHT + 5.0f, SCREEN_WIDTH + 5.0f, SCREEN_HEIGHT - ScaleY(42.0f)), CRGBA(10, 10, 10, 255));
CSprite2d::DrawRect(CRect(-5.0f, SCREEN_HEIGHT + 5.0f, SCREEN_WIDTH + 5.0f, SCREEN_HEIGHT - ScaleY(42.0f)), CRGBA(10, 10, 10, menuManager->FadeIn(255)));

CVector pos = MapToWorld(CVector2D(m_vCrosshair.x, m_vCrosshair.y));
CZone* zoneType0 = CTheZones::FindSmallestZonePositionType(pos, 0);
Expand All @@ -111,7 +116,7 @@ void CMenuNew::DrawZone() {
CFont::SetDropShadowPosition(0);
CFont::SetWrapx(SCREEN_WIDTH);
CFont::SetFontStyle(0);
CFont::SetColor(CRGBA(255, 255, 255, 255));
CFont::SetColor(CRGBA(settings.zoneNameColor.r, settings.zoneNameColor.g, settings.zoneNameColor.b, menuManager->FadeIn(settings.zoneNameColor.a)));
CFont::SetScale(ScaleX(0.54f), ScaleY(1.12f));
CFont::PrintString(ScaleX(16.0f), SCREEN_HEIGHT - ScaleY(34.0f), str);
}
Expand Down Expand Up @@ -201,7 +206,7 @@ void CMenuNew::DrawBlips() {
CSprite2d* sprite = pRadarSprites[RADAR_SPRITE_CENTRE];

if (sprite && flashItem(1000, 200))
DrawSpriteWithRotation(sprite, pos.x, pos.y, ScaleX(RADAR_BLIPS_SCALE), ScaleY(RADAR_BLIPS_SCALE), angle, CRGBA(255, 255, 255, menuManager->FadeIn(255)));
DrawSpriteWithRotation(sprite, pos.x, pos.y, ScaleX(RADAR_BLIPS_SCALE - 1.0f), ScaleY(RADAR_BLIPS_SCALE - 1.0f), angle, CRGBA(255, 255, 255, menuManager->FadeIn(255)));
}
}

Expand Down Expand Up @@ -253,6 +258,9 @@ void CMenuNew::StreamRadarSections() {
}

void CMenuNew::MapInput() {
if (!menuManager)
return;

CPad* pad = CPad::GetPad(0);

if (clearInput) {
Expand Down Expand Up @@ -378,6 +386,7 @@ void CMenuNew::DrawRadarSectionMap(int x, int y, CRect const& rect, CRGBA const&
if (texture) {
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, RwTextureGetRaster(texture));
CSprite2d::SetVertices(rect, col, col, col, col, 0);

RwIm2DRenderPrimitive(rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4);
}
}
Expand Down
4 changes: 4 additions & 0 deletions source/MenuNew.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
#include "plugin.h"
#include "CMenuManager.h"
#include "CRadar.h"
#include "Settings.h"

enum {
#ifdef GTA3
MENUPAGE_MAP = MENUPAGE_NO_MEMORY_CARD,
#endif
};

class CMenuNew {
Expand All @@ -23,6 +26,7 @@ class CMenuNew {
int targetBlipIndex;
CVector targetBlipWorldPos;
bool clearInput;
Settings settings;

public:
CMenuNew();
Expand Down
16 changes: 16 additions & 0 deletions source/Settings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "plugin.h"
#include "Settings.h"

void Settings::Read() {
#ifdef GTA3
plugin::config_file config(PLUGIN_PATH("MenuMapIII.ini"));
#else
plugin::config_file config(PLUGIN_PATH("MenuMapVC.ini"));
#endif

radarMapColor = config["RadarMapColor"].asRGBA(CRGBA(255, 255, 255, 255));
backgroundColor = config["BackgroundColor"].asRGBA(CRGBA(0, 0, 0, 255));
crosshairColor = config["CrosshairColor"].asRGBA(CRGBA(234, 171, 54, 255));
zoneNameColor = config["ZoneNameColor"].asRGBA(CRGBA(255, 255, 255, 255));

}
13 changes: 13 additions & 0 deletions source/Settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

class Settings {
public:
CRGBA radarMapColor;
CRGBA backgroundColor;
CRGBA crosshairColor;
CRGBA zoneNameColor;

public:
void Read();
};

0 comments on commit 302e320

Please sign in to comment.