コード例 #1
0
ファイル: GameSelection.cs プロジェクト: spgarbet/valkyrie
    // Create a menu which will take up the whole screen and have options.  All items are dialog for destruction.
    public GameSelection()
    {
        // This will destroy all
        Destroyer.Destroy();

        Game game = Game.Get();

        game.gameType = new NoGameType();

        // Get the current content for games
        fcD2E = new FetchContent("D2E");
        fcMoM = new FetchContent("MoM");

        // Banner Image
        Sprite    bannerSprite;
        Texture2D newTex = Resources.Load("sprites/banner") as Texture2D;

        GameObject banner = new GameObject("banner");

        banner.tag = "dialog";

        banner.transform.parent = game.uICanvas.transform;

        RectTransform trans = banner.AddComponent <RectTransform>();

        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 1 * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());
        trans.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, (UIScaler.GetWidthUnits() - 18f) * UIScaler.GetPixelsPerUnit() / 2f, 18f * UIScaler.GetPixelsPerUnit());
        banner.AddComponent <CanvasRenderer>();


        UnityEngine.UI.Image image = banner.AddComponent <UnityEngine.UI.Image>();
        bannerSprite = Sprite.Create(newTex, new Rect(0, 0, newTex.width, newTex.height), Vector2.zero, 1);
        image.sprite = bannerSprite;
        image.rectTransform.sizeDelta = new Vector2(18f * UIScaler.GetPixelsPerUnit(), 7f * UIScaler.GetPixelsPerUnit());

        DialogBox db;

        Color startColor = Color.white;

        // If we need to import we can't play this type
        if (fcD2E.NeedImport())
        {
            startColor = Color.gray;
        }
        // Draw D2E button
        TextButton tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 30) / 2, 10), new Vector2(30, 4f), "Descent: Journeys in the Dark Second Edition", delegate { D2E(); }, startColor);

        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetMediumFont();
        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);

        // Draw D2E import button
        if (fcD2E.importAvailable)
        {
            if (fcD2E.NeedImport())
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 14.2f), new Vector2(10, 2f), "Import Content", delegate { Import("D2E"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
            else // Import OK, can redo
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 14.2f), new Vector2(10, 2f), "Reimport Content", delegate { Import("D2E"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
        }
        else // Import unavailable
        {
            db = new DialogBox(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 14.2f), new Vector2(10, 2f), "Import Unavailable", Color.red);
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
            db.AddBorder();
        }

        // Draw MoM button
        startColor = Color.white;
        if (fcMoM.NeedImport())
        {
            startColor = Color.gray;
        }
        tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 30) / 2, 19), new Vector2(30, 4f), "Mansions of Madness Second Edition", delegate { MoM(); }, startColor);
        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetMediumFont();
        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);

        // Draw MoM import button
        if (fcMoM.importAvailable)
        {
            if (fcMoM.NeedImport())
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 23.2f), new Vector2(10, 2f), "Import Content", delegate { Import("MoM"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
            else // Import OK, can redo
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 23.2f), new Vector2(10, 2f), "Reimport Content", delegate { Import("MoM"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
        }
        else // Import unavailable
        {
            db = new DialogBox(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 23.2f), new Vector2(10, 2f), "Import Unavailable", Color.red);
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
            db.AddBorder();
        }
        new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Exit", delegate { Exit(); }, Color.red);
    }
コード例 #2
0
    // Create a menu which will take up the whole screen and have options.  All items are dialog for destruction.
    public GameSelection()
    {
        // This will destroy all
        Destroyer.Destroy();

        Game game = Game.Get();

        game.gameType = new NoGameType();

        fcD2E = new FetchContent("D2E");
        fcMoM = new FetchContent("MoM");

        // Name.  We should replace this with a banner
        DialogBox db = new DialogBox(new Vector2(2, 1), new Vector2(UIScaler.GetWidthUnits() - 4, 3), "Valkyrie");

        db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetLargeFont();

        Color startColor = Color.white;

        if (fcD2E.NeedImport())
        {
            startColor = Color.gray;
        }
        TextButton tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 30) / 2, 10), new Vector2(30, 4f), "Descent: Journeys in the Dark Second Edition", delegate { D2E(); }, startColor);

        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetMediumFont();
        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);

        if (fcD2E.importAvailable)
        {
            if (fcD2E.NeedImport())
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 14.2f), new Vector2(10, 2f), "Import Content", delegate { Import("D2E"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
            else
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 14.2f), new Vector2(10, 2f), "Reimport Content", delegate { Import("D2E"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
        }
        else
        {
            db = new DialogBox(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 14.2f), new Vector2(10, 2f), "Import Unavailable", Color.red);
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
            db.AddBorder();
        }

        startColor = Color.white;
        if (fcMoM.NeedImport())
        {
            startColor = Color.gray;
        }
        tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 30) / 2, 19), new Vector2(30, 4f), "Mansions of Madness Second Edition", delegate { MoM(); }, startColor);
        tb.button.GetComponent <UnityEngine.UI.Text>().fontSize   = UIScaler.GetMediumFont();
        tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);

        if (fcMoM.importAvailable)
        {
            if (fcMoM.NeedImport())
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 23.2f), new Vector2(10, 2f), "Import Content", delegate { Import("MoM"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
            else
            {
                tb = new TextButton(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 23.2f), new Vector2(10, 2f), "Reimport Content", delegate { Import("MoM"); });
                tb.background.GetComponent <UnityEngine.UI.Image>().color = new Color(0, 0.03f, 0f);
            }
        }
        else
        {
            db = new DialogBox(new Vector2((UIScaler.GetWidthUnits() - 10) / 2, 23.2f), new Vector2(10, 2f), "Import Unavailable", Color.red);
            db.textObj.GetComponent <UnityEngine.UI.Text>().fontSize = UIScaler.GetMediumFont();
            db.AddBorder();
        }
        new TextButton(new Vector2(1, UIScaler.GetBottom(-3)), new Vector2(8, 2), "Exit", delegate { Exit(); }, Color.red);
    }
コード例 #3
0
    // Load a saved game, does nothing if file does not exist
    public static void Load()
    {
        Game game = Game.Get();

        try
        {
            if (File.Exists(SaveFile()))
            {
                if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie"))
                {
                    Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie");
                }
                if (!Directory.Exists(Path.GetTempPath() + "/Valkyrie/Load"))
                {
                    Directory.CreateDirectory(Path.GetTempPath() + "/Valkyrie/Load");
                }

                Directory.Delete(Path.GetTempPath() + "/Valkyrie/Load", true);
                ZipFile zip = ZipFile.Read(SaveFile());
                zip.ExtractAll(Path.GetTempPath() + "/Valkyrie/Load");
                zip.Dispose();

                // Check that quest in save is valid
                QuestData.Quest q = new QuestData.Quest(Path.GetTempPath() + "/Valkyrie/Load/quest");
                if (!q.valid)
                {
                    ValkyrieDebug.Log("Error: save contains unsupported quest version." + System.Environment.NewLine);
                    Destroyer.MainMenu();
                    return;
                }

                string data = File.ReadAllText(Path.GetTempPath() + "/Valkyrie/Load/save.ini");

                IniData saveData = IniRead.ReadFromString(data);

                saveData.data["Quest"]["path"] = Path.GetTempPath() + "/Valkyrie/Load/quest/quest.ini";

                saveData.Get("Quest", "valkyrie");

                if (FetchContent.VersionNewer(game.version, saveData.Get("Quest", "valkyrie")))
                {
                    ValkyrieDebug.Log("Error: save is from a future version." + System.Environment.NewLine);
                    Destroyer.MainMenu();
                    return;
                }

                if (!FetchContent.VersionNewerOrEqual(minValkyieVersion, saveData.Get("Quest", "valkyrie")))
                {
                    ValkyrieDebug.Log("Error: save is from an old unsupported version." + System.Environment.NewLine);
                    Destroyer.MainMenu();
                    return;
                }

                Destroyer.Dialog();

                // Restart contend data so we can select from save
                game.cd = new ContentData(game.gameType.DataDirectory());
                // Check if we found anything
                if (game.cd.GetPacks().Count == 0)
                {
                    ValkyrieDebug.Log("Error: Failed to find any content packs, please check that you have them present in: " + game.gameType.DataDirectory() + System.Environment.NewLine);
                    Application.Quit();
                }

                game.cd.LoadContentID("");
                // Load the base content

                // Load content that the save game uses
                Dictionary <string, string> packs = saveData.Get("Packs");
                foreach (KeyValuePair <string, string> kv in packs)
                {
                    game.cd.LoadContentID("");
                    game.cd.LoadContentID(kv.Key);
                }

                // This loads the game
                new Quest(saveData);

                // Draw things on the screen
                game.heroCanvas.SetupUI();
                game.heroCanvas.UpdateImages();
                game.heroCanvas.UpdateStatus();

                if (game.gameType.DisplayMorale())
                {
                    game.moraleDisplay = new MoraleDisplay();
                }
                if (!game.gameType.DisplayHeroes())
                {
                    game.heroCanvas.Clean();
                }

                // Create the menu button
                new MenuButton();
                new LogButton();
                game.stageUI = new NextStageButton();
            }
        }
        catch (System.Exception e)
        {
            ValkyrieDebug.Log("Error: Unable to open save file: " + SaveFile() + " " + e.Message);
            Application.Quit();
        }
    }