Exemplo n.º 1
0
public void Main(string argument)
{
    try
    {
        Echo("Called with " + argument);
        clearScreen();
        string modes = "Static Grid:";
        if (filter_staticGrids)
        {
            modes += green;
        }
        else
        {
            modes += red;
        }
        modes += " Add mode:";
        if (add_mode)
        {
            modes += green;
        }
        else
        {
            modes += red;
        }
        modes += " Group mode:";
        if (group_mode)
        {
            modes += green;
        }
        else
        {
            modes += red;
        }
        writeScreen(modes + "\n");
        int opt;
        if (argument == "reset")
        {
            updatePresets();
            updateControls();
            updateContainers();
            menu("containers");
        }
        else if (argument == "next")
        {
            if (offset < totalContainers)
            {
                offset += 6;
            }
            menu();
        }
        else if (argument == "back")
        {
            if (offset >= 6)
            {
                offset -= 6;
            }
            menu();
        }
        else if (int.TryParse(argument, out opt))
        {
            if (c_menu == "containers")
            {
                if (offset == 0 && opt == 1)
                {
                    menu("options");
                    return;
                }
                else if (offset + opt < totalContainers)
                {
                    c_container = containers[offset + opt - 2];
                    c_group     = null;
                    string name = rgx_tim.Replace(c_container.CustomName, "");
                    writeScreen("Configuring: " + name + "\n");
                    string current = rgx_tim.Match(c_container.CustomName).Groups[1].Value;
                    if (current == "")
                    {
                        writeScreen(red + "No TiM\n");
                    }
                    else
                    {
                        writeScreen("Existing:\n" + yellow + string.Join("\n", current.Split(' ')) + green + "\n");
                    }
                }
                else
                {
                    c_group     = groups[offset + opt - 2 - totalContainers];
                    c_container = null;
                    writeScreen("Configuring GROUP: " + c_group.Name + "\n");
                    List <IMyCargoContainer> g_containers = new List <IMyCargoContainer>();
                    c_group.GetBlocksOfType <IMyCargoContainer>(g_containers);
                    for (int i = 0; i < g_containers.Count; i++)
                    {
                        string name    = rgx_tim.Replace(g_containers[i].CustomName, "");
                        string current = rgx_tim.Match(g_containers[i].CustomName).Groups[1].Value;
                        writeScreen(green + "Item: " + name + "\n");
                        if (current == "")
                        {
                            writeScreen(red + "No TiM\n");
                        }
                        else
                        {
                            writeScreen("Existing:" + yellow + string.Join("\n" + yellow, current.Split(' ')) + "\n");
                        }
                    }
                    offset = 0;
                    total  = timPresets.Count;
                }
                menu("presets");
            }
            else if (c_menu == "presets")
            {
                if (c_container != null)
                {
                    string name = rgx_tim.Replace(c_container.CustomName, "");
                    name.Trim();

                    string[] keys = new string[timPresets.Keys.Count];
                    timPresets.Keys.CopyTo(keys, 0);
                    var preset = timPresets[keys[opt + offset - 1]];

                    string current = rgx_tim.Match(c_container.CustomName).Groups[1].Value;
                    writeScreen("Configuring: " + name + "\n");

                    string expanded = "";
                    if (add_mode)
                    {
                        expanded = string.Join(" ", current, preset);
                    }
                    if (expanded != "")
                    {
                        expanded = "[TIM " + expanded + "]";
                    }
                    c_container.SetCustomName(name + " " + expanded);

                    if (expanded == "")
                    {
                        writeScreen(red + "No TiM\n");
                    }
                    else
                    {
                        writeScreen("Existing:\n" + yellow + string.Join("\n" + green, expanded.Split(' ')) + "\n");
                    }
                }
                else
                {
                    writeScreen("Configuring GROUP: " + c_group.Name + "\n");

                    string[] keys = new string[timPresets.Keys.Count];
                    timPresets.Keys.CopyTo(keys, 0);
                    var preset = timPresets[keys[opt + offset - 1]];

                    List <IMyCargoContainer> g_containers = new List <IMyCargoContainer>();
                    c_group.GetBlocksOfType <IMyCargoContainer>(g_containers);
                    for (int i = 0; i < g_containers.Count; i++)
                    {
                        var    container = g_containers[i];
                        string name      = rgx_tim.Replace(container.CustomName, "");
                        name.Trim();
                        string current = rgx_tim.Match(container.CustomName).Groups[1].Value;
                        writeScreen(green + "Item: " + name + "\n");

                        string expanded = preset;
                        if (add_mode)
                        {
                            expanded = string.Join(" ", current, preset);
                        }
                        if (expanded != "")
                        {
                            expanded = "[TIM " + expanded + "]";
                        }
                        container.SetCustomName(name + " " + expanded);

                        if (expanded == "")
                        {
                            writeScreen(red + "No TiM\n");
                        }
                        else
                        {
                            writeScreen("Existing:" + yellow + string.Join("\n" + yellow, expanded.Split(' ')) + "\n");
                        }
                    }
                }
                menu();
            }
            else if (c_menu == "options")
            {
                if (opt == 1)
                {
                    filter_staticGrids = !filter_staticGrids;
                }
                if (opt == 2)
                {
                    add_mode = !add_mode;
                }
                if (opt == 3)
                {
                    group_mode = !group_mode;
                }
                clearScreen();
                modes = "Static Grid:";
                if (filter_staticGrids)
                {
                    modes += green;
                }
                else
                {
                    modes += red;
                }
                modes += " Add mode:";
                if (add_mode)
                {
                    modes += green;
                }
                else
                {
                    modes += red;
                }
                modes += " Group mode:";
                if (group_mode)
                {
                    modes += green;
                }
                else
                {
                    modes += red;
                }
                writeScreen(modes + "\n");
                menu();
            }
        }
        else
        {
            menu();
        }
    }
    catch (System.Exception ex)
    {
        writeScreen("I Crashed:\n");
        writeScreen(ex.Message + "\n");
        writeScreen(ex.StackTrace + "\n");
    }
}