-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConfigWindow.cs
134 lines (115 loc) · 5.4 KB
/
ConfigWindow.cs
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
130
131
132
133
134
using System;
using System.Linq;
using System.Numerics;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Windowing;
using ImGuiNET;
namespace Doorbell;
public class ConfigWindow : Window {
public ConfigWindow(string name) : base(name, ImGuiWindowFlags.AlwaysAutoResize) {
}
private void DrawAlertConfig(Alert alert) {
ImGui.Checkbox("Play a Sound", ref alert.SoundEnabled);
if (alert.SoundEnabled) {
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.Music)) {
alert.PlaySound();
}
if (ImGui.IsItemHovered()) {
ImGui.SetTooltip("Test Sound");
}
} else {
ImGui.BeginDisabled();
}
ImGui.Indent();
if (ImGui.InputTextWithHint("##Sound File", "Default Doorbell", ref alert.SoundFile, 512)) {
alert.DisposeSound();
}
ImGui.SameLine();
if (ImGuiComponents.IconButton(FontAwesomeIcon.FolderOpen)) {
Plugin.FileDialogManager.OpenFileDialog("Select a Sound File", "Sound Files (wav mp3 ogg){.wav,.mp3,.ogg}", (b, s) => {
alert.SoundFile = s;
});
}
ImGui.SameLine();
ImGui.Text("Sound File");
if (ImGui.SliderFloat("Volume", ref alert.SoundVolume, 0, alert.SoundFile.IsHttpUrl() ? 1 : MathF.Max(3, alert.SoundVolume + 0.01f))) {
if (alert.SoundVolume < 0) alert.SoundVolume = 0;
if (alert.SoundVolume > 1 && alert.SoundFile.IsHttpUrl()) alert.SoundVolume = 1;
alert.DisposeSound();
}
ImGui.Unindent();
if (!alert.SoundEnabled) ImGui.EndDisabled();
ImGui.Checkbox("Show a chat message", ref alert.ChatEnabled);
ImGui.Indent();
if (!alert.ChatEnabled) ImGui.BeginDisabled();
ImGui.InputText("Message", ref alert.ChatFormat, 200);
if (ImGui.IsItemHovered()) {
ImGui.BeginTooltip();
ImGui.Text("Use <link> as a placeholder to link to the player.");
ImGui.Text("Use <name> as a placeholder for the players name.");
ImGui.Text("Use <world> as a placeholder for the players world.");
ImGui.EndTooltip();
}
if (!alert.ChatEnabled) ImGui.EndDisabled();
ImGui.Unindent();
}
private int silenceMinutesSlider;
public override void Draw() {
if (Plugin.Silenced) {
ImGui.PushStyleColor(ImGuiCol.FrameBg, ImGui.ColorConvertFloat4ToU32(ImGuiColors.DalamudRed) & 0x55FFFFFF);
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
var timeRemaining = (Plugin.SilenceTimeSpan == null ? TimeSpan.Zero : Plugin.SilenceTimeSpan - Plugin.SilencedFor.Elapsed).Value;
var str = string.Join(':', new[] { timeRemaining.Days, timeRemaining.Hours, timeRemaining.Minutes, timeRemaining.Seconds }.Select(i => $"{i:00}")).TrimStart('0', ':');
ImGui.DragInt("##silenceMinutes", ref silenceMinutesSlider, 0, 0, 0, Plugin.SilenceTimeSpan == null ? "Silenced until leaving a house." : $"Silenced for {str}", ImGuiSliderFlags.NoInput);
ImGui.PopStyleColor();
if (ImGui.Button("Unsilence Doorbell", new Vector2(ImGui.GetContentRegionAvail().X, 24 * ImGuiHelpers.GlobalScale))) {
Plugin.UnSilence();
}
} else {
ImGui.SetNextItemWidth(ImGui.GetContentRegionAvail().X);
var timeSpan = TimeSpan.FromMinutes(silenceMinutesSlider);
var str = string.Join(':', new[] { timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds }.Select(i => $"{i:00}")).TrimStart('0', ':');
ImGui.SliderInt("##silenceMinutes", ref silenceMinutesSlider, 0, Math.Max(60, silenceMinutesSlider + 1), silenceMinutesSlider <= 0 ? "Until leaving a house," : $"For {str},", ImGuiSliderFlags.NoInput);
if (ImGui.Button("Silence Doorbell", new Vector2(ImGui.GetContentRegionAvail().X, 24 * ImGuiHelpers.GlobalScale))) {
if (silenceMinutesSlider <= 0) {
Plugin.Silence();
} else {
Plugin.Silence(TimeSpan.FromMinutes(silenceMinutesSlider));
}
}
}
ImGui.Separator();
ImGui.PushID("Doorbell_Config_Entered");;
ImGui.Text("When a player enters a house: ");
ImGui.Indent();
DrawAlertConfig(Plugin.Config.Entered);
ImGui.Unindent();
ImGui.Separator();
ImGui.PushID("Doorbell_Config_Left");
ImGui.Text("When a player leaves a house: ");
ImGui.Indent();
DrawAlertConfig(Plugin.Config.Left);
ImGui.Unindent();
ImGui.PopID();
ImGui.Separator();
ImGui.PushID("Doorbell_Config_AlreadyHere");
ImGui.Text("When entering a house with people already inside: ");
ImGui.Indent();
DrawAlertConfig(Plugin.Config.AlreadyHere);
ImGui.Unindent();
ImGui.PopID();
ImGui.Separator();
if (ImGui.Button("Save")) {
Plugin.PluginInterface.SavePluginConfig(Plugin.Config);
}
ImGui.SameLine();
if (ImGui.Button("Save & Close")) {
Plugin.PluginInterface.SavePluginConfig(Plugin.Config);
IsOpen = false;
}
}
}