#region Copyright & License Information /* * Copyright 2007-2022 The OpenRA Developers (see AUTHORS) * 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 OpenRA.Mods.Common.Traits; using OpenRA.Traits; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic { public class DebugMenuLogic : ChromeLogic { [ObjectCreator.UseCtor] public DebugMenuLogic(Widget widget, World world) { var devTrait = world.LocalPlayer.PlayerActor.Trait(); var debugVis = world.WorldActor.TraitOrDefault(); var visibilityCheckbox = widget.GetOrNull("DISABLE_VISIBILITY_CHECKS"); if (visibilityCheckbox != null) BindOrderCheckbox(visibilityCheckbox, world, "DevVisibility", () => devTrait.DisableShroud); var pathCheckbox = widget.GetOrNull("SHOW_UNIT_PATHS"); if (pathCheckbox != null) BindOrderCheckbox(pathCheckbox, world, "DevPathDebug", () => devTrait.PathDebug); var cashButton = widget.GetOrNull("GIVE_CASH"); if (cashButton != null) cashButton.OnClick = () => IssueOrder(world, "DevGiveCash"); var growResourcesButton = widget.GetOrNull("GROW_RESOURCES"); if (growResourcesButton != null) growResourcesButton.OnClick = () => IssueOrder(world, "DevGrowResources"); var fastBuildCheckbox = widget.GetOrNull("INSTANT_BUILD"); if (fastBuildCheckbox != null) BindOrderCheckbox(fastBuildCheckbox, world, "DevFastBuild", () => devTrait.FastBuild); var fastChargeCheckbox = widget.GetOrNull("INSTANT_CHARGE"); if (fastChargeCheckbox != null) BindOrderCheckbox(fastChargeCheckbox, world, "DevFastCharge", () => devTrait.FastCharge); var showCombatCheckbox = widget.GetOrNull("SHOW_COMBATOVERLAY"); if (showCombatCheckbox != null) { showCombatCheckbox.Disabled = debugVis == null; showCombatCheckbox.IsChecked = () => debugVis != null && debugVis.CombatGeometry; showCombatCheckbox.OnClick = () => debugVis.CombatGeometry ^= true; } var showGeometryCheckbox = widget.GetOrNull("SHOW_GEOMETRY"); if (showGeometryCheckbox != null) { showGeometryCheckbox.Disabled = debugVis == null; showGeometryCheckbox.IsChecked = () => debugVis != null && debugVis.RenderGeometry; showGeometryCheckbox.OnClick = () => debugVis.RenderGeometry ^= true; } var showScreenMapCheckbox = widget.GetOrNull("SHOW_SCREENMAP"); if (showScreenMapCheckbox != null) { showScreenMapCheckbox.Disabled = debugVis == null; showScreenMapCheckbox.IsChecked = () => debugVis != null && debugVis.ScreenMap; showScreenMapCheckbox.OnClick = () => debugVis.ScreenMap ^= true; } var terrainGeometryTrait = world.WorldActor.TraitOrDefault(); var showTerrainGeometryCheckbox = widget.GetOrNull("SHOW_TERRAIN_OVERLAY"); if (showTerrainGeometryCheckbox != null && terrainGeometryTrait != null) { showTerrainGeometryCheckbox.IsChecked = () => terrainGeometryTrait.Enabled; showTerrainGeometryCheckbox.OnClick = () => terrainGeometryTrait.Enabled ^= true; } var showDepthPreviewCheckbox = widget.GetOrNull("SHOW_DEPTH_PREVIEW"); if (showDepthPreviewCheckbox != null) { showDepthPreviewCheckbox.Disabled = debugVis == null; showDepthPreviewCheckbox.IsChecked = () => debugVis != null && debugVis.DepthBuffer; showDepthPreviewCheckbox.OnClick = () => debugVis.DepthBuffer ^= true; } var allTechCheckbox = widget.GetOrNull("ENABLE_TECH"); if (allTechCheckbox != null) BindOrderCheckbox(allTechCheckbox, world, "DevEnableTech", () => devTrait.AllTech); var powerCheckbox = widget.GetOrNull("UNLIMITED_POWER"); if (powerCheckbox != null) BindOrderCheckbox(powerCheckbox, world, "DevUnlimitedPower", () => devTrait.UnlimitedPower); var buildAnywhereCheckbox = widget.GetOrNull("BUILD_ANYWHERE"); if (buildAnywhereCheckbox != null) BindOrderCheckbox(buildAnywhereCheckbox, world, "DevBuildAnywhere", () => devTrait.BuildAnywhere); var explorationButton = widget.GetOrNull("GIVE_EXPLORATION"); if (explorationButton != null) explorationButton.OnClick = () => IssueOrder(world, "DevGiveExploration"); var noexplorationButton = widget.GetOrNull("RESET_EXPLORATION"); if (noexplorationButton != null) noexplorationButton.OnClick = () => IssueOrder(world, "DevResetExploration"); var showActorTagsCheckbox = widget.GetOrNull("SHOW_ACTOR_TAGS"); if (showActorTagsCheckbox != null) { showActorTagsCheckbox.Disabled = debugVis == null; showActorTagsCheckbox.IsChecked = () => debugVis != null && debugVis.ActorTags; showActorTagsCheckbox.OnClick = () => debugVis.ActorTags ^= true; } var showCustomTerrainCheckbox = widget.GetOrNull("SHOW_CUSTOMTERRAIN_OVERLAY"); if (showCustomTerrainCheckbox != null) { var customTerrainDebugTrait = world.WorldActor.TraitOrDefault(); showCustomTerrainCheckbox.Disabled = customTerrainDebugTrait == null; if (customTerrainDebugTrait != null) { showCustomTerrainCheckbox.IsChecked = () => customTerrainDebugTrait.Enabled; showCustomTerrainCheckbox.OnClick = () => customTerrainDebugTrait.Enabled ^= true; } } } static void BindOrderCheckbox(CheckboxWidget checkbox, World world, string order, Func getValue) { var isChecked = new PredictedCachedTransform(state => state); checkbox.IsChecked = () => isChecked.Update(getValue()); checkbox.OnClick = () => { isChecked.Predict(!getValue()); IssueOrder(world, order); }; } public static void IssueOrder(World world, string order) { world.IssueOrder(new Order(order, world.LocalPlayer.PlayerActor, false)); } } }