mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
Merge branch 'master' of github.com:Hetal728/MCGalaxy
This commit is contained in:
commit
3f36bca185
@ -264,6 +264,37 @@ namespace MCGalaxy {
|
|||||||
ExtColors[col.Code] = col;
|
ExtColors[col.Code] = col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CustomColor ParseHex(string hex) {
|
||||||
|
if (hex.Length > 0 && hex[0] == '#') hex = hex.Remove(0, 1);
|
||||||
|
if (hex.Length != 3 && hex.Length != 6)
|
||||||
|
throw new ArgumentException("hex must be either 3 or 6 chars long");
|
||||||
|
|
||||||
|
CustomColor c = default(CustomColor);
|
||||||
|
int R, G, B;
|
||||||
|
if (hex.Length == 6) {
|
||||||
|
R = (Hex(hex[0]) << 4) | Hex(hex[1]);
|
||||||
|
G = (Hex(hex[2]) << 4) | Hex(hex[3]);
|
||||||
|
B = (Hex(hex[4]) << 4) | Hex(hex[5]);
|
||||||
|
} else {
|
||||||
|
R = Hex(hex[0]); R |= (R << 4);
|
||||||
|
G = Hex(hex[1]); G |= (G << 4);
|
||||||
|
B = Hex(hex[2]); B |= (B << 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
c.R = (byte)R; c.G = (byte)G; c.B = (byte)B; c.A = 255;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int Hex(char value) {
|
||||||
|
if (value >= '0' && value <= '9')
|
||||||
|
return (int)(value - '0');
|
||||||
|
if (value >= 'a' && value <= 'f')
|
||||||
|
return (int)(value - 'a') + 10;
|
||||||
|
if (value >= 'A' && value <= 'F')
|
||||||
|
return (int)(value - 'A') + 10;
|
||||||
|
throw new ArgumentException("Non hex char: " + value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct CustomColor {
|
public struct CustomColor {
|
||||||
|
@ -73,11 +73,8 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
if (!CheckName(p, args[2]) || !CheckFallback(p, args[3], out fallback)
|
if (!CheckName(p, args[2]) || !CheckFallback(p, args[3], out fallback)
|
||||||
|| !Utils.CheckHex(p, ref args[4])) return;
|
|| !Utils.CheckHex(p, ref args[4])) return;
|
||||||
|
|
||||||
CustomColor col = default(CustomColor);
|
CustomColor col = Colors.ParseHex(args[4]);
|
||||||
col.Code = code; col.Fallback = fallback; col.A = 255;
|
col.Code = code; col.Fallback = fallback; col.Name = args[2];
|
||||||
col.Name = args[2];
|
|
||||||
Color rgb = ColorTranslator.FromHtml("#" + args[4]);
|
|
||||||
col.R = rgb.R; col.G = rgb.G; col.B = rgb.B;
|
|
||||||
Colors.AddExtColor(col);
|
Colors.AddExtColor(col);
|
||||||
Player.Message(p, "Successfully added a custom color.");
|
Player.Message(p, "Successfully added a custom color.");
|
||||||
}
|
}
|
||||||
@ -149,7 +146,7 @@ namespace MCGalaxy.Commands.CPE {
|
|||||||
case "hex":
|
case "hex":
|
||||||
case "color":
|
case "color":
|
||||||
if (!Utils.CheckHex(p, ref args[3])) return;
|
if (!Utils.CheckHex(p, ref args[3])) return;
|
||||||
Color rgb = ColorTranslator.FromHtml("#" + args[3]);
|
CustomColor rgb = Colors.ParseHex(args[3]);
|
||||||
col.R = rgb.R; col.G = rgb.G; col.B = rgb.B;
|
col.R = rgb.R; col.G = rgb.G; col.B = rgb.B;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -161,15 +161,15 @@ namespace MCGalaxy.Commands {
|
|||||||
}
|
}
|
||||||
if (preset == null) { SendPresetsMessage(p); return false; }
|
if (preset == null) { SendPresetsMessage(p); return false; }
|
||||||
|
|
||||||
LevelEnv.SendEnvColorPackets(p, 0, preset.Sky);
|
LevelEnv.UpdateEnvColor(p, 0, preset.Sky);
|
||||||
p.level.SkyColor = preset.Sky;
|
p.level.SkyColor = preset.Sky;
|
||||||
LevelEnv.SendEnvColorPackets(p, 1, preset.Clouds);
|
LevelEnv.UpdateEnvColor(p, 1, preset.Clouds);
|
||||||
p.level.CloudColor = preset.Clouds;
|
p.level.CloudColor = preset.Clouds;
|
||||||
LevelEnv.SendEnvColorPackets(p, 2, preset.Fog);
|
LevelEnv.UpdateEnvColor(p, 2, preset.Fog);
|
||||||
p.level.FogColor = preset.Fog;
|
p.level.FogColor = preset.Fog;
|
||||||
LevelEnv.SendEnvColorPackets(p, 3, preset.Shadow);
|
LevelEnv.UpdateEnvColor(p, 3, preset.Shadow);
|
||||||
p.level.ShadowColor = preset.Shadow;
|
p.level.ShadowColor = preset.Shadow;
|
||||||
LevelEnv.SendEnvColorPackets(p, 4, preset.Sun);
|
LevelEnv.UpdateEnvColor(p, 4, preset.Sun);
|
||||||
p.level.LightColor = preset.Sun;
|
p.level.LightColor = preset.Sun;
|
||||||
|
|
||||||
Level.SaveSettings(p.level);
|
Level.SaveSettings(p.level);
|
||||||
|
@ -90,7 +90,7 @@ namespace MCGalaxy {
|
|||||||
Player.Message(p, "Set {0} color for {1} %Sto #{2}", envTypeName, p.level.name, value);
|
Player.Message(p, "Set {0} color for {1} %Sto #{2}", envTypeName, p.level.name, value);
|
||||||
target = value;
|
target = value;
|
||||||
}
|
}
|
||||||
SendEnvColorPackets(p, envType, value);
|
UpdateEnvColor(p, envType, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool CheckBlock(Player p, string value, string variable, ref int modify) {
|
static bool CheckBlock(Player p, string value, string variable, ref int modify) {
|
||||||
@ -161,22 +161,11 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void SendEnvColorPackets(Player p, byte envType, string value) {
|
internal static void UpdateEnvColor(Player p, byte type, string hex) {
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
foreach (Player pl in players) {
|
foreach (Player pl in players) {
|
||||||
if (pl.level == p.level)
|
if (pl.level != p.level || !pl.HasCpeExt(CpeExt.EnvColors)) continue;
|
||||||
SendEnvColorPacket(pl, envType, value);
|
pl.SendEnvColor(type, hex);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SendEnvColorPacket(Player p, byte envType, string value) {
|
|
||||||
if (p.HasCpeExt(CpeExt.EnvColors)) {
|
|
||||||
try {
|
|
||||||
System.Drawing.Color col = System.Drawing.ColorTranslator.FromHtml("#" + value.ToUpper());
|
|
||||||
p.SendEnvColor(envType, col.R, col.G, col.B);
|
|
||||||
} catch {
|
|
||||||
p.SendEnvColor(envType, -1, -1, -1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,16 @@ namespace MCGalaxy {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] MakeEnvColor(byte type, short r, short g, short b) {
|
||||||
|
byte[] buffer = new byte[8];
|
||||||
|
buffer[0] = Opcode.CpeEnvColors;
|
||||||
|
buffer[1] = type;
|
||||||
|
NetUtils.WriteI16(r, buffer, 2);
|
||||||
|
NetUtils.WriteI16(g, buffer, 4);
|
||||||
|
NetUtils.WriteI16(b, buffer, 6);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] MakeMakeSelection(byte id, string label, Vec3U16 p1, Vec3U16 p2,
|
public static byte[] MakeMakeSelection(byte id, string label, Vec3U16 p1, Vec3U16 p2,
|
||||||
short r, short g, short b, short opacity ) {
|
short r, short g, short b, short opacity ) {
|
||||||
byte[] buffer = new byte[86];
|
byte[] buffer = new byte[86];
|
||||||
@ -83,6 +93,13 @@ namespace MCGalaxy {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] MakeDeleteSelection(byte id) {
|
||||||
|
byte[] buffer = new byte[2];
|
||||||
|
buffer[0] = Opcode.CpeMakeSelection;
|
||||||
|
buffer[1] = id;
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] MakeHackControl(bool canFly, bool canNoclip,
|
public static byte[] MakeHackControl(bool canFly, bool canNoclip,
|
||||||
bool canSpeed, bool canRespawn,
|
bool canSpeed, bool canRespawn,
|
||||||
bool can3rdPerson, short maxJumpHeight) {
|
bool can3rdPerson, short maxJumpHeight) {
|
||||||
|
@ -522,20 +522,6 @@ namespace MCGalaxy {
|
|||||||
Send(buffer);
|
Send(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendEnvColor( byte type, short r, short g, short b ) {
|
|
||||||
byte[] buffer = new byte[8];
|
|
||||||
buffer[0] = Opcode.CpeEnvColors;
|
|
||||||
buffer[1] = type;
|
|
||||||
NetUtils.WriteI16(r, buffer, 2);
|
|
||||||
NetUtils.WriteI16(g, buffer, 4);
|
|
||||||
NetUtils.WriteI16(b, buffer, 6);
|
|
||||||
Send(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendDeleteSelection( byte id ) {
|
|
||||||
SendRaw(Opcode.CpeRemoveSelection, id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SendSetBlockPermission( byte type, bool canplace, bool candelete ) {
|
public void SendSetBlockPermission( byte type, bool canplace, bool candelete ) {
|
||||||
byte[] buffer = new byte[4];
|
byte[] buffer = new byte[4];
|
||||||
buffer[0] = Opcode.CpeSetBlockPermission;
|
buffer[0] = Opcode.CpeSetBlockPermission;
|
||||||
|
@ -203,12 +203,16 @@ namespace MCGalaxy {
|
|||||||
SendEnvColor(4, level.LightColor);
|
SendEnvColor(4, level.LightColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SendEnvColor(byte type, string src) {
|
public void SendEnvColor(byte type, string hex) {
|
||||||
|
if (String.IsNullOrEmpty(hex)) {
|
||||||
|
Send(Packet.MakeEnvColor(type, -1, -1, -1)); return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Color col = System.Drawing.ColorTranslator.FromHtml("#" + src.ToUpper());
|
CustomColor c = Colors.ParseHex(hex);
|
||||||
SendEnvColor(type, col.R, col.G, col.B);
|
Send(Packet.MakeEnvColor(type, c.R, c.G, c.B));
|
||||||
} catch {
|
} catch (Exception ex) {
|
||||||
SendEnvColor(type, -1, -1, -1);
|
Send(Packet.MakeEnvColor(type, -1, -1, -1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,10 +251,10 @@ namespace MCGalaxy {
|
|||||||
RawHeldBlock = block;
|
RawHeldBlock = block;
|
||||||
|
|
||||||
if ((action == 0 || block == 0) && !level.Deletable) {
|
if ((action == 0 || block == 0) && !level.Deletable) {
|
||||||
SendMessage("You cannot currently delete blocks in this level.");
|
SendMessage("Deleting blocks is disabled in this level.");
|
||||||
RevertBlock(x, y, z); return;
|
RevertBlock(x, y, z); return;
|
||||||
} else if (action == 1 && !level.Buildable) {
|
} else if (action == 1 && !level.Buildable) {
|
||||||
SendMessage("You cannot currently place blocks in this level.");
|
SendMessage("Placing blocks is disabled in this level.");
|
||||||
RevertBlock(x, y, z); return;
|
RevertBlock(x, y, z); return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,27 +36,25 @@ namespace MCGalaxy {
|
|||||||
OutputItems(p, items, 0, items.Count, lines, formatter);
|
OutputItems(p, items, 0, items.Count, lines, formatter);
|
||||||
Player.Message(p, "Showing {0} 1-{1} (out of {1})", type, items.Count);
|
Player.Message(p, "Showing {0} 1-{1} (out of {1})", type, items.Count);
|
||||||
} else if (!int.TryParse(modifier, out page)) {
|
} else if (!int.TryParse(modifier, out page)) {
|
||||||
Player.Message(p, "Page must be either \"all\" or an integer.");
|
Player.Message(p, "Input must be either \"all\" or an integer.");
|
||||||
} else {
|
} else {
|
||||||
OutputPage(p, items, formatter, cmd, type, page, lines);
|
OutputPage(p, items, formatter, cmd, type, page, lines);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OutputPage<T>(Player p, IList<T> items, Func<T, int, string> formatter,
|
static void OutputPage<T>(Player p, IList<T> items, Func<T, int, string> formatter,
|
||||||
string cmd, string type, int page, bool lines) {
|
string cmd, string type, int start, bool lines) {
|
||||||
int perPage = lines ? 10 : 30;
|
int perPage = lines ? 10 : 30;
|
||||||
int total = items.Count, maxPage = total / perPage;
|
start = Utils.Clamp(start - 1, 0, items.Count - 1); // want item numbers to start at 1
|
||||||
page = Utils.Clamp(page - 1, 0, maxPage); // want page numbers to start at 1
|
int end = Math.Min(start + perPage, items.Count);
|
||||||
|
OutputItems(p, items, start, end, lines, formatter);
|
||||||
|
|
||||||
int entriesEnd = Math.Min((page + 1) * perPage, total);
|
if (end < items.Count) {
|
||||||
OutputItems(p, items, page * perPage, entriesEnd, lines, formatter);
|
|
||||||
|
|
||||||
if (page < maxPage) {
|
|
||||||
Player.Message(p, "Showing {0} {1}-{2} (out of {3}) Next: %T/{4} {5}",
|
Player.Message(p, "Showing {0} {1}-{2} (out of {3}) Next: %T/{4} {5}",
|
||||||
type, page * perPage + 1, entriesEnd, total, cmd, page + 2);
|
type, start + 1, end, items.Count, cmd, start + 1 + perPage);
|
||||||
} else {
|
} else {
|
||||||
Player.Message(p, "Showing {0} {1}-{2} (out of {3})",
|
Player.Message(p, "Showing {0} {1}-{2} (out of {3})",
|
||||||
type, page * perPage + 1, entriesEnd, total);
|
type, start + 1, end, items.Count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user