mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-10 14:44:17 +00:00
add ability to change paintjob from UI
This commit is contained in:
parent
3c2ff6569a
commit
204f0be4f5
2 changed files with 92 additions and 3 deletions
|
@ -57,5 +57,10 @@ namespace SanAndreasUnity.Importing.Vehicles
|
|||
{
|
||||
get { return _vals[index]; }
|
||||
}
|
||||
|
||||
public int[][] GetAllColorIndices()
|
||||
{
|
||||
return (int[][])_vals.Clone();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,15 +5,30 @@ using SanAndreasUnity.Importing.Items;
|
|||
using SanAndreasUnity.Importing.Items.Definitions;
|
||||
using SanAndreasUnity.Behaviours;
|
||||
using SanAndreasUnity.Behaviours.Vehicles;
|
||||
using SanAndreasUnity.Importing.Vehicles;
|
||||
using SanAndreasUnity.Utilities;
|
||||
|
||||
namespace SanAndreasUnity.UI {
|
||||
|
||||
public class VehicleSpawnerWindow : PauseMenuWindow {
|
||||
|
||||
private List<IGrouping<VehicleType, VehicleDef>> vehicleGroupings = null;
|
||||
private int[] columnWidths = new int[]{ 150, 120, 30, 70 };
|
||||
private List<IGrouping<VehicleType, VehicleDef>> vehicleGroupings = null;
|
||||
private int[] columnWidths = new int[] { 150, 120, 30, 70 };
|
||||
private string m_searchText = "";
|
||||
|
||||
private static GUIStyle s_colorBoxStyle = null;
|
||||
private static GUIStyle ColorBoxStyle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_colorBoxStyle != null)
|
||||
return s_colorBoxStyle;
|
||||
|
||||
s_colorBoxStyle = new GUIStyle { normal = new GUIStyleState { background = Texture2D.whiteTexture } };
|
||||
return s_colorBoxStyle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
VehicleSpawnerWindow() {
|
||||
|
@ -60,6 +75,48 @@ namespace SanAndreasUnity.UI {
|
|||
|
||||
protected override void OnWindowGUIBeforeContent()
|
||||
{
|
||||
// current vehicle info
|
||||
|
||||
if (Ped.Instance != null && Ped.Instance.CurrentVehicle != null)
|
||||
{
|
||||
var vehicle = Ped.Instance.CurrentVehicle;
|
||||
|
||||
GUILayout.Label("Current vehicle:");
|
||||
|
||||
GUILayout.Label(vehicle.Definition.GameName, GUILayout.Width(this.columnWidths[0]));
|
||||
|
||||
GUILayout.Label("Change paintjob:");
|
||||
|
||||
var oldBackgroundColor = GUI.backgroundColor;
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (GUIUtils.ButtonWithCalculatedSize("Random"))
|
||||
OnPaintjobPressed(null);
|
||||
|
||||
var defaultClrs = CarColors.GetCarDefaults(vehicle.Definition.ModelName);
|
||||
|
||||
if (defaultClrs != null)
|
||||
{
|
||||
var colors = defaultClrs.GetAllColorIndices()
|
||||
.Select(indices => CarColors.FromIndices(indices));
|
||||
|
||||
foreach (var colorArray in colors)
|
||||
{
|
||||
if (colorArray.Length == 0)
|
||||
continue;
|
||||
DisplayPaintjob(colorArray);
|
||||
GUILayout.Space(5);
|
||||
}
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUI.backgroundColor = oldBackgroundColor;
|
||||
|
||||
GUILayout.Space(15);
|
||||
}
|
||||
|
||||
// search box
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
|
@ -83,7 +140,7 @@ namespace SanAndreasUnity.UI {
|
|||
return;
|
||||
|
||||
|
||||
GUILayout.Space (10);
|
||||
GUILayout.Space(10);
|
||||
|
||||
// for each vehicle, display a button which spawns it
|
||||
|
||||
|
@ -139,6 +196,33 @@ namespace SanAndreasUnity.UI {
|
|||
|
||||
}
|
||||
|
||||
private void DisplayPaintjob(Color32[] colors)
|
||||
{
|
||||
int width = 30 / colors.Length;
|
||||
|
||||
foreach (var color in colors)
|
||||
{
|
||||
DisplaySingleColor(color, width, colors);
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplaySingleColor(Color32 color, int width, Color32[] allColors)
|
||||
{
|
||||
GUI.backgroundColor = color;
|
||||
if (GUILayout.Button(GUIContent.none, ColorBoxStyle, GUILayout.Width(width), GUILayout.Height(30)))
|
||||
OnPaintjobPressed(allColors);
|
||||
}
|
||||
|
||||
private void OnPaintjobPressed(Color32[] colors)
|
||||
{
|
||||
SendCommand("/paintjob " + (colors != null ? string.Join(" ", colors.Select(c => GetColorString(c))) : ""));
|
||||
}
|
||||
|
||||
private string GetColorString(Color32 color)
|
||||
{
|
||||
return "#" + ColorUtility.ToHtmlStringRGBA(color);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue