Esempio n. 1
0
    //弹出一个消息
    public void PopMsg(string msg, Color color)
    {
        float minY = m_StartY + (float)m_PopingObjs.Count * m_ItemHeight;

        if (IsSameItem(msg))
        {
            return;
        }

        //将一些过矮的元素提升
        foreach (TipItem curr in m_PopingObjs)
        {
            GameObject obj = curr.obj;
            if (obj.transform.localPosition.y < minY)
            {
                Vector3 pos = obj.transform.localPosition;
                pos.y = minY;
                obj.transform.localPosition = pos;
            }

            minY -= m_ItemHeight;
        }

        //创建item对象
        GameObject item = GameObjectExtension.InstantiateFromPreobj(m_ItemMB, m_ItemMB.transform.parent.gameObject);

        item.SetActive(true);
        NGUITools.MarkParentAsChanged(item);

        TipItem newItem = new TipItem()
        {
            lostTime = 0, obj = item
        };

        m_PopingObjs.Add(newItem);

        //设置标签
        string[] findpath = new string[1];
        findpath[0] = "Label";

        GameObject lableObj = GameObjectExtension.FindChild(item.transform, findpath).gameObject;
        UILabel    cmlabel  = lableObj.GetComponent <UILabel>();

        cmlabel.text  = msg;
        cmlabel.color = color;

        //解除位置绑定关系
        UIRect cm_rect = item.GetComponent <UIRect>();

        cm_rect.SetAnchor((GameObject)null);

        if (!m_CoroutineIsDoing)
        {
            CoroutineManage.Single.StartCoroutine(coUpdate());
        }
    }
Esempio n. 2
0
    public void SetSword()
    {
        var weapon = FindObjectOfType <Sword>();

        if (weapon == null)
        {
            seperatedSword = Instantiate(Resources.Load("Prefabs/sword") as GameObject);
        }
        else
        {
            seperatedSword = weapon.gameObject;
        }
        seperatedSword.GetComponent <InteractOnButton2D>().OnButtonPress.AddListener(ExtractWeapon);
        tipItem = seperatedSword.GetComponent <TipItem>();
    }
Esempio n. 3
0
    public bool IsSameItem(string msg)
    {
        bool isSame = false;

        for (int nIndex = 0; nIndex < m_PopingObjs.Count; nIndex++)
        {
            TipItem pItem = m_PopingObjs[nIndex];
            UILabel lbl   = pItem.obj.GetComponentInChildren <UILabel>();
            if (lbl == null)
            {
                continue;
            }
            if (lbl.text == msg)
            {
                isSame         = true;
                pItem.lostTime = 0.0f;
                break;
            }
        }

        return(isSame);
    }
Esempio n. 4
0
 float GetTipSize(TipItem tip, TipData data)
 {
     return(40);
 }
Esempio n. 5
0
 void TipItemUpdate(TipItem tip, TipData data, int index)
 {
     tip.content.Text = data.content;
 }
Esempio n. 6
0
        //load Tips
        public async void loadTips(Grid tipGrid, ProgressBar progressBar)
        {
            //bool for error
            bool error = false;

            //url
            string url = "https://api.foursquare.com/v2/users/self/tips?sort=recent&oauth_token=" + App.accessToken + "&v=" + App.date;

            //string will store json response
            string response = null;

            try
            {
                response = await client.GetStringAsync(url);
            }
            catch
            {
                //set error to true for caught exception
                error = true;
            }

            //if no error then deserialize
            if (!error)
            {
                //bool for json errors
                bool jsonError = false;

                //object to parts json
                TipClass.RootObject tc = null;

                //try catch incase json fails
                try
                {
                    tc = JsonConvert.DeserializeObject <TipClass.RootObject>(response);
                }
                catch
                {
                    //make true if exception caught
                    jsonError = true;
                }

                //if no error then continue
                if (!jsonError)
                {
                    for (int x = 0; x < tc.response.tips.count; x++)
                    {
                        TipItem.Add(new TipsItem()
                        {
                            restName = tc.response.tips.items[x].venue.name,
                            id       = tc.response.tips.items[x].venue.id,
                            tipNote  = tc.response.tips.items[x].text
                        });
                    }

                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        progressBar.Visibility = Visibility.Collapsed;
                        progressBar.IsEnabled  = false;
                        tipGrid.Visibility     = Visibility.Visible;
                    });
                }
            }
        }
Esempio n. 7
0
 private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
 {
     SelectedItem = ((sender as FrameworkElement).DataContext as TipItem);
     Close();
     SelectedItem.Action?.Invoke();
 }
Esempio n. 8
0
    const float movespeed = 100.0f; //移动速度
    //更新popTip位置
    IEnumerator coUpdate()
    {
        m_CoroutineIsDoing = true;

        while (m_PopingObjs.Count > 0)
        {
            //List<TipItem> needRemove = new List<TipItem>();
            float deltaTime = Time.deltaTime;
            for (int nIndex = 0; nIndex < m_PopingObjs.Count; nIndex++)
            {
                m_PopingObjs[nIndex].lostTime += deltaTime;
            }
            //foreach (TipItem curr in m_PopingObjs)
            //{
            //    curr.lostTime += deltaTime;
            //}
            //foreach (TipItem curr in m_PopingObjs)
            for (int nIndex = 0; nIndex < m_PopingObjs.Count; nIndex++)
            {
                TipItem curr = m_PopingObjs[nIndex];
                if (curr.lostTime < waitTime)
                {
                    continue;
                }
                if (curr.obj == null)
                {
                    continue;
                }
                GameObject obj = curr.obj;

                UIWidget cm_widget = obj.GetComponent <UIWidget>();

                //计算tween起始和结束位置
                Vector3 endpos = obj.transform.localPosition;
                endpos.y = m_EndY;

                Vector3 frompos = obj.transform.localPosition;

                //防止poptip反向移动
                if (endpos.y < frompos.y)
                {
                    endpos.y = frompos.y + 10;
                }

                float hideDuration = (endpos.y - frompos.y) / movespeed;

                //设置位置tween参数
                {
                    TweenPosition tweenPositionCM = obj.GetComponent <TweenPosition>();
                    tweenPositionCM.from     = frompos;
                    tweenPositionCM.to       = endpos;
                    tweenPositionCM.duration = hideDuration;
                    tweenPositionCM.style    = TweenAlpha.Style.Once;
                    tweenPositionCM.enabled  = true;
                }

                //设置alpha tween参数
                {
                    TweenAlpha alphaCM = obj.GetComponent <TweenAlpha>();
                    alphaCM.from     = cm_widget.alpha;
                    alphaCM.to       = 0;
                    alphaCM.duration = hideDuration;
                    alphaCM.style    = TweenAlpha.Style.Once;
                    alphaCM.enabled  = true;
                }

                //m_PopingObjs.Remove(curr);

                //定时销毁这个对象
                new MonoEX.Timer(hideDuration + 1).Play().OnComplete(() => OnDestroyItem(curr.obj));
                break;
            }



            yield return(null);
        }

        m_CoroutineIsDoing = false;
    }