Esempio n. 1
0
    /// <summary>
    /// 1行パネルを作成する
    /// </summary>
    /// <returns></returns>
    public Image CreateRowPanel_200(GameObject Content, float offsetY)
    {
        Image panel = UICreator.CreatePanel(Content);

        //サイズ調整
        RectTransform rectTransform = panel.GetComponent <RectTransform>();

        rectTransform.anchorMin        = new Vector2(0, 1);
        rectTransform.anchorMax        = new Vector2(1, 1);
        rectTransform.pivot            = new Vector2(0.5f, 1);
        rectTransform.anchoredPosition = Vector2.zero;
        rectTransform.offsetMax        = new Vector2(0, offsetY * -180);
        rectTransform.offsetMin        = new Vector2(0, -180f);
        rectTransform.sizeDelta        = new Vector2(0, 180f);

        return(panel);
    }
Esempio n. 2
0
    /// <summary>
    /// 記事パネルを生成する
    /// </summary>
    /// <param name="parent"></param>
    /// <returns></returns>
    public IEnumerator CreateNewsPanel_200(GameObject parent, float offsetMinX, MsgBaseNewsData news)
    {
        //パネルを生成する
        Image panel = UICreator.CreatePanel(parent);

        //サイズ調整
        RectTransform rectTransform = panel.GetComponent <RectTransform>();

        rectTransform.anchorMin        = new Vector2(0.5f, 0);
        rectTransform.anchorMax        = new Vector2(0.5f, 1);
        rectTransform.pivot            = new Vector2(0.5f, 0.5f);
        rectTransform.anchoredPosition = Vector2.zero;
        rectTransform.offsetMax        = Vector2.zero;
        rectTransform.offsetMin        = new Vector2(offsetMinX, 0);
        rectTransform.sizeDelta        = new Vector2(638, 0);

        //コンテンツを生成
        CreateNewsImage_200(panel.gameObject, news);
        StartCoroutine(CreateNewsText200(panel.gameObject, news.TITLE));

        yield return(panel);
    }
Esempio n. 3
0
        void InitUI()
        {
            // 主Canvs 开关
            #region MainCanvas
            mainCanvas = UICreator.CreateCanvas(name: "IllustratedHandbookCanvas");
#if UNITY_EDITOR
            mainCanvas.GetComponent <Canvas>().renderMode  = RenderMode.ScreenSpaceCamera;
            mainCanvas.GetComponent <Canvas>().worldCamera = GameObject.Find("Main Camera").GetComponent <Camera>();
#else
            mainCanvas.GetComponent <Canvas>().renderMode = RenderMode.ScreenSpaceOverlay;
#endif
            mainCanvas.GetComponent <Canvas>().sortingLayerName = "GUI";
            mainCanvas.GetComponent <Canvas>().sortingOrder     = 998; // ShowTips 的 sortingorder 为1000
            DontDestroyOnLoad(mainCanvas);
            mainPanel        = UICreator.CreatePanel(mainCanvas.gameObject, "MainPanel");
            mainPanel.sprite = Resources.Load("Graphics/BaseUI/GUI_Window_Big_Black_NoColor", typeof(Sprite)) as Sprite;
            mainPanel.color  = new Color32(100, 100, 100, 255);
            SetAnchor(mainPanel.gameObject, v3(1), v2(0.5f), v2(0.5f), Vector2.zero, Vector2.zero).sizeDelta = v2(700, 600);
            #endregion

            // 主面板
            #region MainPanel
            handbookPanel = UICreator.CreatePanel(mainPanel.gameObject, "IllustratedHandbookPanel");
            SetAnchor(handbookPanel.gameObject, v3(1), v2(0), v2(1), v2(10), v2(-10, -25));

            titlePanel = UICreator.CreatePanel(handbookPanel.gameObject, "TitlePanel");
            SetAnchor(titlePanel.gameObject, v3(1), v2(0.5f, 1), v2(0.5f, 1), v2(0), v2(0)).sizeDelta = v2(680, 50);
            titlePanel.rectTransform.anchoredPosition3D = v3(0, -25, 0);

            titlePanel.gameObject.AddComponent(typeof(EventTrigger));
            titlePanelOndrag = titlePanel.GetComponent <EventTrigger>();
            EventTrigger.Entry eventEntry = new EventTrigger.Entry();
            eventEntry.eventID = EventTriggerType.Drag;
            eventEntry.callback.AddListener((data) =>
            {
                OnDragDelegate((PointerEventData)data);
            });
            titlePanelOndrag.triggers.Add(eventEntry);


            titleText = CreateText("TitleText", titlePanel.gameObject, "<b>图鉴/添加物品 1.0.2</b>", Color.white, 27, v2(0.5f, 1), v2(0.5f, 1), v2(680, 30), v2(0, -25));
            #endregion


            // 加载中面板
            #region LoadingPanel
            loadingPanel = UICreator.CreatePanel(handbookPanel.gameObject, "LoadingPanel");
            SetAnchor(loadingPanel.gameObject, v3(1), v2(0), v2(1), v2(0), v2(0, -50));

            // 加载中文字区域
            loadingTextPanel        = UICreator.CreatePanel(loadingPanel.gameObject, "LoadingTextPanel");
            loadingTextPanel.sprite = Resources.Load("Graphics/BaseUI/GUI_BarBack", typeof(Sprite)) as Sprite;
            loadingTextPanel.color  = new Color32(255, 255, 255, 44);
            SetAnchor(loadingTextPanel.gameObject, v3(1), v2(0), v2(1), v2(20, 130), v2(-20, 0));

            tipText = CreateText("TipText", loadingTextPanel.gameObject,
                                 "游戏未开始 尚未加载数据\n\n请先开始游戏~\n\n\n" +
                                 "<size=16><color=white><b>Tips:</b>\n Ctrl + F11开关窗口\n<b>拖动标题</b>可以移动窗口哦\n" +
                                 "获取书籍会随机残页、无法查看促织\n" +
                                 "获取物品后需重新打开背包才看的到\n推荐配合《功法书籍显示》MOD使用\n<color=red>NEW</color> 在人物菜单切换到同道可以将物品直接添加到同道背包(不会影响亲密)\n" +
                                 "<b>工具无错</b> 请<b>自觉</b>平衡游戏体验</color></size>",
                                 new Color32(0, 255, 213, 255), 28, v2(0.5f), v2(0.5f), v2(600, 400), v2(0)
                                 );

            aboutText = CreateText("AboutText", loadingPanel.gameObject, "By: yyuueexxiinngg", Color.white, 14, v2(0), v2(0), v2(160, 30), v2(128.8f, 13.9f));
            aboutText.GetComponent <Text>().alignment = TextAnchor.UpperLeft;

            NGAButton = CreateButton("NGAButton", loadingPanel.gameObject, "点此打开本MOD NGA发布地址", Color.white, "Graphics/BaseUI/GUI_Base", Color.black, v2(0.5f, 0), v2(0.5f, 0), v2(500, 31), v2(0, 100));
            NGAButton.GetComponent <Button>().onClick.AddListener(() =>
            {
                Application.OpenURL("https://nga.178.com/read.php?tid=15239374");
            });

            GithubButton = CreateButton("GithubBotton", loadingPanel.gameObject, "点此打开MOD开源项目Github地址", Color.white, "Graphics/BaseUI/GUI_Base", Color.black, v2(0.5f, 0), v2(0.5f, 0), v2(500, 31), v2(0, 55));
            GithubButton.GetComponent <Button>().onClick.AddListener(() =>
            {
                Application.OpenURL("https://github.com/yyuueexxiinngg/Taiwu_mods");
            });
            #endregion

            // 过滤面板
            #region FilterPanel
            filterPanel = UICreator.CreatePanel(handbookPanel.gameObject, "FilterPanel");
            SetAnchor(filterPanel.gameObject, v3(1), v2(0), v2(1), v2(50, 50), v2(-50, -50));

            itemTypePanel = UICreator.CreatePanel(filterPanel.gameObject, "ItemTypeGrid");
            SetAnchor(itemTypePanel.gameObject, v3(1), v2(0), v2(1), v2(0, 100), v2(0, -50));

            itemTypePanel.gameObject.AddComponent <GridLayoutGroup>();
            itemTypePanel.GetComponent <GridLayoutGroup>().cellSize = v2(110, 30);
            itemTypePanel.GetComponent <GridLayoutGroup>().spacing  = v2(6, 3);

            CreateText("FilterTypeLabel", filterPanel.gameObject, "当前选择种类:", Color.white, 14, v2(0, 1), v2(0, 1), v2(160, 30), v3(50, -30, 0));
            filterTypeCurrent = CreateText("FilterTypeCurrent", filterPanel.gameObject, "未初始化", Color.white, 20, v2(0, 1), v2(0, 1), v2(160, 30), v3(120, -30, 0));


            itemLevelPanel = UICreator.CreatePanel(filterPanel.gameObject, "ItemLevelGrid");
            SetAnchor(itemLevelPanel.gameObject, v3(1), v2(0), v2(1), v2(0), v2(0, -370));

            itemLevelPanel.gameObject.AddComponent <GridLayoutGroup>();
            itemLevelPanel.GetComponent <GridLayoutGroup>().cellSize = v2(140, 30);
            itemLevelPanel.GetComponent <GridLayoutGroup>().spacing  = v2(6, 3);

            CreateText("FilterLevelLabel", filterPanel.gameObject, "当前选择品级:", Color.white, 14, v2(0, 1), v2(0, 1), v2(160, 30), v3(300, -30, 0));
            filterLevelCurrent = CreateText("FilterLevelCurrent", filterPanel.gameObject, itemLevel[selectedLevel].Split('|')[0], Color.white, 20, v2(0, 1), v2(0, 1), v2(160, 30), v3(380, -30, 0));

            var filterCancelBtn  = CreateButton("FilterCancelBtn", filterPanel.gameObject, "取消", Color.white, "Graphics/BaseUI/GUI_ValuBack", Color.white, v2(0), v2(0), v2(200, 30), v2(160, -25));
            var filterRefreshBtn = CreateButton("FilterRefreshBtn", filterPanel.gameObject, "刷新物品列表", Color.white, "Graphics/BaseUI/GUI_ValuBack", Color.white, v2(1, 0), v2(1, 0), v2(200, 30), v2(-160, -25));

            filterCancelBtn.GetComponent <Button>().onClick.AddListener(() =>
            {
                filterPanel.gameObject.SetActive(false);
                loadedPanel.gameObject.SetActive(true);
            });

            filterRefreshBtn.GetComponent <Button>().onClick.AddListener(() =>
            {
                selectedType  = selectedTypeUnsaved;
                selectedLevel = selectedLevelUnsaved;
                // 清空物品列表
                itemList = new Dictionary <int, Dictionary <int, string> >();

                if (selectedType != 0) // 如果选择不是全部
                {
                    foreach (var item in dataInstance.presetitemDate)
                    {
                        // item.Value[5]即为物品种类 item.Value[8]即为物品品级
                        if (int.Parse(item.Value[5]) == selectedType && (selectedLevel == 0 || int.Parse(item.Value[8]) == selectedLevel))
                        {
                            itemList[item.Key] = item.Value;
                        }
                    }
                }
                else // 如果是全部
                {
                    if (selectedLevel == 0) // 如果品级是全部
                    {
                        itemList = dataInstance.presetitemDate;
                    }
                    else
                    {
                        foreach (var item in dataInstance.presetitemDate)
                        {
                            if (int.Parse(item.Value[8]) == selectedLevel)
                            {
                                itemList[item.Key] = item.Value;
                            }
                        }
                    }
                }
                DrawItems();
                filterPanel.gameObject.SetActive(false);
                loadedPanel.gameObject.SetActive(true);
            });


            #endregion


            // 加载完成后面板
            #region LoadedPanel
            loadedPanel = UICreator.CreatePanel(handbookPanel.gameObject, "LoadedPanel");
            SetAnchor(loadedPanel.gameObject, v3(1), v2(0), v2(1), v2(0, 50), v2(0, -50));


            itemPanel        = UICreator.CreatePanel(loadedPanel.gameObject, "ItemPanel");
            itemPanel.sprite = Resources.Load("Graphics/BaseUI/GUI_BarBack", typeof(Sprite)) as Sprite;
            itemPanel.color  = new Color32(255, 255, 255, 44);
            SetAnchor(itemPanel.gameObject, v3(1), v2(0), v2(1), v2(20, 0), v2(-20, 0));

            var selectionPanel = UICreator.CreatePanel(itemPanel.gameObject, "SelectionPanel");
            SetAnchor(selectionPanel.gameObject, v3(1), v2(0), v2(1), v2(30, 415), v2(-30, -15));

            var itemFilterButton = CreateButton("ItemFilterButton", selectionPanel.gameObject, "过滤", Color.white, "Graphics/BaseUI/GUI_ValuBack", Color.white, v2(0.5f), v2(0.5f), v2(160, 30), v3(0));
            itemFilterButton.GetComponent <Button>().onClick.AddListener(() =>
            {
                string[] itemTypes = itemType.Split('|');
                filterTypeCurrent.GetComponent <Text>().text  = itemTypes[selectedType];
                filterLevelCurrent.GetComponent <Text>().text = itemLevel[selectedLevel].Split('|')[0];
                loadedPanel.gameObject.SetActive(false);
                filterPanel.gameObject.SetActive(true);
            });

            // 物品栏
            itemGrid = new GameObject("ItemGrid", typeof(GridLayoutGroup));
            itemGrid.transform.SetParent(itemPanel.transform);
            var itemGridComponent = itemGrid.GetComponent <GridLayoutGroup>();
            itemGridComponent.cellSize    = v2(65, 65);
            itemGridComponent.startCorner = GridLayoutGroup.Corner.UpperLeft;
            itemGridComponent.startAxis   = GridLayoutGroup.Axis.Horizontal;

            SetAnchor(itemGrid.gameObject, v3(1), v2(0), v2(1), v2(30, 0), v2(0, -50));

            itemBack = Resources.LoadAll <Sprite>("Graphics/ItemIcon/ItemIconBack");
            itemIcon = Resources.LoadAll <Sprite>("Graphics/ItemIcon/ItemIcon");


            EventTrigger.Entry itemSlotOnMouseEnterEntry = new EventTrigger.Entry();
            itemSlotOnMouseEnterEntry.eventID = EventTriggerType.PointerEnter;
            itemSlotOnMouseEnterEntry.callback.AddListener((data) =>
            {
                OnMouseEnterDelegate((PointerEventData)data);
            });

            EventTrigger.Entry itemSlotOnMouseExitEntry = new EventTrigger.Entry();
            itemSlotOnMouseExitEntry.eventID = EventTriggerType.PointerExit;
            itemSlotOnMouseExitEntry.callback.AddListener((data) =>
            {
                OnMouseExitDelegate((PointerEventData)data);
            });

            // 物品槽
            for (int i = 0; i < 54; i++)
            {
                var itemSlot = new GameObject("ItemSlot|" + i, typeof(RectTransform));
                itemSlot.transform.SetParent(itemGrid.transform);
                itemSlot.transform.localScale = v3(1);

                itemSlot.AddComponent(typeof(Button));
                itemSlot.GetComponent <Button>().onClick.AddListener(
                    () =>
                {
                    if (itemSlot.name.Split('|')[1] != "10000")
                    {
                        if (DateFile.instance.GetItem(ActorMenu.instance.actorMenu.activeInHierarchy ? ActorMenu.instance.acotrId : DateFile.instance.MianActorID(), int.Parse(itemSlot.name.Split('|')[1]), 1, true) > 0)
                        {
                            TipsWindow.instance.SetTips(5007, new string[] { dataInstance.GetActorName(ActorMenu.instance.actorMenu.activeInHierarchy ? ActorMenu.instance.acotrId : DateFile.instance.MianActorID()), itemList[int.Parse(itemSlot.name.Split('|')[1])][0], "" }, 100);
                        }
                        else
                        {
                            TipsWindow.instance.SetTips(0, new string[] { "无法添加此物品~" }, 100);
                        }
                    }
                    else
                    {
                        TipsWindow.instance.SetTips(0, new string[] { "无法添加促织~" }, 100);
                    }
                }
                    );

                itemSlot.AddComponent(typeof(EventTrigger));
                var itemSlotOnHover = itemSlot.GetComponent <EventTrigger>();
                itemSlotOnHover.triggers.Add(itemSlotOnMouseEnterEntry);
                itemSlotOnHover.triggers.Add(itemSlotOnMouseExitEntry);

                var itemBackObj = new GameObject("ItemBack", typeof(Image));
                itemBackObj.transform.SetParent(itemSlot.transform);
                itemBackObj.GetComponent <Image>().sprite            = itemBack[4];
                itemBackObj.GetComponent <Image>().color             = new Color32(254, 47, 17, 255);
                itemBackObj.transform.localScale                     = v3(1);
                itemBackObj.GetComponent <RectTransform>().sizeDelta = v2(60, 60);
                itemBackObj.GetComponent <Image>().preserveAspect    = true;

                var itemIconObj = new GameObject("ItemIcon", typeof(Image));
                itemIconObj.transform.SetParent(itemBackObj.transform);
                itemIconObj.GetComponent <Image>().sprite            = itemIcon[i];
                itemIconObj.transform.localScale                     = v3(1);
                itemIconObj.GetComponent <RectTransform>().sizeDelta = v2(40, 40);

                // 物品下标文字 i.e. 0/0 本MOD未使用到所以没有赋值
                CreateText("ItemText", itemBackObj, "", Color.white, 14, v2(0), v2(1, 0.3f), v2(1), v3(0));
                itemIconObj.GetComponent <Image>().preserveAspect = true;

                // itemSlot.SetActive(false);
                Vector3 position = itemSlot.transform.localPosition;
                position.z = 0;
                itemSlot.transform.localPosition = position;

                itemSlots.Add(itemSlot);
            }

            prePageButton  = CreateButton("PrePageBotton", loadedPanel.gameObject, "上一页", Color.white, "Graphics/BaseUI/GUI_ValuBack", Color.white, v2(0), v2(0), v2(200, 30), v2(160, -25));
            nextPageButton = CreateButton("PrePageBotton", loadedPanel.gameObject, "下一页", Color.white, "Graphics/BaseUI/GUI_ValuBack", Color.white, v2(1, 0), v2(1, 0), v2(200, 30), v2(-160, -25));

            var itemPageTextObj = CreateText("ItemPageText", loadedPanel.gameObject, "0/0", Color.white, 20, v2(0.5f, 0), v2(0.5f, 0), v2(80, 30), v3(0, -25, 0));
            itemPageText = itemPageTextObj.GetComponent <Text>();

            // 初始化页标
            itemPageText.text = "1/1";

            prePageButton.GetComponent <Button>().onClick.AddListener(
                () =>
            {
                if (itemSlotPage > 0)
                {
                    // 如果到达过最后一页 遍历一遍itemSlots全部激活
                    if (finalPageReached)
                    {
                        foreach (var itemSlot in itemSlots)
                        {
                            itemSlot.SetActive(true);
                        }
                    }

                    --itemSlotPage;

                    // 用以获取当前循环对应的itemSlot
                    int index = 0;

                    foreach (var item in itemList.Skip(itemSlotPage * 54).Take(54))
                    {
                        itemSlots[index].name = "ItemSlot|" + item.Key;
                        itemSlots[index].transform.GetChild(0).GetChild(0).GetComponent <Image>().sprite = itemIcon[int.Parse(item.Value[98])];
                        itemSlots[index].transform.GetChild(0).GetComponent <Image>().sprite             = itemBack[int.Parse(item.Value[4])];
                        itemSlots[index].transform.GetChild(0).GetChild(1).GetComponent <Text>().text    = item.Value[0];
                        Color backgroundColor = Color.white;
                        ColorUtility.TryParseHtmlString(itemLevel[int.Parse(item.Value[8])].Split('|')[1], out backgroundColor);
                        itemSlots[index].transform.GetChild(0).GetComponent <Image>().color = backgroundColor;
                        index++;
                    }

                    itemPageText.text = string.Format("{0}/{1}", itemSlotPage + 1, itemList.Count % 54 == 0 ? itemList.Count / 54 : (itemList.Count / 54) + 1);
                }
            }
                );

            nextPageButton.GetComponent <Button>().onClick.AddListener(
                () =>
            {
                if (itemSlotPage < itemList.Count / 54)
                {
                    ++itemSlotPage;

                    int index = 0;

                    foreach (var item in itemList.Skip(itemSlotPage * 54).Take(54))
                    {
                        if (itemSlotPage * 54 <= itemList.Count - 54)
                        {
                            finalPageReached = false;
                        }
                        else
                        {
                            finalPageReached = true;
                        }
                        itemSlots[index].name = "ItemSlot|" + item.Key;
                        itemSlots[index].transform.GetChild(0).GetChild(0).GetComponent <Image>().sprite = itemIcon[int.Parse(item.Value[98])];
                        itemSlots[index].transform.GetChild(0).GetComponent <Image>().sprite             = itemBack[int.Parse(item.Value[4])];
                        itemSlots[index].transform.GetChild(0).GetChild(1).GetComponent <Text>().text    = item.Value[0];
                        Color backgroundColor = Color.white;
                        ColorUtility.TryParseHtmlString(itemLevel[int.Parse(item.Value[8])].Split('|')[1], out backgroundColor);
                        itemSlots[index].transform.GetChild(0).GetComponent <Image>().color = backgroundColor;
                        index++;
                    }

                    itemPageText.text = string.Format("{0}/{1}", itemSlotPage + 1, itemList.Count % 54 == 0 ? itemList.Count / 54 : (itemList.Count / 54) + 1);

                    if (finalPageReached)
                    {
                        for (int i = 53; i >= index; i--)
                        {
                            itemSlots[i].SetActive(false);
                        }
                    }
                }
            }
                );
            #endregion

            loadedPanel.gameObject.SetActive(false);
            loadingPanel.gameObject.SetActive(true);
            filterPanel.gameObject.SetActive(false);
        }