public Player(World world, Session.Client client, PlayerReference pr, int index) { World = world; Index = index; Palette = "player" + index; InternalName = pr.Name; PlayerRef = pr; if (client != null) { ClientIndex = client.Index; ColorRamp = client.ColorRamp; PlayerName = client.Name; Country = world.GetCountries() .FirstOrDefault(c => client.Country == c.Race) ?? world.GetCountries().Random(world.SharedRandom); } else { ClientIndex = 0; /* it's a map player, "owned" by host */ ColorRamp = pr.ColorRamp; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; Country = world.GetCountries() .FirstOrDefault(c => pr.Race == c.Race) ?? world.GetCountries().Random(world.SharedRandom); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); }
public override void Tick() { if (cachedRamp == Ramp) return; preview.ApplyRemap(new PlayerColorRemap(RemapIndices, Ramp)); cachedRamp = Ramp; }
public PlayerColorRemap(int[] Ramp, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ var baseIndex = Ramp[0]; var RemapRamp = GetRemapRamp(Ramp); remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public PlayerColorRemap(PaletteFormat fmt, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ var baseIndex = GetRemapBase(fmt); var ramp = GetRemapRamp(fmt); remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public override bool Equals(object obj) { if (obj == null) { return(false); } ColorRamp o = (ColorRamp)obj; return(o == this); }
public PlayerColorRemap(ColorRamp c, PaletteFormat fmt) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ var baseIndex = (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80; var ramp = (fmt == PaletteFormat.cnc) ? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 } : new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public PlayerColorRemap(PaletteFormat fmt, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); /* temptemp: this can be expressed better */ var baseIndex = (fmt == PaletteFormat.cnc) ? 0xb0 : (fmt == PaletteFormat.d2k) ? 240 : 80; var ramp = (fmt == PaletteFormat.cnc) ? new[] { 0, 2, 4, 6, 8, 10, 13, 15, 1, 3, 5, 7, 9, 11, 12, 14 } : new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; remapColors = ramp.Select((x, i) => Pair.New(baseIndex + i, ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
public ColorPickerLogic(Widget widget, ColorRamp initialRamp, Action<ColorRamp> onChange, Action<ColorRamp> onSelect, WorldRenderer worldRenderer) { var panel = widget; ramp = initialRamp; var hueSlider = panel.Get<SliderWidget>("HUE"); var satSlider = panel.Get<SliderWidget>("SAT"); var lumSlider = panel.Get<SliderWidget>("LUM"); Action sliderChanged = () => { ramp = new ColorRamp((byte)(255*hueSlider.Value), (byte)(255*satSlider.Value), (byte)(255*lumSlider.Value), 10); onChange(ramp); }; hueSlider.OnChange += _ => sliderChanged(); satSlider.OnChange += _ => sliderChanged(); lumSlider.OnChange += _ => sliderChanged(); Action updateSliders = () => { hueSlider.Value = ramp.H / 255f; satSlider.Value = ramp.S / 255f; lumSlider.Value = ramp.L / 255f; }; panel.Get<ButtonWidget>("SAVE_BUTTON").OnClick = () => onSelect(ramp); var randomButton = panel.Get<ButtonWidget>("RANDOM_BUTTON"); if (randomButton != null) randomButton.OnClick = () => { var hue = (byte)Game.CosmeticRandom.Next(255); var sat = (byte)Game.CosmeticRandom.Next(255); var lum = (byte)Game.CosmeticRandom.Next(51,255); ramp = new ColorRamp(hue, sat, lum, 10); updateSliders(); sliderChanged(); }; // Set the initial state updateSliders(); onChange(ramp); }
public CncColorPickerLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] ColorRamp initialRamp, [ObjectCreator.Param] Action<ColorRamp> onChange, [ObjectCreator.Param] Action<ColorRamp> onSelect, [ObjectCreator.Param] WorldRenderer worldRenderer) { var panel = widget.GetWidget("COLOR_CHOOSER"); ramp = initialRamp; var hueSlider = panel.GetWidget<SliderWidget>("HUE_SLIDER"); var satSlider = panel.GetWidget<SliderWidget>("SAT_SLIDER"); var lumSlider = panel.GetWidget<SliderWidget>("LUM_SLIDER"); Action sliderChanged = () => { ramp = new ColorRamp((byte)(255*hueSlider.Value), (byte)(255*satSlider.Value), (byte)(255*lumSlider.Value), 10); onChange(ramp); }; hueSlider.OnChange += _ => sliderChanged(); satSlider.OnChange += _ => sliderChanged(); lumSlider.OnChange += _ => sliderChanged(); Action updateSliders = () => { hueSlider.Value = ramp.H / 255f; satSlider.Value = ramp.S / 255f; lumSlider.Value = ramp.L / 255f; }; panel.GetWidget<ButtonWidget>("SAVE_BUTTON").OnClick = () => onSelect(ramp); panel.GetWidget<ButtonWidget>("RANDOM_BUTTON").OnClick = () => { var hue = (byte)Game.CosmeticRandom.Next(255); var sat = (byte)Game.CosmeticRandom.Next(255); var lum = (byte)Game.CosmeticRandom.Next(51,255); ramp = new ColorRamp(hue, sat, lum, 10); updateSliders(); sliderChanged(); }; // Set the initial state updateSliders(); onChange(ramp); }
public Player(World world, Session.Client client, Session.Slot slot, PlayerReference pr) { World = world; InternalName = pr.Name; PlayerReference = pr; string botType = null; // Real player or host-created bot if (client != null) { ClientIndex = client.Index; ColorRamp = client.ColorRamp; PlayerName = client.Name; botType = client.Bot; Country = world.GetCountries() .FirstOrDefault(c => client.Country == c.Race) ?? world.GetCountries().Random(world.SharedRandom); } else { // Map player ClientIndex = 0; // Owned by the host (todo: fix this) ColorRamp = pr.ColorRamp; PlayerName = pr.Name; NonCombatant = pr.NonCombatant; botType = pr.Bot; Country = world.GetCountries() .FirstOrDefault(c => pr.Race == c.Race) ?? world.GetCountries().Random(world.SharedRandom); } PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); // Enable the bot logic on the host IsBot = botType != null; if (IsBot && Game.IsHost) { var logic = PlayerActor.TraitsImplementing<IBot>() .FirstOrDefault(b => b.Info.Name == botType); if (logic == null) Log.Write("debug", "Invalid bot type: {0}", botType); else logic.Activate(this); } }
public PlayerColorRemap(int[] Ramp, ColorRamp c) { var c1 = c.GetColor(0); var c2 = c.GetColor(1); // temptemp: this can be expressed better var baseIndex = Ramp[0]; var RemapRamp = Ramp.Select(r => r - Ramp[0]).ToArray(); if (Ramp[0] > Ramp[15]) // reversed remapping { baseIndex = Ramp[15]; for (int i = 15; i > 0; i--) { RemapRamp = Ramp.Select(r => r - Ramp[15]).ToArray(); } } remapColors = RemapRamp.Select((x, i) => Pair.New(baseIndex + i, Exts.ColorLerp(x / 16f, c1, c2))) .ToDictionary(u => u.First, u => u.Second); }
internal LobbyLogic([ObjectCreator.Param( "widget" )] Widget lobby, [ObjectCreator.Param] OrderManager orderManager, [ObjectCreator.Param] WorldRenderer worldRenderer) { this.orderManager = orderManager; this.worldRenderer = worldRenderer; this.lobby = lobby; Game.BeforeGameStart += CloseWindow; Game.LobbyInfoChanged += UpdateCurrentMap; Game.LobbyInfoChanged += UpdatePlayerList; UpdateCurrentMap(); CurrentColorPreview = Game.Settings.Player.ColorRamp; Players = lobby.GetWidget<ScrollPanelWidget>("PLAYERS"); LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL"); RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE"); EmptySlotTemplate = Players.GetWidget("TEMPLATE_EMPTY"); EmptySlotTemplateHost = Players.GetWidget("TEMPLATE_EMPTY_HOST"); LocalSpectatorTemplate = Players.GetWidget("TEMPLATE_LOCAL_SPECTATOR"); RemoteSpectatorTemplate = Players.GetWidget("TEMPLATE_REMOTE_SPECTATOR"); NewSpectatorTemplate = Players.GetWidget("TEMPLATE_NEW_SPECTATOR"); var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW"); mapPreview.Map = () => Map; mapPreview.OnMouseDown = mi => { var map = mapPreview.Map(); if (map == null || mi.Button != MouseButton.Left || orderManager.LocalClient.State == Session.ClientState.Ready) return; var p = map.SpawnPoints .Select((sp, i) => Pair.New(mapPreview.ConvertToPreview(map, sp), i)) .Where(a => (a.First - mi.Location).LengthSquared < 64) .Select(a => a.Second + 1) .FirstOrDefault(); var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == p); if (p == 0 || !owned) orderManager.IssueOrder(Order.Command("spawn {0} {1}".F(orderManager.LocalClient.Index, p))); }; mapPreview.SpawnColors = () => { var spawns = Map.SpawnPoints; var sc = new Dictionary<int2, Color>(); for (int i = 1; i <= spawns.Count(); i++) { var client = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i); if (client == null) continue; sc.Add(spawns.ElementAt(i - 1), client.ColorRamp.GetColor(0)); } return sc; }; CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>() .ToDictionary(a => a.Race, a => a.Name); CountryNames.Add("random", "Random"); var mapButton = lobby.GetWidget<ButtonWidget>("CHANGEMAP_BUTTON"); mapButton.OnClick = () => { Widget.OpenWindow("MAP_CHOOSER", new WidgetArgs() { { "orderManager", orderManager }, { "mapName", MapUid } }); }; mapButton.IsVisible = () => mapButton.Visible && Game.IsHost; var disconnectButton = lobby.GetWidget<ButtonWidget>("DISCONNECT_BUTTON"); disconnectButton.OnClick = () => { CloseWindow(); Game.Disconnect(); Game.LoadShellMap(); Widget.OpenWindow("MAINMENU_BG"); }; var allowCheats = lobby.GetWidget<CheckboxWidget>("ALLOWCHEATS_CHECKBOX"); allowCheats.IsChecked = () => orderManager.LobbyInfo.GlobalSettings.AllowCheats; allowCheats.OnClick = () => { if (Game.IsHost) orderManager.IssueOrder(Order.Command( "allowcheats {0}".F(!orderManager.LobbyInfo.GlobalSettings.AllowCheats))); }; var startGameButton = lobby.GetWidget<ButtonWidget>("START_GAME_BUTTON"); startGameButton.OnClick = () => { mapButton.Visible = false; disconnectButton.Visible = false; orderManager.IssueOrder(Order.Command("startgame")); }; // Todo: Only show if the map requirements are met for player slots startGameButton.IsVisible = () => Game.IsHost; bool teamChat = false; var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE"); var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD"); chatTextField.OnEnterKey = () => { if (chatTextField.Text.Length == 0) return true; var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text); orderManager.IssueOrder(order); chatTextField.Text = ""; return true; }; chatTextField.OnTabKey = () => { teamChat ^= true; chatLabel.Text = (teamChat) ? "Team:" : "Chat:"; return true; }; Game.AddChatLine += AddChatLine; }
void UpdatePlayerColor(float hf, float sf, float lf, float r) { var ramp = new ColorRamp((byte) (hf*255), (byte) (sf*255), (byte) (lf*255), (byte)(r*255)); Game.Settings.Player.ColorRamp = ramp; Game.Settings.Save(); orderManager.IssueOrder(Order.Command("color {0} {1}".F(orderManager.LocalClient.Index, ramp))); }
void UpdateColorPreview(float hf, float sf, float lf, float r) { CurrentColorPreview = new ColorRamp((byte)(hf * 255), (byte)(sf * 255), (byte)(lf * 255), (byte)(r * 255)); }
public Player(World world, Session.Client client, PlayerReference pr, int index) { World = world; Index = index; Palette = "player" + index; ColorRamp = client.ColorRamp; PlayerName = client.Name; InternalName = pr.Name; Country = world.GetCountries() .FirstOrDefault(c => client != null && client.Country == c.Race) ?? world.GetCountries().Random(world.SharedRandom); ClientIndex = client.Index; PlayerRef = pr; PlayerActor = world.CreateActor("Player", new TypeDictionary { new OwnerInit(this) }); }
public Bitmap RenderShp(Palette p, int pos) { int swidth = 0; int sheight = 0; byte hk; byte s; byte l; if (oldshp == false) {swidth = shp.Width; sheight = shp.Height;} if (oldshp == true) {swidth = shpold.Width; sheight = shpold.Height;} hk = Convert.ToByte(pbColor.BackColor.GetHue()*0.7+1); s = Convert.ToByte(pbColor.BackColor.GetSaturation()*255); l = Convert.ToByte(pbColor.BackColor.GetBrightness() * 255); ColorRamp CRamp = new ColorRamp(hk, s, l, 25); if (mnuRemap.Checked) { p = new Palette(p, new PlayerColorRemap(CRamp, palf)); } CRamp.GetColor(0).ToArgb(); var bitmap = new Bitmap(swidth, sheight); var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb); unsafe { int* q = (int*)data.Scan0.ToPointer(); var stride2 = data.Stride >> 2; for (var i = 0; i < swidth; i++) for (var j = 0; j < sheight; j++) { if (oldshp == false) { var frame = shp[pos]; q[j * stride2 + i] = p.GetColor(frame.Image[i + swidth * j]).ToArgb(); } if (oldshp == true) { var frame = shpold[pos]; q[j * stride2 + i] = p.GetColor(frame.Image[i + swidth * j]).ToArgb(); } } } bitmap.UnlockBits(data); return bitmap; }
public Bitmap RenderPNG(Palette p, int pos) { Bitmap bmp = png.ToBitmap(pos); if (mnuRemap.Checked) { byte hk = Convert.ToByte(pbColor.BackColor.GetHue() * 0.7 + 1); byte s = Convert.ToByte(pbColor.BackColor.GetSaturation() * 255); byte l = Convert.ToByte(pbColor.BackColor.GetBrightness() * 255); ColorRamp CRamp = new ColorRamp(hk, s, l, 25); for (int x = 0; x < bmp.Width - 1; x++) { for (int y = 0; y < bmp.Height - 1; y++) { Color c = bmp.GetPixel(x, y); c = Color.FromArgb(c.A, CalculateHueChange(c, CRamp.GetColor(0).GetHue(), CRamp.GetColor(0).GetSaturation(), CRamp.GetColor(0).GetBrightness())); bmp.SetPixel(x, y, c); } } } return bmp; }