Example #1
0
        private static void ShowMessage(Texture2D texture, ServerResponseData response)
        {
            MessageDisplayLogic.IncreaseTimesShown(response.MessageName);
            MessageDisplayLogic.SetLastMessageShownDate(response.MessageName);

            InfoMessage.ShowMessage(texture, response);
        }
Example #2
0
        private static void ProcessServerReply(WWW www, object args)
        {
            if (www.text.Contains("error"))
            {
                //			return;
                throw new InvalidOperationException("Received a error response from the server:\n" + www.text);
            }

            var responseData = ServerResponseData.DeserializeFromXML(www.text);

            if (null == responseData)
            {
                return;
            }
            //			throw new InvalidOperationException("Unable to deserialize XML response:\n" + www.text);

//			Debug.Log("Response:\n" +
//			          "MessageType: " + responseData.MessageType + "\n" +
//			          "ImageUrl: " + responseData.ImageUrl + "\n" +
//			          "TargetUrl: " + responseData.TargetUrl + "\n" +
//			          "TimesToShow: " + responseData.TimesToShow + "\n" +
//			          "IntervalInMinutes: " + responseData.IntervalInMinutes + "\n");
            MessageDisplayLogic.ResetIfShould(responseData);

            if (!MessageDisplayLogic.CanShowMessage(responseData))
            {
                return;
            }

            LoadTexture(responseData);
        }
Example #3
0
        private static string GetResetTokenKeyName(ServerResponseData response)
        {
            if (response.ResetToken < 0)
            {
                return(null);
            }

            return(InfoMessageBootstrap.PluginName + "_" + response.MessageName + "_reset_token");
        }
Example #4
0
        public static void ShowMessage(Texture2D texture, ServerResponseData responseData)
        {
            var rect = MakeCenteredRect(texture.width + 20, texture.height + 20);

            var window = EditorWindow.GetWindowWithRect <InfoMessage>(rect, true, InfoMessageBootstrap.PluginName, true);

            window.position      = rect;
            window._texture      = texture;
            window._responseData = responseData;
        }
Example #5
0
        private static void LoadTexture(ServerResponseData response)
        {
            if (string.IsNullOrEmpty(response.ImageUrl))
            {
                return;
            }
            //			throw new Exception("No ImageUrl provided in response");

            StartWWWRequest(response.ImageUrl, ProcessWWWTexture, response);
        }
Example #6
0
        public static bool ExceededMaxTimesToShow(ServerResponseData response)
        {
            var timesMessageWasShownKey = GetTimesMessageWasShownKey(response.MessageName);

            EditorPrefsHelper.InitIfUndefined(timesMessageWasShownKey, 0);

            int timesMessageWasShown = GetTimesMessageWasShown(response.MessageName);

            return(timesMessageWasShown >= response.TimesToShow);
        }
Example #7
0
        public static bool CanShowMessage(ServerResponseData response)
        {
            if (!HasEnoughTimePassed(response))
            {
                return(false);
            }

            if (ExceededMaxTimesToShow(response))
            {
                return(false);
            }

            return(true);
        }
Example #8
0
        public static void ResetIfShould(ServerResponseData response)
        {
            if (response.ResetToken < 0)
            {
                return;
            }

            var resetTokenKey = GetResetTokenKeyName(response);

            bool shouldReset = !EditorPrefs.HasKey(resetTokenKey) || (EditorPrefs.GetInt(resetTokenKey) != response.ResetToken);

            if (shouldReset)
            {
                                #if DEBUG_INFO_MESSAGE
                Debug.Log("Reset");
                                #endif
                //Reset mesage info
                MessageDisplayLogic.SetTimesMessageWasShown(response.MessageName, 0);
                MessageDisplayLogic.SetLastMessageShownDate(response.MessageName);
            }

            //Update reset token
            EditorPrefs.SetInt(resetTokenKey, response.ResetToken);
        }
Example #9
0
        public static bool HasEnoughTimePassed(ServerResponseData response)
        {
            string messageDateKey = GetMessageDateKey(response.MessageName);

            string currentDate = System.DateTime.Now.Ticks.ToString();

            bool newKey = !EditorPrefs.HasKey(messageDateKey);

            EditorPrefsHelper.InitIfUndefined(messageDateKey, currentDate);

            long   lastTimeMessageShownTicks     = long.Parse(EditorPrefs.GetString(messageDateKey));
            double minutesPassedSinceLastMessage = System.TimeSpan.FromTicks(System.DateTime.Now.Ticks - lastTimeMessageShownTicks).TotalMinutes;

            var timesMessageWasShown = GetTimesMessageWasShown(response.MessageName);

            var interval = response.IntervalInMinutes * (Mathf.Exp(timesMessageWasShown) - 1);

                        #if DEBUG_INFO_MESSAGE
            Debug.Log("timesMessageWasShown: " + timesMessageWasShown + "; interval: " +
                      minutesPassedSinceLastMessage + "/" + interval);
                        #endif

            return(newKey || minutesPassedSinceLastMessage >= interval);
        }
Example #10
0
        public static void ShowMessage(Texture2D texture, ServerResponseData responseData)
        {
            var rect = MakeCenteredRect(texture.width + 20, texture.height + 20);

            var window = EditorWindow.GetWindowWithRect<InfoMessage>(rect, true, InfoMessageBootstrap.PluginName, true);

            window.position = rect;
            window._texture = texture;
            window._responseData = responseData;
        }
Example #11
0
        public static bool ExceededMaxTimesToShow(ServerResponseData response)
        {
            var timesMessageWasShownKey = GetTimesMessageWasShownKey(response.MessageName);

            EditorPrefsHelper.InitIfUndefined( timesMessageWasShownKey, 0 );

            int timesMessageWasShown = GetTimesMessageWasShown( response.MessageName );

            return timesMessageWasShown >= response.TimesToShow;
        }
Example #12
0
        public static bool HasEnoughTimePassed( ServerResponseData response )
        {
            string messageDateKey = GetMessageDateKey( response.MessageName );

            string currentDate = System.DateTime.Now.Ticks.ToString();

            bool newKey = !EditorPrefs.HasKey( messageDateKey );

            EditorPrefsHelper.InitIfUndefined( messageDateKey, currentDate );

            long lastTimeMessageShownTicks = long.Parse( EditorPrefs.GetString( messageDateKey ) );
            double minutesPassedSinceLastMessage = System.TimeSpan.FromTicks(System.DateTime.Now.Ticks - lastTimeMessageShownTicks).TotalMinutes;

            var timesMessageWasShown = GetTimesMessageWasShown( response.MessageName );

            var interval = response.IntervalInMinutes * ( Mathf.Exp(timesMessageWasShown) - 1 );

            #if DEBUG_INFO_MESSAGE
            Debug.Log("timesMessageWasShown: " + timesMessageWasShown + "; interval: " +
                      minutesPassedSinceLastMessage + "/" + interval);
            #endif

            return newKey || minutesPassedSinceLastMessage >= interval;
        }
Example #13
0
        public static bool CanShowMessage(ServerResponseData response)
        {
            if ( !HasEnoughTimePassed( response ) )
                return false;

            if ( ExceededMaxTimesToShow( response ) )
                return false;

            return true;
        }
Example #14
0
        private static void ShowMessage( Texture2D texture, ServerResponseData response)
        {
            MessageDisplayLogic.IncreaseTimesShown( response.MessageName );
            MessageDisplayLogic.SetLastMessageShownDate( response.MessageName );

            InfoMessage.ShowMessage( texture, response );
        }
Example #15
0
        private static void LoadTexture(ServerResponseData response)
        {
            if ( string.IsNullOrEmpty( response.ImageUrl ) )
                return;
            //			throw new Exception("No ImageUrl provided in response");

            StartWWWRequest( response.ImageUrl, ProcessWWWTexture, response );
        }
Example #16
0
        private static string GetResetTokenKeyName( ServerResponseData response )
        {
            if (response.ResetToken < 0) return null;

            return InfoMessageBootstrap.PluginName + "_" + response.MessageName + "_reset_token";
        }
Example #17
0
        public static void ResetIfShould( ServerResponseData response )
        {
            if (response.ResetToken < 0 )
                return;

            var resetTokenKey = GetResetTokenKeyName( response );

            bool shouldReset = !EditorPrefs.HasKey( resetTokenKey ) || (EditorPrefs.GetInt( resetTokenKey ) != response.ResetToken);
            if ( shouldReset ) {
                #if DEBUG_INFO_MESSAGE
                Debug.Log("Reset");
                #endif
                //Reset mesage info
                MessageDisplayLogic.SetTimesMessageWasShown( response.MessageName, 0 );
                MessageDisplayLogic.SetLastMessageShownDate( response.MessageName );
            }

            //Update reset token
            EditorPrefs.SetInt( resetTokenKey, response.ResetToken );
        }