public override void OnInspectorGUI()
    {
        EditorGUIUtility.LookLikeControls();

        Mode oldMode = mode;

        mode = (Mode)EditorGUIUtils.Toolbar(mode);
        EditorGUILayout.Separator();
        if (mode != oldMode)
        {
            EditorGUIUtility.keyboardControl = 0;
        }

        if (mode == Mode.AtlasSet)
        {
            DrawAtlasesList(blockSet);
            if (blockSet.GetAtlas(selectedAtlas) != null)
            {
                DrawAtlasEditor(blockSet.GetAtlas(selectedAtlas));
            }
        }
        if (mode == Mode.BlockSet)
        {
            DrawBlockSet(blockSet);
            EditorGUILayout.Separator();

            if (blockSet.GetBlock(selectedBlock) != null)
            {
                BlockEditor.DrawBlockEditor(blockSet.GetBlock(selectedBlock), blockSet);
            }
        }
        if (mode == Mode.XML)
        {
            if (oldMode != mode)
            {
                xml = blockSet.GetData();
            }

            xmlScrollPosition = GUILayout.BeginScrollView(xmlScrollPosition);
            GUIStyle style = new GUIStyle(GUI.skin.box);
            style.alignment = TextAnchor.UpperLeft;
            xml             = EditorGUILayout.TextArea(xml, GUILayout.ExpandWidth(true));
            blockSet.SetData(xml);
            GUILayout.EndScrollView();

            if (GUILayout.Button("Import"))
            {
                BlockSetImport.Import(blockSet, blockSet.GetData());
                GUI.changed = true;
            }
        }

        if (GUI.changed)
        {
            string data = BlockSetExport.Export(blockSet);
            blockSet.SetData(data);
            EditorUtility.SetDirty(blockSet);
        }
    }
Beispiel #2
0
    public TreeGenerator(Map map)
    {
        this.map = map;
        BlockSet blockSet = map.GetBlockSet();

        wood   = blockSet.GetBlock("Wood");
        leaves = blockSet.GetBlock("Leaves");
    }
Beispiel #3
0
    public TerrainGenerator(Map map)
    {
        this.map      = map;
        this.bmanager = new BiomeManager(map);
        BlockSet blockSet = map.GetBlockSet();

        water = blockSet.GetBlock("Water");
        grass = blockSet.GetBlock("Grass");
        dirt  = blockSet.GetBlock("Dirt");
    }
Beispiel #4
0
    /**
     * DrawBlockList draws the current BlockSet
     */
    private static int DrawBlockList(BlockSet blocks, int selected, ref Vector2 scrollPosition)
    {
        scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(200));

        GUIStyle normal = GUI.skin.button;
        GUIStyle active = new GUIStyle(normal);

        active.normal = active.active;

        for (int i = 0; i < blocks.GetCount(); i++)
        {
            Block block = blocks.GetBlock(i);
            if (i == selected)
            {
                GUI.skin.button = active;
            }
            if (GUILayout.Button(block.GetName()))
            {
                if (selected != i)
                {
                    GUIUtility.keyboardControl = 0;
                }
                selected = i;
            }
            GUI.skin.button = normal;
        }

        GUILayout.EndScrollView();
        return(selected);
    }
Beispiel #5
0
    /**
     * OnInspectorGUI defines what the BlockSet looks like in the unity editor
     */
    public override void OnInspectorGUI()
    {
        Atlas[] list = DrawAtlasesEditor(blockSet.GetAtlases());
        blockSet.SetAtlases(list);
        EditorGUILayout.Separator();

        DrawBlockSetEditor(blockSet);
        EditorGUILayout.Separator();

        if (blockSet.GetBlock(selectedBlock) != null)
        {
            DrawBlockEditor(blockSet.GetBlock(selectedBlock), blockSet);
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(blockSet);
            Repaint();
        }
    }
Beispiel #6
0
    void OnGUI()
    {
        Rect rect     = new Rect(Screen.width - 180, 0, 180, Screen.height);
        int  oldIndex = index;

        index = DrawList(rect, index, blockSet.GetBlocks(), ref scrollPosition);
        if (oldIndex != index)
        {
            BuildBlock(blockSet.GetBlock(index));
        }
    }
Beispiel #7
0
 public void SetBlockSet(BlockSet blockSet)
 {
     this.blockSet = blockSet;
     index         = Mathf.Clamp(index, 0, blockSet.GetBlockCount() + blockSet.GetItemCount());
     if (index < blockSet.GetBlockCount())
     {
         BuildBlock(blockSet.GetBlock(index));
     }
     if (index > blockSet.GetBlockCount())
     {
         BuildItem(blockSet.GetItem(index - blockSet.GetBlockCount()));
     }
 }
Beispiel #8
0
    public TerrainGenerator(Map map)
    {
        this.map = map;
        BlockSet blockSet = map.GetBlockSet();

        water = blockSet.GetBlock("Water");

        grass = blockSet.GetBlock("Grass");
        dirt  = blockSet.GetBlock("Dirt");
        sand  = blockSet.GetBlock("Sand");
        stone = blockSet.GetBlock("Stone");

        snow = blockSet.GetBlock("Snow");
        ice  = blockSet.GetBlock("Ice");
    }
Beispiel #9
0
    public TreeGenerator(Map map)
    {
        this.map = map;
        BlockSet blockSet = map.GetBlockSet();

        dirtWood   = blockSet.GetBlock("DirtWood");
        dirtLeaves = blockSet.GetBlock("DirtLeaves");

        snowWood   = blockSet.GetBlock("SnowWood");
        snowLeaves = blockSet.GetBlock("SnowLeaves");


        sandWood   = blockSet.GetBlock("SandWood");
        sandLeaves = blockSet.GetBlock("SandLeaves");

        cactus = blockSet.GetBlock("Cactus");
    }
Beispiel #10
0
 private static Block DrawInventory(BlockSet blockSet, ref Vector2 scrollPosition, Block selected)
 {
     scrollPosition = GUILayout.BeginScrollView(scrollPosition);
     for (int i = 0, y = 0; i < blockSet.GetBlockCount(); y++)
     {
         GUILayout.BeginHorizontal();
         for (int x = 0; x < 8; x++, i++)
         {
             Block block = blockSet.GetBlock(i);
             if (DrawBlock(block, block == selected && selected != null))
             {
                 selected = block;
             }
         }
         GUILayout.EndHorizontal();
     }
     GUILayout.EndScrollView();
     return(selected);
 }
Beispiel #11
0
    /**
     * DrawBlockSetEditor draws and handles the editing of the BlockSet
     */
    private static void DrawBlockSetEditor(BlockSet blockSet)
    {
        GUILayout.BeginVertical("box");
        selectedBlock = DrawBlockList(blockSet, selectedBlock, ref blockSetScrollPosition);
        EditorGUILayout.Separator();

        GUILayout.BeginHorizontal();
        if (GUILayout.Button("Add Cube"))
        {
            selectedBlock = blockSet.Add(new Cube("new Cube"));
        }
        if (GUILayout.Button("Add Cross"))
        {
            selectedBlock = blockSet.Add(new Cross("new Cross"));
        }
        GUILayout.EndHorizontal();
        if (GUILayout.Button("Remove") && blockSet.GetBlock(selectedBlock) != null)
        {
            Undo.RecordObject(blockSet, "Remove block");
            blockSet.Remove(selectedBlock);
            selectedBlock = Mathf.Clamp(selectedBlock, 0, blockSet.GetCount() - 1);
        }
        GUILayout.EndVertical();
    }
Beispiel #12
0
    private static Entity DrawInventory(BlockSet blockSet, ref Vector2 scrollPosition, Entity selected)
    {
        scrollPosition = GUILayout.BeginScrollView(scrollPosition);
        int y = 0;

        for (int i = 0; i < blockSet.GetBlockCount(); y++)
        {
            GUILayout.BeginHorizontal();
            for (int x = 0; x < 8; x++, i++)
            {
                Block block = blockSet.GetBlock(i);
                if (DrawBlock(block, block == BlockUnderSelection && BlockUnderSelection != null))
                {
                    selected = block;
                    IsBlockUnderSelection = true;
                }
            }
            GUILayout.EndHorizontal();
        }
        for (int i = 0; i < blockSet.GetItemCount(); y++)
        {
            GUILayout.BeginHorizontal();
            for (int x = 0; x < 8; x++, i++)
            {
                Item item = blockSet.GetItem(i);
                if (DrawBlock(item, item == ItemUnderSelection && ItemUnderSelection != null))
                {
                    selected             = item;
                    IsItemUnderSelection = true;
                }
            }
            GUILayout.EndHorizontal();
        }
        GUILayout.EndScrollView();
        return(selected);
    }
Beispiel #13
0
    //Check equivalence of block type at position
    public bool CheckEquivalentBlocks(int blockIndex, int x, int y, int z)
    {
        BlockData blockData = GetBlock(x, y, z);

        return(blockData != null && blockData.block != null && HasBlockSet() && blockData.block.GetName().Equals(blockSet.GetBlock(blockIndex).GetName()));
    }
Beispiel #14
0
    public void LoadLevel()
    {
        int verticalOffset = 85;

        Debug.Log("About to load level folder: " + _fullMapPath + ".");

        Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath);

        Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager();

        BlockSet blockSet = _map.GetBlockSet();

        _map.GetSunLightmap().SetSunHeight(3, 3, 3);

        foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager)
        {
            // Loop through x-axis of chunks in this region
            for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++)
            {
                // Loop through z-axis of chunks in this region.
                for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++)
                {
                    // Retrieve the chunk at the current position in our 2D loop...
                    Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ);

                    if (mcChunkRef != null)
                    {
                        if (mcChunkRef.IsTerrainPopulated)
                        {
                            // Ok...now to stick the blocks in...

                            for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++)
                            {
                                for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++)
                                {
                                    for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++)
                                    {
                                        int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ);

                                        Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY + verticalOffset, iMCChunkInternalZ);

                                        if (iBlockID != 0)
                                        {
                                            switch (iBlockID)
                                            {
                                            case 3:                                             // Dirt to first grass
                                                iBlockID = 1;
                                                break;

                                            case 12:                                             // Grass to grass
                                                iBlockID = 1;
                                                break;

                                            case 13:                                             // Gravel to stone
                                                iBlockID = 4;
                                                break;

                                            case 1:                                             // Stone to second stone
                                                iBlockID = 5;
                                                break;

                                            case 16:                                             // Coal ore to fungus
                                                iBlockID = 17;
                                                break;

                                            case 15:                                             // Iron ore to pumpkin
                                                iBlockID = 20;
                                                break;

                                            case 9:                                             // Water to water
                                                iBlockID = 8;
                                                break;

                                            default:
                                                Debug.Log("Unmapped BlockID: " + iBlockID);
                                                break;
                                            }

                                            Block newBlock = blockSet.GetBlock(iBlockID);

                                            _map.SetBlock(new BlockData(newBlock), blockPos);

                                            Vector3i chunkPos = Chunk.ToChunkPosition(blockPos);

                                            _map.SetDirty(chunkPos);
                                        }
                                    } // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++)
                                }     // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++)
                            }         // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++)
                        }             // End if (mcChunkRef.IsTerrainPopulated)
                    }                 // End if (mcChunkRef != null)
                }                     // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++)
            }                         // End for (int iMCChunkX  = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++)
        }                             // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager )

        Debug.Log("Loaded level: " + _fullMapPath + ".");

        _map.AddColliders();

//		List3D<Chunk> chunkList = _map.GetChunks ();
//
//		for (int minX = chunkList.GetMinX(); minX < chunkList.GetMaxX(); minX++)
//		{
//			for (int minY = chunkList.GetMinY(); minY < chunkList.GetMaxY(); minY++)
//			{
//				for (int minZ = chunkList.GetMinZ(); minZ < chunkList.GetMaxZ(); minZ++)
//				{
//					Vector3i chunkPos = new Vector3i(minX, minY, minZ);
//
//					Chunk mapChunk = _map.GetChunk (chunkPos);
//
//					Debug.Log ("LOL [" + minX + ", " + minY + ", " + minZ + "].");
//				}
//			}
//		}
//
//		foreach (Chunk loadedChunk in _map.Get
//		{
//			Vector3i loadedChunkPos = loadedChunk.GetPosition();
//			Debug.Log ("MOG A CHUNK!!! [" + loadedChunkPos.x + ", " + loadedChunkPos.y + ", " + loadedChunkPos.z + "].");
//		}
    }     // End public void LoadLevel()
Beispiel #15
0
 public void SetBlockSet(BlockSet blockSet)
 {
     this.blockSet = blockSet;
     index         = Mathf.Clamp(index, 0, blockSet.GetBlockCount());
     BuildBlock(blockSet.GetBlock(index));
 }