コード例 #1
0
ファイル: ClientController.cs プロジェクト: wrighp/Innkeeper
 /// <summary>
 /// Called whenever a client joins the game
 /// Create a statblock to add to the scene
 /// </summary>
 override public void OnStartClient()
 {
     base.OnStartClient();
     if (isServer)
     {
         PagePacket packet = new PagePacket();
         packet.name     = "statblock";
         packet.pageType = PagePacket.PageType.StatBlockUI;
         StatBlockUIData sbd = new StatBlockUIData();
         sbd.name       = packet.name;
         packet.data    = SerializationManager.SerializeObject(sbd);
         packet.destroy = false;
         CmdSendPagePacket(packet);
     }
 }
コード例 #2
0
ファイル: FileManager.cs プロジェクト: wrighp/Innkeeper
    /// <summary>
    /// Propmt user to save a template based on the campaign
    /// </summary>
    /// <param name="template">Name of the selected template</param>
    /// <param name="campaignName">Name of the current campain</param>
    public void SaveTemplate(string template, string campaignName)
    {
        TextAsset[] templateAssets = Resources.LoadAll <TextAsset>("Templates");
        Dictionary <string, string> templateAssetNames = new Dictionary <string, string>();

        for (int i = 0; i < templateAssets.Length; i++)
        {
            templateAssetNames.Add(templateAssets[i].name, templateAssets[i].text);
        }

        string          path = SerializationManager.CreatePath(campaignName + "/" + template + "-mod.sbd");
        StatBlockUIData data = new StatBlockUIData();

        data.text = templateAssetNames[template];
        SerializationManager.SaveObject(path, data);
    }
コード例 #3
0
ファイル: PageManager.cs プロジェクト: wrighp/Innkeeper
    /// <summary>
    /// Load a page, called by a campaign file
    /// </summary>
    /// <param name="file">File to load a page for</param>
    public void SwitchPage(CampaignFile file)
    {
        DeletePage();
        Debug.Log("Switching to page: " + file.GetFileName());

        string fullPath = file.GetCampaign().GetCampaignName() + "/" + file.GetFileName() + "." + file.GetExtension();

        fullPath = SerializationManager.CreatePath(fullPath);

        //Get the file extension to determine what file type to display
        switch (file.GetExtension())
        {
        case "sbd":
        {
            pinManager.SetActive(false);
            currrentPage = Instantiate(prefabs[0], viewport.transform);
            StatBlockUIData uiData = (StatBlockUIData)SerializationManager.LoadObject(fullPath);

            currrentPage.GetComponent <StatBlockForm>().BuildPage(uiData);
            currrentPage.GetComponent <StatBlockForm>().fullPath = fullPath;
            currrentPage.GetComponent <StatBlockForm>().campaign = file.GetCampaign().GetCampaignName();
            break;
        }

        case "map":
        {
            pinManager.SetActive(true);
            currrentPage = Instantiate(prefabs[1], viewport.transform);
            SharedImageData uiData = (SharedImageData)SerializationManager.LoadObject(fullPath);
            currrentPage.GetComponent <MapForm>().campaign = file.GetCampaign().GetCampaignName();
            currrentPage.GetComponent <MapForm>().BuildPage(uiData);
            break;
        }

        default:
        {
            Debug.Log(file.GetExtension() + " is not a proper extension!");
            return;
        }
        }

        scrollRect.enabled = true;
        scrollRect.content = currrentPage.GetComponent <RectTransform>();

        SetActiveCampaignView(false);
    }
コード例 #4
0
ファイル: NetworkHandler.cs プロジェクト: wrighp/Innkeeper
    /// <summary>
    /// Build a page based on recived page packets
    /// </summary>
    /// <param name="packet">Contains all data needed to build a page</param>
    private void BuildPage(PagePacket packet)
    {
        switch (packet.pageType)
        {
        case PagePacket.PageType.StatBlockUI:
        {
            StatBlockUIData uiData = (StatBlockUIData)SerializationManager.LoadObject(packet.data);
            //Create statblockui
            GameObject parent    = GameObject.Find("Canvas/Page View/Viewport");
            GameObject statBlock = Instantiate(prefabs[0], parent.transform);
            statBlock.GetComponent <StatBlockForm>().BuildPage(uiData);
            pages.Add(packet.name, statBlock);
            break;
        }

        default:
        {
            Debug.LogError("Received Unsupported PagePacket type: " + packet.pageType);
            break;
        }
        }
    }
コード例 #5
0
    /// <summary>
    /// Call to create UI elements from StatBlockUIData
    /// Passing in data with an empty string creates based on template
    /// </summary>
    /// <param name="data">All the data needed to specify the page type</param>
    public override void BuildPage(PageData data)
    {
        StatBlockUIData uiData = (StatBlockUIData)data;

        /* rows holds a list object of lineData objectss
         * For each line in the statblock file passed to the parser,
         * a lineData struct is created which stores
         *      words:       array of strings separated by tabs,
         *                   modified to remove ` marks and [] brackets
         *      weights:     a list object of ints containing the weights
         *                   corresponding to the strings in words
         *                   e.g. words[i] has a weight weights[i]
         *      forms:       a list object of WordType enums that correspond
         *                   to each string in words:
         *                      String:      a regular string
         *                      StringInput: an alphanumeric input
         *                      NumInput:    a numeric input
         *                      Checked:     a checked checkbox
         *                      Unchecked:   an unchecked checkbox
         *                   e.g. words[i] having a field is forms[i]
         *      listing:     a ListType enum that denotes if this line
         *                   of data is the start of a list, the end of
         *                   a list, or neither
         *      totalWeight: the total weight of the line
         *                   NOTE: totalWeight = -1 indicates an empty
         *                   space. totalWeight = 0 indicates this line
         *                   is not visible
         */
        string sourceText;

        if (uiData.text == null)
        {
            sourceText = textAsset.text;
        }
        else
        {
            sourceText = uiData.text;
        }

        List <LineData> rows = StatBlockParser.StringToLineData(sourceText, stringWeight, numWeight, checkWeight);

        Transform layoutGroup = testLayout;

        GameObject.Instantiate(lineSegmentUI, layoutGroup);
        //Iterate through every row of lie data, creating the specified prefab, filling its contents with the user defined data
        for (int i = 0, rowsCount = rows.Count; i < rowsCount; i++)
        {
            LineData row = rows[i];

            if (row.listing == LineData.ListType.Start || row.listing == LineData.ListType.End)
            {
                continue;
            }
            if (row.totalWeight == 0)
            {
                //If "//" then skip line spacing
                continue;
            }
            Transform lineSpacer = ((GameObject)GameObject.Instantiate(lineSegmentUI, layoutGroup)).transform;
            if (row.totalWeight == -1)
            {
                //If "#" then skip building words
                continue;
            }

            for (int j = 0; j < row.words.Length; j++)
            {
                var text = row.words[j];

                GameObject obj;
                switch (row.forms[j])
                {
                case WordType.StringInput:
                    obj = (GameObject)GameObject.Instantiate(stringInputUI, lineSpacer);
                    obj.GetComponent <InputField>().text = text;
                    obj.GetComponent <InputField>().onEndEdit.AddListener(delegate { SaveStatblock(); });
                    break;

                case WordType.NumInput:
                    obj = (GameObject)GameObject.Instantiate(numInputUI, lineSpacer);
                    obj.GetComponent <InputField>().text = text;
                    obj.GetComponent <InputField>().onEndEdit.AddListener(delegate { SaveStatblock(); });
                    break;

                case WordType.Checked:
                    obj = (GameObject)GameObject.Instantiate(checkboxUIOn, lineSpacer);
                    obj.GetComponent <Toggle>().onValueChanged.AddListener(delegate { SaveStatblock(); });
                    break;

                case WordType.Unchecked:
                    obj = (GameObject)GameObject.Instantiate(checkboxUI, lineSpacer);
                    obj.GetComponent <Toggle>().onValueChanged.AddListener(delegate { SaveStatblock(); });
                    break;

                case WordType.String:
                    obj = (GameObject)GameObject.Instantiate(textUI, lineSpacer);
                    obj.GetComponent <Text>().text = text;
                    break;

                default:
                    break;
                }
            }
        }
    }
コード例 #6
0
    /// <summary>
    /// Call to get stat block data from ui elements
    /// </summary>
    /// <returns>Return a statblockuidata that can be converted to string</returns>
    public StatBlockUIData CreateStatBlockUIData()
    {
        StatBlockUIData uiData = new StatBlockUIData();
        List <LineData> rows   = new List <LineData>();

        //Loop through UI elements and convert to list of linedata

        //Iterate trhouh each row of elements
        for (int i = 0; i < transform.childCount; ++i)
        {
            LineData      lD    = new LineData();
            List <string> words = new List <string>();
            Transform     t     = testLayout.GetChild(i);

            //Iterate through each element addings its information to the statblockuidata
            for (int j = 0; j < t.childCount; ++j)
            {
                Transform child = t.GetChild(j);
                switch (child.tag)
                {
                case "Input":
                {
                    lD.forms.Add(WordType.StringInput);
                    words.Add(child.GetComponent <InputField>().text);
                    lD.totalWeight += stringWeight;
                    lD.weights.Add(stringWeight);
                    break;
                }

                case "NumInput":
                {
                    lD.forms.Add(WordType.NumInput);
                    words.Add(child.GetComponent <InputField>().text);
                    lD.totalWeight += numWeight;
                    lD.weights.Add(numWeight);
                    break;
                }

                case "Text":
                {
                    lD.forms.Add(WordType.String);
                    words.Add(child.GetComponent <Text>().text);
                    lD.totalWeight += stringWeight;
                    lD.weights.Add(stringWeight);
                    break;
                }

                case "ToggleOn":
                {
                    lD.forms.Add(WordType.Checked);
                    words.Add("on");
                    lD.totalWeight += checkWeight;
                    lD.weights.Add(checkWeight);
                    break;
                }

                case "ToggleOff":
                {
                    lD.forms.Add(WordType.Unchecked);
                    words.Add("off");
                    lD.totalWeight += checkWeight;
                    lD.weights.Add(checkWeight);
                    break;
                }

                default:
                {
                    Debug.LogError("Invalid type passed to CreateStatBlockUiData");
                    break;
                }
                }
            }
            lD.words = words.ToArray();
            //If empty line spacer set the total weight to 0
            if (t.childCount == 0)
            {
                lD.totalWeight = 0;
            }

            //Set weights
            lD.stringWeight = stringWeight;
            lD.numWeight    = numWeight;
            lD.checkWeight  = checkWeight;
            rows.Add(lD);
        }
        uiData.text = StatBlockParser.LineDataToString(rows, stringWeight, numWeight, checkWeight);
        return(uiData);
    }
コード例 #7
0
    /// <summary>
    /// Event Listener, Serialize and save the current statblock to the system
    /// </summary>
    public void SaveStatblock()
    {
        StatBlockUIData sbd = CreateStatBlockUIData();

        SerializationManager.SaveObject(fullPath, sbd);
    }