예제 #1
0
    // PopulateCharmList - Generates the list of charms the player currently owns.
    public void PopulateCharmList()
    {
        // For every charm the player has...
        for (int i = 0; i < gm.marble.charms.Count; i++)
        {
            // Instantiate the button and put it where it belongs,
            CharmButton newButton = Instantiate(charmButton).GetComponent <CharmButton>();
            newButton.transform.SetParent(charmContainer.transform);

            // Update the button's info,
            newButton.charmIcon.sprite = gm.marble.charms[i].data.icon;
            newButton.charmIcon.color  = gm.marble.charms[i].data.tint;
            newButton.charmName.text   = gm.marble.charms[i].type;
            newButton.charmCost.text   = gm.marble.charms[i].data.cost.ToString();
            newButton.equippedIcon.gameObject.SetActive(gm.marble.charms[i].equipped);

            // Make the button do things when clicked,
            newButton.GetComponent <Button>().onClick.AddListener(gm.marble.charms[i].ToggleEquip);
            int i2 = i;                 // This is necessary to make the next line function properly.
            newButton.GetComponent <Button>().onClick.AddListener(() => { newButton.equippedIcon.gameObject.SetActive(gm.marble.charms[i2].equipped); });

            // Make the buttons show descriptions when hovered over by using code I don't fully understand,
            EventTrigger.TriggerEvent trigger = new EventTrigger.TriggerEvent();
            EventTrigger.Entry        entry   = new EventTrigger.Entry();

            trigger.AddListener((eventData) => { description.text = gm.marble.charms[i2].data.description; });

            entry.eventID  = EventTriggerType.PointerEnter;
            entry.callback = trigger;

            newButton.GetComponent <EventTrigger>().triggers.Add(entry);


            // ... and set the scale back to one? Why this is necessary I don't know, but it is.
            newButton.transform.localScale = Vector3.one;
        }
    }
예제 #2
0
        // 初始化设置
        private void InitializeSetting()
        {
            // 设置窗体属性
            this.Icon = Properties.Resources.icon;
            this.Text = "过滤规则测试";

            // 绘制窗体背景
            DrawFormBackground();

            #region 创建窗体组件
            // 创建关闭系统按钮
            CharmSysButton btnClose = new CharmSysButton
            {
                SysButtonType = SysButtonType.Close,
                ToolTipText   = "关闭",
                Location      = new Point(this.Width - 44, 1)
            };

            // 创建测试目录文本框
            CharmTextBox txtTestDir = new CharmTextBox
            {
                Location = new Point(110, 10 + TITLE_HEIGHT),
                Width    = 330
            };
            // 创建浏览路径按钮
            CharmButton btnViewPath = new CharmButton
            {
                ButtonType = ButtonType.Classic_Size_08223,
                Text       = "浏览路径",
                ForeColor  = Color.DarkGreen,
                Location   = new Point(455, 12 + TITLE_HEIGHT)
            };

            // 创建测试规则按钮
            CharmButton btnTest = new CharmButton
            {
                ButtonType = ButtonType.Classic_Size_12425,
                Text       = "开始测试规则",
                ForeColor  = Color.MediumSlateBlue,
                Location   = new Point(420, 435),
            };

            // 将控件添加到集合中
            this.Controls.Add(txtTestDir);

            // 创建控件集合
            mControls = new List <Control> {
                txtTestDir
            };
            mCharmControls = new List <CharmControl> {
                btnClose, btnViewPath, btnTest
            };

            // 关联控件事件
            btnClose.MouseClick    += btnClose_MouseClick;
            btnViewPath.MouseClick += btnViewPath_MouseClick;
            btnTest.MouseClick     += btnTest_MouseClick;
            #endregion

            // 加载本地设置
            LoadLocalSetting();
        }