Esempio n. 1
0
 protected MapPreviewWidget(MapPreviewWidget other)
     : base(other)
 {
     lastMap = other.lastMap;
     Map = other.Map;
     SpawnColors = other.SpawnColors;
 }
Esempio n. 2
0
        public override void DrawInner( World world )
        {
            if (UnownedSpawn == null)
                UnownedSpawn = ChromeProvider.GetImage("spawnpoints", "unowned");
            if (OwnedSpawn == null)
                OwnedSpawn = ChromeProvider.GetImage("spawnpoints", "owned");

            var map = Map();
            if( map == null ) return;

            if (lastMap != map)
            {
                lastMap = map;

                // Update image data
                var preview = PreviewCache[map];
                if( mapChooserSheet == null || mapChooserSheet.Size.Width != preview.Width || mapChooserSheet.Size.Height != preview.Height )
                    mapChooserSheet = new Sheet(new Size( preview.Width, preview.Height ) );

                mapChooserSheet.Texture.SetData( preview );
                mapChooserSprite = new Sprite( mapChooserSheet, new Rectangle( 0, 0, map.Width, map.Height ), TextureChannel.Alpha );

                // Update map rect
                PreviewScale = Math.Min(RenderBounds.Width * 1.0f / map.Width, RenderBounds.Height * 1.0f / map.Height);
                var size = Math.Max(map.Width, map.Height);
                var dw = (int)(PreviewScale * (size - map.Width)) / 2;
                var dh = (int)(PreviewScale * (size - map.Height)) / 2;
                MapRect = new Rectangle(RenderBounds.X + dw, RenderBounds.Y + dh, (int)(map.Width * PreviewScale), (int)(map.Height * PreviewScale));
            }

            Game.Renderer.RgbaSpriteRenderer.DrawSprite( mapChooserSprite,
                new float2(MapRect.Location),
                new float2( MapRect.Size ) );

            Game.Renderer.RgbaSpriteRenderer.Flush();

            // Overlay spawnpoints
            var colors = SpawnColors();
            foreach (var p in map.SpawnPoints)
            {
                var pos = ConvertToPreview(map, p);
                var sprite = UnownedSpawn;
                var offset = new int2(-UnownedSpawn.bounds.Width/2, -UnownedSpawn.bounds.Height/2);

                if (colors.ContainsKey(p))
                {
                    sprite = OwnedSpawn;
                    offset = new int2(-OwnedSpawn.bounds.Width/2, -OwnedSpawn.bounds.Height/2);
                    WidgetUtils.FillRectWithColor(new Rectangle(pos.X + offset.X + 2, pos.Y + offset.Y + 2, 12, 12), colors[p]);
                    Game.Renderer.LineRenderer.Flush();
                }
                Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos + offset);
            }

            Game.Renderer.Flush();
        }
Esempio n. 3
0
        internal MapChooserDelegate(
            [ObjectCreator.Param( "widget" )] Widget bg,
            [ObjectCreator.Param] OrderManager orderManager,
            [ObjectCreator.Param] string mapName)
        {
            if (mapName != null)
                Map = Game.modData.AvailableMaps[mapName];
            else
                Map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Value;

            var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
            bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
            bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
            bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Width, Map.Height);
            bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
            bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();

            bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
            {
                orderManager.IssueOrder(Order.Command("map " + Map.Uid));
                Widget.CloseWindow();
                return true;
            };

            bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
            {
                Widget.CloseWindow();
                return true;
            };

            var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
            int offset = itemTemplate.Bounds.Y;
            foreach (var kv in Game.modData.AvailableMaps)
            {
                var map = kv.Value;
                if (!map.Selectable)
                    continue;

                var template = itemTemplate.Clone() as LabelWidget;
                template.Id = "MAP_{0}".F(map.Uid);
                template.GetText = () => "   " + map.Title;
                template.GetBackground = () => ((Map == map) ? "dialog2" : null);
                template.OnMouseDown = mi => { Map = map; return true; };
                template.Parent = ml;

                template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
                template.IsVisible = () => true;
                ml.AddChild(template);

                offset += template.Bounds.Height;
                ml.ContentHeight += template.Bounds.Height;
            }
        }
Esempio n. 4
0
        internal MapChooserDelegate(
            [ObjectCreator.Param( "widget" )] Widget bg,
            [ObjectCreator.Param] OrderManager orderManager,
            [ObjectCreator.Param] string mapName)
        {
            if (mapName != null)
                Map = Game.modData.AvailableMaps[mapName];
            else
                Map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Value;

            var ml = bg.GetWidget<ScrollPanelWidget>("MAP_LIST");
            bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
            bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
            bg.GetWidget<LabelWidget>("CURMAP_AUTHOR").GetText = () => Map.Author;
            bg.GetWidget<LabelWidget>("CURMAP_DESC").GetText = () => Map.Description;
            bg.GetWidget<LabelWidget>("CURMAP_DESC_LABEL").IsVisible = () => Map.Description != null;
            bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Bounds.Width, Map.Bounds.Height);
            bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
            bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();

            bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
            {
                orderManager.IssueOrder(Order.Command("map " + Map.Uid));
                Widget.CloseWindow();
                return true;
            };

            bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
            {
                Widget.CloseWindow();
                return true;
            };

            var itemTemplate = ml.GetWidget<ContainerWidget>("MAP_TEMPLATE");
            foreach (var kv in Game.modData.AvailableMaps.OrderBy(kv => kv.Value.Title).OrderBy(kv => kv.Value.PlayerCount))
            {
                var map = kv.Value;
                if (!map.Selectable)
                    continue;

                var template = itemTemplate.Clone() as ContainerWidget;
                template.Id = "MAP_{0}".F(map.Uid);
                template.GetBackground = () => ((Map == map) ? "dialog2" : null);
                template.OnMouseDown = mi => { if (mi.Button != MouseButton.Left) return false;  Map = map; return true; };
                template.IsVisible = () => true;
                template.GetWidget<LabelWidget>("TITLE").GetText = () => map.Title;
                template.GetWidget<LabelWidget>("PLAYERS").GetText = () => "{0}".F(map.PlayerCount);
                template.GetWidget<LabelWidget>("TYPE").GetText = () => map.Type;
                ml.AddChild(template);
            }
        }
Esempio n. 5
0
        public MapChooserDelegate()
        {
            var r = Widget.RootWidget;
            var bg = r.GetWidget("MAP_CHOOSER");
            bg.SpecialOneArg = (map) => RefreshMapList(map);
            var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");

            bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
            bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
            bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Width, Map.Height);
            bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
            bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();

            bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
            {
                Game.IssueOrder(Order.Command("map " + Map.Uid));
                r.CloseWindow();
                return true;
            };

            bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
            {
                r.CloseWindow();
                return true;
            };

            var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
            int offset = itemTemplate.Bounds.Y;
            foreach (var kv in Game.modData.AvailableMaps)
            {
                var map = kv.Value;
                if (!map.Selectable)
                    continue;

                var template = itemTemplate.Clone() as LabelWidget;
                template.Id = "MAP_{0}".F(map.Uid);
                template.GetText = () => "   " + map.Title;
                template.GetBackground = () => ((Map == map) ? "dialog2" : null);
                template.OnMouseDown = mi => { Map = map; return true; };
                template.Parent = ml;

                template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
                template.IsVisible = () => true;
                ml.AddChild(template);

                offset += template.Bounds.Height;
                ml.ContentHeight += template.Bounds.Height;
            }
        }
Esempio n. 6
0
 void UpdateCurrentMap()
 {
     if (MapUid == Game.LobbyInfo.GlobalSettings.Map) return;
     MapUid = Game.LobbyInfo.GlobalSettings.Map;
     Map = Game.modData.AvailableMaps[MapUid];
 }
Esempio n. 7
0
 public int2 ConvertToPreview(MapStub map, int2 point)
 {
     return new int2(MapRect.X + (int)(PreviewScale*(point.X - map.TopLeft.X)) , MapRect.Y + (int)(PreviewScale*(point.Y - map.TopLeft.Y)));
 }
Esempio n. 8
0
 public void RefreshMapList(object uidobj)
 {
     // Set the default selected map
     var uid = uidobj as string;
     if (uid != null)
         Map = Game.modData.AvailableMaps[uid];
     else
         Map = Game.modData.AvailableMaps.FirstOrDefault().Value;
 }
Esempio n. 9
0
        Dictionary<string, MapStub> FindMaps(string[] mods)
        {
            var paths = mods.SelectMany(p => FindMapsIn("mods/" + p + "/maps/"));

            Dictionary<string, MapStub> ret = new Dictionary<string, MapStub>();
            foreach (var path in paths)
            {
                var map = new MapStub(path);
                if (ret.ContainsKey(map.Uid))
                    System.Console.WriteLine("Ignoring duplicate map: {0}", path);
                else
                    ret.Add(map.Uid, map);
            }
            return ret;
        }