project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Roomlist.java
author Medo <smaxein@googlemail.com>
Mon, 20 Aug 2012 21:05:57 +0200
changeset 7584 7831c84cc644
parent 7508 763d3961400b
child 10017 de822cd3df3a
permissions -rw-r--r--
License change: With the agreement of Xeli, I changed the Hedgeroid license to GPLv2+ (from GPLv2).
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: 7508
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
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: 7508
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: 7508
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
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: 7508
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: 7508
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: 7508
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: 7508
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
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: 7508
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: 7508
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: 7508
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: 7508
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
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: 7508
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: 7508
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: 7508
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    19
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
package org.hedgewars.hedgeroid.netplay;
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    22
import java.util.Map;
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    23
import java.util.TreeMap;
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    24
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    25
import org.hedgewars.hedgeroid.Datastructures.Room;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    26
import org.hedgewars.hedgeroid.Datastructures.RoomWithId;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    27
import org.hedgewars.hedgeroid.util.ObservableTreeMap;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    28
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    29
public class Roomlist extends ObservableTreeMap<String, RoomWithId> {
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
	private long nextId = 1;
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    31
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    32
	public void updateList(Room[] newRooms) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    33
		Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    34
		for(Room room : newRooms) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    35
			RoomWithId oldEntry = get(room.name);
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    36
			if(oldEntry == null) {
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    37
				newMap.put(room.name, new RoomWithId(room, nextId++));
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    38
			} else {
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    39
				newMap.put(room.name, new RoomWithId(room, oldEntry.id));
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    40
			}
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    41
		}
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    42
		replaceContent(newMap);
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    43
	}
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    45
	public void addRoomWithNewId(Room room) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    46
		put(room.name, new RoomWithId(room, nextId++));
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
	}
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    49
	public void updateRoom(String name, Room room) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    50
		RoomWithId oldEntry = get(name);
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
		if(oldEntry == null) {
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    52
			addRoomWithNewId(room);
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
		} else {
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    54
			remove(name);
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    55
			put(room.name, new RoomWithId(room, oldEntry.id));
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
		}
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
	}
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
}