Skip to content

Commit

Permalink
Add radio and blips options
Browse files Browse the repository at this point in the history
  • Loading branch information
oldnapalm committed Oct 3, 2021
1 parent e652806 commit 51f90e5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
37 changes: 32 additions & 5 deletions CommunityRaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,16 @@ public CommunityRaces()

private void AddRacesBlips()
{
foreach (RaceBlip race in _races)
race.Add();
if (Config.RacesBlips)
foreach (RaceBlip race in _races)
race.Add();
}

private void RemoveRacesBlips()
{
foreach (RaceBlip race in _races)
race.Remove();
if (Config.RacesBlips)
foreach (RaceBlip race in _races)
race.Remove();
}

/// <summary>
Expand Down Expand Up @@ -243,6 +245,11 @@ private void StartRace(Race race)
_currentVehicle.IsPersistent = false;
_currentVehicle.FreezePosition = true;

if (Config.Radio == "RadioOff")
Function.Call(Hash.SET_VEH_RADIO_STATION, _currentVehicle.Handle, "OFF");
else
SetRadioStation();

int spawnlen = 0;
switch (Config.Opponents)
{
Expand Down Expand Up @@ -792,6 +799,19 @@ public void BuildMenu(Race race)
Config.SecondaryColor = item.Items[index].ToString();
};

SetRadioStation();
var radioList = new List<dynamic> { "Random" };
Enum.GetValues(typeof(RadioStation)).Cast<RadioStation>().ToList().ForEach(r => { if (r != RadioStation.Unknown) radioList.Add(r); });
int selectedRadio = 0;
if (Enum.TryParse(Config.Radio, out RadioStation radio))
selectedRadio = radioList.IndexOf(radio);
var radioItem = new UIMenuListItem("Radio", radioList, selectedRadio);
radioItem.OnListChanged += (item, index) =>
{
Config.Radio = item.Items[index].ToString();
SetRadioStation();
};

var confimItem = new UIMenuItem("Start Race");
confimItem.Activated += (item, index) =>
{
Expand Down Expand Up @@ -819,6 +839,7 @@ public void BuildMenu(Race race)
GUI.MainMenu.AddItem(carItem);
GUI.MainMenu.AddItem(primaryColorItem);
GUI.MainMenu.AddItem(secondaryColorItem);
GUI.MainMenu.AddItem(radioItem);
GUI.MainMenu.AddItem(opponentsItem);
if (race.LapsAvailable)
{
Expand All @@ -833,7 +854,7 @@ public void BuildMenu(Race race)
}
GUI.MainMenu.AddItem(confimItem);
GUI.MainMenu.RefreshIndex();
GUI.MainMenu.CurrentSelection = race.LapsAvailable ? 10 : 9;
GUI.MainMenu.CurrentSelection = race.LapsAvailable ? 11 : 10;
}

private void SetVehicleColors()
Expand All @@ -854,5 +875,11 @@ private void SetVehicleColors()
}
else _vehicleSecondaryColor = _previewVehicle.SecondaryColor;
}

private void SetRadioStation()
{
if (Enum.TryParse(Config.Radio, out RadioStation radio))
Game.RadioStation = radio;
}
}
}
2 changes: 2 additions & 0 deletions CommunityRaces.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ TRAFFIC = True
PEDS = True
PRIMARYCOLOR = Random
SECONDARYCOLOR = Random
RADIO = Random
OPPONENTS = Random
LAPS = 1
CAYOPERICOLOADER = True
RACESBLIPS = True
TELEPORTKEY = F8

[GHOST]
Expand Down
15 changes: 15 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public static class Config
public static int Opacity;
public static bool Collision;
public static bool CayoPericoLoader;
public static bool RacesBlips;
public static Keys TeleportKey;

static Config()
Expand All @@ -21,6 +22,7 @@ static Config()
Opacity = o * 51;
Collision = _settings.GetValue("Ghost", "Collision", false);
CayoPericoLoader = _settings.GetValue("Main", "CayoPericoLoader", true);
RacesBlips = _settings.GetValue("Main", "RacesBlips", true);
TeleportKey = (Keys)Enum.Parse(typeof(Keys), _settings.GetValue("Main", "TeleportKey", "F8"), true);
}

Expand Down Expand Up @@ -102,6 +104,19 @@ public static string SecondaryColor
}
}

public static string Radio
{
get
{
return _settings.GetValue<string>("Main", "Radio", "Random");
}
set
{
_settings.SetValue<string>("Main", "Radio", value);
_settings.Save();
}
}

public static string Opponents
{
get
Expand Down

0 comments on commit 51f90e5

Please sign in to comment.