forked from BosslandGmbH/HBRelog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterProfile.cs
More file actions
183 lines (164 loc) · 5.53 KB
/
CharacterProfile.cs
File metadata and controls
183 lines (164 loc) · 5.53 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
Copyright 2012 HighVoltz
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Media;
using HighVoltz.HBRelog.Tasks;
using HighVoltz.HBRelog.Settings;
namespace HighVoltz.HBRelog
{
sealed public class CharacterProfile : INotifyPropertyChanged
{
public ProfileSettings Settings { get; set; }
public bool IsRunning { get; private set; }
public bool IsPaused { get; private set; }
public readonly TaskManager TaskManager;
public ObservableCollection<BMTask> Tasks { get; private set; }
public CharacterProfile()
{
Settings = new ProfileSettings();
Tasks = new ObservableCollection<BMTask>();
TaskManager = new TaskManager(this);
}
private string _status;
/// <summary>
/// Status message
/// </summary>
public string Status
{
get { return _status; }
set { _status = value; NotifyPropertyChanged("Status"); }
}
private string _tooltip;
/// <summary>
/// Tooltip message
/// </summary>
public string Tooltip
{
get { return _tooltip; }
set
{
if (value != _tooltip)
{
_tooltip = value;
NotifyPropertyChanged("Tooltip");
}
}
}
private string _taskTooltip;
/// <summary>
/// Current Task Tooltip message. Displayed in main ToolTip
/// </summary>
public string TaskTooltip
{
get { return _taskTooltip; }
set
{
if (value != _taskTooltip)
{
_taskTooltip = value;
UpdateTooltip();
}
}
}
private string _botInfoTooltip;
/// <summary>
/// Bot info Tooltip message. Displayed in main ToolTip
/// </summary>
public string BotInfoTooltip
{
get { return _botInfoTooltip; }
set
{
if (value != _botInfoTooltip)
{
_botInfoTooltip = value;
UpdateTooltip();
}
}
}
void UpdateTooltip()
{
Tooltip = string.Format("{0}{1}",
!string.IsNullOrEmpty(TaskTooltip) ? TaskTooltip + "\n" : null,
BotInfoTooltip);
}
public void Pulse()
{
if (IsRunning && !IsPaused)
{
TaskManager.Pulse();
}
}
public void Pause()
{
Status = "Paused";
if (TaskManager.WowManager.LockToken != null && TaskManager.WowManager.LockToken.IsValid)
{
TaskManager.WowManager.LockToken.ReleaseLock();
}
IsPaused = true;
}
public void Start()
{
Status = "Running";
if (!IsPaused)
TaskManager.Start();
IsRunning = true;
IsPaused = false;
}
public void Stop()
{
Status = "Stopped";
TaskManager.Stop();
IsRunning = false;
IsPaused = false;
}
private string _lastLog;
public void Log(string format, params object[] args)
{
var msg = string.Format(format, args);
if (msg == _lastLog)
return;
_lastLog = msg;
if (HbRelogManager.Settings.UseDarkStyle)
HBRelog.Log.Write(Colors.LightBlue, Settings.ProfileName + ": ", Colors.LightGreen, "{0}", msg);
else
HBRelog.Log.Write(Colors.DarkSlateBlue, Settings.ProfileName + ": ", Colors.DarkGreen, "{0}", msg);
}
public void Err(string format, params object[] args)
{
HBRelog.Log.Write(HbRelogManager.Settings.UseDarkStyle ? Colors.LightBlue : Colors.DarkSlateBlue,
Settings.ProfileName + ": ", Colors.Red, format, args);
}
public CharacterProfile ShadowCopy()
{
var cp = (CharacterProfile)MemberwiseClone();
cp.Tasks = new ObservableCollection<BMTask>();
foreach (var bmTask in Tasks)
{
cp.Tasks.Add(bmTask.ShadowCopy());
}
cp.Settings = Settings.ShadowCopy();
return cp;
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string name)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
}
}