project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/netplay/Roomlist.java
author Medo <smaxein@googlemail.com>
Sat, 18 Aug 2012 00:47:51 +0200
changeset 7508 763d3961400b
parent 7491 d954c1a36e51
child 7584 7831c84cc644
permissions -rw-r--r--
Hedgeroid: Frantic scrabbling toward the deadline - Added activities for weapon/scheme editors (unfinished) - Completed tablet version of netroom activity - Added map preview - Fixed default team files having the wrong names - Restructuring - Updated frontlib JNA bindings to respect the latest frontlib changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
package org.hedgewars.hedgeroid.netplay;
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
     3
import java.util.Map;
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
     4
import java.util.TreeMap;
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
     5
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
     6
import org.hedgewars.hedgeroid.Datastructures.Room;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
     7
import org.hedgewars.hedgeroid.Datastructures.RoomWithId;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
     8
import org.hedgewars.hedgeroid.util.ObservableTreeMap;
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
     9
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    10
public class Roomlist extends ObservableTreeMap<String, RoomWithId> {
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
	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
    12
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    13
	public void updateList(Room[] newRooms) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    14
		Map<String, RoomWithId> newMap = new TreeMap<String, RoomWithId>();
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    15
		for(Room room : newRooms) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    16
			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
    17
			if(oldEntry == null) {
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    18
				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
    19
			} else {
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    20
				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
    21
			}
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    22
		}
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    23
		replaceContent(newMap);
7352
641f11cdd319 Hedgeroid: Reworked player and room lists, added menus, added playername query
Medo <smaxein@googlemail.com>
parents: 7346
diff changeset
    24
	}
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    26
	public void addRoomWithNewId(Room room) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    27
		put(room.name, new RoomWithId(room, nextId++));
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
	}
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
	
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    30
	public void updateRoom(String name, Room room) {
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    31
		RoomWithId oldEntry = get(name);
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
		if(oldEntry == null) {
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    33
			addRoomWithNewId(room);
7342
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
		} else {
7476
2fb781bbdd51 Hedgeroid: Start using the frontlib for more operations
Medo <smaxein@googlemail.com>
parents: 7461
diff changeset
    35
			remove(name);
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents: 7491
diff changeset
    36
			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
    37
		}
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
	}
0e29eec2df5c Hedgeroid: Got the roomlist working... more or less.
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
}