project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java
changeset 7582 714310efad8f
parent 7476 2fb781bbdd51
child 7584 7831c84cc644
equal deleted inserted replaced
7580:c92596feac0d 7582:714310efad8f
    33 	private static final int MECHAT_COLOR = Color.CYAN;
    33 	private static final int MECHAT_COLOR = Color.CYAN;
    34 	private static final int WARN_COLOR = Color.RED;
    34 	private static final int WARN_COLOR = Color.RED;
    35 	private static final int ERROR_COLOR = Color.RED;
    35 	private static final int ERROR_COLOR = Color.RED;
    36 	
    36 	
    37 	private final Context context;
    37 	private final Context context;
    38 	private List<Observer> observers = new LinkedList<Observer>();
    38 	private List<Listener> observers = new LinkedList<Listener>();
    39 	private List<CharSequence> log = new LinkedList<CharSequence>();
    39 	private List<CharSequence> log = new LinkedList<CharSequence>();
    40 	
    40 	
    41 	public MessageLog(Context context) {
    41 	public MessageLog(Context context) {
    42 		this.context = context;
    42 		this.context = context;
    43 	}
    43 	}
    68 	}
    68 	}
    69 	
    69 	
    70 	private void appendRaw(CharSequence msg) {
    70 	private void appendRaw(CharSequence msg) {
    71 		if(log.size() > BACKLOG_LINES) {
    71 		if(log.size() > BACKLOG_LINES) {
    72 			log.remove(0);
    72 			log.remove(0);
    73 			for(Observer o : observers) {
    73 			for(Listener o : observers) {
    74 				o.lineRemoved();
    74 				o.lineRemoved();
    75 			}
    75 			}
    76 		}
    76 		}
    77 		log.add(msg);
    77 		log.add(msg);
    78 		for(Observer o : observers) {
    78 		for(Listener o : observers) {
    79 			o.lineAdded(msg);
    79 			o.lineAdded(msg);
    80 		}
    80 		}
    81 	}
    81 	}
    82 	
    82 	
    83 	void appendPlayerJoin(String playername) {
    83 	void appendPlayerJoin(String playername) {
   111 			break;
   111 			break;
   112 		case Frontlib.NETCONN_MSG_TYPE_WARNING:
   112 		case Frontlib.NETCONN_MSG_TYPE_WARNING:
   113 			append(withColor("***"+msg, WARN_COLOR));
   113 			append(withColor("***"+msg, WARN_COLOR));
   114 			break;
   114 			break;
   115 		case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
   115 		case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
   116 			// TODO Display in popup?
       
   117 			append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
   116 			append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
   118 			break;
   117 			break;
   119 		case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
   118 		case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
   120 			appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
   119 			appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
   121 			break;
   120 			break;
   123 			Log.e("MessageLog", "Unknown messagetype "+type);
   122 			Log.e("MessageLog", "Unknown messagetype "+type);
   124 		}
   123 		}
   125 	}
   124 	}
   126 	
   125 	
   127 	void clear() {
   126 	void clear() {
   128 		for(Observer o : observers) {
   127 		for(Listener o : observers) {
   129 			o.clear();
   128 			o.clear();
   130 		}
   129 		}
   131 		log.clear();
   130 		log.clear();
   132 	}
   131 	}
   133 	
   132 	
   134 	public void registerObserver(Observer o) {
   133 	public void addListener(Listener o) {
   135 		observers.add(o);
   134 		observers.add(o);
   136 	}
   135 	}
   137 	
   136 	
   138 	public void unregisterObserver(Observer o) {
   137 	public void removeListener(Listener o) {
   139 		observers.remove(o);
   138 		observers.remove(o);
   140 	}
   139 	}
   141 	
   140 	
   142 	public static interface Observer {
   141 	public static interface Listener {
   143 		void lineAdded(CharSequence text);
   142 		void lineAdded(CharSequence text);
   144 		void lineRemoved();
   143 		void lineRemoved();
   145 		void clear();
   144 		void clear();
   146 	}
   145 	}
   147 
   146