private void ajouterArticleToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (struc == null || struc.IsDisposed)
     {
         struc           = new Structure();
         struc.MdiParent = this;
         struc.Show();
     }
     else
     {
         struc.WindowState = FormWindowState.Maximized;
         struc.Activate();
     }
 }
Exemple #2
0
    //place a building
    public Structure SpawnStructure(string type, int x, int y, float buildingRotation)
    {
        //don't do if not possible
        if (!CanSpawnStructure(type, x, y, buildingRotation))
        {
            return(null);
        }

        //retrieve data about structure
        StructureData data = StructureDatabase.GetData(type);

        int   sizex  = data.sizex;
        int   sizey  = data.sizey;
        float alignx = data.Alignx;
        float aligny = data.Aligny;

        //if placing a mapentrance or mapexit, remove existing one
        if (data.builtOnce)
        {
            //find object
            GameObject g = GameObject.Find(type);

            //only try to delete it if it exists
            if (g != null)
            {
                Structure m = g.GetComponent <Structure>();
                Demolish(m.X, m.Y);
            }
        }

        //destroy roads beneath area if they're there
        else if (data.hasRoadTiles)
        {
            for (int a = x; a < sizex + x; a++)
            {
                for (int b = y; b < sizey + y; b++)
                {
                    PlaceOnRoads = true;
                    Demolish(x, y);
                }
            }
        }

        //switch size dimensions if building is rotated
        if (buildingRotation % 180 != 0)
        {
            int tempszx = sizex;
            int tempszy = sizey;
            sizex = tempszy;
            sizey = tempszx;

            float tempalignx = alignx;
            float tempaligny = aligny;
            alignx = tempaligny;
            aligny = tempalignx;
        }

        GameObject go = SpawnObject("Structures", type, x, y, buildingRotation);

        go.transform.position += new Vector3(alignx, 0, aligny);

        //unless object is a mapentrance or mapexit, put its coords in its name
        go.name = type + "_" + x + "_" + y;
        if (data.builtOnce)
        {
            go.name = type;
        }

        //rename the area it takes up to its name
        Map.RenameArea(go.name, x, y, sizex, sizey);

        Structure s = go.GetComponent <Structure>();

        if (s == null)
        {
            Debug.LogError(type + " has no structure component");
        }
        s.X           = x;
        s.Y           = y;
        s.Sizex       = sizex;
        s.Sizey       = sizey;
        s.DisplayName = data.displayName;
        s.world       = this;
        s.Activate();

        return(s);
    }