private void ComposeDialog() { ElementBounds mapBounds = ElementBounds.Fixed(0, 28, 1200, 800); 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 (dialogType == 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); } Vec3d centerPos = capi.World.Player.Entity.Pos.XYZ; if (SingleComposer != null) { SingleComposer.Dispose(); } SingleComposer = capi.Gui .CreateCompo("worldmap", dialogBounds) .AddShadedDialogBG(bgBounds, false) .AddIf(dialogType == EnumDialogType.Dialog) .AddDialogTitleBar("World Map", OnTitleBarClose) .AddInset(mapBounds, 2) .EndIf() .BeginChildElements(bgBounds) .AddHoverText("", CairoFont.WhiteDetailText(), 350, mapBounds.FlatCopy(), "hoverText") .AddInteractiveElement(new GuiElementMap(mapComponents, centerPos, capi, mapBounds), "mapElem") .EndChildElements() .Compose() ; SingleComposer.OnRecomposed += SingleComposer_OnRecomposed; mapElem = SingleComposer.GetElement("mapElem") as GuiElementMap; mapElem.viewChanged = viewChanged; mapElem.ZoomAdd(1, 0.5f, 0.5f); hoverTextElem = SingleComposer.GetHoverText("hoverText"); hoverTextElem.SetAutoWidth(true); if (listenerId != 0) { capi.Event.UnregisterGameTickListener(listenerId); } listenerId = capi.Event.RegisterGameTickListener( (dt) => { mapElem.EnsureMapFullyLoaded(); if (requireRecompose) { TryClose(); TryOpen(); requireRecompose = false; } } , 100); }
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); }