Mouse Bindings + Action Bar
Implemented mouse bindings for input screen Implemented action bar bindings for input screen
This commit is contained in:
parent
296a7f2958
commit
40c244190b
48 changed files with 538 additions and 93 deletions
|
|
@ -96,7 +96,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
get => _playerSettings ??= File.Exists(_playerSettingsFilePath)
|
||||
? MessagePackSerializer.Deserialize<PlayerSettings>(File.ReadAllBytes(_playerSettingsFilePath))
|
||||
: new PlayerSettings {Name = Environment.UserName};
|
||||
: GetDefaultPlayerSettings();
|
||||
}
|
||||
private static string _playerSettingsFilePath => Path.Combine(GameDataDirectory.FullName, "PlayerSettings.msgpack");
|
||||
public static void SavePlayerSettings()
|
||||
|
|
@ -104,6 +104,18 @@ public class ActionGameManager : MonoBehaviour
|
|||
File.WriteAllBytes(_playerSettingsFilePath, MessagePackSerializer.Serialize(_playerSettings));
|
||||
}
|
||||
|
||||
private static PlayerSettings GetDefaultPlayerSettings()
|
||||
{
|
||||
var settings = new PlayerSettings();
|
||||
settings.Name = Environment.UserName;
|
||||
settings.InputSettings.ActionBarInputs.Add("<Keyboard>/leftShift");
|
||||
settings.InputSettings.ActionBarInputs.Add("<Mouse>/leftButton");
|
||||
settings.InputSettings.ActionBarInputs.Add("<Mouse>/rightButton");
|
||||
settings.InputSettings.ActionBarInputs.Add("<Mouse>/middleButton");
|
||||
for (int i = 1; i < 6; i++) settings.InputSettings.ActionBarInputs.Add($"<Keyboard>/{i}");
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static Sector CurrentSector;
|
||||
public static bool IsTutorial;
|
||||
|
||||
|
|
@ -122,12 +134,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
public PostProcessVolume SevereHeatstrokePP;
|
||||
public PostProcessVolume SevereHypothermiaPP;
|
||||
|
||||
[Header("Input Icons")]
|
||||
public Sprite ShiftIcon;
|
||||
public Sprite MouseLeftIcon;
|
||||
public Sprite MouseRightIcon;
|
||||
public Sprite MouseMiddleIcon;
|
||||
|
||||
[Header("Scene Links")]
|
||||
public Transform ActionBar;
|
||||
public ActionBarSlot ActionBarSlot;
|
||||
|
|
@ -420,6 +426,19 @@ public class ActionGameManager : MonoBehaviour
|
|||
action.started += context => slot.Binding?.Activate();
|
||||
action.canceled += context => slot.Binding?.Deactivate();
|
||||
|
||||
var shortName = controlPath.Substring(controlPath.LastIndexOf('/') + 1);
|
||||
var sprite = Resources.Load<Sprite>($"Sprites/Input/{shortName}");
|
||||
if (sprite != null)
|
||||
{
|
||||
slot.InputIcon.sprite = sprite;
|
||||
slot.InputLabel.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.InputLabel.text = shortName;
|
||||
slot.InputIcon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
slot.PointerEnterTrigger.OnPointerEnterAsObservable().Subscribe(_ =>
|
||||
{
|
||||
//Debug.Log($"Pointer entered action bar slot {controlPath}");
|
||||
|
|
@ -453,29 +472,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
return slot;
|
||||
}
|
||||
|
||||
var shift = createBinding("<Keyboard>/leftShift");
|
||||
shift.InputIcon.sprite = ShiftIcon;
|
||||
shift.InputLabel.gameObject.SetActive(false);
|
||||
|
||||
var left = createBinding("<Mouse>/leftButton");
|
||||
left.InputIcon.sprite = MouseLeftIcon;
|
||||
left.InputLabel.gameObject.SetActive(false);
|
||||
|
||||
var right = createBinding("<Mouse>/rightButton");
|
||||
right.InputIcon.sprite = MouseRightIcon;
|
||||
right.InputLabel.gameObject.SetActive(false);
|
||||
|
||||
var middle = createBinding("<Mouse>/middleButton");
|
||||
middle.InputIcon.sprite = MouseMiddleIcon;
|
||||
middle.InputLabel.gameObject.SetActive(false);
|
||||
foreach (var actionBarInput in PlayerSettings.InputSettings.ActionBarInputs) createBinding(actionBarInput);
|
||||
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
var num = createBinding($"<Keyboard>/{i}");
|
||||
num.InputIcon.gameObject.SetActive(false);
|
||||
num.InputLabel.text = i.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ public class PlayerSettings
|
|||
[Key(1)] public SavedGame SavedRun;
|
||||
[Key(2)] public bool TutorialPassed;
|
||||
[Key(3)] public Dictionary<string, string> HashedStoryFiles = new Dictionary<string, string>();
|
||||
[Key(4)] public PlayerGameplaySettings GameplaySettings;
|
||||
[Key(5)] public PlayerInputSettings InputSettings;
|
||||
[Key(4)] public PlayerGameplaySettings GameplaySettings = new PlayerGameplaySettings();
|
||||
[Key(5)] public PlayerInputSettings InputSettings = new PlayerInputSettings();
|
||||
|
||||
public string FormatTemperature(float t)
|
||||
{
|
||||
|
|
@ -19,7 +19,7 @@ public class PlayerSettings
|
|||
{
|
||||
TemperatureUnit.Kelvin => $"{Format(t)}°K",
|
||||
TemperatureUnit.Celsius => $"{Format(t - 273.15f)}°C",
|
||||
TemperatureUnit.Fahrenheit => $"{Format((t - 273.15f) * (9f / 5) + 32)}°F",
|
||||
TemperatureUnit.Fahrenheit => $"{Format(t * (9f / 5) - 459.67f)}°F",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
|
|
@ -58,5 +58,6 @@ public class PlayerGameplaySettings
|
|||
public class PlayerInputSettings
|
||||
{
|
||||
[Key(0)] public Dictionary<string, string> InputActionMap = new Dictionary<string, string>();
|
||||
[Key(1)] public bool FiveButtonMouse;
|
||||
[Key(1)] public List<string> ActionBarInputs = new List<string>();
|
||||
[Key(2)] public bool FiveButtonMouse;
|
||||
}
|
||||
Loading…
Reference in a new issue