Add new map editor UI.

This commit is contained in:
Paul Chote
2015-04-06 14:57:13 +01:00
parent d211fe9fe1
commit 469f47aeea
28 changed files with 2142 additions and 11 deletions

View File

@@ -98,26 +98,33 @@ namespace OpenRA.Mods.Common.Traits
return t.Variants.Keys.Random(Game.CosmeticRandom);
}
public int ResourceDensityAt(CPos c)
{
// Set density based on the number of neighboring resources
var adjacent = 0;
var type = Tiles[c].Type;
for (var u = -1; u < 2; u++)
for (var v = -1; v < 2; v++)
if (Map.MapResources.Value[c + new CVec(u, v)].Type == type.Info.ResourceType)
adjacent++;
return Math.Max(int2.Lerp(0, type.Info.MaxDensity, adjacent, 9), 1);
}
public virtual CellContents UpdateDirtyTile(CPos c)
{
var t = Tiles[c];
var type = t.Type;
// Empty tile
if (t.Type == null)
if (type == null)
{
t.Sprite = null;
return t;
}
// Set density based on the number of neighboring resources
var adjacent = 0;
var type = t.Type;
for (var u = -1; u < 2; u++)
for (var v = -1; v < 2; v++)
if (Map.MapResources.Value[c + new CVec(u, v)].Type == type.Info.ResourceType)
adjacent++;
t.Density = Math.Max(int2.Lerp(0, type.Info.MaxDensity, adjacent, 9), 1);
t.Density = ResourceDensityAt(c);
var sprites = type.Variants[t.Variant];
var frame = int2.Lerp(0, sprites.Length - 1, t.Density - 1, type.Info.MaxDensity);

View File

@@ -23,6 +23,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("The widget tree to open when a regular map is loaded (i.e. the ingame UI).")]
public readonly string IngameRoot = "INGAME_ROOT";
[Desc("The widget tree to open when the map editor is loaded.")]
public readonly string EditorRoot = "EDITOR_ROOT";
[Desc("Remove any existing UI when a map is loaded.")]
public readonly bool ClearRoot = true;
@@ -44,7 +47,9 @@ namespace OpenRA.Mods.Common.Traits
if (info.ClearRoot)
Ui.ResetAll();
var widget = world.Type == WorldType.Shellmap ? info.ShellmapRoot : info.IngameRoot;
var widget = world.Type == WorldType.Shellmap ? info.ShellmapRoot :
world.Type == WorldType.Editor ? info.EditorRoot : info.IngameRoot;
Game.LoadWidget(world, widget, Ui.Root, new WidgetArgs());
}
}