public void SetCountryDecorator(int groupIndex, string countryName, CountryDecorator decorator) { // Get the group decorator container CountryDecoratorGroupInfo di = GetDecoratorGroup(groupIndex, true); if (decorator.countryName == null || !decorator.countryName.Equals(countryName)) { decorator.countryName = countryName; } di.SetDecorator(decorator); }
public void SetDecorator(CountryDecorator decorator) { int k = GetDecoratorIndex(decorator.countryName); if (k >= 0) { decorators [k] = decorator; } else { decorators.Add(decorator); } decorator.isNew = false; UpdateDecorators(true); }
public override void OnInspectorGUI() { if (_decorator == null) { return; } bool requestChanges = false; EditorGUILayout.Separator(); EditorGUILayout.BeginVertical(blackStyle); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Group", GUILayout.Width(120)); int oldGroup = _decorator.GUIGroupIndex; _decorator.GUIGroupIndex = EditorGUILayout.Popup(_decorator.GUIGroupIndex, groupNames, GUILayout.MaxWidth(200)); if (_decorator.GUIGroupIndex != oldGroup || decoratorGroup == null) { decoratorGroup = _decorator.GetDecoratorGroup(_decorator.GUIGroupIndex, true); } if (GUILayout.Button("Clear")) { _decorator.ClearDecoratorGroup(_decorator.GUIGroupIndex); if (decorator != null) { decorator.isNew = true; } ReloadGroupNames(); _decorator.ReloadCountryNames(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Enabled", GUILayout.Width(120)); decoratorGroup.active = EditorGUILayout.Toggle(decoratorGroup.active, GUILayout.Width(20)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); // country selector EditorGUILayout.BeginHorizontal(); GUILayout.Label("Country", GUILayout.Width(120)); if (_decorator.lastCountryCount != _map.countries.Length) { _decorator.ReloadCountryNames(); } int selection = EditorGUILayout.Popup(_decorator.GUICountryIndex, _decorator.countryNames); if (selection != _decorator.GUICountryIndex) { SetCountryFromCombo(selection); } bool prevc = _decorator.groupByContinent; GUILayout.Label("Grouped"); _decorator.groupByContinent = EditorGUILayout.Toggle(_decorator.groupByContinent, GUILayout.Width(20)); if (_decorator.groupByContinent != prevc) { _decorator.ReloadCountryNames(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(120)); DrawWarningLabel("(Click on SceneView to select a country)"); EditorGUILayout.EndHorizontal(); // type of decoration if (_decorator.GUICountryName.Length > 0) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(120)); if (GUILayout.Button("Toggle Zoom")) { ToggleZoomState(); } EditorGUILayout.EndHorizontal(); CountryDecorator existingDecorator = _decorator.GetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName); if (existingDecorator != null) { decorator = existingDecorator; } else if (decorator == null || !decorator.countryName.Equals(_decorator.GUICountryName)) { decorator = new CountryDecorator(_decorator.GUICountryName); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("Hidden", GUILayout.Width(120)); bool prevHidden = decorator.hidden; decorator.hidden = EditorGUILayout.Toggle(decorator.hidden); if (prevHidden != decorator.hidden) { requestChanges = true; } EditorGUILayout.EndHorizontal(); if (!decorator.hidden) { EditorGUILayout.BeginHorizontal(); GUILayout.Label("Label Visible", GUILayout.Width(120)); bool prevLabelVisible = decorator.labelVisible; decorator.labelVisible = EditorGUILayout.Toggle(decorator.labelVisible); if (prevLabelVisible != decorator.labelVisible) { requestChanges = true; } EditorGUILayout.EndHorizontal(); if (decorator.labelVisible) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Text", GUILayout.Width(120)); string prevLabel = decorator.customLabel; decorator.customLabel = EditorGUILayout.TextField(decorator.customLabel); if (!prevLabel.Equals(decorator.customLabel)) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Font", GUILayout.Width(120)); Font prevFont = decorator.labelFontOverride; decorator.labelFontOverride = (Font)EditorGUILayout.ObjectField(decorator.labelFontOverride, typeof(Font), false); if (decorator.labelFontOverride != prevFont) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Custom Color", GUILayout.Width(120)); decorator.labelOverridesColor = EditorGUILayout.Toggle(decorator.labelOverridesColor, GUILayout.Width(40)); if (decorator.labelOverridesColor) { GUILayout.Label("Color", GUILayout.Width(40)); Color prevColor = decorator.labelColor; decorator.labelColor = EditorGUILayout.ColorField(decorator.labelColor, GUILayout.Width(50)); if (prevColor != decorator.labelColor) { requestChanges = true; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Custom Size", GUILayout.Width(120)); decorator.labelOverridesFontSize = EditorGUILayout.Toggle(decorator.labelOverridesFontSize, GUILayout.Width(40)); if (decorator.labelOverridesFontSize) { GUILayout.Label("Size", GUILayout.Width(40)); float prevSize = decorator.labelFontSize; decorator.labelFontSize = EditorGUILayout.Slider(decorator.labelFontSize, 0.01f, 1.0f); if (prevSize != decorator.labelFontSize) { requestChanges = true; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Offset", GUILayout.Width(120)); Vector2 prevLabelOffset = decorator.labelOffset; decorator.labelOffset = EditorGUILayout.Vector2Field("", decorator.labelOffset); if (prevLabelOffset != decorator.labelOffset) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Rotation", GUILayout.Width(120)); float prevLabelRotation = decorator.labelRotation; decorator.labelRotation = EditorGUILayout.Slider(decorator.labelRotation, 0, 359); if (prevLabelRotation != decorator.labelRotation) { requestChanges = true; } EditorGUILayout.EndHorizontal(); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("Colorized", GUILayout.Width(120)); bool prevColorized = decorator.isColorized; decorator.isColorized = EditorGUILayout.Toggle(decorator.isColorized); if (prevColorized != decorator.isColorized) { requestChanges = true; } if (decorator.isColorized) { GUILayout.Label("Fill Color", GUILayout.Width(120)); Color prevColor = decorator.fillColor; decorator.fillColor = EditorGUILayout.ColorField(decorator.fillColor, GUILayout.Width(50)); if (prevColor != decorator.fillColor) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Include All Regions", GUILayout.Width(120)); bool prevIncludeAllRegions = decorator.includeAllRegions; decorator.includeAllRegions = EditorGUILayout.Toggle(decorator.includeAllRegions); if (prevIncludeAllRegions != decorator.includeAllRegions) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("Texture", GUILayout.Width(120)); Texture2D prevTexture = decorator.texture; decorator.texture = (Texture2D)EditorGUILayout.ObjectField(decorator.texture, typeof(Texture2D), false); if (decorator.texture != prevTexture) { requestChanges = true; } if (decorator.texture != null) { EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Include All Regions", GUILayout.Width(120)); prevIncludeAllRegions = decorator.applyTextureToAllRegions; decorator.applyTextureToAllRegions = EditorGUILayout.Toggle(decorator.applyTextureToAllRegions); if (prevIncludeAllRegions != decorator.applyTextureToAllRegions) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); Vector2 prevVector = decorator.textureScale; decorator.textureScale = EditorGUILayout.Vector2Field(" Scale", decorator.textureScale); if (prevVector != decorator.textureScale) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); prevVector = decorator.textureOffset; decorator.textureOffset = EditorGUILayout.Vector2Field(" Offset", decorator.textureOffset); if (prevVector != decorator.textureOffset) { requestChanges = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label(" Rotation", GUILayout.Width(120)); float prevFloat = decorator.textureRotation; decorator.textureRotation = EditorGUILayout.Slider(decorator.textureRotation, 0, 360); if (prevFloat != decorator.textureRotation) { requestChanges = true; } } EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal(); if (decorator.isNew) { if (GUILayout.Button("Assign")) { _decorator.SetCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName, decorator); ReloadGroupNames(); _decorator.ReloadCountryNames(); } } else if (GUILayout.Button("Remove")) { decorator = null; _decorator.RemoveCountryDecorator(_decorator.GUIGroupIndex, _decorator.GUICountryName); ReloadGroupNames(); _decorator.ReloadCountryNames(); } EditorGUILayout.EndHorizontal(); if (!decoratorGroup.active) { DrawWarningLabel("Enable the decoration group to activate changes"); } } EditorGUILayout.EndVertical(); if (requestChanges) { _decorator.ForceUpdateDecorators(); } }
public void UpdateDecorators(bool ignoreActive) { if (!active && !ignoreActive) { return; } if (decorators == null || map == null) { return; } bool needsLabelRedraw = false; bool needsFrontiersRedraw = false; int decoratorsActiveCount = 0; for (int k = 0; k < decorators.Count; k++) { CountryDecorator decorator = decorators [k]; // Check if something needs to be changed int countryIndex = map.GetCountryIndex(decorator.countryName); if (countryIndex >= 0) { decoratorsActiveCount++; Country country = map.countries [countryIndex]; Region mainRegion = country.regions[country.mainRegionIndex]; if (active) { // label Font override if (country.labelFontOverride != decorator.labelFontOverride) { country.labelFontOverride = decorator.labelFontOverride; needsLabelRedraw = true; } // label color override if (country.labelColorOverride != decorator.labelOverridesColor) { country.labelColorOverride = decorator.labelOverridesColor; needsLabelRedraw = true; } if (country.labelColorOverride && country.labelColor != decorator.labelColor) { country.labelColor = decorator.labelColor; needsLabelRedraw = true; } // label visible if (country.labelVisible != decorator.labelVisible) { country.labelVisible = decorator.labelVisible; needsLabelRedraw = true; } // label rotation if (country.labelRotation != decorator.labelRotation) { country.labelRotation = decorator.labelRotation; needsLabelRedraw = true; } // label offset if (country.labelOffset != decorator.labelOffset) { country.labelOffset = decorator.labelOffset; needsLabelRedraw = true; } // custom label if ((country.customLabel == null && decorator.customLabel.Length > 0) || (country.customLabel != null && country.customLabel != decorator.customLabel)) { if (decorator.customLabel.Length > 0) { country.customLabel = decorator.customLabel; } else { country.customLabel = null; } if (country.labelGameObject != null) { DestroyImmediate(country.labelGameObject); } needsLabelRedraw = true; } // label font size override if (country.labelFontSizeOverride != decorator.labelOverridesFontSize) { country.labelFontSizeOverride = decorator.labelOverridesFontSize; needsLabelRedraw = true; } if (country.labelFontSizeOverride && country.labelFontSize != decorator.labelFontSize) { country.labelFontSize = decorator.labelFontSize; needsLabelRedraw = true; } // colorize if (decorator.isColorized) { if (decorator.includeAllRegions) { map.ToggleCountrySurface(countryIndex, true, decorator.fillColor, decorator.texture, decorator.textureScale, decorator.textureOffset, decorator.textureRotation, decorator.applyTextureToAllRegions); } else { map.ToggleCountryMainRegionSurface(countryIndex, true, decorator.fillColor, decorator.texture, decorator.textureScale, decorator.textureOffset, decorator.textureRotation); } } else if (!decorator.isColorized && mainRegion.customMaterial != null) { map.HideCountrySurface(countryIndex); } // hidden if (country.hidden != decorator.hidden) { country.hidden = decorator.hidden; needsFrontiersRedraw = true; } } else { if (country.labelFontOverride != null) { country.labelFontOverride = null; needsLabelRedraw = true; } if (country.labelColorOverride) { country.labelColorOverride = false; needsLabelRedraw = true; } if (country.labelFontSizeOverride) { country.labelFontSizeOverride = false; needsLabelRedraw = true; } if (!country.labelVisible) { country.labelVisible = true; needsLabelRedraw = true; } if (country.customLabel != null) { country.customLabel = null; needsLabelRedraw = true; } if (country.labelRotation > 0) { country.labelRotation = 0; needsLabelRedraw = true; } if (country.labelOffset != Misc.Vector2zero) { country.labelOffset = Misc.Vector2zero; needsLabelRedraw = true; } if (country.hidden) { country.hidden = false; needsFrontiersRedraw = true; } if (mainRegion.customMaterial != null) { mainRegion.customMaterial = null; map.HideCountrySurface(countryIndex); } } } } if (needsFrontiersRedraw) { map.OptimizeFrontiers(); map.Redraw(); } else if (needsLabelRedraw) { map.RedrawMapLabels(); } map.currentDecoratorCount = decoratorsActiveCount; }