project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/MessageLog.java
author koda
Tue, 15 Oct 2013 01:15:39 +0200
changeset 9543 1826b5315369
parent 7584 7831c84cc644
child 10017 de822cd3df3a
permissions -rw-r--r--
Fix bug #656 by using the right resolution values
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     5
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     6
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     8
 * of the License, or (at your option) any later version.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    13
 * GNU General Public License for more details.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    15
 * You should have received a copy of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    16
 * along with this program; if not, write to the Free Software
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    19
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
package org.hedgewars.hedgeroid.netplay;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    22
import java.util.Collection;
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    23
import java.util.Collections;
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import java.util.Date;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import java.util.LinkedList;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
import java.util.List;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
import org.hedgewars.hedgeroid.R;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7444
diff changeset
    29
import org.hedgewars.hedgeroid.frontlib.Frontlib;
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
import android.content.Context;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
import android.graphics.Color;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
import android.graphics.Typeface;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
import android.text.Html;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
import android.text.Spannable;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
import android.text.SpannableString;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
import android.text.SpannableStringBuilder;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
import android.text.Spanned;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
import android.text.TextUtils;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
import android.text.format.DateFormat;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
import android.text.style.ForegroundColorSpan;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
import android.text.style.RelativeSizeSpan;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
import android.text.style.StyleSpan;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
import android.util.Log;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
public class MessageLog {
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    47
	private static final int BACKLOG_LINES = 200;
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
	private static final int INFO_COLOR = Color.GRAY;
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    50
	private static final int PLAYERINFO_COLOR = Color.GREEN;
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	private static final int CHAT_COLOR = Color.GREEN;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
	private static final int MECHAT_COLOR = Color.CYAN;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
	private static final int WARN_COLOR = Color.RED;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
	private static final int ERROR_COLOR = Color.RED;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
	private final Context context;
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    57
	private List<Listener> observers = new LinkedList<Listener>();
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    58
	private List<CharSequence> log = new LinkedList<CharSequence>();
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
	public MessageLog(Context context) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
		this.context = context;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
	private Spanned makeLogTime() {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
		String time = DateFormat.getTimeFormat(context).format(new Date());
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
		return withColor("[" + time + "] ", INFO_COLOR);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
	private static Spanned span(CharSequence s, Object o) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
		Spannable spannable = new SpannableString(s);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
		spannable.setSpan(o, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
		return spannable;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
	private static Spanned withColor(CharSequence s, int color) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
		return span(s, new ForegroundColorSpan(color));
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
	private static Spanned bold(CharSequence s) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
		return span(s, new StyleSpan(Typeface.BOLD));
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
	private void append(CharSequence msg) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
		SpannableStringBuilder ssb = new SpannableStringBuilder();
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    85
		ssb.append(makeLogTime()).append(msg);
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
		appendRaw(ssb);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
	private void appendRaw(CharSequence msg) {
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    90
		if(log.size() > BACKLOG_LINES) {
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    91
			log.remove(0);
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    92
			for(Listener o : observers) {
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    93
				o.lineRemoved();
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    94
			}
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
		}
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    96
		log.add(msg);
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
    97
		for(Listener o : observers) {
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
    98
			o.lineAdded(msg);
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
    99
		}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   100
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   101
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   102
	void appendPlayerJoin(String playername) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   103
		append(withColor("***" + context.getResources().getString(R.string.log_player_join, playername), INFO_COLOR));
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
	void appendPlayerLeave(String playername, String partMsg) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
		String msg = "***";
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
		if(partMsg != null) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   109
			msg += context.getResources().getString(R.string.log_player_leave_with_msg, playername, partMsg);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
		} else {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
			msg += context.getResources().getString(R.string.log_player_leave, playername);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   112
		}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   113
		append(withColor(msg, INFO_COLOR));
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
	void appendChat(String playerName, String msg) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
		if(msg.startsWith("/me ")) {
7444
2e31f114f57e Hedgeroid: various improvements:
Medo <smaxein@googlemail.com>
parents: 7352
diff changeset
   118
			append(withColor("*"+playerName+" "+msg.substring(4), MECHAT_COLOR));
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   119
		} else {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   120
			Spanned name = bold(playerName+": ");
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
			Spanned fullMessage = withColor(TextUtils.concat(name, msg), CHAT_COLOR);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
			append(fullMessage);			
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
		}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
	void appendMessage(int type, String msg) {
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
		switch(type) {
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7444
diff changeset
   128
		case Frontlib.NETCONN_MSG_TYPE_ERROR:
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   129
			append(withColor("***"+msg, ERROR_COLOR));
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   130
			break;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7444
diff changeset
   131
		case Frontlib.NETCONN_MSG_TYPE_WARNING:
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   132
			append(withColor("***"+msg, WARN_COLOR));
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   133
			break;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7444
diff changeset
   134
		case Frontlib.NETCONN_MSG_TYPE_PLAYERINFO:
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
   135
			append(withColor(msg.replace("\n", " "), PLAYERINFO_COLOR));
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   136
			break;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7444
diff changeset
   137
		case Frontlib.NETCONN_MSG_TYPE_SERVERMESSAGE:
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   138
			appendRaw(span(TextUtils.concat("\n", Html.fromHtml(msg), "\n"), new RelativeSizeSpan(1.5f)));
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   139
			break;
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   140
		default:
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   141
			Log.e("MessageLog", "Unknown messagetype "+type);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   142
		}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   143
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
	
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
	void clear() {
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
   146
		for(Listener o : observers) {
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   147
			o.clear();
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   148
		}
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
		log.clear();
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
	
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
   152
	public void addListener(Listener o) {
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
		observers.add(o);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
	
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
   156
	public void removeListener(Listener o) {
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
		observers.remove(o);
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   159
	
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7476
diff changeset
   160
	public static interface Listener {
7346
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   161
		void lineAdded(CharSequence text);
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   162
		void lineRemoved();
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   163
		void clear();
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   164
	}
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   165
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   166
	public Collection<CharSequence> getLog() {
b0f67c5b4215 Hedgeroid: Lobby activity improvements
Medo <smaxein@googlemail.com>
parents: 7332
diff changeset
   167
		return Collections.unmodifiableList(log);
7332
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   168
	}
3f2e130f9715 Hedgeroid: Chat and player list work now, but everything is very much WIP
Medo <smaxein@googlemail.com>
parents:
diff changeset
   169
}