#region Copyright & License Information /* * Copyright (c) The OpenRA Developers and Contributors * This file is part of OpenRA, which is free software. It is made * available to you under the terms of the GNU General Public License * as published by the Free Software Foundation, either version 3 of * the License, or (at your option) any later version. For more * information, see COPYING. */ #endregion using System; using System.Collections.Generic; using System.Collections.Immutable; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic { [IncludeStaticFluentReferences( typeof(UpdateTilingPathPlanEditorAction), typeof(PaintTilingPathEditorAction), typeof(TilingPathToolInfo))] public sealed class TilingPathToolLogic : ChromeLogic { [ObjectCreator.UseCtor] public TilingPathToolLogic( Widget widget, World world, ModData modData, WorldRenderer worldRenderer, Dictionary logicArgs) { var tool = world.WorldActor.Trait(); var editorActionManager = world.WorldActor.Trait(); var editorWidget = widget.Parent.Parent.Parent.Parent.Get("MAP_EDITOR"); ((ScrollPanelWidget)widget).Layout.AdjustChildren(); var editCheckbox = widget.Get("EDIT"); editCheckbox.Disabled = !tool.Available; if (!tool.Available) return; editCheckbox.IsChecked = () => editorWidget.CurrentBrush is EditorTilingPathBrush; editCheckbox.OnClick = () => editorWidget.SetBrush( editCheckbox.IsChecked() ? null : new EditorTilingPathBrush(tool)); void SetupDropDown( string name, ImmutableArray choices, Func read, Action write) { var dropDown = widget .Get(name) .Get("DROPDOWN"); dropDown.GetText = read; dropDown.OnMouseDown = _ => { ScrollItemWidget SetupItem(string choice, ScrollItemWidget template) { bool IsSelected() => choice == read(); void OnClick() => write(choice); var item = ScrollItemWidget.Setup(template, IsSelected, OnClick); item.Get("LABEL").GetText = () => choice; return item; } dropDown.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", choices.Length * 30, choices, SetupItem); }; } SetupDropDown("START_TYPE", tool.StartTypes, () => tool.StartType, tool.SetStartType); SetupDropDown("INNER_TYPE", tool.InnerTypes, () => tool.InnerType, tool.SetInnerType); SetupDropDown("END_TYPE", tool.EndTypes, () => tool.EndType, tool.SetEndType); var deviationSlider = widget.Get("DEVIATION").Get("SLIDER"); deviationSlider.GetValue = () => tool.MaxDeviation; deviationSlider.OnChange += (value) => tool.SetMaxDeviation((int)value); var closedLoopsCheckbox = widget.Get("CLOSED_LOOPS"); closedLoopsCheckbox.IsChecked = () => tool.ClosedLoops; closedLoopsCheckbox.OnClick = () => tool.SetClosedLoops(!tool.ClosedLoops); var resetButton = widget.Get("RESET"); resetButton.IsDisabled = () => tool.Plan == null; resetButton.OnClick = () => editorActionManager.Add( new UpdateTilingPathPlanEditorAction(tool, null)); var reverseButton = widget.Get("REVERSE"); reverseButton.IsDisabled = () => tool.Plan == null; reverseButton.OnClick = () => editorActionManager.Add( new UpdateTilingPathPlanEditorAction(tool, tool.Plan.Reversed())); var randomizeButton = widget.Get("RANDOMIZE"); randomizeButton.IsDisabled = () => tool.Plan == null; randomizeButton.OnClick = () => tool.SetRandomSeed(Environment.TickCount); var paintButton = widget.Get("PAINT"); paintButton.IsDisabled = () => tool.EditorBlitSource == null; paintButton.OnClick = () => editorActionManager.Add( new PaintTilingPathEditorAction(tool)); } } }