public void ToggleMap(EnumDialogType asType)
        {
            bool isDlgOpened = worldMapDlg != null && worldMapDlg.IsOpened();

            if (!capi.World.Config.GetBool("allowMap", true))
            {
                if (isDlgOpened)
                {
                    worldMapDlg.TryClose();
                }
                return;
            }

            if (worldMapDlg != null)
            {
                if (!isDlgOpened)
                {
                    if (asType == EnumDialogType.HUD)
                    {
                        capi.Settings.Bool["showMinimapHud"] = true;
                    }

                    worldMapDlg.Open(asType);
                    foreach (MapLayer layer in MapLayers)
                    {
                        layer.OnMapOpenedClient();
                    }
                    clientChannel.SendPacket(new OnMapToggle()
                    {
                        OpenOrClose = true
                    });

                    return;
                }
                else
                {
                    if (worldMapDlg.DialogType != asType)
                    {
                        worldMapDlg.Open(asType);
                        return;
                    }

                    if (asType == EnumDialogType.HUD)
                    {
                        capi.Settings.Bool["showMinimapHud"] = false;
                    }
                    else if (capi.Settings.Bool["showMinimapHud"])
                    {
                        worldMapDlg.Open(EnumDialogType.HUD);
                        return;
                    }
                }

                worldMapDlg.TryClose();
                return;
            }

            worldMapDlg           = new GuiDialogWorldMap(onViewChangedClient, capi);
            worldMapDlg.OnClosed += () => {
                foreach (MapLayer layer in MapLayers)
                {
                    layer.OnMapClosedClient();
                }
                clientChannel.SendPacket(new OnMapToggle()
                {
                    OpenOrClose = false
                });
            };

            worldMapDlg.Open(asType);
            foreach (MapLayer layer in MapLayers)
            {
                layer.OnMapOpenedClient();
            }
            clientChannel.SendPacket(new OnMapToggle()
            {
                OpenOrClose = true
            });

            if (asType == EnumDialogType.HUD)
            {
                capi.Settings.Bool["showMinimapHud"] = true;
            }
        }
 public void Open(EnumDialogType type)
 {
     this.dialogType = type;
     opened          = false;
     TryOpen();
 }
Beispiel #3
0
        private GuiComposer ComposeDialog(EnumDialogType dlgType)
        {
            GuiComposer compo;

            ElementBounds mapBounds = ElementBounds.Fixed(0, 28, mapWidth, mapHeight);
            ElementBounds layerList = mapBounds.RightCopy().WithFixedSize(1, 350);

            ElementBounds bgBounds = ElementBounds.Fill.WithFixedPadding(3);

            bgBounds.BothSizing = ElementSizing.FitToChildren;
            bgBounds.WithChildren(mapBounds, layerList);

            ElementBounds dialogBounds =
                ElementStdBounds.AutosizedMainDialog
                .WithAlignment(EnumDialogArea.CenterMiddle)
                .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, 0);

            if (dlgType == EnumDialogType.HUD)
            {
                mapBounds = ElementBounds.Fixed(0, 0, 250, 250);

                bgBounds            = ElementBounds.Fill.WithFixedPadding(2);
                bgBounds.BothSizing = ElementSizing.FitToChildren;
                bgBounds.WithChildren(mapBounds);

                dialogBounds =
                    ElementStdBounds.AutosizedMainDialog
                    .WithAlignment(EnumDialogArea.RightTop)
                    .WithFixedAlignmentOffset(-GuiStyle.DialogToScreenPadding, GuiStyle.DialogToScreenPadding);

                compo = hudDialog;
            }
            else
            {
                compo = fullDialog;
            }

            Cuboidd beforeBounds = null;

            if (compo != null)
            {
                beforeBounds = (compo.GetElement("mapElem") as GuiElementMap)?.CurrentBlockViewBounds;
                compo.Dispose();
            }

            compo = capi.Gui
                    .CreateCompo("worldmap" + dlgType, dialogBounds)
                    .AddShadedDialogBG(bgBounds, false)
                    .AddIf(dlgType == EnumDialogType.Dialog)
                    .AddDialogTitleBar("World Map", OnTitleBarClose)
                    .AddInset(mapBounds, 2)
                    .EndIf()
                    .BeginChildElements(bgBounds)
                    .AddHoverText("", CairoFont.WhiteDetailText(), 350, mapBounds.FlatCopy(), "hoverText")
                    .AddInteractiveElement(new GuiElementMap(capi.ModLoader.GetModSystem <WorldMapManager>().MapLayers, capi, mapBounds, dlgType == EnumDialogType.HUD), "mapElem")
                    .EndChildElements()
                    .Compose()
            ;

            compo.OnRecomposed += SingleComposer_OnRecomposed;

            GuiElementMap mapElem = compo.GetElement("mapElem") as GuiElementMap;

            if (beforeBounds != null)
            {
                mapElem.chunkViewBoundsBefore = beforeBounds.ToCuboidi().Div(capi.World.BlockAccessor.ChunkSize);
            }
            mapElem.viewChanged = viewChanged;
            mapElem.ZoomAdd(1, 0.5f, 0.5f);



            var hoverTextElem = compo.GetHoverText("hoverText");

            hoverTextElem.SetAutoWidth(true);

            if (listenerId == 0)
            {
                listenerId = capi.Event.RegisterGameTickListener(
                    (dt) =>
                {
                    if (!IsOpened())
                    {
                        return;
                    }

                    GuiElementMap singlec = SingleComposer.GetElement("mapElem") as GuiElementMap;
                    singlec?.EnsureMapFullyLoaded();

                    if (requireRecompose)
                    {
                        var dlgtype = dialogType;
                        capi.ModLoader.GetModSystem <WorldMapManager>().ToggleMap(dlgtype);
                        capi.ModLoader.GetModSystem <WorldMapManager>().ToggleMap(dlgtype);
                        requireRecompose = false;
                    }
                }
                    , 100);
            }

            capi.World.FrameProfiler.Mark("composeworldmap");
            return(compo);
        }