Example #1
0
        public void LoadData(ProgressBar bar)
        {
            highViewMap = new Texture(4, 4 /*, new byte[] { 255, 0, 0 }*/);
            //effects: 0=not, 1=up, 2=down, 3=break, 4=deacy, 5=destroy 6=entf//
            //AreaPermanent->typ: 0=water, 1=nature, 2=road,3=saltwater
            GGL.IO.Parser parser = new GGL.IO.Parser();
            string[]      names;


            Console.WriteLine("//load: gameZonesData");
            parser.ParseFile("../Data/config/Zones.gd");
            names = parser.ObjectNames;
            Zones = new Zone[names.Length];
            for (int i = 0; i < Zones.Length; i++)
            {
                string name = names[i];
                Zones[i] = new Zone();
                Zones[i].Load(i, name,
                              parser.GetAttribute <string>(name, "name"),
                              parser.GetAttribute <byte[]>(name, "color"),
                              parser.GetAttribute <byte[]>(name, "supportTyp"),
                              parser.GetAttribute <byte[]>(name, "canBuildOnTyp")
                              );
            }
            parser.Clear();

            Console.WriteLine("//load: gameResourcesData");
            parser.ParseFile("../Data/config/gameResources.gd");
            names     = parser.ObjectNames;
            Resources = new GameResources[names.Length];
            for (int i = 0; i < Resources.Length; i++)
            {
                string name = names[i];
                Resources[i] = new GameResources();
                Resources[i].Load(i, name,
                                  parser.GetAttribute <string>(name, "name"),
                                  parser.GetAttribute <int>(name, "initValue"),
                                  parser.GetAttribute <bool>(name, "physical"),
                                  parser.GetAttribute <bool>(name, "storable")
                                  );
            }
            parser.Clear();

            Console.WriteLine("//load: gameAreaData");
            parser.ParseFile("../Data/config/gameArea.gd");
            names = parser.ObjectNames;
            Areas = new GameArea[names.Length];
            for (int i = 0; i < Areas.Length; i++)
            {
                string name = names[i];
                Areas[i] = new GameArea();
                Areas[i].Load(i, name,
                              parser.GetAttribute <string>(name, "name"),
                              parser.GetAttribute <bool>(name, "smooth")
                              );
            }
            parser.Clear();

            for (int i = 0; i < Resources.Length; i++)
            {
                parser.AddEnum("res", Resources[i].Name.ToLower(), i);
            }
            for (int i = 0; i < Areas.Length; i++)
            {
                parser.AddEnum("area", Areas[i].Name.ToLower(), i);
            }
            parser.AddEnum("effect", new string[] { "not", "up", "down", "break", "deacy", "destroy", "entf" });
            parser.AddEnum("gmode", new string[] { "not", "all", "foCu", "foEn", "cuEn", "fo", "cu", "en", "st" });
            parser.AddEnum("bmode", new string[] { "single", "brush", "rnline", "eqline", "cnline", "rnarea", "eqarea" });
            parser.AddEnum("i", "min", int.MinValue); parser.AddEnum("i", "max", int.MaxValue);

            parser.ParseFile("../Data/config/gameObject.gd");
            names       = parser.ObjectNames;
            Objects     = new GameObject[names.Length];
            bar.Value   = 0;
            bar.Maximum = Objects.Length;
            for (int i = 0; i < Objects.Length; i++)
            {
                bar.Value++;
                string name = names[i];
                Objects[i] = new GameObject(i);
                Objects[i].LoadBasic(i, name,
                                     parser.GetAttribute <string>(name, "name"),
                                     parser.GetAttribute <string>(name, "groundPath"),
                                     parser.GetAttribute <string>(name, "structPath"),
                                     parser.GetAttribute <byte>(name, "size"),
                                     parser.GetAttribute <byte>(name, "groundMode"),
                                     parser.GetAttribute <byte>(name, "structMode"),
                                     parser.GetAttribute <byte[]>(name, "groundNeighbors"),
                                     parser.GetAttribute <byte[]>(name, "structNeighbors")
                                     );
                Objects[i].LoadTypRefs(
                    parser.GetAttribute <byte[]>(name, "upgradeTyp"),
                    parser.GetAttribute <byte[]>(name, "downgradeTyp"),
                    parser.GetAttribute <byte[]>(name, "demolitionTyp"),
                    parser.GetAttribute <byte[]>(name, "decayTyp"),
                    parser.GetAttribute <byte[]>(name, "destroyTyp"),
                    parser.GetAttribute <byte[]>(name, "canBuiltOn")
                    );
                Objects[i].LoadSimData(
                    parser.GetAttribute <int[]>(name, "AreaPermanent"),
                    parser.GetAttribute <int[]>(name, "AreaDependent"),
                    parser.GetAttribute <int[]>(name, "ResourcesEffect"),
                    parser.GetAttribute <int[]>(name, "ResourcesBuild"),
                    parser.GetAttribute <int[]>(name, "ResourcesPermanent"),
                    parser.GetAttribute <int[]>(name, "ResourcesMonthly"),
                    parser.GetAttribute <int[]>(name, "ResourcesDependent")
                    );
                Objects[i].LoadScriptSource(
                    parser.GetAttribute <string>(name, "onupdate")
                    );
            }
            parser.Clear();
            groundTexture = new Texture("../Data/texture/ground/texture.png");
            zoneTexture   = new Texture("../Data/texture/effect/zoon.png");
            gui           = new Texture("../Data/texture/gui/aktivField.png");

            compile();

            TextureAtlas._DEBUG();
        }
Example #2
0
        public MenuOverlay()
        {
            listBox                       = new Control.ButtonList();
            listBox.BackColor             = Color.FromArgb(255, 0, 255);
            listBox.ItemHeight            = 26;
            listBox.ItemDistance          = 4;
            listBox.Font                  = new Font("Franklin Gothic Medium", 11.25f);
            listBox.ChangeItem           += new System.EventHandler(listBox_ChangeItem);
            listBox.Enabled               = true;
            listBox.BorderImage           = new Bitmap("../Data/texture/gui/border.png");
            listBox.ButtonBorderImage     = new Bitmap("../Data/texture/gui/border2.png");
            listBox.ButtonDownBorderImage = new Bitmap("../Data/texture/gui/border3.png");
            Controls.Add(listBox);

            imageButtons = new ImageButton[10];
            buildOptions = new BuildOption[10][];
            InitializeComponent();
            GGL.IO.Parser parser = new GGL.IO.Parser();
            parser.AddAttribute("string", "name", "");
            parser.AddAttribute("int", "value", "-1");
            parser.AddAttribute("int", "typ", "1");
            parser.AddAttribute("int", "mode", "0");
            parser.AddAttribute("byte[]", "replace", "[]");
            parser.AddAttribute("byte[]", "color", "[]");
            parser.AddEnum("mode", new string[] { "single", "brush", "line", "equalLine", "cnline", "area", "equalArea" });
            parser.AddEnum("typ", new string[] { "label", "build", "zone" });
            for (int i = 0; i < Program.Game.Objects.Length; i++)
            {
                parser.AddEnum("obj", Program.Game.Objects[i].Name, i);
            }
            for (int i = 0; i < Program.Game.Zones.Length; i++)
            {
                parser.AddEnum("zone", Program.Game.Zones[i].Name, i);
            }
            Console.WriteLine("//load: gui");
            parser.ParseFile("../Data/config/guiBuildMenu.gd");

            for (int i = 0; i < 10; i++)
            {
                if (parser.Exists("button_" + i))
                {
                    imageButtons[i]          = new ImageButton();
                    imageButtons[i].Size     = new Size(64, 64);
                    imageButtons[i].Anchor   = AnchorStyles.Left;
                    imageButtons[i].Location = new Point(8, 72 * i);
                    imageButtons[i].Visible  = true;
                    string btnname = parser.GetAttribute <string>("button_" + i, "name");
                    if (File.Exists("../Data/texture/gui/" + btnname + ".png"))
                    {
                        imageButtons[i].LoadImages(new Bitmap("../Data/texture/gui/" + btnname + ".png"), new Bitmap("../Data/texture/gui/" + btnname + "Down.png"));
                    }
                    else
                    {
                        imageButtons[i].LoadImages(new Bitmap("../Data/texture/gui/empty.png"), new Bitmap("../Data/texture/gui/emptyDown.png"));
                    }
                    Controls.Add(imageButtons[i]);

                    int size = -1;
                    while (parser.Exists(btnname + "_" + ++size))
                    {
                        ;
                    }
                    buildOptions[i] = new BuildOption[size];
                    for (int i2 = 0; i2 < buildOptions[i].Length; i2++)
                    {
                        string name    = btnname + "_" + i2;
                        int    typ     = parser.GetAttribute <int>(name, "typ");
                        int    value   = parser.GetAttribute <int>(name, "value");
                        int    mode    = parser.GetAttribute <int>(name, "mode");
                        var    text    = parser.GetAttribute <string>(name, "name");
                        var    replace = parser.GetAttribute <byte[]>(name, "replace");
                        var    bytes   = parser.GetAttribute <byte[]>(name, "color");
                        if (bytes.Length == 3)
                        {
                            buildOptions[i][i2] = new BuildOption(text, typ, value, mode, replace, Color.FromArgb(bytes[0], bytes[1], bytes[2]));
                        }
                        else
                        {
                            buildOptions[i][i2] = new BuildOption(text, typ);
                        }
                    }
                    imageButtons[i].SwitchMode  = true;
                    imageButtons[i].ButtonDown += new System.EventHandler(imageButton_ButtonDown);
                    imageButtons[i].ButtonUp   += new System.EventHandler(imageButton_ButtonUp);
                }
            }
            this.DoubleBuffered = true;
            Width  = Program.MainWindow.Width;
            Height = Program.MainWindow.Height;
        }