project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/RoomStateManager.java
author Wuzzy <Wuzzy2@mail.ru>
Fri, 24 May 2019 22:27:19 +0200
changeset 15067 0730c68fdf97
parent 10017 de822cd3df3a
permissions -rw-r--r--
Backed out changeset 76003912e31d (whoops)
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
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
package org.hedgewars.hedgeroid;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    22
import java.util.Map;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    23
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import org.hedgewars.hedgeroid.Datastructures.Scheme;
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    26
import org.hedgewars.hedgeroid.Datastructures.Team;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    27
import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
import org.hedgewars.hedgeroid.Datastructures.Weaponset;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
/**
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    31
 * This interface is supposed to abstract the handling of room state for several
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    32
 * fragments that can display and manipulate it. The purpose of this is to allow
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    33
 * using these fragments both for setting up networked and local games, despite
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    34
 * the fact that for local games the settings can be changed immediately in
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    35
 * memory, while they have to be sent out to the server for networked games.
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    36
 *
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    37
 * If/when the state changes as result of calling one of the "changeX" or
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    38
 * "requestX" functions, that will also trigger the corresponding change
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    39
 * listener method. There is no guarantee that calling a changeX method will
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    40
 * actually change the setting (e.g. if you're not room chief).
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    41
 *
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
 * For local games, getChiefStatus is always true.
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    43
 *
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    44
 * Implementations of this interface are probably not thread safe and should
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7508
diff changeset
    45
 * only be used on the UI thread.
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
 */
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
public interface RoomStateManager {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
    // Query current state
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
    MapRecipe getMapRecipe();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
    boolean getChiefStatus();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    51
    Scheme getScheme();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
    String getGameStyle();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
    Weaponset getWeaponset();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
    Map<String, TeamInGame> getTeams();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    55
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
    // Manipulate state
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
    void changeMapRecipe(MapRecipe map);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    58
    void changeMapTheme(String theme);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    60
    /**
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
     * This function sets both the map's name and generator. There is no function
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
     * to change them independendly since e.g. the QtFrontend relies on them being
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
     * consistent.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    64
     *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
     * If the name parameter is equal to one of the MapRecipe.MAPNAME_REGULAR, MAPNAME_MAZE
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
     * or MAPNAME_DRAWN constants, the map generator is set accordingly. Otherwise, the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
     * map generator is set to represent a mapfile. The map's name is always set to
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    68
     * the parameter.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
     */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
    void changeMapNameAndGenerator(String mapName);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    71
    void changeMapTemplate(int template);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    72
    void changeMazeSize(int mazeSize);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
    void changeMapSeed(String seed);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    74
    void changeMapDrawdata(byte[] drawdata);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    75
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    76
    void changeScheme(Scheme scheme);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    77
    void changeGameStyle(String style);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
    void changeWeaponset(Weaponset weaponset);
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    80
    void requestAddTeam(Team team, int colorIndex);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    81
    void requestRemoveTeam(String teamname);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
    void changeTeamColorIndex(String teamname, int colorIndex);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    83
    void changeTeamHogCount(String teamname, int hogcount);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    84
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    85
    // Observe changes
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    86
    void addListener(Listener observer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
    void removeListener(Listener observer);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    88
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    89
    public interface Listener {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    90
        void onMapChanged(MapRecipe recipe);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    91
        void onChiefStatusChanged(boolean isChief);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    92
        void onSchemeChanged(Scheme scheme);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    93
        void onGameStyleChanged(String gameStyle);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    94
        void onWeaponsetChanged(Weaponset weaponset);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    95
        void onTeamsChanged(Map<String, TeamInGame> teams);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    96
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    97
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    98
    public static class ListenerAdapter implements Listener {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    99
        public void onMapChanged(MapRecipe recipe) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   100
        public void onChiefStatusChanged(boolean isChief) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   101
        public void onSchemeChanged(Scheme scheme) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   102
        public void onGameStyleChanged(String gameStyle) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   103
        public void onWeaponsetChanged(Weaponset weaponset) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   104
        public void onTeamsChanged(Map<String, TeamInGame> teams) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   105
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   106
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   107
    public interface Provider {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   108
        RoomStateManager getRoomStateManager();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   109
    }
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
}