Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            int BlockType = Block_Of[comboBox1.SelectedIndex];
            int Count = 100, i;
            int result = Client.ListBlocksOfType(BlockType, List, ref Count);

            ShowResult(result);
            if (result == 0)
            {
                TxtList.Clear();
                for (i = 0; i < Count; i++)
                {
                    string s = Convert.ToString(List[i], 10);
                    TxtList.Text = TxtList.Text + s + " ";
                }
            }
        }
Exemplo n.º 2
0
    public void OnGUI()
    {
        var style = new GUIStyle
        {
            alignment = TextAnchor.MiddleCenter,
            fontSize  = 18,
            font      = Resources.GetBuiltinResource <Font>("Arial.ttf")
        };

        style.normal.textColor  = Color.black;
        style.normal.background = Texture2D.whiteTexture;

        var styleInput = new GUIStyle(style);

        styleInput.normal.background = Texture2D.grayTexture;

        if (!GameStarted)
        {
            if (!Directory.Exists($@"{GetPath}\Modules"))
            {
                throw new Exception("Directory Modules is required");
            }

            // Search module
            GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Texture2D.blackTexture);
            input = GUI.TextField(
                new Rect(Screen.width / 2 - 100, Screen.height / 2 - 55, 200, 40),
                input,
                styleInput
                );
            if (
                GUI.Button(
                    new Rect(Screen.width / 2 - 100, Screen.height / 2 + 15, 200, 40),
                    "Find module",
                    style
                    )
                )
            {
                var pathModule       = $@"{GetPath}\Modules\{input}\";
                var pathModuleBlocks = $@"{GetPath}\Modules\{input}\Blocks";
                if (
                    Directory.Exists(pathModule) &&
                    Directory.Exists(pathModuleBlocks)
                    )
                {
                    // Adding external textures to the blocks list
                    var allBlocks = Directory.GetFiles(pathModuleBlocks);
                    var index     = 0;
                    foreach (var file in allBlocks)
                    {
                        var parse = Path.GetFileNameWithoutExtension(file);
                        var txt   = new Texture2D(Generator.BlockSize * 2, Generator.BlockSize * 2);
                        txt.LoadImage(File.ReadAllBytes(file));
                        var block = new TxtList
                        {
                            texture = txt,
                            name    = parse
                        };
                        Textures[index] = block;
                        index++;
                    }
                    Textures = Textures.Where(txt => txt != null).ToArray();

                    CurrentModule = input;
                    GameStarted   = true;

                    // Start the game once
                    StartGame();
                }
                else
                {
                    Tools.MessageBoxInfo($"Module {input} isn't complete or not exists.", "Error");
                }
            }

            return;
        }

        // First context menu
        if (
            contextMenuOpen &&
            !contextBlockMenuOpen &&
            !contextGeneralMenuOpen
            )
        {
            GUI.DrawTexture(new Rect(
                                fixedMousePosition.x,
                                Screen.height - fixedMousePosition.y,
                                330, 145
                                ), Noir);

            if (GUI.Button(new Rect(
                               fixedMousePosition.x + 15,
                               Screen.height - fixedMousePosition.y + 15,
                               300, 50
                               ), "Change block texture", style))
            {
                contextMenuOpen      = false;
                contextBlockMenuOpen = true;
            }
            else if (GUI.Button(new Rect(
                                    fixedMousePosition.x + 15,
                                    Screen.height - fixedMousePosition.y + 80,
                                    300, 50
                                    ), "General options", style))
            {
                contextMenuOpen        = false;
                contextGeneralMenuOpen = true;
            }
        }

        // Menu context for blocks
        if (!contextMenuOpen && contextBlockMenuOpen)
        {
            var line   = 0;
            var column = 0;
            var list   = new Rect[164];
            for (var iteration = 0; iteration < Textures.Length; iteration++)
            {
                list[iteration] = new Rect(
                    fixedMousePosition.x + 15 + (50 * column) + (15 * column),
                    (Screen.height - fixedMousePosition.y) + 15 + (50 * line) + (15 * line),
                    50, 50
                    );
                column++;
                if (column % 5 != 0)
                {
                    continue;
                }
                line++;
                column = 0;
            }

            GUI.DrawTexture(new Rect(
                                fixedMousePosition.x,
                                Screen.height - fixedMousePosition.y,
                                15 + (50 * 5) + (15 * 5),
                                15 + (50 * (line + 1)) + (15 * (line + 1))
                                ), Texture2D.whiteTexture);

            var index = 0;
            foreach (var txtObj in Textures)
            {
                if (GUI.Button(list[index], txtObj.texture, style))
                {
                    contextObject.GetComponent <SpriteRenderer>().sprite = Sprite.Create(
                        txtObj.texture,
                        new Rect(0, 0, Generator.BlockSize * 2, Generator.BlockSize * 2),
                        new Vector2(1, 1), Generator.BlockSize * 2
                        );
                    var uniq = contextObject.GetComponent <Uniq>();
                    ((string[])((object[])Generator.Levels[0])[2 + uniq.line])[uniq.column] = txtObj.name;
                }

                index++;
            }
        }

        // Menu context for general options
        if (!contextMenuOpen && contextGeneralMenuOpen)
        {
            GUI.DrawTexture(new Rect(
                                fixedMousePosition.x,
                                Screen.height - fixedMousePosition.y,
                                330, 145
                                ), Noir);

            if (GUI.Button(new Rect(
                               fixedMousePosition.x + 15,
                               Screen.height - fixedMousePosition.y + 15,
                               300, 50
                               ), "Save map", style))
            {
                SaveMap();
            }
            else if (GUI.Button(new Rect(
                                    fixedMousePosition.x + 15,
                                    Screen.height - fixedMousePosition.y + 80,
                                    300, 50
                                    ), "Load map", style))
            {
                LoadMap();
            }
        }
    }