Repository navigation
Expand file tree
/
Copy pathFieldLogApp.cs
More file actions
71 lines (58 loc) · 2.57 KB
/
Copy pathFieldLogApp.cs
File metadata and controls
71 lines (58 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
using CitizenFX.Core;
using CitizenFX.Core.Native;
using FivePRS.Client.Terminal;
using FivePRS.Core.Models;
namespace ExampleApps
{
public class FieldLogApp : TerminalApp
{
private const int MaxEntries = 50;
private const int MaxNoteLength = 200;
private readonly List<Dictionary<string, object>> _entries = new();
public override string Id => "fieldlog";
public override string Label => "Field Log";
public override string Color => "#0d9488";
public override string Icon => "M4 20h16 M6 16l9-9 3 3-9 9H6z";
public override int Order => 710;
public override string? Page => "apps/fieldlog/index.html";
public override string? Badge => _entries.Count > 0 ? _entries.Count.ToString() : null;
public override bool IsAvailable(PlayerData player) => player.IsOnDuty;
public override void OnOpened() => Send("entries", _entries);
public override void OnAction(string action, IDictionary<string, object> data)
{
switch (action)
{
case "add":
var note = data.TryGetValue("note", out var value) ? Convert.ToString(value)?.Trim() ?? string.Empty : string.Empty;
if (note.Length == 0) return;
_entries.Insert(0, new Dictionary<string, object>
{
["time"] = DateTime.Now.ToString("HH:mm"),
["location"] = CurrentLocation(),
["note"] = note.Length > MaxNoteLength ? note.Substring(0, MaxNoteLength) : note,
});
if (_entries.Count > MaxEntries) _entries.RemoveAt(_entries.Count - 1);
break;
case "clear":
_entries.Clear();
break;
default:
return;
}
Refresh();
Send("entries", _entries);
}
private static string CurrentLocation()
{
var position = Game.PlayerPed.Position;
uint street = 0, crossing = 0;
API.GetStreetNameAtCoord(position.X, position.Y, position.Z, ref street, ref crossing);
var zone = API.GetLabelText(API.GetNameOfZone(position.X, position.Y, position.Z));
var parts = new[] { API.GetStreetNameFromHashKey(street), zone }.Where(part => !string.IsNullOrEmpty(part) && part != "NULL");
return string.Join(", ", parts);
}
}
}