public void free()
        {
            if (pannelActive)
            {
                swapView();
            }


            settingsPannel.RemoveAllChildren();
            settingsPannel.Remove();
            settingsPannel = null;

            startIcon.RemoveAllChildren();
            startIcon.Remove();
            startIcon = null;

            buttonDict.Clear();
            buttonDict = null;

            pbar = null;
        }
        public StartWithBaseUI(Builder builder, UIState uistate, Mod mod)
        {
            this.builder = builder;
            FieldInfo field = typeof(UIWorldLoad).GetField("_progressBar", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null && uistate is UIWorldLoad)
            {
                pbar = (UIGenProgressBar)field.GetValue(uistate);
            }
            else
            {
                pbar = null;
            }

            field = typeof(UIWorldLoad).GetField("_progressMessage", BindingFlags.Instance | BindingFlags.NonPublic);
            if (field != null && uistate is UIWorldLoad)
            {
                pmes = (UIHeader)field.GetValue(uistate);
            }
            else
            {
                pmes = null;
            }



            doNotBuildBase = false;
            pauseActive    = false;


            settingsPannel = new UIPanel();
            settingsPannel.Left.Precent = 2.025f;
            settingsPannel.Top.Precent  = 0.025f;
            settingsPannel.Width.Set(0f, 0.95f);
            settingsPannel.Height.Set(0f, 0.95f);
            settingsPannel.SetPadding(0);
            settingsPannel.BackgroundColor = new Color(73, 94, 171);

            buttonDict = new Dictionary <string, UIScalableImageButtton>();

            string content = "base";
            UIScalableImageButtton base2Button = new UIScalableImageButtton(mod.GetTexture("images/base2"), content);

            base2Button.Id = "ba2";
            buttonDict.Add(base2Button.Id, base2Button);

            UIScalableImageButtton base3Button = new UIScalableImageButtton(mod.GetTexture("images/base3"), content);

            base3Button.Id = "ba3";
            buttonDict.Add(base3Button.Id, base3Button);

            UIScalableImageButtton base3bButton = new UIScalableImageButtton(mod.GetTexture("images/base3b"), content);

            base3bButton.Id = "b3b";
            buttonDict.Add(base3bButton.Id, base3bButton);

            UIScalableImageButtton base4Button = new UIScalableImageButtton(mod.GetTexture("images/base4e"), content);

            base4Button.Id = "ba4";
            buttonDict.Add(base4Button.Id, base4Button);

            UIScalableImageButtton base6Button = new UIScalableImageButtton(mod.GetTexture("images/base6"), content);

            base6Button.Id = "ba6";
            buttonDict.Add(base6Button.Id, base6Button);


            content = "tile";
            foreach (var sty in builder.TileTypeDict)
            {
                UIScalableImageButtton fur = new UIScalableImageButtton(ModContent.GetTexture("Terraria/Item_" + sty.Value.ItemID), content);
                fur.Id = sty.Key;
                buttonDict.Add(fur.Id, fur);
            }
            content = "wall";
            foreach (var sty in builder.wallTypeDict)
            {
                UIScalableImageButtton fur = new UIScalableImageButtton(ModContent.GetTexture("Terraria/Item_" + sty.Value.ItemIDofWallType), content);
                fur.Id = sty.Key;
                buttonDict.Add(fur.Id, fur);
            }

            content = "deskChair";//former namer furniture
            foreach (var sty in builder.deskChairTypeDict)
            {
                UIScalableImageButtton dc = new UIScalableImageButtton(ModContent.GetTexture("Terraria/Item_" + sty.Value.ItemIDWorkBench), content);
                dc.Id = sty.Key;
                buttonDict.Add(dc.Id, dc);
            }

            content = "lantern";
            foreach (var sty in builder.lanternTypeDict)
            {
                UIScalableImageButtton fur = new UIScalableImageButtton(ModContent.GetTexture("Terraria/Item_" + sty.Value.ItemIDLantern), content);
                fur.Id = sty.Key;
                buttonDict.Add(fur.Id, fur);
            }
            content = "platform";
            foreach (var sty in builder.platformTypeDict)
            {
                UIScalableImageButtton fur = new UIScalableImageButtton(ModContent.GetTexture("Terraria/Item_" + sty.Value.ItemID), content);
                fur.Id = sty.Key;
                buttonDict.Add(fur.Id, fur);
            }

            content = "numbers";
            UIScalableImageButtton pause = new UIScalableImageButtton(mod.GetTexture("images/pause"), content);

            pause.Id = "counterPause";
            buttonDict.Add(pause.Id, pause);

            UIScalableImageButtton rand = new UIScalableImageButtton(mod.GetTexture("images/qm"), content);

            rand.Id = "random";
            buttonDict.Add(rand.Id, rand);
            for (int num = 0; num < 10; num++)
            {
                UIScalableImageButtton fur = new UIScalableImageButtton(mod.GetTexture("images/" + num), content);
                fur.Id = "config" + num;
                buttonDict.Add(fur.Id, fur);
            }
            UIScalableImageButtton save = new UIScalableImageButtton(mod.GetTexture("images/configSave"), content);

            save.Id = "configSave";
            buttonDict.Add(save.Id, save);

            statusText = new UIText("", 0.5f, true);
            settingsPannel.Append(statusText);
            statusText.HAlign        = 0.5f;
            statusText.VAlign        = 1.0f;
            statusText.PaddingBottom = pause.Height.Pixels + 2 * paddingY;
            statusText.MarginLeft    = 0;
            statusText.TextColor     = new Color(0.85f, 0.85f, 0.85f, 0.85f);

            counterText = new UIText("42", 2, true);
            settingsPannel.Append(counterText);
            counterText.HAlign        = 0.0f;
            counterText.VAlign        = 1.0f;
            counterText.PaddingBottom = paddingY;
            counterText.MarginLeft    = padding;



            foreach (var but in buttonDict)
            {
                UIScalableImageButtton butt = buttonDict[but.Key];
                settingsPannel.Append(butt);
                butt.OnClick      += clickBase;
                butt.OnRightClick += rightClickPannel;
                //butt.SetVisibility(0.8f, 0.8f);
            }


            InitButtons();
            setSize();
            uistate.Append(settingsPannel);
            settingsPannel.OnRightClick += rightClickPannel;
            uistate.Append(settingsPannel);

            startIcon = new UIScalableImageButtton(Texture2D.FromStream(Main.instance.GraphicsDevice, new MemoryStream(mod.GetFileBytes("icon.png"))), content);
            startIcon.Height.Pixels *= 2;
            startIcon.Width.Pixels  *= 2;
            startIcon.PaddingRight   = -startIcon.Width.Pixels;
            startIcon.PaddingTop     = -startIcon.Height.Pixels;
            startIcon.VAlign         = 0f;
            startIcon.HAlign         = 1f;
            startIcon.OnClick       += leftClickicon;
            startIcon.OnRightClick  += rightClickicon;
            uistate.Append(startIcon);
            //uistate.Append(this);

            lastSave = -1;
        }