Exemplo n.º 1
0
 public override bool Precache(VM vm, uint persistID)
 {
     if (!base.Precache(vm, persistID))
     {
         //we need to ask the data service for this name
         DataService.Request(Server.DataService.Model.MaskedStruct.Messaging_Icon_Avatar, persistID).ContinueWith(x =>
         {
             if (x.IsFaulted || x.IsCanceled || x.Result == null)
             {
                 return;
             }
             var ava       = (Avatar)x.Result;
             var failCount = 0;
             while (ava.Avatar_Name == "Retrieving...")
             {
                 if (failCount++ > 100)
                 {
                     return;
                 }
                 Thread.Sleep(100);
             }
             GameThread.NextUpdate(y =>
             {
                 AvatarNames[persistID] = ava.Avatar_Name;
             });
         });
     }
     return(true);
 }
Exemplo n.º 2
0
        public void MessageReceived(AriesClient client, object message)
        {
            if (!(message is DBRequestWrapperPDU))
            {
                return;
            }

            DBRequestWrapperPDU response = (DBRequestWrapperPDU)message;

            if (response.Body is cTSONetMessageStandard)
            {
                var body = (cTSONetMessageStandard)response.Body;
                var type = DBResponseTypeUtils.FromResponseID(body.DatabaseType.Value);

                //TODO: I feel like a sequence id would be better for matching up request / responses, perhaps the old protocol has this and we've just missed it
                var callback = PendingRequests[response.SendingAvatarID];//.FirstOrDefault(x => x.ResponseType == type);
                if (callback != null)
                {
                    PendingRequests.Remove(body.SendingAvatarID);

                    GameThread.NextUpdate(x =>
                    {
                        try
                        {
                            callback.Callback(body.ComplexParameter);
                        }
                        catch (Exception ex)
                        {
                            //LOG.Error(ex);
                        }
                    });
                }
            }
        }
Exemplo n.º 3
0
        public void MessageReceived(AriesClient client, object message)
        {
            if (message is MailResponse msg)
            {
                GameThread.NextUpdate(x =>
                {
                    switch (msg.Type)
                    {
                    case MailResponseType.NEW_MAIL:
                    case MailResponseType.POLL_RESPONSE:
                    case MailResponseType.SEND_SUCCESS:
                        //cool. we got mail, or got the mail we sent back.
                        if (msg.Messages.Length == 0)
                        {
                            return;     //didnt actually get anything
                        }
                        foreach (var mail in msg.Messages)
                        {
                            InboxStore.Save(mail);
                        }
                        View.UpdateInbox();
                        if (msg.Type == MailResponseType.POLL_RESPONSE)
                        {
                            //show a message indicating we recieved new mail while we were offline.
                            UIAlert alert = null;
                            alert         = UIScreen.GlobalShowAlert(new UIAlertOptions
                            {
                                Title   = GameFacade.Strings.GetString("225", "1"),
                                Message = GameFacade.Strings.GetString("225", msg.Messages.Length > 1 ? "3" : "2", new string[] { msg.Messages.Length.ToString() }),
                                Buttons = new UIAlertButton[]
                                {
                                    new UIAlertButton(UIAlertButtonType.Yes, btn =>
                                    {
                                        //show the inbox
                                        ((CoreGameScreen)UIScreen.Current).OpenInbox();
                                        UIScreen.RemoveDialog(alert);
                                    }),
                                    new UIAlertButton(UIAlertButtonType.No, btn =>
                                    {
                                        UIScreen.RemoveDialog(alert);
                                    })
                                }
                            }, true);
                        }

                        if (msg.Type != MailResponseType.SEND_SUCCESS)
                        {
                            //alert user that mail has been recieved via sound and flashing icon
                            HIT.HITVM.Get.PlaySoundEvent(UISounds.LetterRecieve);
                            ((CoreGameScreen)UIScreen.Current).FlashInbox(true);
                        }
                        else
                        {
                            HIT.HITVM.Get.PlaySoundEvent(UISounds.LetterSend);
                        }
                        break;
                    }
                });
            }
        }
Exemplo n.º 4
0
        void RefreshCity(BindingChange[] changes)
        {
            if (CurrentCity.Value != null)
            {
                var mapData = LotTileEntry.GenFromCity(CurrentCity.Value);

                //We know if lots are online, we can update the data service
                DataService.GetMany <Lot>(mapData.Select(x => (object)(uint)x.packed_pos).ToArray()).ContinueWith(x =>
                {
                    if (!x.IsCompleted)
                    {
                        return;
                    }

                    foreach (var lot in x.Result)
                    {
                        var mapItem = mapData.FirstOrDefault(y => y.packed_pos == lot.Id);
                        if (mapItem != null)
                        {
                            lot.Lot_IsOnline = (mapItem.flags & LotTileFlags.Online) == LotTileFlags.Online;
                        }
                    }
                });

                GameThread.NextUpdate((state) => View.populateCityLookup(mapData));
            }
        }
Exemplo n.º 5
0
 private void RefreshHead()
 {
     GameThread.NextUpdate(x =>
     {
         var avatar = CurrentAvatar.Value;
         if (avatar != null)
         {
             var content      = FSO.Content.Content.Get();
             var outfit       = content.AvatarOutfits.Get(_HeadOutfitId);
             var appearanceId = outfit.GetAppearance((Vitaboy.AppearanceType)avatar.Avatar_Appearance.AvatarAppearance_SkinTone);
             var appearance   = content.AvatarAppearances.Get(appearanceId);
             if (appearance.ThumbnailID.FileID == 0)
             {
                 var tex = UI.Model.UIIconCache.GenHeadTex(_HeadOutfitId, 0);
                 Icon    = new LoadedTextureRef(tex);
             }
             else
             {
                 var thumbnail = content.AvatarThumbnails.Get(appearance.ThumbnailID);
                 Icon          = thumbnail;
             }
         }
         else
         {
             Icon = null;
         }
     });
 }
Exemplo n.º 6
0
 public Texture2D Get(GraphicsDevice device)
 {
     lock (this)
     {
         if (_Instance == null || _Instance.IsDisposed) //|| ((CachableTexture2D)result).BeingDisposed)
         {
             using (var stream = GetStream())
             {
                 if (Thread.CurrentThread == FSOEnvironment.GameThread)
                 {
                     _Instance = Process(device, stream);
                 }
                 else
                 {
                     //We need to get into the game thread to do this work
                     _Instance = GameThread.NextUpdate <Texture2D>(x =>
                     {
                         return(Process(device, stream));
                     }).Result;
                 }
             }
             if (!FSOEnvironment.DirectX)
             {
                 GC.SuppressFinalize(_Instance); //do not run the default finalizer on the texture.
             }
             _Instance.Tag = this;               //form a destiny bond with the texture
         }
         return(_Instance);
     }
 }
Exemplo n.º 7
0
        public void MessageReceived(IoSession session, object message)
        {
            if (message is VMNetMessage)
            {
                GameThread.NextUpdate(x =>
                {
                    var nmsg = (VMNetMessage)message;
                    var cli  = (VMNetClient)session.GetAttribute('c');
                    if (cli.AvatarState == null)
                    {
                        //we're still waiting for the avatar state so the user can join
                        if (nmsg.Type == VMNetMessageType.AvatarData)
                        {
                            var state = new VMNetAvatarPersistState();
                            try
                            {
                                state.Deserialize(new System.IO.BinaryReader(new MemoryStream(nmsg.Data)));
                            }
                            catch (Exception)
                            {
                                return;
                            }
                            cli.PersistID   = state.PersistID;
                            cli.AvatarState = state;

                            OnConnect(cli);
                        }
                    }
                    else
                    {
                        OnMessage(cli, nmsg);
                    }
                });
            }
        }
Exemplo n.º 8
0
 public void RejectUpdate()
 {
     GameThread.NextUpdate(state =>
     {
         UIScreen.RemoveDialog(_UpdaterAlert);
         if (state.ShiftDown)
         {
             _UpdaterAlert = UIScreen.GlobalShowAlert(new UIAlertOptions
             {
                 Title   = GameFacade.Strings.GetString("f101", "11"),
                 Message = GameFacade.Strings.GetString("f101", "12"),
                 Width   = 500,
                 Buttons = UIAlertButton.Ok(y =>
                 {
                     //Regulator.AsyncTransition("AvatarData");
                     UIScreen.RemoveDialog(_UpdaterAlert);
                     Continue(true);
                     //View.LoginDialog.Visible = true;
                     //View.LoginProgress.Visible = true;
                 })
             }, true);
         }
         else
         {
             Continue(false);
             //View.LoginDialog.Visible = true;
             //View.LoginProgress.Visible = true;
             //Regulator.AsyncReset();
         }
     });
 }
Exemplo n.º 9
0
        public void GetWork(Action <int, uint> callback)
        {
            var client  = Client();
            var request = new RestRequest("userapi/city/thumbwork.json", Method.GET);

            request.AddHeader("authorization", "bearer " + AuthKey);

            client.ExecuteAsync(request, (resp, h) =>
            {
                var ok = resp.StatusCode == System.Net.HttpStatusCode.OK;

                GameThread.NextUpdate(x =>
                {
                    if (!ok || resp.Content == "")
                    {
                        callback(-1, (ok)?0:uint.MaxValue);
                    }
                    else
                    {
                        dynamic obj = JsonConvert.DeserializeObject(resp.Content);
                        callback(Convert.ToInt32(obj.shard_id), Convert.ToUInt32(obj.location));
                    }
                });
            });
        }
Exemplo n.º 10
0
 public void AsyncAPILotThumbnail(uint shardId, uint lotId, Action <Texture2D> callback)
 {
     Api.GetThumbnailAsync(shardId, lotId, (data) =>
     {
         if (data != null)
         {
             GameThread.NextUpdate(x =>
             {
                 if (UIScreen.Current != this)
                 {
                     return;
                 }
                 using (var mem = new MemoryStream(data))
                 {
                     try
                     {
                         callback(ImageLoader.FromStream(GameFacade.GraphicsDevice, mem));
                     } catch
                     {
                     }
                 }
             });
         }
     });
 }
        public void SendLetter(MessageItem letter)
        {
            var cref = Network.MyCharacterRef;

            if (View.MyUser.Value == null)
            {
                View.MyUser.Value = cref;
                DataService.Request(MaskedStruct.Messaging_Message_Avatar, Network.MyCharacter).ContinueWith(x =>
                {
                    GameThread.NextUpdate(y =>
                    {
                        SendLetter(letter);
                    });
                });
                return;
            }

            letter.SenderID = cref.Id;
            if (letter.SenderName == null)
            {
                letter.SenderName = cref.Name;
            }
            letter.TargetID = Message.User.Id;

            Network.CityClient.Write(new MailRequest
            {
                Type = MailRequestType.SEND,
                Item = letter
            });

            Close();
        }
Exemplo n.º 12
0
 public override bool CloseAttempt()
 {
     GameThread.NextUpdate(x =>
     {
         if (CloseAlert == null)
         {
             var canSave = vm != null;
             CloseAlert  = new UIMobileAlert(new FSO.Client.UI.Controls.UIAlertOptions
             {
                 Title   = GameFacade.Strings.GetString("153", "1"),             //quit?
                 Message = GameFacade.Strings.GetString("153", canSave?"6":"2"), //are you sure (2), save before quitting (3)
                 Buttons =
                     canSave?
                     UIAlertButton.YesNoCancel(
                         (b) => { Save(); GameFacade.Game.Exit(); },
                         (b) => { GameFacade.Game.Exit(); },
                         (b) => { CloseAlert.Close(); CloseAlert = null; }
                         )
                 :
                     UIAlertButton.YesNo(
                         (b) => { GameFacade.Game.Exit(); },
                         (b) => { CloseAlert.Close(); CloseAlert = null; }
                         )
             });
             GlobalShowDialog(CloseAlert, true);
         }
     });
     return(false);
 }
Exemplo n.º 13
0
        public InboxController(UIInbox view, IClientDataService dataService, IDatabaseService database, Network.Network net)
        {
            this.View            = view;
            this.DataService     = dataService;
            this.DatabaseService = database;
            this.Network         = net;

            this.InboxStore = UIMessageStore.Store;
            try
            {
                InboxStore.Load((int)net.MyCharacter);
            } catch
            {
                //oops, we couldnt load the local data...
                //assuming it failed anywhere, it will download from server as if timestamp were 0.
            }

            this.Network.CityClient.AddSubscriber(this);

            Network.CityClient.Write(new MailRequest
            {
                Type        = MailRequestType.POLL_INBOX, //we're ready to recieve any pending roommate requests
                TimestampID = InboxStore.LastMessageTime
            });

            GameThread.NextUpdate(x =>
            {
                View.UpdateInbox();
            });
        }
Exemplo n.º 14
0
        /// <summary>
        /// Finds a lot owned by us, then returns its name, along with if we are its owner.
        /// </summary>
        /// <param name="callback">A function to take the name and owner status found. Name is null if a lot was not found.</param>
        public void GetOurLotsName(Action <string, bool> callback)
        {
            DataService.Request(MaskedStruct.SimPage_Main, Network.MyCharacter)
            .ContinueWith(x =>
            {
                var avatar = x.Result as Avatar;
                if (avatar == null)
                {
                    return;
                }

                var lotLoc = avatar.Avatar_LotGridXY;
                if (lotLoc == 0)
                {
                    GameThread.NextUpdate(state => callback(null, false));
                }
                else
                {
                    DataService.Request(MaskedStruct.PropertyPage_LotInfo, lotLoc).ContinueWith(y =>
                    {
                        var lot = y.Result as Lot;
                        if (lot == null)
                        {
                            GameThread.NextUpdate(state => callback(null, false));
                        }
                        else
                        {
                            GameThread.NextUpdate(state => {
                                callback(lot.Lot_Name, lot.Lot_LeaderID == Network.MyCharacter);
                            });
                        }
                    });
                }
            });
        }
Exemplo n.º 15
0
 private void OBJToFSOM(OBJ obj)
 {
     GameThread.NextUpdate(x =>
     {
         var mesh = new DGRP3DMesh(ActiveDGRP, obj, Client.GameFacade.GraphicsDevice);
         if (IffMode)
         {
             var fsom = ActiveObject.Resource.Get <FSOM>(ActiveDGRP.ChunkID);
             if (fsom == null)
             {
                 fsom                = new FSOM();
                 fsom.ChunkLabel     = "OBJ Import Mesh";
                 fsom.ChunkID        = ActiveDGRP.ChunkID;
                 fsom.ChunkProcessed = true;
                 fsom.ChunkType      = "FSOM";
                 fsom.AddedByPatch   = true;
                 (ActiveObject.Resource.Sprites ?? ActiveObject.Resource.MainIff).AddChunk(fsom);
             }
             Content.Content.Get().Changes.QueueResMod(new ResAction(() =>
             {
                 fsom.SetMesh(mesh);
                 Content.Content.Get().RCMeshes.ClearCache(ActiveDGRP);
                 Debug3D.ForceUpdate();
             }, fsom));
         }
         else
         {
             Content.Content.Get().RCMeshes.Replace(ActiveDGRP, mesh);
             Debug3D.ForceUpdate();
         }
     });
 }
Exemplo n.º 16
0
        public void SendIM(string body)
        {
            var cref = Network.MyCharacterRef;

            View.AddMessage(cref, body, IMEntryType.MESSAGE_OUT);

            if (View.MyUser.Value == null)
            {
                View.MyUser.Value = cref;
                DataService.Request(MaskedStruct.Messaging_Message_Avatar, Network.MyCharacter).ContinueWith(x =>
                {
                    GameThread.NextUpdate(y =>
                    {
                        View.RenderMessages();
                    });
                });
            }

            if (Message.User.Type != Common.Enum.UserReferenceType.AVATAR)
            {
                return;
            }

            Network.CityClient.Write(new InstantMessage {
                FromType = Common.Enum.UserReferenceType.AVATAR,
                From     = Network.MyCharacter,
                Message  = body,
                To       = Message.User.Id,
                Type     = InstantMessageType.MESSAGE,
                AckID    = Guid.NewGuid().ToString()
            });
        }
Exemplo n.º 17
0
 void OnConnect(IoSession session, IConnectFuture future)
 {
     Session = session;
     GameThread.NextUpdate(x =>
     {
         OnConnectComplete();
     });
 }
Exemplo n.º 18
0
        public Rectangle GetEmoji(string emojiID)
        {
            int index;

            if (EmojiToIndex.TryGetValue(emojiID, out index))
            {
                return(RectForIndex(index));
            }
            else
            {
                index = NextIndex++;
                ExpandIfNeeded();
                lock (IncompleteSpaces) IncompleteSpaces.Add(index);
                var client = new WebClient();
                client.DownloadDataCompleted += (object sender, DownloadDataCompletedEventArgs e) =>
                {
                    if (e.Cancelled || e.Error != null || e.Result == null)
                    {
                        lock (ErrorSpaces) ErrorSpaces.Add(index);
                    }
                    else
                    {
                        GameThread.NextUpdate(x =>
                        {
                            try
                            {
                                using (var mem = new MemoryStream(e.Result))
                                {
                                    var tex = Texture2D.FromStream(GD, mem);

                                    var decimated = TextureUtils.Decimate(tex, GD, 72 / DefaultRes, true);
                                    //blit this into our emoji buffer
                                    GD.SetRenderTarget(EmojiTex);
                                    if (needClear)
                                    {
                                        GD.Clear(Color.TransparentBlack);
                                        needClear = false;
                                    }
                                    EmojiBatch.Begin(blendState: BlendState.NonPremultiplied, sortMode: SpriteSortMode.Immediate);
                                    EmojiBatch.Draw(decimated, RectForIndex(index), Color.White);
                                    EmojiBatch.End();
                                    GD.SetRenderTarget(null);
                                }
                            }
                            catch (Exception)
                            {
                                lock (ErrorSpaces) ErrorSpaces.Add(index);
                            }
                        });
                    }
                    lock (IncompleteSpaces) IncompleteSpaces.Remove(index);
                };
                client.DownloadDataAsync(new Uri((emojiID[0] == '!')?(emojiID.Substring(1)):(Source + emojiID + ".png")));
                Emojis.Add(emojiID);
                EmojiToIndex[emojiID] = index;
                return(RectForIndex(index));
            }
        }
Exemplo n.º 19
0
 void DownloadClient_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
 {
     if (e.Error != null || e.Cancelled)
     {
         GameThread.NextUpdate(x => OnComplete?.Invoke(false));
         return;
     }
     AdvanceDownloader();
 }
Exemplo n.º 20
0
        public void P_Show(string evt, string text)
        {
            int mode;

            int.TryParse(text, out mode);
            if (mode < 1 || mode > 2)
            {
                mode = 1;
            }
            var split = text.Split('\n');

            EODController.ShowEODMode(new EODLiveModeOpt
            {
                Buttons    = 0,
                Expandable = false,
                Height     = EODHeight.Normal,
                Length     = EODLength.None,
                Timer      = EODTimer.None,
                Tips       = EODTextTips.None
            });

            var style = TextStyle.DefaultLabel.Clone();

            style.Shadow  = true;
            Add(SeeDialog = new UILabel()
            {
                Position     = new Microsoft.Xna.Framework.Vector2(0, 32),
                Size         = new Microsoft.Xna.Framework.Vector2(472, 112),
                Alignment    = TextAlignment.Center | TextAlignment.Middle,
                CaptionStyle = style,
                Caption      = GameFacade.Strings.GetString("f120", "36")
            });

            if (UIBulletinDialog.Present)
            {
                GameThread.NextUpdate(x => OnClose());
            }
            else
            {
                Dialog = new UIBulletinDialog(LotController?.vm?.TSOState?.NhoodID ?? 0);
                Dialog.OnModeChange += (dmode) =>
                {
                    Send("bulletin_mode", dmode.ToString());
                };
                Dialog.CloseButton.OnButtonClick += (btn) => OnClose();
                if (mode == 2)
                {
                    Dialog.SelectedPost(null);
                }
                else
                {
                    Send("bulletin_mode", "0");
                }
                UIScreen.GlobalShowDialog(Dialog, false);
                //Send("bulletin_mode", ((mode == 1) ? 0 : 2).ToString());
            }
        }
Exemplo n.º 21
0
        private void BHAVEditor_Deactivate(object sender, EventArgs e)
        {
            EditorControl.ClearMouseState();
            var ui = EditorControl.FSOUI;

            GameThread.NextUpdate(state =>
            {
                ui.CleanupFocus(state);
            });
        }
Exemplo n.º 22
0
 public void Resolve()
 {
     Resolver.ContinueWith(x =>
     {
         //Dispatch in the update loop
         GameThread.NextUpdate(y =>
         {
             TaskSource.SetResult(x.Result);
         });
     });
 }
Exemplo n.º 23
0
 public void RemoveExternal(UIExternalContainer cont)
 {
     lock (m_ExtContainers)
     {
         //todo: release resources?
         GameThread.NextUpdate(x =>
         {
             cont.Removed();
         });
         m_ExtContainers.Remove(cont);
     }
 }
Exemplo n.º 24
0
        private void RefreshTooltip(BindingChange[] changes)
        {
            //Called if price, online or name change
            GameThread.NextUpdate((state) =>
            {
                if (CurrentHoverLot.Value != null)
                {
                    var lot      = CurrentHoverLot.Value;
                    var name     = lot.Lot_Name;
                    var occupied = IsTileOccupied((int)(lot.Id >> 16), (int)(lot.Id & 0xFFFF));
                    if (!occupied)
                    {
                        var text = GameFacade.Strings.GetString("215", "9", new string[] { lot.Lot_Price.ToString() });
                        var flat = Realestate.GetSlope((ushort)(lot.Id >> 16), (ushort)(lot.Id & 0xFFFF));
                        var map  = Realestate.GetMap();
                        var type = map.GetTerrain((ushort)(lot.Id >> 16), (ushort)(lot.Id & 0xFFFF));

                        text += "\r\n" + type.ToString() + ", " + ((flat == 0)?"Flat":"Sloped (" + flat + ")");

                        var nhood = View.NeighGeom.NhoodNearest((int)(lot.Id >> 16), (int)(lot.Id & 0xFFFF));
                        if (nhood != -1)
                        {
                            var nhoodObj = View.NeighGeom.Data[nhood];
                            text        += "\r\n" + nhoodObj.Name;
                        }
                        Parent.Screen.CityTooltip.Text = text;
                    }
                    else
                    {
                        var text = GameFacade.Strings.GetString("215", "3", new string[] { name });
                        if (lot.Lot_LeaderID == Network.MyCharacter)
                        {
                            text += "\r\n" + GameFacade.Strings.GetString("215", "5");
                        }
                        else if (!lot.Lot_IsOnline)
                        {
                            text += "\r\n" + GameFacade.Strings.GetString("215", "6");
                        }

                        if (lot.Lot_IsOnline)
                        {
                            text += "\r\n" + GameFacade.Strings.GetString("215", "4", new string[] { lot.Lot_NumOccupants.ToString() });
                        }
                        Parent.Screen.CityTooltip.Text = text;
                    }
                }
                else
                {
                    Parent.Screen.CityTooltip.Text = null;
                }
            });
        }
Exemplo n.º 25
0
        public void DisplayEmail(MessageItem item)
        {
            UserReference r = null;

            switch (item.Type)
            {
            case 1:
                r = UserReference.Of(UserReferenceType.TSO); break;     //vote

            case 2:
                r = UserReference.Of(UserReferenceType.TSO); break;     //club

            case 3:
                r = UserReference.Of(UserReferenceType.MAXIS); break;

            case 4:
                r = UserReference.Of(UserReferenceType.TSO); break;

            case 5:
                r = UserReference.Of(UserReferenceType.TSO); break;     //house

            case 6:
                r = UserReference.Of(UserReferenceType.TSO); break;     //roommate
            }
            if (r == null)
            {
                DataService.Get <Avatar>(item.SenderID).ContinueWith(x =>
                {
                    GameThread.NextUpdate(y =>
                    {
                        var msg = Chat.ReadLetter(UserReference.Wrap(x.Result), item);
                        if (msg != null)
                        {
                            Chat.SetEmailMessage(msg, item);
                            Chat.ShowWindow(msg);
                        }
                    });
                });
            }
            else
            {
                GameThread.NextUpdate(y =>
                {
                    var msg = Chat.ReadLetter(r, item);
                    if (msg != null)
                    {
                        Chat.SetEmailMessage(msg, item);
                        Chat.ShowWindow(msg);
                    }
                });
            }
        }
Exemplo n.º 26
0
        public override void Speak(string text, bool gender, int ipitch)
        {
            var Synth = new System.Speech.Synthesis.SpeechSynthesizer();

            Synth.SelectVoiceByHints((gender) ? System.Speech.Synthesis.VoiceGender.Female : System.Speech.Synthesis.VoiceGender.Male);
            if (text == "")
            {
                return;
            }
            var voci   = Synth.GetInstalledVoices();
            var stream = new System.IO.MemoryStream();
            var pitch  = Math.Max(0.1f, ipitch / 100f + 1f); //below 0.1 is just stupid, so just clamp there.

            if (pitch < 1f)
            {
                Synth.Rate = 10 - (int)(pitch * 10);
            }
            else
            {
                Synth.Rate = (int)(10 / pitch) - 10;
            }
            Synth.SetOutputToWaveStream(stream);
            Synth.SpeakAsync(text);

            EventHandler <System.Speech.Synthesis.SpeakCompletedEventArgs> OnComplete = null;

            OnComplete = (obj, evt) =>
            {
                GameThread.NextUpdate((u) =>
                {
                    stream.Seek(0, System.IO.SeekOrigin.Begin);
                    var sfx    = SoundEffect.FromStream(stream);
                    var inst   = sfx.CreateInstance();
                    inst.Pitch = pitch - 1f;
                    inst.Play();

                    GameThreadInterval interval = null;
                    interval = GameThread.SetInterval(() =>
                    {
                        if (inst.State == SoundState.Stopped)
                        {
                            sfx.Dispose(); //just catch and dispose these when appropriate
                            interval.Clear();
                        }
                    }, 1000);
                    Synth.Dispose();
                });
                Synth.SpeakCompleted -= OnComplete;
            };

            Synth.SpeakCompleted += OnComplete;
        }
Exemplo n.º 27
0
 public void MessageReceived(AriesClient client, object message)
 {
     if (message is InstantMessage instantMsg)
     {
         if (instantMsg.Type == InstantMessageType.MESSAGE || instantMsg.Type == InstantMessageType.FAILURE_ACK)
         {
             GameThread.NextUpdate((_) =>
             {
                 HandleInstantMessage((InstantMessage)message);
             });
         }
     }
 }
Exemplo n.º 28
0
        public void AdvanceDownloader()
        {
            if (CurrentItem >= Items.Length)
            {
                GameThread.NextUpdate(x => OnComplete?.Invoke(true));
                return;
            }
            var item = Items[CurrentItem++];

            ItemMeta = item;
            Directory.CreateDirectory(Path.GetDirectoryName(item.DestPath));
            DownloadClient.DownloadFileAsync(new Uri(item.Url), item.DestPath);
        }
Exemplo n.º 29
0
        public void SessionClosed(IoSession session)
        {
            var cli = (VMNetClient)session.GetAttribute('c');

            if (cli != null)
            {
                GameThread.NextUpdate(x =>
                {
                    OnDisconnect(cli);
                });
            }

            lock (Sessions) Sessions.Remove(session);
        }
Exemplo n.º 30
0
        public void AcceptUpdate(UpdatePath path)
        {
            UIScreen.RemoveDialog(_UpdaterAlert);

            try
            {
                if (path.FullZipStart)
                {
                    System.IO.File.WriteAllText("PatchFiles/clean.txt", "CLEAN");
                }
                else
                {
                    System.IO.File.Delete("PatchFiles/clean.txt");
                }
            } catch
            {
            }

            var downloader = new UIWebDownloaderDialog(GameFacade.Strings.GetString("f101", "1"), BuildFiles(path));

            downloader.OnComplete += (bool success) => {
                UIScreen.RemoveDialog(downloader);
                if (success)
                {
                    _UpdaterAlert = UIScreen.GlobalShowAlert(new UIAlertOptions
                    {
                        Title   = GameFacade.Strings.GetString("f101", "3"),
                        Message = GameFacade.Strings.GetString("f101", "13"),
                        Buttons = UIAlertButton.Ok(y =>
                        {
                            UIScreen.RemoveDialog(_UpdaterAlert);
                            RestartGamePatch();
                        })
                    }, true);
                }
                else
                {
                    UIScreen.GlobalShowAlert(new UIAlertOptions
                    {
                        Title   = GameFacade.Strings.GetString("f101", "30"),
                        Message = GameFacade.Strings.GetString("f101", "28"),
                        Buttons = UIAlertButton.Ok(y =>
                        {
                            Continue(false);
                        })
                    }, true);
                }
            };
            GameThread.NextUpdate(y => UIScreen.GlobalShowDialog(downloader, true));
        }