Ejemplo n.º 1
0
        private void ShootDuck()
        {
            // Shoot the duck
            if (GetCollision())
            {
                if (Hud.Hud.NumShotsLeft > 0)
                {
                    // Post message to the score board.
                    ScoreMessage message = new ScoreMessage()
                    {
                        ScoreIncrement = 10
                    };
                    Channels.PostMessage("score", message);

                    DuckHitMessage duckHitMessage = new DuckHitMessage()
                    {
                        State = DuckIndicatorStateEnum.Hit
                    };
                    Channels.PostMessage("duckhit", duckHitMessage);

                    Channels.PostMessage("soundeffects", new SoundEffectMessage()
                    {
                        SoundEffectToPlay = "death"
                    });
                    State = DuckStateEnum.Dead;
                }
            }
        }
Ejemplo n.º 2
0
    public void PropagateScore()
    {
        _scoreUI.SetScore(LeftScore, RightScore);
        var scoreMessage = new ScoreMessage(LeftScore, RightScore);

        _server.SendToAll(scoreMessage);
    }
Ejemplo n.º 3
0
        // ================================

        /// <summary>Call this function to reset the game</summary>
        /// <param name="ResetLogs">Whether the logs should be reset</param>
        internal static void Reset(bool ResetLogs)
        {
            // track manager
            for (int i = 0; i < TrackManager.Tracks.Length; i++)
            {
                TrackManager.Tracks[i] = new TrackManager.Track();
            }
            // train manager
            TrainManager.Trains = new TrainManager.Train[] { };
            // game
            Interface.ClearMessages();
            CurrentInterface = InterfaceType.Normal;
            RouteComment     = "";
            RouteImage       = "";
            RouteAccelerationDueToGravity = 9.80665;
            RouteRailGauge              = 1.435;
            RouteInitialAirPressure     = 101325.0;
            RouteInitialAirTemperature  = 293.15;
            RouteInitialElevation       = 0.0;
            RouteSeaLevelAirPressure    = 101325.0;
            RouteSeaLevelAirTemperature = 293.15;
            Stations = new RouteStation[] { };
            CurrentRoute.Sections = new Section[] { };
            BufferTrackPositions  = new double[] { };
            //Messages = new Message[] { };
            MarkerTextures           = new Texture[] { };
            PointsOfInterest         = new PointOfInterest[] { };
            PrecedingTrainTimeDeltas = new double[] { };
            PrecedingTrainSpeedLimit = double.PositiveInfinity;
            CurrentRoute.BogusPretrainInstructions = new BogusPretrainInstruction[] { };
            TrainName  = "";
            TrainStart = TrainStartMode.EmergencyBrakesNoAts;
            CurrentRoute.NoFogStart   = (float)Math.Max(1.33333333333333 * Interface.CurrentOptions.ViewingDistance, 800.0);
            CurrentRoute.NoFogEnd     = (float)Math.Max(2.66666666666667 * Interface.CurrentOptions.ViewingDistance, 1600.0);
            CurrentRoute.PreviousFog  = new Fog(CurrentRoute.NoFogStart, CurrentRoute.NoFogEnd, Color24.Grey, 0.0);
            CurrentRoute.CurrentFog   = new Fog(CurrentRoute.NoFogStart, CurrentRoute.NoFogEnd, Color24.Grey, 0.5);
            CurrentRoute.NextFog      = new Fog(CurrentRoute.NoFogStart, CurrentRoute.NoFogEnd, Color24.Grey, 1.0);
            InfoTotalTriangles        = 0;
            InfoTotalTriangleStrip    = 0;
            InfoTotalQuads            = 0;
            InfoTotalQuadStrip        = 0;
            InfoTotalPolygon          = 0;
            InfoStaticOpaqueFaceCount = 0;
            if (ResetLogs)
            {
                LogRouteName       = "";
                LogTrainName       = "";
                LogDateTime        = DateTime.Now;
                CurrentScore       = new Score();
                ScoreMessages      = new ScoreMessage[] { };
                ScoreLogs          = new ScoreLog[64];
                ScoreLogCount      = 0;
                BlackBoxEntries    = new BlackBoxEntry[256];
                BlackBoxEntryCount = 0;
                BlackBoxNextUpdate = 0.0;
            }
            // renderer
            Renderer.Reset();
        }
Ejemplo n.º 4
0
        // ================================

        /// <summary>Call this function to reset the game</summary>
        /// <param name="ResetLogs">Whether the logs should be reset</param>
        /// <param name="ResetRenderer">Whether the renderer should be reset</param>
        internal static void Reset(bool ResetLogs, bool ResetRenderer)
        {
            // track manager
            for (int i = 0; i < Program.CurrentRoute.Tracks.Count; i++)
            {
                int key = Program.CurrentRoute.Tracks.ElementAt(i).Key;
                Program.CurrentRoute.Tracks[key] = new Track();
            }
            // train manager
            TrainManager.Trains = new TrainManager.Train[] { };
            // game
            Interface.ClearMessages();
            CurrentInterface             = InterfaceType.Normal;
            Program.CurrentRoute.Comment = "";
            Program.CurrentRoute.Image   = "";
            Program.CurrentRoute.Atmosphere.AccelerationDueToGravity = 9.80665;
            Program.CurrentRoute.Atmosphere.InitialAirPressure       = 101325.0;
            Program.CurrentRoute.Atmosphere.InitialAirTemperature    = 293.15;
            Program.CurrentRoute.Atmosphere.InitialElevation         = 0.0;
            Program.CurrentRoute.Atmosphere.SeaLevelAirPressure      = 101325.0;
            Program.CurrentRoute.Atmosphere.SeaLevelAirTemperature   = 293.15;
            Program.CurrentRoute.BufferTrackPositions = new double[] { };
            //Messages = new Message[] { };
            Program.Renderer.Marker.MarkerTextures = new Texture[] { };
            Program.CurrentRoute.PointsOfInterest  = new PointOfInterest[] { };
            PrecedingTrainTimeDeltas = new double[] { };
            PrecedingTrainSpeedLimit = double.PositiveInfinity;
            Program.CurrentRoute.BogusPreTrainInstructions = new BogusPreTrainInstruction[] { };
            TrainName  = "";
            TrainStart = TrainStartMode.EmergencyBrakesNoAts;
            Program.CurrentRoute.NoFogStart  = (float)Math.Max(1.33333333333333 * Interface.CurrentOptions.ViewingDistance, 800.0);
            Program.CurrentRoute.NoFogEnd    = (float)Math.Max(2.66666666666667 * Interface.CurrentOptions.ViewingDistance, 1600.0);
            Program.CurrentRoute.PreviousFog = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 0.0);
            Program.CurrentRoute.CurrentFog  = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 0.5);
            Program.CurrentRoute.NextFog     = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 1.0);
            if (ResetLogs)
            {
                LogRouteName       = "";
                LogTrainName       = "";
                LogDateTime        = DateTime.Now;
                CurrentScore       = new Score();
                ScoreMessages      = new ScoreMessage[] { };
                ScoreLogs          = new ScoreLog[64];
                ScoreLogCount      = 0;
                BlackBoxEntries    = new BlackBoxEntry[256];
                BlackBoxEntryCount = 0;
                BlackBoxNextUpdate = 0.0;
            }
            // renderer
            if (ResetRenderer)
            {
                Program.Renderer.InfoTotalTriangles     = 0;
                Program.Renderer.InfoTotalTriangleStrip = 0;
                Program.Renderer.InfoTotalQuads         = 0;
                Program.Renderer.InfoTotalQuadStrip     = 0;
                Program.Renderer.InfoTotalPolygon       = 0;
                Program.Renderer.Reset();
            }
        }
Ejemplo n.º 5
0
    public bool ScoreHandler(BaseMessage msg)
    {
        ScoreMessage castMsg = (ScoreMessage)msg;

        Score += castMsg.score;

        return(true);
    }
    public void SendScore(int score, Vector3 scorePos, int lives)
    {
        ScoreMessage msg = new ScoreMessage();

        msg.score    = score;
        msg.scorePos = scorePos;
        msg.lives    = lives;
        NetworkServer.SendToAll(MyMsgType.Score, msg);
    }
Ejemplo n.º 7
0
 private void HandleScore(ScoreMessage scoreMessage)
 {
     ViewController.Instance.UpdateLog(scoreMessage.PlayerName, "Gained " + scoreMessage.ScoreDif.ToString() + " points");
     if (scoreMessage.MissedBy > 0)
     {
         ViewController.Instance.UpdateLog(scoreMessage.PlayerName, "Missed bid by " + scoreMessage.MissedBy.ToString() + " points");
     }
     ViewController.Instance.UpdateScoreInfo(scoreMessage.PlayerName, scoreMessage.Score);
 }
Ejemplo n.º 8
0
    private void CmdChangeFace(int id, bool lv)
    {
        ScoreMessage msg = new ScoreMessage();

        msg.clinetid      = id;
        msg.facedirection = lv;
        msg.scorePos      = Vector3.zero;
        msg.lives         = 0;
        Debug.Log("Server cmd");
        NetworkServer.SendToAll(100, msg);
    }
Ejemplo n.º 9
0
    public void SendScore(int score, Vector3 scorePos, int lives)
    {
        ScoreMessage msg = new ScoreMessage();

        msg.score    = score;
        msg.scorePos = scorePos;
        msg.lives    = lives;

        Debug.Log("Sending score...");
        myClient.Send(MyMsgType.Score, msg);
    }
Ejemplo n.º 10
0
 private void ShowScoreString(string scoreText, string timeRewardText)
 {
     for (int i = 0; i < scoreMessages.Length; i++)
     {
         if (scoreMessages[i].gameObject.activeSelf == false)
         {
             ScoreMessage scoreMessage = scoreMessages[i];
             scoreMessage.SetText(scoreText, timeRewardText);
             break;
         }
     }
 }
Ejemplo n.º 11
0
        /// <summary>Call this function to reset the game</summary>
        /// <param name="ResetLogs">Whether the logs should be reset</param>
        internal static void Reset(bool ResetLogs)
        {
            // track manager
            for (int i = 0; i < Program.CurrentRoute.Tracks.Count; i++)
            {
                int key = Program.CurrentRoute.Tracks.ElementAt(i).Key;
                Program.CurrentRoute.Tracks[key] = new Track();
            }
            // train manager
            Program.TrainManager.Trains = new TrainBase[] { };
            // game
            Interface.LogMessages.Clear();
            Program.CurrentHost.MissingFiles.Clear();
            if (Program.Renderer.CurrentInterface != InterfaceType.Menu)
            {
                Program.Renderer.CurrentInterface = InterfaceType.Normal;
            }

            Program.CurrentRoute.Comment              = "";
            Program.CurrentRoute.Image                = "";
            Program.CurrentRoute.Atmosphere           = new Atmosphere();
            Program.CurrentRoute.LightDefinitions     = new LightDefinition[] { };
            Program.CurrentRoute.BufferTrackPositions = new double[] { };
            //Messages = new Message[] { };
            Program.Renderer.Marker.MarkerTextures            = new Texture[] { };
            Program.CurrentRoute.PointsOfInterest             = new PointOfInterest[] { };
            Program.CurrentRoute.PrecedingTrainTimeDeltas     = new double[] { };
            Interface.CurrentOptions.PrecedingTrainSpeedLimit = double.PositiveInfinity;
            Program.CurrentRoute.BogusPreTrainInstructions    = new BogusPreTrainInstruction[] { };
            Interface.CurrentOptions.TrainName  = "";
            Interface.CurrentOptions.TrainStart = TrainStartMode.EmergencyBrakesNoAts;
            Program.CurrentRoute.NoFogStart     = (float)Math.Max(1.33333333333333 * Interface.CurrentOptions.ViewingDistance, 800.0);
            Program.CurrentRoute.NoFogEnd       = (float)Math.Max(2.66666666666667 * Interface.CurrentOptions.ViewingDistance, 1600.0);
            Program.CurrentRoute.PreviousFog    = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 0.0);
            Program.CurrentRoute.CurrentFog     = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 0.5);
            Program.CurrentRoute.NextFog        = new Fog(Program.CurrentRoute.NoFogStart, Program.CurrentRoute.NoFogEnd, Color24.Grey, 1.0);
            if (ResetLogs)
            {
                LogRouteName       = "";
                LogTrainName       = "";
                LogDateTime        = DateTime.Now;
                CurrentScore       = new Score();
                ScoreMessages      = new ScoreMessage[] { };
                ScoreLogs          = new ScoreLog[64];
                ScoreLogCount      = 0;
                BlackBoxEntries    = new BlackBoxEntry[256];
                BlackBoxEntryCount = 0;
                BlackBoxNextUpdate = 0.0;
            }
        }
Ejemplo n.º 12
0
    public void OnChangePos(NetworkMessage netMsg)
    {
        ScoreMessage msg = netMsg.ReadMessage <ScoreMessage>();

        Debug.Log("OnScoreMessage " + msg.clinetid);
        if (msg.clinetid == 33)
        {
            return;
        }
        if (GameManager.Instance.ID != msg.clinetid)
        {
            changeScale(msg.facedirection);
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        /// 同步分数
        /// </summary>
        /// <param name="self"></param>
        private static void SyncScore(this GameController self)
        {
            Room room = self.GetParent <Room>();

            for (int i = 0; i < room.Players.Length; i++)
            {
                var p   = room.Players[i];
                var msg = new ScoreMessage {
                    Seat = p.SeatIndex, Score = p.GetComponent <ScoreComponent>().Score
                };

                foreach (Player player in room.Players)
                {
                    room.SendActor(player, msg);
                }
            }
        }
Ejemplo n.º 14
0
    internal ScoreMessage PushLocal(object message,
            Color? color, GUIStyle style, GUIStyle styleHighDensity,
            int? messageQueueID, ScoreFlashFollow3D follow3D)
    {
        // Unity fails on compiling: (int)ScoreFlash.DefaultMessageQueueID.Default

        // if this instance of ScoreFlash is not enabled - there's no point in registering the message
        if (!this.enabled) {
            return new ScoreMessage(this, this, message);
        }

        #region Initializing the Message

        // note: messageQueueID null => do not put the message in the queue (used internally)
        // if we have a value here, we're never in the scene view => false
        if (messageQueueID.HasValue) {
            SetIsSceneView(false);
        }

        IHasVisualDesigner scoreFlashLayout = this;
        if (message is ScoreFlashLayout) {
            ScoreFlashLayout sender = (ScoreFlashLayout)message;
            scoreFlashLayout = sender;
            message = sender.MessageForScoreFlash;
        }

        ScoreMessage msg = new ScoreMessage(this, scoreFlashLayout, message);

        if (follow3D != null) {
            msg.SetScoreFlashFollow3D(follow3D);
            if (msg.FollowLocation != null && !allFollow3Ds.Contains(msg.FollowLocation)) {
                allFollow3Ds.Add(msg.FollowLocation);
            }
        }

        msg.isDebug = isDebugMode;
        msg.pos = NGUtil.Scale(new Vector2(fadeInOffsetX, fadeInOffsetY));
        msg.rotationSpeed = fadeOutInitialRotationSpeed;
        msg.useRealTime = timeReference == TimeReference.UseRealTime;

        if (msg.scoreFlashRenderer == null) {
            if (rendering == RenderingType.CustomRenderer && scoreFlashRenderer != null) {
                // do we still have objects in the pool? if so => take on from there ;-)
                ScoreFlashRendererBase objectFromPool = GetRendererFromPool();
                if (objectFromPool != null) {
                    msg.scoreFlashRenderer = objectFromPool;
                } else {
                    Transform parent = scoreFlashRenderer.RequiresCustomParent && customParent != null
                        ? customParent : this.transform;
                    msg.scoreFlashRenderer = scoreFlashRenderer.CreateInstance(parent);
                    msg.scoreFlashRenderer.name = string.Format("Renderer_{0:0000}", rendererIndex++);
                }
            }
        } else { // if we have a renderer "delivered" with the message, do the parent assignment now
            if (scoreFlashRenderer.RequiresCustomParent && customParent != null) {
                msg.scoreFlashRenderer.transform.SetParent(customParent);
            } else {
                msg.scoreFlashRenderer.transform.SetParent(this.transform);
            }
        }

        // if a style is passed to the method, this overwrites the font definition!
        if (style == null && rendering == RenderingType.UnityGUI_Font) {
            style = GetStyleFromPool();
            style.font = CurrentFont;
            style.normal.textColor = Color.white;
            style.alignment = (TextAnchor)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAnchor);
            style.wordWrap = false;
        }

        // if we are using UnityGUI, the following is relevant ...
        if (style == null) {
            if (CurrentSkin == null && msg.scoreFlashRenderer == null) {
                Debug.LogError(
                    string.Format(
                    "You have not assigned a GUISkin and called PushLocal without a style - this won't work! "
                    + "Either assign a GUISkin to ScoreFlash, or use one of the Push-methods that take a "
                    + "GUIStyle as parameter! Message '{0}' will not be shown!", message), this);
                return msg;
            }

            if (CurrentSkin != null) {
                if (CurrentSkin.FindStyle(guiStyleName) == null) {
                    if (!hasWarnedMissingCustomStyle) {
                        Debug.LogWarning(
                            string.Format("Your GUISkin does not have custom style '{0}' - please add that custom style "
                            + "and configure it with your desired font. Using label style instead!", guiStyleName),
                            CurrentSkin);
                        hasWarnedMissingCustomStyle = true;
                    }
                    style = GetStyleFromPool(CurrentSkin.label);
                } else {
                    style = GetStyleFromPool(CurrentSkin.FindStyle(guiStyleName));
                }
                // we need these two and people (including myself) forget to assign them => hardcode it!
                //style.alignment = TextAnchor.UpperCenter; // this is now overridden with innerAnchor

                // this may be overridden when the message exceeds maxWidth
                style.wordWrap = false;
            }
        }
        if (styleHighDensity == null) {
            styleHighDensity = style;
        }

        // this is just an initial reference position - it may be overwritten later!
        if (follow3D == null) {
            msg.ScreenAlign = scoreFlashLayout.ScreenAlign;
            msg.InnerAnchor = scoreFlashLayout.LockInnerAnchor ? msg.ScreenAlign : scoreFlashLayout.InnerAnchor;
            msg.OriginalPosition = NGAlignment.GetScreenBasedReferencePosition(msg.ScreenAlign, Vector2.zero, IsSceneView);
            msg.ReferencePosition = NGAlignment.GetScreenBasedReferencePosition(msg.ScreenAlign, scoreFlashLayout.Position, IsSceneView);
        }

        if (style != null) {
            AssignStyle(msg, style, styleHighDensity);
        }

        if (!color.HasValue) {
            AssignColors(msg);
        } else {
            AssignAlphaMultipliedColor(msg, color.Value);
        }

        // when passing a custom renderer, don't use the one ScoreFlash might define
        if (msg.scoreFlashRenderer != null) {
            // this is put down here because ScoreFlashRendererUnityGUI needs the style to calculate the size
            msg.scoreFlashRenderer.Initialize(msg);
            Rect pos = msg.Position;
            Vector2 size = msg.scoreFlashRenderer.GetSize(msg);
            pos.width = size.x;
            pos.height = size.y;
            msg.Position = pos;
        }

        if (messageQueueID.HasValue) {
            if (!scoreMessages.ContainsKey(messageQueueID.Value)) {
                scoreMessages[messageQueueID.Value] = new NGQueue<ScoreMessage>();
            }
            NGQueue<ScoreMessage> messageQueue = scoreMessages[messageQueueID.Value];

            messageQueue.Enqueue(msg);
            if (messageQueue.Count > maxSimultanuousMessages) {
                messageQueue.QueueOrderedList[messageQueue.Count - maxSimultanuousMessages - 1].LocalTimeScale = 8;
            }

            AnimateMessages(); // make sure everything is immediately initialized
        #if LOGGING_FACADE // if narayana games Logging Facade is available, we add some logging
        log.DebugFormat("Received score message: '{0}'", msg.Text);
        #endif
        }

        return msg;
        #endregion Initializing the Message
    }
Ejemplo n.º 15
0
    private void AnimatePhases(float myDeltaTime, ScoreMessage msg, float addToRead)
    {
        if (msg.Age < fadeInTimeSeconds) { // phase 1: fade in
            float diffFrac = msg.Age / fadeInTimeSeconds;

            msg.CurrentTextColor = NGEasing.EaseOnCurve(fadeInColorCurve, msg.fadeInColor, msg.readColorStart, diffFrac);
            msg.pos.x = NGEasing.EaseOnCurve(fadeInOffsetXCurve, NGUtil.Scale(fadeInOffsetX), 0, diffFrac);
            msg.pos.y = NGEasing.EaseOnCurve(fadeInOffsetYCurve, NGUtil.Scale(fadeInOffsetY), 0, diffFrac);
            msg.Scale = NGEasing.EaseOnCurve(fadeInScaleCurve, fadeInScale, 1, diffFrac);
        } else if (msg.Age < (fadeInTimeSeconds + readTimeSeconds + addToRead)) { // phase 2: read
            float diffFrac = (msg.Age - fadeInTimeSeconds) / (readTimeSeconds + addToRead);
            msg.CurrentPhase = ScoreMessage.Phase.Read;

            msg.CurrentTextColor = NGEasing.EaseOnCurve(readColorCurve, msg.readColorStart, msg.readColorEnd, diffFrac);
            msg.Scale = NGEasing.EaseOnCurve(readScaleCurve, 1, readScale, diffFrac);
            msg.velocity.x = NGEasing.EaseOnCurve(readVelocityXCurve, 0, NGUtil.Scale(readFloatRightVelocity), diffFrac);
            msg.velocity.y = NGEasing.EaseOnCurve(readVelocityCurve, 0, NGUtil.Scale(readFloatUpVelocity), diffFrac);

            msg.pos.x += msg.velocity.x * myDeltaTime;
            msg.pos.y -= msg.velocity.y * myDeltaTime;
        } else { // phase 3: fade out
            float diffFrac = (msg.Age - (fadeInTimeSeconds + readTimeSeconds + addToRead)) / fadeOutTimeSeconds;
            msg.CurrentPhase = ScoreMessage.Phase.FadeOut;

            msg.CurrentTextColor = NGEasing.EaseOnCurve(fadeOutColorCurve, msg.readColorEnd, msg.fadeOutColor, diffFrac);
            msg.Scale = NGEasing.EaseOnCurve(fadeOutScaleCurve, readScale, fadeOutScale, diffFrac);
            msg.velocity.x = NGEasing.EaseOnCurve(fadeOutVelocityXCurve, NGUtil.Scale(readFloatRightVelocity), NGUtil.Scale(fadeOutFloatRightVelocity), diffFrac);
            msg.velocity.y = NGEasing.EaseOnCurve(fadeOutVelocityCurve, NGUtil.Scale(readFloatUpVelocity), NGUtil.Scale(fadeOutFloatUpVelocity), diffFrac);

            msg.pos.x += msg.velocity.x * myDeltaTime;
            msg.pos.y -= msg.velocity.y * myDeltaTime;

            msg.rotationSpeed += fadeOutRotationAcceleration * myDeltaTime;
            msg.Rotation += msg.rotationSpeed * myDeltaTime;
        }
        // assign outline color with alpha based on current value from phase
        msg.OutlineColor = colorOutline;
        msg.OutlineColorAlpha = msg.CurrentTextColor.a * colorOutline.a;
    }
Ejemplo n.º 16
0
 /// <summary>
 ///     Calculates a pixel offset based on msg.Alignment.ScreenAlign. 
 /// </summary>
 /// <remarks>
 ///     You'll want to use this when your GUI system only supports top left
 ///     positioning (like UnityGUI does, for example). It gives you an offset
 ///     vector that you can use in your implementation of 
 ///     <see cref="ScoreFlashRendererBase.UpdateMessage(ScoreMessage)"/> 
 ///     to calculate an offset, or in your rendering code (e.g. when using
 ///     UnityGUI). This only works, when your renderer returns correct and
 ///     reliable values for width and height, so if your GUI system supports
 ///     it, it's preferable to use its positioning system instead. See
 ///     <see cref="NGAlignment.ConvertAlignment(NGAlignment.ScreenAlign, NGAlignment.AlignmentType)"/> for a
 ///     convenient way to convert ScoreFlashs alignment enumeration
 ///     to GUIText.TextAnchors, NGUI style and EZ GUI style.
 /// </remarks>
 /// <param name="msg"></param>
 /// <returns></returns>
 public static Vector2 GetAlignBasedOffset(ScoreMessage msg)
 {
     return NGAlignment.GetAlignBasedOffset(msg.InnerAnchor, msg.Position);
 }
Ejemplo n.º 17
0
 internal void AssignAlphaMultipliedColor(ScoreMessage msg, Color color)
 {
     msg.fadeInColor = color;
     msg.readColorStart = color;
     msg.readColorEnd = color;
     msg.fadeOutColor = color;
     /*
      * apply multipliers on all colorSelectionModes except FadePhases
      * FadePhases has the alpha values assigned through the colors
      * for each phase, so we don't need this here
      */
     msg.fadeInColor.a *= alphaFadeInMultiplier;
     msg.readColorStart.a *= alphaReadStartMultiplier;
     msg.readColorEnd.a *= alphaReadEndMultiplier;
     msg.fadeOutColor.a *= alphaFadeOutMultiplier;
 }
Ejemplo n.º 18
0
    public void onMessageReceived(NetworkMessage netMsg)
    {
        ScoreMessage msg = netMsg.ReadMessage <ScoreMessage>();

        NetworkServer.SendToAll(MyMsgType.Score, msg);
    }
Ejemplo n.º 19
0
    private void HandleMessage(string message)
    {
        try
        {
            lock (MessageTasks)
            {
                ErrorResponse errorResponse = JsonConvert.DeserializeObject <ErrorResponse>(message);
                if (errorResponse.IsValid())
                {
                    Debug.Log("ErrorResponse: " + errorResponse.ErrorMessage);
                    return;
                }

                DisconnectMessage disconnectMessage = JsonConvert.DeserializeObject <DisconnectMessage>(message);
                if (disconnectMessage.IsValid())
                {
                    HandleDisconnect(disconnectMessage);
                    return;
                }

                RestartMessage restartMessage = JsonConvert.DeserializeObject <RestartMessage>(message);
                if (restartMessage.IsValid())
                {
                    HandleRestart(restartMessage);
                    return;
                }

                GameTypeMessage gameTypeMessage = JsonConvert.DeserializeObject <GameTypeMessage>(message);
                if (gameTypeMessage.IsValid())
                {
                    ViewController.Instance.UpdateGameTypes(gameTypeMessage.GameTypes);
                    return;
                }

                JoinResponse joinResponse = JsonConvert.DeserializeObject <JoinResponse>(message);
                if (joinResponse.IsValid())
                {
                    HandleJoinResponse(joinResponse);
                    return;
                }

                AvailableGamesMessage gamesMessage = JsonConvert.DeserializeObject <AvailableGamesMessage>(message);
                if (gamesMessage.IsValid())
                {
                    ViewController.Instance.UpdateAvailableGames(gamesMessage.AvailableGames);
                    return;
                }

                JoinMessage joinMessage = JsonConvert.DeserializeObject <JoinMessage>(message);
                if (joinMessage.IsValid())
                {
                    HandleJoin(joinMessage);
                    return;
                }

                StartMessage startMessage = JsonConvert.DeserializeObject <StartMessage>(message);
                if (startMessage.IsValid())
                {
                    HandleStart(startMessage);
                    return;
                }

                BidMessage bidMessage = JsonConvert.DeserializeObject <BidMessage>(message);
                if (bidMessage.IsValid())
                {
                    HandleBid(bidMessage);
                    return;
                }

                KittyMessage kittyMessage = JsonConvert.DeserializeObject <KittyMessage>(message);
                if (kittyMessage.IsValid())
                {
                    HandleKitty(kittyMessage);
                    return;
                }

                TrumpMessage trumpMessage = JsonConvert.DeserializeObject <TrumpMessage>(message);
                if (trumpMessage.IsValid())
                {
                    HandleTrump(trumpMessage);
                    return;
                }

                MeldPointsMessage meldPointsMessage = JsonConvert.DeserializeObject <MeldPointsMessage>(message);
                if (meldPointsMessage.IsValid())
                {
                    HandleMeldPoints(meldPointsMessage);
                    return;
                }

                MeldMessage meldMessage = JsonConvert.DeserializeObject <MeldMessage>(message);
                if (meldMessage.IsValid())
                {
                    HandleMeld(meldMessage);
                    return;
                }

                PassMessage passMessage = JsonConvert.DeserializeObject <PassMessage>(message);
                if (passMessage.IsValid())
                {
                    HandlePass(passMessage);
                    return;
                }

                ScoreMessage scoreMessage = JsonConvert.DeserializeObject <ScoreMessage>(message);
                if (scoreMessage.IsValid())
                {
                    HandleScore(scoreMessage);
                    return;
                }

                TurnMessage turnMessage = JsonConvert.DeserializeObject <TurnMessage>(message);
                if (turnMessage.IsValid())
                {
                    HandleTurn(turnMessage);
                    return;
                }

                TrickMessage trickMessage = JsonConvert.DeserializeObject <TrickMessage>(message);
                if (trickMessage.IsValid())
                {
                    HandleTrick(trickMessage);
                    return;
                }

                TrickInfoMessage trickInfoMessage = JsonConvert.DeserializeObject <TrickInfoMessage>(message);
                if (trickInfoMessage.IsValid())
                {
                    HandleTrickInfo(trickInfoMessage);
                    return;
                }

                GameOverMessage gameOverMessage = JsonConvert.DeserializeObject <GameOverMessage>(message);
                if (gameOverMessage.IsValid())
                {
                    HandleGameOver(gameOverMessage);
                    return;
                }
            }
        }
        catch (Exception err)
        {
            Debug.Log("OnMessage error: " + err.Message);
            Debug.Log("OnMessage stack trace: " + err.StackTrace);
        }
    }
 /// <summary>
 ///     Update the message. The implementation needs
 ///     to make sure that you update position, scale, color and outline
 ///     color as well as the text.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override void UpdateMessage(ScoreMessage msg)
 {
     this.msg = msg;
     // we don't need to do anything here, because the renderer
     // pulls the information from ScoreMessage msg while rendering
     // NGUI / EZ GUI solutions do the "interesting stuff" in this method
 }
Ejemplo n.º 21
0
 private float CalcAddToRead(ScoreMessage msg)
 {
     float addToRead = 0;
     if (msg.Text.Length > readMinLengthCharsToAddTime) {
         addToRead = readAddTimeSeconds;
         // this should usually not happen; for "ultra-long texts"; if that's still not sufficient: simply ignore ...
         if (msg.Text.Length > 2 * readMinLengthCharsToAddTime) {
             addToRead += readAddTimeSeconds;
         }
     }
     return addToRead;
 }
Ejemplo n.º 22
0
 /// <summary>
 ///     Shortcut for pushing messages in a specific color directly using this ScoreFlashLayout instance.
 /// </summary>
 /// <remarks>
 ///     Calls <see cref="IScoreFlash.PushLocal(object, Color)"/> on <see cref="defaultScoreFlash"/>
 ///     (or using the single ScoreFlash instance if defaultScoreFlash wasn't assigned).
 /// </remarks>
 /// <param name="message">the message to send, could also be a custom renderer (or any object)</param>
 /// <param name="color">
 ///     Use this to control the color the message is sent with. Uses RGB from <c>color</c>,
 ///     and multiplies <c>color.a</c> with the current alpha value depending on the settings
 ///     in the ScoreFlash instance that this message was pushed to
 /// </param>
 /// <returns>return the ScoreMessage representing msg</returns>
 public ScoreMessage Push(object message, Color color)
 {
     HandlePreviousMessage();
     messageForScoreFlash = message;
     currentMessage = DefaultScoreFlash.PushLocal(this, color, this.GetInstanceID());
     ApplyMessageSettings(currentMessage);
     return currentMessage;
 }
Ejemplo n.º 23
0
 private void ApplyMessageSettings(ScoreMessage msg)
 {
     msg.FreezeOnRead = freezeOnRead;
 }
 /// <summary>
 ///     The size of the achievement on the screen, based on texture size of
 ///     <c>textureAchievementNormalEarned</c>.
 /// </summary>
 /// <param name="msg">ignored</param>
 public override Vector2 GetSize(ScoreMessage msg)
 {
     return new Vector2(textureAchievementNormalEarned.width, textureAchievementNormalEarned.height);
 }
Ejemplo n.º 25
0
		// ================================

		internal static void Reset(bool ResetLogs) {
			// track manager
			TrackManager.CurrentTrack = new TrackManager.Track();
			// train manager
			TrainManager.Trains = new TrainManager.Train[] { };
			// game
			Debug.ClearMessages();
			CurrentInterface = InterfaceType.Normal;
			RouteComment = "";
			RouteImage = "";
			RouteAccelerationDueToGravity = 9.80665;
			RouteRailGauge = 1.435;
			RouteInitialAirPressure = 101325.0;
			RouteInitialAirTemperature = 293.15;
			RouteInitialElevation = 0.0;
			RouteSeaLevelAirPressure = 101325.0;
			RouteSeaLevelAirTemperature = 293.15;
			Stations = new Station[] { };
			Sections = new Section[] { };
			BufferTrackPositions = new double[] { };
			Messages = new Message[] { };
			MarkerTextures = new Textures.Texture[] { };
			PointsOfInterest = new PointOfInterest[] { };
			PrecedingTrainTimeDeltas = new double[] { };
			PrecedingTrainSpeedLimit = double.PositiveInfinity;
			BogusPretrainInstructions = new BogusPretrainInstruction[] { };
			TrainName = "";
			TrainStart = TrainStartMode.EmergencyBrakesNoAts;
			NoFogStart = (float)Math.Max(1.33333333333333 * Options.Current.ViewingDistance, 800.0);
			NoFogEnd = (float)Math.Max(2.66666666666667 * Options.Current.ViewingDistance, 1600.0);
			PreviousFog = new Fog(NoFogStart, NoFogEnd, new Color24(128, 128, 128), 0.0);
			CurrentFog = new Fog(NoFogStart, NoFogEnd, new Color24(128, 128, 128), 0.5);
			NextFog = new Fog(NoFogStart, NoFogEnd, new Color24(128, 128, 128), 1.0);
			InfoTotalTriangles = 0;
			InfoTotalTriangleStrip = 0;
			InfoTotalQuads = 0;
			InfoTotalQuadStrip = 0;
			InfoTotalPolygon = 0;
			InfoStaticOpaqueFaceCount = 0;
			if (ResetLogs) {
				LogRouteName = "";
				LogTrainName = "";
				LogDateTime = DateTime.Now;
				CurrentScore = new Score();
				ScoreMessages = new ScoreMessage[] { };
				ScoreLogs = new ScoreLog[64];
				ScoreLogCount = 0;
				BlackBoxEntries = new BlackBoxEntry[256];
				BlackBoxEntryCount = 0;
				BlackBoxNextUpdate = 0.0;
			}
			// renderer
			Renderer.Reset();
		}
Ejemplo n.º 26
0
    public void OnScore(NetworkMessage netMsg)
    {
        ScoreMessage msg = netMsg.ReadMessage <ScoreMessage>();

        Debug.Log("OnScoreMessage " + msg.score);
    }
Ejemplo n.º 27
0
    private void AssignColors(ScoreMessage msg)
    {
        switch (colorSelectionMode) {
            case ColorControl.FadePhases:
                msg.fadeInColor = fadeInColor;
                msg.readColorStart = readColorStart;
                msg.readColorEnd = readColorEnd;
                msg.fadeOutColor = fadeOutColor;
                break;
            case ColorControl.UseColorFromSkin:
                if (msg.style == null) {
                    Debug.LogError(
                        "Trying to use ColorControl.UseColorFromSkin without a skin assigned or a GUIStyle passed! "
                        + " You either need to assign a skin, or pass a GUIStyle in the push-method, or choose another "
                        + " Color Selection Mode!");
                } else {
                    AssignAlphaMultipliedColor(msg, msg.style.normal.textColor);
                }
                break;
            case ColorControl.Sequence:
                if (CheckForColors(msg)) {
                    AssignAlphaMultipliedColor(msg, colors[colorIndex++ % colors.Count]);
                }
                break;
            case ColorControl.Random:
                if (CheckForColors(msg)) {
                    int index = Random.Range(0, colors.Count);
                    int counter = 0;
                    /*
                     * we check for colors.Count > 2 because with only
                     * two colors to pick from, our "use previous color prevention"
                     * would lead to the two colors simply alterating; so in
                     * that case, to achieve a bit of randomness, being able
                     * to show the same color twice is actually better
                     */
                    while (colors.Count > 2 && (previousIndex == index || usedColorIndices.Contains(index))) {
                        index = Random.Range(0, colors.Count);
                        /*
                         * we only try twice the number of available colors
                         * if that fails, either we had very bad luck or the
                         * number of colors has meanwhile changed and we might
                         * never find an index from the available numbers that
                         * is not yet used; colors.Count * 2 is really just
                         * a heuristic; you could put any number in here
                         */
                        if (usedColorIndices.Count >= colors.Count || counter > colors.Count * 2) {
        #if LOGGING_FACADE
                            log.DebugFormat(
                                "Cleared used indices usedColorIndices.Count={0} >= colors.Count={1} || counter={2} > colors.Count * 2={3}",
                                usedColorIndices.Count, colors.Count, counter, colors.Count * 2);
        #endif
                            usedColorIndices.Clear();
                            counter++;
                        }
                    }
        #if LOGGING_FACADE
                    log.DebugFormat("Using color: {0}", index);
        #endif
                    previousIndex = index;
                    usedColorIndices.Add(index);
                    AssignAlphaMultipliedColor(msg, colors[index]);
                }
                break;

        }
    }
Ejemplo n.º 28
0
    private void SpreadMessages(float myDeltaTime, ScoreMessage msg, ScoreMessage nextMsg)
    {
        float distance = Mathf.Abs(Mathf.Abs(msg.pos.y) - Mathf.Abs(nextMsg.pos.y));
        float requiredHeight = NGUtil.Scale(minDistanceBetweenMessages) + nextMsg.Position.height;
        if (distance < requiredHeight) {
            msg.pos.y -= myDeltaTime * (requiredHeight - distance) * spreadSpeed;

            float addToRead = CalcAddToRead(msg);

            if (msg.Age < fadeInTimeSeconds + readTimeSeconds + addToRead) {
                msg.AddDeltaTimeToAge(myDeltaTime);
            }
            msg.UpdateRenderer();
        }
    }
Ejemplo n.º 29
0
    private void AssignStyle(ScoreMessage msg, GUIStyle style, GUIStyle styleHighDensity)
    {
        msg.style = NGUtil.IsHighDensityDisplay ? styleHighDensity : style;

        msg.style.alignment = (TextAnchor)NGAlignment.ConvertAlignment(msg.InnerAnchor, NGAlignment.AlignmentType.TextAnchor);
        //msg.style.alignment = TextAnchor.UpperLeft;

        // initialize position (y will be assigned in Update)
        GUIContent msgText = new GUIContent(msg.Text);
        Vector2 size = msg.style.CalcSize(msgText);
        float maxWidth = msg.MaxWidth;
        if (size.x > maxWidth) {
            msg.style.wordWrap = true;
        #if LOGGING_FACADE
            log.DebugFormat("Applying width fix for '{0}' (word wrapping activated!)", msg.Text);
        #endif
            size.x = maxWidth;
            size.y = msg.style.CalcHeight(msgText, size.x);
        }
        Rect position = msg.Position;
        position.width = size.x;
        position.height = size.y;
        msg.Position = position;

        msg.styleOutline = GetStyleFromPool(msg.style);
    }
Ejemplo n.º 30
0
        /// <summary>
        ///     Update the message.
        /// </summary>
        /// <param name="msg">the current version of the message</param>
        public override void UpdateMessage(ScoreMessage msg)
        {
            transform.position = msg.FollowLocation.CurrentTranslatedPosition;
            transform.LookAt(msg.Follow3D.referenceCamera.transform.position, msg.Follow3D.referenceCamera.transform.up);

            // are we visible (we may be behind the player when rendering ScoreFlashFollow3D stuff)
            text.enabled = msg.IsVisible;

            // push text and color to Unity UI label
            text.text = msg.Text;
            text.color = msg.CurrentTextColor;

            Vector2 position = new Vector2(msg.Position.x, msg.Position.y);
            position -= msg.OriginalPosition;
            rt.anchoredPosition = new Vector2(position.x, -position.y);

            // ... ok, I guess these are kind of obvious, aren't they?
            text.transform.localScale = msg.Scale * Vector3.one;
            textTransform.localRotation = Quaternion.Euler(0, 180, -msg.Rotation);
        }
Ejemplo n.º 31
0
 private bool CheckForColors(ScoreMessage msg)
 {
     if (colors == null || colors.Count == 0) {
         if (msg.style == null) {
             Debug.LogError(
                 "No colors assigned, no skin assigned - please set up ScoreFlash correctly: "
                 +"Either assign colors, or a skin, or select Color Selection Mode: FadePhases!");
         } else {
             Debug.LogWarning(
                 string.Format("No Colors assigned - cannot use Color Selection Mode: {0}! Using skin color as fallback!",
                 colorSelectionMode));
             AssignAlphaMultipliedColor(msg, msg.style.normal.textColor);
         }
         return false;
     }
     return true;
 }
Ejemplo n.º 32
0
 /// <summary>
 ///     The size of the message on screen. This is using 
 ///     text.preferredWith and text.preferredHeight.
 /// </summary>
 /// <param name="msg">the current version of the message</param>
 public override Vector2 GetSize(ScoreMessage msg)
 {
     text.text = msg.Text;
     DoLayout();
     return new Vector2(text.preferredWidth, rt.sizeDelta.y);
 }
Ejemplo n.º 33
0
 /// <summary>
 ///     Shortcut for pushing messages in a specific color directly using this ScoreFlashFollow3D instance.
 /// </summary>
 /// <remarks>
 ///     Calls <see cref="IScoreFlash.PushWorld(ScoreFlashFollow3D, object, Color)"/> on <see cref="defaultScoreFlash"/>
 ///     (or using the single ScoreFlash instance if defaultScoreFlash wasn't assigned).
 /// </remarks>
 /// <param name="message">the message to send, could also be a custom renderer (or any object)</param>
 /// <param name="color">
 ///     Use this to control the color the message is sent with. Uses RGB from <c>color</c>,
 ///     and multiplies <c>color.a</c> with the current alpha value depending on the settings
 ///     in the ScoreFlash instance that this message was pushed to
 /// </param>
 /// <returns>return the ScoreMessage representing msg during </returns>
 public ScoreMessage Push(object message, Color color)
 {
     HandlePreviousMessage();
     currentMessage = DefaultScoreFlash.PushWorld(this, message, color);
     ApplyMessageSettings(currentMessage);
     return currentMessage;
 }
Ejemplo n.º 34
0
        public override void Initialize(ScoreMessage msg)
        {
            Vector2 sd = rt.sizeDelta;
            sd.x = msg.MaxWidth;
            rt.sizeDelta = sd;

            text.text = msg.Text;

            /*
             * Note: We simply keep the anchor, pivot and text alignment as
             * set up in the prefab - this gives us more flexibility!
             */

            DoLayout();
        }