Beispiel #1
0
        public EditorActorBrush(EditorViewportControllerWidget editorWidget, ActorInfo actor, PlayerReference owner, WorldRenderer wr)
        {
            this.editorWidget = editorWidget;
            worldRenderer = wr;
            world = wr.World;
            editorLayer = world.WorldActor.Trait<EditorActorLayer>();

            Actor = actor;
            this.owner = owner;

            preview = editorWidget.Get<ActorPreviewWidget>("DRAG_ACTOR_PREVIEW");
            preview.GetScale = () => worldRenderer.Viewport.Zoom;
            preview.IsVisible = () => editorWidget.CurrentBrush == this;

            var buildingInfo = actor.Traits.GetOrDefault<BuildingInfo>();
            if (buildingInfo != null)
            {
                locationOffset = -FootprintUtils.AdjustForBuildingSize(buildingInfo);
                previewOffset = FootprintUtils.CenterOffset(world, buildingInfo);
            }

            var td = new TypeDictionary();
            td.Add(new FacingInit(facing));
            td.Add(new TurretFacingInit(facing));
            td.Add(new OwnerInit(owner.Name));
            td.Add(new RaceInit(owner.Race));
            preview.SetPreview(actor, td);

            // The preview widget may be rendered by the higher-level code before it is ticked.
            // Force a manual tick to ensure the bounds are set correctly for this first draw.
            Tick();
        }
Beispiel #2
0
 public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr)
 {
     if (pr == null)
         return;
     if (pr.LockColor)
     {
         c.Color1 = pr.Color;
         c.Color2 = pr.Color2;
     }
     if (pr.LockRace)
         c.Country = pr.Race;
 }
Beispiel #3
0
		public ActorSelectorLogic(Widget widget, World world, WorldRenderer worldRenderer, Ruleset modRules)
		{
			this.modRules = modRules;
			this.world = world;
			this.worldRenderer = worldRenderer;

			editor = widget.Parent.Get<EditorViewportControllerWidget>("MAP_EDITOR");
			ownersDropDown = widget.Get<DropDownButtonWidget>("OWNERS_DROPDOWN");

			panel = widget.Get<ScrollPanelWidget>("ACTORTEMPLATE_LIST");
			itemTemplate = panel.Get<ScrollItemWidget>("ACTORPREVIEW_TEMPLATE");
			panel.Layout = new GridLayout(panel);

			var editorLayer = world.WorldActor.Trait<EditorActorLayer>();

			selectedOwner = editorLayer.Players.Players.Values.First();
			Func<PlayerReference, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
			{
				var item = ScrollItemWidget.Setup(template, () => selectedOwner == option, () =>
				{
					selectedOwner = option;

					ownersDropDown.Text = selectedOwner.Name;
					ownersDropDown.TextColor = selectedOwner.Color.RGB;

					IntializeActorPreviews();
				});

				item.Get<LabelWidget>("LABEL").GetText = () => option.Name;
				item.GetColor = () => option.Color.RGB;

				return item;
			};

			ownersDropDown.OnClick = () =>
			{
				var owners = editorLayer.Players.Players.Values.OrderBy(p => p.Name);
				ownersDropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", 270, owners, setupItem);
			};

			ownersDropDown.Text = selectedOwner.Name;
			ownersDropDown.TextColor = selectedOwner.Color.RGB;

			IntializeActorPreviews();
		}
Beispiel #4
0
        void LoadPlayer(IniFile file, string section, bool isRA)
        {
            string c;
            string race;
            switch (section)
            {
                case "Spain":
                    c = "gold";
                    race = "allies";
                    break;
                case "England":
                    c = "green";
                    race = "allies";
                    break;
                case "Ukraine":
                    c = "orange";
                    race = "soviet";
                    break;
                case "Germany":
                    c = "black";
                    race = "allies";
                    break;
                case "France":
                    c = "teal";
                    race = "allies";
                    break;
                case "Turkey":
                    c = "salmon";
                    race = "allies";
                    break;
                case "Greece":
                case "GoodGuy":
                    c = isRA? "blue" : "gold";
                    race = isRA ? "allies" : "gdi";
                    break;
                case "USSR":
                case "BadGuy":
                    c = "red";
                    race = isRA ? "soviet" : "nod";
                    break;
                case "Special":
                case "Neutral":
                default:
                    c = "neutral";
                    race = isRA ? "allies" : "gdi";
                    break;
            }

            var color = namedColorMapping[c];

            var pr = new PlayerReference
            {
                Name = section,
                OwnsWorld = section == "Neutral",
                NonCombatant = section == "Neutral",
                Race = race,
                ColorRamp = new ColorRamp(
                        (byte)((color.First.GetHue() / 360.0f) * 255),
                        (byte)(color.First.GetSaturation() * 255),
                        (byte)(color.First.GetBrightness() * 255),
                        (byte)(color.Second.GetBrightness() * 255))
            };

            var neutral = new [] {"Neutral"};
            foreach (var s in file.GetSection(section, true))
            {
                Console.WriteLine(s.Key);
                switch(s.Key)
                {
                    case "Credits":
                        pr.InitialCash = int.Parse(s.Value);
                    break;
                    case "Allies":
                        pr.Allies = s.Value.Split(',').Intersect(Players).Except(neutral).ToArray();
                        pr.Enemies = s.Value.Split(',').SymmetricDifference(Players).Except(neutral).ToArray();
                    break;
                }
            }

            Map.Players.Add(section, pr);
        }
Beispiel #5
0
		void LoadPlayer(IniFile file, string section, bool isRA)
		{
			string c;
			string faction;
			switch (section)
			{
				case "Spain":
					c = "gold";
					faction = "allies";
					break;
				case "England":
					c = "green";
					faction = "allies";
					break;
				case "Ukraine":
					c = "orange";
					faction = "soviet";
					break;
				case "Germany":
					c = "black";
					faction = "allies";
					break;
				case "France":
					c = "teal";
					faction = "allies";
					break;
				case "Turkey":
					c = "salmon";
					faction = "allies";
					break;
				case "Greece":
				case "GoodGuy":
					c = isRA ? "blue" : "gold";
					faction = isRA ? "allies" : "gdi";
					break;
				case "USSR":
				case "BadGuy":
					c = "red";
					faction = isRA ? "soviet" : "nod";
					break;
				case "Special":
				case "Neutral":
				default:
					c = "neutral";
					faction = isRA ? "allies" : "gdi";
					break;
			}

			var pr = new PlayerReference
			{
				Name = section,
				OwnsWorld = section == "Neutral",
				NonCombatant = section == "Neutral",
				Faction = faction,
				Color = namedColorMapping[c]
			};

			var neutral = new[] { "Neutral" };
			foreach (var s in file.GetSection(section, true))
			{
				switch (s.Key)
				{
					case "Allies":
						pr.Allies = s.Value.Split(',').Intersect(players).Except(neutral).ToArray();
						pr.Enemies = s.Value.Split(',').SymmetricDifference(players).Except(neutral).ToArray();
						break;
					default:
						Console.WriteLine("Ignoring unknown {0}={1} for player {2}", s.Key, s.Value, pr.Name);
						break;
				}
			}

			// Overwrite default player definitions if needed
			if (!mapPlayers.Players.ContainsKey(section))
				mapPlayers.Players.Add(section, pr);
			else
				mapPlayers.Players[section] = pr;
		}
Beispiel #6
0
 static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr)
 {
     if (!pr.Playable) return null;
     return new Session.Slot
     {
         MapPlayer = pr.Name,
         Bot = null,	/* todo: allow the map to specify a bot class? */
         Closed = false,
     };
 }
Beispiel #7
0
 static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr)
 {
     if (!pr.Playable) return null;
     if (Game.Settings.Server.LockBots)
         pr.AllowBots = false;
     return new Session.Slot
     {
         PlayerReference = pr.Name,
         Closed = false,
         AllowBots = pr.AllowBots,
         LockRace = pr.LockRace,
         LockColor = pr.LockColor,
         LockTeam = pr.LockTeam,
         LockSpawn = pr.LockSpawn,
         Required = pr.Required,
     };
 }
Beispiel #8
0
        void LoadPlayer(IniFile file, string section, bool isRA)
        {
            var c = (section == "BadGuy") ? "red" :
                        (isRA) ? "blue" : "gold";

            var color = namedColorMapping[c];

            var pr = new PlayerReference
            {
                Name = section,
                OwnsWorld = (section == "Neutral"),
                NonCombatant = (section == "Neutral"),
                Race = (isRA) ? ((section == "BadGuy") ? "soviet" : "allies") : ((section == "BadGuy") ? "nod" : "gdi"),
                ColorRamp = new ColorRamp(
                        (byte)((color.First.GetHue() / 360.0f) * 255),
                        (byte)(color.First.GetSaturation() * 255),
                        (byte)(color.First.GetBrightness() * 255),
                        (byte)(color.Second.GetBrightness() * 255))
            };

            var Neutral = new List<string>(){"Neutral"};
            foreach (var s in file.GetSection(section, true))
            {
                Console.WriteLine(s.Key);
                switch(s.Key)
                {
                    case "Credits":
                        pr.InitialCash = int.Parse(s.Value);
                    break;
                    case "Allies":
                        pr.Allies = s.Value.Split(',').Intersect(Players).Except(Neutral).ToArray();
                        pr.Enemies = s.Value.Split(',').SymmetricDifference(Players).Except(Neutral).ToArray();
                    break;
                }
            }

            Map.Players.Add(section, pr);
        }
Beispiel #9
0
 static Session.Slot MakeSlotFromPlayerReference(PlayerReference pr)
 {
     if (!pr.Playable) return null;
     return new Session.Slot
     {
         PlayerReference = pr.Name,
         Closed = false,
         AllowBots = pr.AllowBots,
         LockRace = pr.LockRace,
         LockColor = pr.LockColor,
         LockTeam = pr.LockTeam,
         LockSpawn = pr.LockSpawn
     };
 }
Beispiel #10
0
 public static void SyncClientToPlayerReference(Session.Client c, PlayerReference pr)
 {
     if (pr == null)
         return;
     if (pr.LockColor)
         c.Color = pr.Color;
     else
         c.Color = c.PreferredColor;
     if (pr.LockRace)
         c.Country = pr.Race;
     if (pr.LockSpawn)
         c.SpawnPoint = pr.Spawn;
     if (pr.LockTeam)
         c.Team = pr.Team;
 }