Notify icon doesn't autofocus when clicked and shows player count, first work on getting /undoplayer to work with console

This commit is contained in:
UnknownShadow200 2017-05-30 21:15:31 +10:00
parent a7b3d9e2c8
commit efeff445d7
10 changed files with 34 additions and 46 deletions

View File

@ -369,21 +369,21 @@ namespace MCGalaxy.Gui
// //
this.icon_openConsole.Name = "icon_openConsole"; this.icon_openConsole.Name = "icon_openConsole";
this.icon_openConsole.Size = new System.Drawing.Size(157, 22); this.icon_openConsole.Size = new System.Drawing.Size(157, 22);
this.icon_openConsole.Text = "Open Console"; this.icon_openConsole.Text = "Open console";
this.icon_openConsole.Click += new System.EventHandler(this.openConsole_Click); this.icon_openConsole.Click += new System.EventHandler(this.openConsole_Click);
// //
// icon_shutdown // icon_shutdown
// //
this.icon_shutdown.Name = "icon_shutdown"; this.icon_shutdown.Name = "icon_shutdown";
this.icon_shutdown.Size = new System.Drawing.Size(157, 22); this.icon_shutdown.Size = new System.Drawing.Size(157, 22);
this.icon_shutdown.Text = "Shutdown Server"; this.icon_shutdown.Text = "Shutdown server";
this.icon_shutdown.Click += new System.EventHandler(this.shutdownServer_Click); this.icon_shutdown.Click += new System.EventHandler(this.shutdownServer_Click);
// //
// icon_restart // icon_restart
// //
this.icon_restart.Name = "icon_restart"; this.icon_restart.Name = "icon_restart";
this.icon_restart.Size = new System.Drawing.Size(157, 22); this.icon_restart.Size = new System.Drawing.Size(157, 22);
this.icon_restart.Text = "Restart Server"; this.icon_restart.Text = "Restart server";
this.icon_restart.Click += new System.EventHandler(this.icon_restart_Click); this.icon_restart.Click += new System.EventHandler(this.icon_restart_Click);
// //
// main_btnProps // main_btnProps

View File

@ -22,10 +22,12 @@ namespace MCGalaxy.Gui {
public partial class Window : Form { public partial class Window : Form {
PlayerProperties playerProps; PlayerProperties playerProps;
public void UpdatePlayersListBox() { void UpdatePlayers() {
RunOnUiThread( RunOnUiThread(
delegate { delegate {
pl_listBox.Items.Clear(); pl_listBox.Items.Clear();
UpdateNotifyIconText();
Player[] players = PlayerInfo.Online.Items; Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) foreach (Player p in players)
pl_listBox.Items.Add(p.name); pl_listBox.Items.Add(p.name);

View File

@ -74,12 +74,17 @@ namespace MCGalaxy.Gui {
} }
void MakeNotifyIcon() { void UpdateNotifyIconText() {
notifyIcon.Text = Server.name.Truncate(63); int playerCount = PlayerInfo.Online.Count;
string players = " (" + playerCount + " players)";
notifyIcon.Text = (Server.name + players).Truncate(63);
}
void MakeNotifyIcon() {
UpdateNotifyIconText();
notifyIcon.ContextMenuStrip = this.icon_context; notifyIcon.ContextMenuStrip = this.icon_context;
notifyIcon.Icon = this.Icon; notifyIcon.Icon = this.Icon;
notifyIcon.Visible = true; notifyIcon.Visible = true;
notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon1_MouseClick);
} }
void InitServer() { void InitServer() {
@ -114,11 +119,11 @@ namespace MCGalaxy.Gui {
public void RunOnUiThread(Action act) { Invoke(act); } public void RunOnUiThread(Action act) { Invoke(act); }
void Player_PlayerConnect(Player p) { void Player_PlayerConnect(Player p) {
UpdatePlayersListBox(); UpdatePlayers();
} }
void Player_PlayerDisconnect(Player p, string reason) { void Player_PlayerDisconnect(Player p, string reason) {
UpdatePlayersListBox(); UpdatePlayers();
} }
void Player_OnSendMap(Player p, byte[] buffer) { void Player_OnSendMap(Player p, byte[] buffer) {
@ -149,7 +154,7 @@ namespace MCGalaxy.Gui {
Invoke(new VoidDelegate(SettingsUpdate)); Invoke(new VoidDelegate(SettingsUpdate));
} else { } else {
Text = Server.name + " - " + Server.SoftwareNameVersioned; Text = Server.name + " - " + Server.SoftwareNameVersioned;
notifyIcon.Text = Server.name.Truncate(63); UpdateNotifyIconText();
} }
} }
@ -193,6 +198,7 @@ namespace MCGalaxy.Gui {
Invoke(new PlayerListCallback(UpdateClientList), playerList); return; Invoke(new PlayerListCallback(UpdateClientList), playerList); return;
} }
UpdateNotifyIconText();
if (main_Players.DataSource == null) if (main_Players.DataSource == null)
main_Players.DataSource = pc; main_Players.DataSource = pc;
@ -303,7 +309,7 @@ namespace MCGalaxy.Gui {
MCGalaxy.Gui.App.ExitProgram(false); MCGalaxy.Gui.App.ExitProgram(false);
notifyIcon.Dispose(); notifyIcon.Dispose();
} }
if (Server.shuttingDown || MessageBox.Show("Really shutdown the server? All players will be disconnected!", "Exit", MessageBoxButtons.OKCancel) == DialogResult.OK) { if (Server.shuttingDown || MessageBox.Show("Really shutdown the server? All players will be disconnected!", "Exit", MessageBoxButtons.OKCancel) == DialogResult.OK) {
if (!Server.shuttingDown) MCGalaxy.Gui.App.ExitProgram(false); if (!Server.shuttingDown) MCGalaxy.Gui.App.ExitProgram(false);
notifyIcon.Dispose(); notifyIcon.Dispose();
@ -328,12 +334,6 @@ namespace MCGalaxy.Gui {
ShowInTaskbar = WindowState != FormWindowState.Minimized; ShowInTaskbar = WindowState != FormWindowState.Minimized;
} }
void notifyIcon1_MouseClick(object sender, MouseEventArgs e) {
Show();
BringToFront();
WindowState = FormWindowState.Normal;
}
void openConsole_Click(object sender, EventArgs e) { void openConsole_Click(object sender, EventArgs e) {
Show(); Show();
BringToFront(); BringToFront();
@ -347,7 +347,7 @@ namespace MCGalaxy.Gui {
void tabs_Click(object sender, EventArgs e) { void tabs_Click(object sender, EventArgs e) {
try { UpdateUnloadedList(); } try { UpdateUnloadedList(); }
catch { } catch { }
try { UpdatePlayersListBox(); } try { UpdatePlayers(); }
catch { } catch { }
try { try {

View File

@ -29,7 +29,6 @@ namespace MCGalaxy.Commands.Moderation {
public override string type { get { return CommandTypes.Moderation; } } public override string type { get { return CommandTypes.Moderation; } }
public override bool museumUsable { get { return true; } } public override bool museumUsable { get { return true; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } } public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override bool SuperUseable { get { return false; } } // TODO: fix this to work from IRC and Console
public override CommandAlias[] Aliases { public override CommandAlias[] Aliases {
get { return new[] { new CommandAlias("xundo", null, "all"), get { return new[] { new CommandAlias("xundo", null, "all"),
new CommandAlias("undoarea", "area"), new CommandAlias("ua", "area") }; } new CommandAlias("undoarea", "area"), new CommandAlias("ua", "area") }; }

View File

@ -101,9 +101,9 @@ namespace MCGalaxy.Undo {
/// <summary> Arguments provided to an UndoFormat for retrieving undo data. </summary> /// <summary> Arguments provided to an UndoFormat for retrieving undo data. </summary>
public class UndoFormatArgs { public class UndoFormatArgs {
/// <summary> Player associated with this undo, can be console or IRC. </summary> /// <summary> Level to retrieve undo data on. </summary>
internal readonly Player Player; internal readonly string LevelName;
/// <summary> Small work buffer, used to avoid memory allocations. </summary> /// <summary> Small work buffer, used to avoid memory allocations. </summary>
internal byte[] Temp; internal byte[] Temp;
@ -115,15 +115,13 @@ namespace MCGalaxy.Undo {
/// <summary> First instance in time that undo data should be retrieved back to. </summary> /// <summary> First instance in time that undo data should be retrieved back to. </summary>
internal readonly DateTime Start; internal readonly DateTime Start;
public UndoFormatArgs(Player p, DateTime start) { public UndoFormatArgs(string lvlName, DateTime start) {
Player = p; Start = start; LevelName = lvlName; Start = start;
} }
} }
public struct UndoFormatEntry { public struct UndoFormatEntry {
public string LevelName; public DateTime Time;
public DateTime Time;
public ushort X, Y, Z; public ushort X, Y, Z;
public ExtBlock Block; public ExtBlock Block;
public ExtBlock NewBlock; public ExtBlock NewBlock;

View File

@ -31,7 +31,6 @@ namespace MCGalaxy.Undo {
public override IEnumerable<UndoFormatEntry> GetEntries(Stream s, UndoFormatArgs args) { public override IEnumerable<UndoFormatEntry> GetEntries(Stream s, UndoFormatArgs args) {
List<ChunkHeader> list = new List<ChunkHeader>(); List<ChunkHeader> list = new List<ChunkHeader>();
UndoFormatEntry pos; UndoFormatEntry pos;
bool super = Player.IsSuper(args.Player);
DateTime start = args.Start; DateTime start = args.Start;
ReadHeaders(list, s); ReadHeaders(list, s);
@ -40,8 +39,7 @@ namespace MCGalaxy.Undo {
// Can we safely discard the entire chunk? // Can we safely discard the entire chunk?
bool inRange = chunk.BaseTime.AddTicks(65536 * TimeSpan.TicksPerSecond) >= start; bool inRange = chunk.BaseTime.AddTicks(65536 * TimeSpan.TicksPerSecond) >= start;
if (!inRange) { args.Stop = true; yield break; } if (!inRange) { args.Stop = true; yield break; }
if (!super && !args.Player.level.name.CaselessEq(chunk.LevelName)) continue; if (!args.LevelName.CaselessEq(chunk.LevelName)) continue;
pos.LevelName = chunk.LevelName;
s.Seek(chunk.DataPosition, SeekOrigin.Begin); s.Seek(chunk.DataPosition, SeekOrigin.Begin);
if (args.Temp == null) if (args.Temp == null)

View File

@ -31,7 +31,6 @@ namespace MCGalaxy.Undo {
public override IEnumerable<UndoFormatEntry> GetEntries(Stream s, UndoFormatArgs args) { public override IEnumerable<UndoFormatEntry> GetEntries(Stream s, UndoFormatArgs args) {
List<ChunkHeader> list = new List<ChunkHeader>(); List<ChunkHeader> list = new List<ChunkHeader>();
UndoFormatEntry pos; UndoFormatEntry pos;
bool super = Player.IsSuper(args.Player);
DateTime start = args.Start; DateTime start = args.Start;
ReadHeaders(list, s); ReadHeaders(list, s);
@ -40,8 +39,7 @@ namespace MCGalaxy.Undo {
// Can we safely discard the entire chunk? // Can we safely discard the entire chunk?
bool inRange = chunk.BaseTime.AddTicks((65536 >> 2) * TimeSpan.TicksPerSecond) >= start; bool inRange = chunk.BaseTime.AddTicks((65536 >> 2) * TimeSpan.TicksPerSecond) >= start;
if (!inRange) { args.Stop = true; yield break; } if (!inRange) { args.Stop = true; yield break; }
if (!super && !args.Player.level.name.CaselessEq(chunk.LevelName)) continue; if (!args.LevelName.CaselessEq(chunk.LevelName)) continue;
pos.LevelName = chunk.LevelName;
s.Seek(chunk.DataPosition, SeekOrigin.Begin); s.Seek(chunk.DataPosition, SeekOrigin.Begin);
if (args.Temp == null) if (args.Temp == null)

View File

@ -30,8 +30,6 @@ namespace MCGalaxy.Undo {
public override IEnumerable<UndoFormatEntry> GetEntries(Stream s, UndoFormatArgs args) { public override IEnumerable<UndoFormatEntry> GetEntries(Stream s, UndoFormatArgs args) {
UndoFormatEntry pos = default(UndoFormatEntry); UndoFormatEntry pos = default(UndoFormatEntry);
string[] lines = new StreamReader(s).ReadToEnd().SplitSpaces(); string[] lines = new StreamReader(s).ReadToEnd().SplitSpaces();
Player p = args.Player;
bool super = Player.IsSuper(p);
DateTime start = args.Start; DateTime start = args.Start;
// because we have space to end of each entry, need to subtract one otherwise we'll start at a "". // because we have space to end of each entry, need to subtract one otherwise we'll start at a "".
@ -43,8 +41,7 @@ namespace MCGalaxy.Undo {
if (pos.Time < start) { args.Stop = true; yield break; } if (pos.Time < start) { args.Stop = true; yield break; }
string map = lines[(i * items) - 7]; string map = lines[(i * items) - 7];
if (!super && !p.level.name.CaselessEq(map)) continue; if (!args.LevelName.CaselessEq(map)) continue;
pos.LevelName = map;
pos.X = ushort.Parse(lines[(i * items) - 6]); pos.X = ushort.Parse(lines[(i * items) - 6]);
pos.Y = ushort.Parse(lines[(i * items) - 5]); pos.Y = ushort.Parse(lines[(i * items) - 5]);

View File

@ -67,7 +67,7 @@ namespace MCGalaxy.Drawing.Ops {
} }
} }
UndoFormatArgs args = new UndoFormatArgs(Player, Start); UndoFormatArgs args = new UndoFormatArgs(Level.name, Start);
DoOldHighlight(args); DoOldHighlight(args);
} }

View File

@ -71,7 +71,7 @@ namespace MCGalaxy.Drawing.Ops {
} }
} }
UndoFormatArgs args = new UndoFormatArgs(Player, Start); UndoFormatArgs args = new UndoFormatArgs(Level.name, Start);
DoOldUndo(args); DoOldUndo(args);
} }
@ -107,17 +107,13 @@ namespace MCGalaxy.Drawing.Ops {
} }
void DoOldUndo(Stream s, UndoFormat format, UndoFormatArgs args) { void DoOldUndo(Stream s, UndoFormat format, UndoFormatArgs args) {
Level lvl = args.Player == null ? null : args.Player.level; DrawOpBlock block;
string lastMap = null;
DrawOpBlock block;
foreach (UndoFormatEntry P in format.GetEntries(s, args)) { foreach (UndoFormatEntry P in format.GetEntries(s, args)) {
if (P.LevelName != lastMap) lvl = LevelInfo.FindExact(P.LevelName); if (P.Time > End) continue;
if (lvl == null || P.Time > End) continue;
if (P.X < Min.X || P.Y < Min.Y || P.Z < Min.Z) continue; if (P.X < Min.X || P.Y < Min.Y || P.Z < Min.Z) continue;
if (P.X > Max.X || P.Y > Max.Y || P.Z > Max.Z) continue; if (P.X > Max.X || P.Y > Max.Y || P.Z > Max.Z) continue;
byte lvlBlock = lvl.GetTile(P.X, P.Y, P.Z); byte lvlBlock = Level.GetTile(P.X, P.Y, P.Z);
if (lvlBlock == P.NewBlock.BlockID || Block.Convert(lvlBlock) == Block.water if (lvlBlock == P.NewBlock.BlockID || Block.Convert(lvlBlock) == Block.water
|| Block.Convert(lvlBlock) == Block.lava || lvlBlock == Block.grass) { || Block.Convert(lvlBlock) == Block.lava || lvlBlock == Block.grass) {