1 package org.hedgewars.hedgeroid; |
1 package org.hedgewars.hedgeroid; |
|
2 |
|
3 import java.util.Map; |
2 |
4 |
3 import org.hedgewars.hedgeroid.Datastructures.MapRecipe; |
5 import org.hedgewars.hedgeroid.Datastructures.MapRecipe; |
4 import org.hedgewars.hedgeroid.Datastructures.Scheme; |
6 import org.hedgewars.hedgeroid.Datastructures.Scheme; |
|
7 import org.hedgewars.hedgeroid.Datastructures.Team; |
|
8 import org.hedgewars.hedgeroid.Datastructures.TeamInGame; |
5 import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
9 import org.hedgewars.hedgeroid.Datastructures.Weaponset; |
6 |
10 |
7 /** |
11 /** |
8 * This interface is supposed to abstract the handling of room state for several fragments |
12 * This interface is supposed to abstract the handling of room state for several |
9 * that can display and manipulate it. The purpose of this is to allow using these fragments |
13 * fragments that can display and manipulate it. The purpose of this is to allow |
10 * both for setting up networked and local games, despite the fact that for local games |
14 * using these fragments both for setting up networked and local games, despite |
11 * the settings can be changed immediately in memory, while they have to be sent out to the |
15 * the fact that for local games the settings can be changed immediately in |
12 * server for networked games. |
16 * memory, while they have to be sent out to the server for networked games. |
13 * |
17 * |
14 * If/when the state changes as result of calling one of the "changeX" functions, that will |
18 * If/when the state changes as result of calling one of the "changeX" or |
15 * also trigger the corresponding change listener method. There is no guarantee that calling |
19 * "requestX" functions, that will also trigger the corresponding change |
16 * a changeX method will actually change the setting (e.g. if you're not room chief). |
20 * listener method. There is no guarantee that calling a changeX method will |
|
21 * actually change the setting (e.g. if you're not room chief). |
17 * |
22 * |
18 * For local games, getChiefStatus is always true. |
23 * For local games, getChiefStatus is always true. |
19 * |
24 * |
20 * Implementations of this interface are probably not thread safe and should only be used on |
25 * Implementations of this interface are probably not thread safe and should |
21 * the UI thread. |
26 * only be used on the UI thread. |
22 */ |
27 */ |
23 public interface RoomStateManager { |
28 public interface RoomStateManager { |
24 // Query current state |
29 // Query current state |
25 MapRecipe getMapRecipe(); |
30 MapRecipe getMapRecipe(); |
26 boolean getChiefStatus(); |
31 boolean getChiefStatus(); |
27 Scheme getScheme(); |
32 Scheme getScheme(); |
28 String getGameStyle(); |
33 String getGameStyle(); |
29 Weaponset getWeaponset(); |
34 Weaponset getWeaponset(); |
|
35 Map<String, TeamInGame> getTeams(); |
30 |
36 |
31 // Manipulate state |
37 // Manipulate state |
32 void changeMapRecipe(MapRecipe map); |
38 void changeMapRecipe(MapRecipe map); |
33 void changeMapTheme(String theme); |
39 void changeMapTheme(String theme); |
34 |
40 |
50 |
56 |
51 void changeScheme(Scheme scheme); |
57 void changeScheme(Scheme scheme); |
52 void changeGameStyle(String style); |
58 void changeGameStyle(String style); |
53 void changeWeaponset(Weaponset weaponset); |
59 void changeWeaponset(Weaponset weaponset); |
54 |
60 |
55 // Observe state |
61 void requestAddTeam(Team team, int colorIndex); |
56 void registerObserver(Observer observer); |
62 void requestRemoveTeam(String teamname); |
57 void unregisterObserver(Observer observer); |
63 void changeTeamColorIndex(String teamname, int colorIndex); |
|
64 void changeTeamHogCount(String teamname, int hogcount); |
58 |
65 |
59 public interface Observer { |
66 // Observe changes |
|
67 void addListener(Listener observer); |
|
68 void removeListener(Listener observer); |
|
69 |
|
70 public interface Listener { |
60 void onMapChanged(MapRecipe recipe); |
71 void onMapChanged(MapRecipe recipe); |
61 void onChiefStatusChanged(boolean isChief); |
72 void onChiefStatusChanged(boolean isChief); |
62 void onSchemeChanged(Scheme scheme); |
73 void onSchemeChanged(Scheme scheme); |
63 void onGameStyleChanged(String gameStyle); |
74 void onGameStyleChanged(String gameStyle); |
64 void onWeaponsetChanged(Weaponset weaponset); |
75 void onWeaponsetChanged(Weaponset weaponset); |
|
76 void onTeamsChanged(Map<String, TeamInGame> teams); |
|
77 } |
|
78 |
|
79 public static class ListenerAdapter implements Listener { |
|
80 public void onMapChanged(MapRecipe recipe) {} |
|
81 public void onChiefStatusChanged(boolean isChief) {} |
|
82 public void onSchemeChanged(Scheme scheme) {} |
|
83 public void onGameStyleChanged(String gameStyle) {} |
|
84 public void onWeaponsetChanged(Weaponset weaponset) {} |
|
85 public void onTeamsChanged(Map<String, TeamInGame> teams) {} |
65 } |
86 } |
66 |
87 |
67 public interface Provider { |
88 public interface Provider { |
68 RoomStateManager getRoomStateManager(); |
89 RoomStateManager getRoomStateManager(); |
69 } |
90 } |