forked from Facepunch/Rust.Community
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommunityEntity.Pie.cs
More file actions
130 lines (114 loc) · 5.5 KB
/
Copy pathCommunityEntity.Pie.cs
File metadata and controls
130 lines (114 loc) · 5.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using ProtoBuf;
using UnityEngine;
public partial class CommunityEntity
{
#if SERVER
[ServerVar]
public static void pietest(ConsoleSystem.Arg arg)
{
using var pie = Facepunch.Pool.Get<CustomPie>();
pie.menus = Facepunch.Pool.Get<System.Collections.Generic.List<CustomPieMenu>>();
AddPieMenu(pie, "Switch Night", "Switch to night mode", "env.time 0", "assets/icons/device_add.png", false, false, "", "");
AddPieMenu(pie, "Switch Day", "Switch to day mode", "env.time 12", "assets/icons/device_add.png", false, false, "", "");
AddPieMenu(pie, "Rain", "Make it rain on the server", "sv weather.load storm", "assets/icons/embrella.png", false, false, "", "");
AddPieMenu(pie, "Be Malicious", "This attempts to open your player inventory.", "inventory.toggle", "assets/icons/explosion_sprite.png", false, false, "", "");
AddPieMenu(pie, "Left/Right Test", "Pick one or the other", "pietest_prev", "assets/icons/facepunch.png", false, false, "pietest_prev", "pietest_next");
AddPieMenu(pie, "Exit", "Close this context menu", "", "assets/icons/close.png", false, false, "", "");
ServerInstance.SendPie(arg.Player(), pie);
}
[ServerVar]
public static void pietest_prev(ConsoleSystem.Arg arg)
{
using var pie = Facepunch.Pool.Get<CustomPie>();
pie.menus = Facepunch.Pool.Get<System.Collections.Generic.List<CustomPieMenu>>();
AddPieMenu(pie, "Go Back", null, "pietest", "assets/icons/fun.png", false, false, "", "");
AddPieMenu(pie, "Or Don't", "You went previous", "pietest", "assets/icons/fun.png", true, false, "", "");
ServerInstance.SendPie(arg.Player(), pie);
}
[ServerVar]
public static void pietest_next(ConsoleSystem.Arg arg)
{
using var pie = Facepunch.Pool.Get<CustomPie>();
pie.menus = Facepunch.Pool.Get<System.Collections.Generic.List<CustomPieMenu>>();
AddPieMenu(pie, "Go Back", null, "pietest", "assets/icons/fun.png", false, false, "", "");
AddPieMenu(pie, "Or Don't", "You went next", "pietest", "assets/icons/fun.png", true, false, "", "");
ServerInstance.SendPie(arg.Player(), pie);
}
private static void AddPieMenu(CustomPie pie, string name, string description, string command, string sprite, bool disabled, bool selected, string next, string prev)
{
var pieMenu = Facepunch.Pool.Get<CustomPieMenu>();
pieMenu.name = name;
pieMenu.description = description;
pieMenu.command = command;
pieMenu.sprite = sprite;
pieMenu.disabled = disabled;
pieMenu.selected = selected;
pieMenu.nextCommand = next;
pieMenu.prevCommand = prev;
pie.menus.Add(pieMenu);
}
public void SendPie(BasePlayer player, CustomPie pie)
{
ClientRPC(RpcTarget.Player("OpenPie", player), pie);
}
#endif
#if CLIENT
[RPC_Client]
public void OpenPie(RPCMessage rpc)
{
using var pie = rpc.read.Proto<CustomPie>();
if (UIInventory.isOpen || UICrafting.isOpen || UIContacts.isOpen || UIClans.IsOpen || UIDialog.isOpen)
{
if (!string.IsNullOrEmpty(pie.closeCommand))
{
ConsoleSystem.Run(ConsoleSystem.Option.Client.FromServer(), pie.closeCommand);
}
return;
}
ContextMenuUI.Start(ContextMenuUI.MenuType.Custom, string.IsNullOrEmpty(pie.closeCommand) ? null : () =>
{
ConsoleSystem.Run(ConsoleSystem.Option.Client.FromServer(), pie.closeCommand);
});
for (int i = 0; i < pie.menus.Count; i++)
{
var menu = pie.menus[i];
var sprite = string.IsNullOrEmpty(menu.sprite) ? GetOrRequestSprite(menu.imageId) : FileSystem.Load<Sprite>(menu.sprite);
var menuCommand = menu.command;
var menuDisabledCommand = menu.disabledCommand;
var menuNextCommand = menu.nextCommand;
var menuPrevCommand = menu.prevCommand;
ContextMenuUI.AddOptionPhrase(
namePhrase: menu.name,
descPhrase: menu.description,
icon: sprite,
action: string.IsNullOrEmpty(menuCommand) ? null : (ply) =>
{
ConsoleSystem.Run(ConsoleSystem.Option.Client.FromServer(), menuCommand);
},
actionDisabled: string.IsNullOrEmpty(menuDisabledCommand) ? null : ((ply) =>
{
ConsoleSystem.Run(ConsoleSystem.Option.Client.FromServer(), menuDisabledCommand);
}),
actionNext: string.IsNullOrEmpty(menuNextCommand) ? null : ((ply) =>
{
ConsoleSystem.Run(ConsoleSystem.Option.Client.FromServer(), menuNextCommand);
PieMenu.Instance.Close(true);
}),
actionPrev: string.IsNullOrEmpty(menuPrevCommand) ? null : ((ply) =>
{
ConsoleSystem.Run(ConsoleSystem.Option.Client.FromServer(), menuPrevCommand);
PieMenu.Instance.Close(true);
}),
order: menu.order,
disabled: menu.disabled,
selected: menu.selected,
colorMode: menu.color != default ? new PieMenu.MenuOption.ColorMode()
{
Mode = (PieMenu.MenuOption.ColorMode.PieMenuSpriteColorOption)menu.colorMode,
CustomColor = menu.color
} : null);
}
ContextMenuUI.End();
}
#endif
}