Ejemplo n.º 1
0
        public List <FeedMs> GetFeedList(int width, Shared.GetFont titleFont, Shared.GetFont dateFont, Shared.GetFont bodyFont)
        {
            TextBlob textBlob = new TextBlob(bodyFont, "label", width);

            //parse JSON string into List of Dictionaries.
            List <FeedMs> allFeeds = new List <FeedMs>();

            try
            {
#if NETFX_CORE
                // For some reason the WinRT Json Serializer doesn't want to
                // deserialize our objects so we'll just have to do it manually.
                //var items = Deserialize<List<Dictionary<string, string>>>(rawGetData);

                List <Dictionary <string, string> > items = HackDeserialize(rawGetData);
#else
                var js    = new System.Web.Script.Serialization.JavaScriptSerializer();
                var items = js.Deserialize <List <Dictionary <string, string> > >(rawGetData);
#endif

                //build news feed.
                foreach (var item in items)
                {
                    FeedMs feedItem = new FeedMs(new Vector2(24, 0), textBlob, titleFont, dateFont, bodyFont);
                    feedItem.Title      = item["Title"];
                    feedItem.Body       = item["Text"];
                    feedItem.DateString = item["Date"];
                    feedItem.CreateHyperlink(HyperlinkType.URL, Strings.Localize("mainMenu.readMoreHere"), item["URL"]);
                    allFeeds.Add(feedItem);
                }
            }
            catch { }
            return(allFeeds);
        }
Ejemplo n.º 2
0
        // c'tor
        public LiveFeedDisplay()
        {
            this.msNewsFeed = new NewsFeeds();
            this.smallblob  = new TextBlob(UI2D.Shared.GetGameFont18Bold, Strings.Localize("mainMenu.news"), 300);
            this.smallblob.Justification = UIGridElement.Justification.Left;
            this.flagMoreBlob            = new TextBlob(expandFlagFont, Strings.Localize("mainMenu.more"), 80);
            this.flagLessBlob            = new TextBlob(expandFlagFont, Strings.Localize("mainMenu.less"), 80);


            this.newsScroller = new ItemScroller(scrollBoxPos, FeedSize, new Color(0.0f, 0.0f, 0.0f, 0.0f), null, null);
            this.hitBox       = new AABB2D(new Vector2(0, 0), FeedSize);
            // this.Header_bg = BokuGame.Load<Texture2D>(BokuGame.Settings.MediaPath + @"Textures\twitter_Icon");
            this.cloudTR = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudTR");
            this.cloudBR = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudBR");

            this.cloudTL = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudTL");
            this.cloudBL = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudBL");

            this.cloudTC = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudTC");
            this.cloudBC = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudBC");

            this.cloudLC     = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudLC");
            this.cloudRC     = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudRC");
            this.cloudCenter = BokuGame.Load <Texture2D>(BokuGame.Settings.MediaPath + @"Textures\MainMenu\cloudCenter");

            newsScroller.Clear();
            FeedMs item = new FeedMs(FeedSize, "Getting News feed...", TitleFont, DateFont, BodyFont);

            newsScroller.AddItem(item);

            //Twitter.GetTweets();
            msNewsFeed.BeginFetchNews();

            gettingFeeds = true;
        }   // end of c'tor
Ejemplo n.º 3
0
        public bool AddFeed(string rawData, ref List <FeedMs> msFeed, int width, Shared.GetFont tFont, Shared.GetFont dFont, Shared.GetFont bFont)
        {
            char lastChar;
            char nextChar;

            TextBlobHL TextBlobHL = new TextBlobHL(bFont, "label", width);
            FeedMs     feedItem   = null;

            currentFeedSection = FeedSection.keyNone;
            if (rawData.StartsWith("\"" + keyTitle + "\""))
            {
                feedItem = new FeedMs(new Vector2(24, 0), TextBlobHL, tFont, dFont, bFont);
                string[] delimiterChars = { "\":\"", "\",\"" };
                string[] fields         = rawData.Split(delimiterChars, StringSplitOptions.None);
                foreach (string field in fields)
                {
                    nextChar = field[field.Length - 1];
                    if (currentFeedSection != FeedSection.keyNone)
                    {
                        ProcessKey(ref feedItem, field, currentFeedSection);
                        currentFeedSection = FeedSection.keyNone;
                    }
                    else if (field.Contains("\"" + keyTitle))
                    {
                        currentFeedSection = FeedSection.keyTitle;
                    }
                    else if (field.Contains(keyText))
                    {
                        currentFeedSection = FeedSection.keyText;
                    }
                    else if (field.Contains(keyLink))
                    {
                        currentFeedSection = FeedSection.keyLink;
                    }
                    else if (field.Contains(keyTwitter))
                    {
                        currentFeedSection = FeedSection.keyTwitter;
                    }
                    else if (field.Contains(keyDate))
                    {
                        currentFeedSection = FeedSection.keyDate;
                    }
                    lastChar = field[0];
                }
                msFeed.Add(feedItem);
            }


            return(true);
        }
Ejemplo n.º 4
0
        private void ProcessKey(ref FeedMs newsItem, string data, FeedSection key)
        {
            switch (key)
            {
            case FeedSection.keyTitle:
                newsItem.Title = data;
                ; break;

            case FeedSection.keyText:
                newsItem.Body = data;
                break;

            case FeedSection.keyDate:
                newsItem.DateString = data;
                break;

            case FeedSection.keyTwitter:;
                break;

            case FeedSection.keyLink:
                newsItem.CreateHyperlink(HyperlinkType.URL, "\nRead more Here!", data);
                break;
            }
        }
Ejemplo n.º 5
0
        }   // end of c'tor

        public void Update(Camera camera)
        {
            if (gettingFeeds)
            {
                msNewsFeed.Update();
                if (msNewsFeed.CurrentState == NewsFeeds.OpState.Failed)
                {
                    newsScroller.Clear();
                    FeedMs item = new FeedMs(FeedSize, "Failed to get news feed...", TitleFont, DateFont, BodyFont);
                    newsScroller.AddItem(item);
                    gettingFeeds       = false;
                    newsScroller.Dirty = true;
                }
                else if (msNewsFeed.CurrentState == NewsFeeds.OpState.Retrieving)
                {
                    newsScroller.Clear();
                    FeedMs item = new FeedMs(FeedSize, "Updating news...", TitleFont, DateFont, BodyFont);
                    newsScroller.AddItem(item);
                    //gettingFeeds = false;
                    newsScroller.Dirty = true;
                }
                else if (msNewsFeed.CurrentState == NewsFeeds.OpState.Retrieved)
                {
                    try
                    {
                        // Done getting Tweets
                        newsScroller.Clear();
                        List <FeedMs> feedList = msNewsFeed.GetFeedList(
                            (int)(FeedSize.X - newsScroller.ScrollBoxSize.X), TitleFont, DateFont, BodyFont);
                        if (feedList != null)
                        {
                            foreach (FeedMs newsItem in feedList)
                            {
                                newsScroller.AddItem(newsItem);
                            }
                        }
                        newsScroller.ResizeItemWidths();
                        gettingFeeds       = false;
                        newsScroller.Dirty = true;
                    }
                    catch
                    {
                        newsScroller.Clear();
                        FeedMs item = new FeedMs(FeedSize, "Error getting news feed...", TitleFont, DateFont, BodyFont);
                        newsScroller.AddItem(item);
                        gettingFeeds       = false;
                        newsScroller.Dirty = true;
                    }
                }
            }

            Vector2 pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);

            if (moreLessHitBox.Contains(pureMouseHit) && MouseInput.Left.WasReleased)
            {
                expanded = !expanded;
            }

            //check touch hit
            TouchContact touch = TouchInput.GetOldestTouch();

            if (TouchInput.WasLastReleased && moreLessHitBox.Contains(touch.position))
            {
                expanded = !expanded;
            }

            // Even if not active we need to refresh the rendertarget.
            newsScroller.RefreshRT();

            if (Active)
            {
                newsScroller.Update(camera);

                if (camera == null)
                {
                    camera = new PerspectiveUICamera();
                }

                if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse)
                {
                    Vector2 hit = MouseInput.GetAspectRatioAdjustedPosition(camera, useOverscanForHitTesting);
                    pureMouseHit = new Vector2(MouseInput.Position.X, MouseInput.Position.Y);
                    if (!IsInScrollwindow(pureMouseHit))
                    {
                        // Don't Deactivate here just because the mouse cursor has left the bounds of the scroll window.
                        // We should only deactivate if ComboRight is pressed.
                        //Deactivate();

                        // But if we're out of bounds and the used clicks, then Deactivate()
                        if (MouseInput.Left.WasPressed)
                        {
                            Deactivate();
                        }
                    }
                    else if (MouseInput.PrevPosition != MouseInput.Position)
                    {
                        newsScroller.Activate();
                    }

                    if (true) //newsScroller.IsFocused)
                    {
                        if (Actions.ComboUp.WasPressedOrRepeat)
                        {
                            newsScroller.FocusPrev();
                        }
                        else if (Actions.ComboDown.WasPressedOrRepeat)
                        {
                            newsScroller.FocusNext();
                        }
                        else if (Actions.ComboRight.WasPressed)
                        {
                            Deactivate();
                        }
                        if (Actions.ZoomIn.WasPressedOrRepeat)
                        {
                            newsScroller.FocusPrevItem();
                        }
                        else if (Actions.ZoomOut.WasPressedOrRepeat)
                        {
                            newsScroller.FocusNextItem();
                        }
                    }

                    if (Actions.ComboLeft.WasPressed)
                    {
                        newsScroller.Activate();
                    }
                }
                else if (GamePadInput.ActiveMode == GamePadInput.InputMode.GamePad)
                {
                    HandleGamepadInput();
                }
            } // end if active.
        }     // end of Update()