project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/SettingsFragment.java
author Wuzzy <Wuzzy2@mail.ru>
Sun, 29 Oct 2017 19:06:02 +0100
changeset 12803 fdb3730aa0e2
parent 10017 de822cd3df3a
permissions -rw-r--r--
ACF6: Make sure player only gets portal gun at the portal sequence, and not a pile full of weapons and ropes
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
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
import java.io.File;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
import java.io.FileNotFoundException;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import java.io.IOException;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import java.util.Collections;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
import java.util.List;
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7568
diff changeset
    27
import java.util.Map;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
import org.hedgewars.hedgeroid.R;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
import org.hedgewars.hedgeroid.Datastructures.FrontendDataUtils;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
import org.hedgewars.hedgeroid.Datastructures.Scheme;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
import org.hedgewars.hedgeroid.Datastructures.Schemes;
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7568
diff changeset
    34
import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
import org.hedgewars.hedgeroid.Datastructures.Weaponset;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
import org.hedgewars.hedgeroid.Datastructures.Weaponsets;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
import org.hedgewars.hedgeroid.util.FileUtils;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    38
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
import android.graphics.drawable.Drawable;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    40
import android.os.Bundle;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    41
import android.support.v4.app.Fragment;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    42
import android.util.Log;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    43
import android.view.LayoutInflater;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    44
import android.view.View;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    45
import android.view.ViewGroup;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
import android.widget.AdapterView;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
import android.widget.AdapterView.OnItemSelectedListener;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
import android.widget.ArrayAdapter;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    49
import android.widget.ImageView;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
import android.widget.Spinner;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
import android.widget.Toast;
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents: 7568
diff changeset
    53
public class SettingsFragment extends Fragment {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    54
    private Spinner styleSpinner, schemeSpinner, weaponsetSpinner, themeSpinner;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    55
    private ImageView themeIcon;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    56
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    57
    private List<String> styles;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    58
    private List<Scheme> schemes;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    59
    private List<Weaponset> weaponsets;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    60
    private List<String> themes;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    61
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    62
    private RoomStateManager stateManager;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    63
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    64
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    65
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    66
            Bundle savedInstanceState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    67
        View v = inflater.inflate(R.layout.fragment_settings, container, false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    68
        themeIcon = (ImageView)v.findViewById(R.id.imgTheme);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    69
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    70
        try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    71
            styles = FrontendDataUtils.getGameStyles(getActivity());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    72
            schemes = Schemes.loadAllSchemes(getActivity());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    73
            weaponsets = Weaponsets.loadAllWeaponsets(getActivity());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    74
            themes = FrontendDataUtils.getThemes(getActivity());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    75
        } catch (IOException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    76
            Toast.makeText(getActivity().getApplicationContext(), R.string.error_missing_sdcard_or_files, Toast.LENGTH_LONG).show();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    77
            getActivity().finish();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    78
            return null;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    79
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    80
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    81
        Collections.sort(styles, String.CASE_INSENSITIVE_ORDER);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    82
        Collections.sort(schemes, Scheme.NAME_ORDER);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    83
        Collections.sort(weaponsets, Weaponset.NAME_ORDER);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    84
        Collections.sort(themes, String.CASE_INSENSITIVE_ORDER);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    85
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    86
        styleSpinner = prepareSpinner(v, R.id.spinGameplay, styles, styleSelectedListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    87
        schemeSpinner = prepareSpinner(v, R.id.spinGamescheme, Schemes.toNameList(schemes), schemeSelectedListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    88
        weaponsetSpinner = prepareSpinner(v, R.id.spinweapons, Weaponsets.toNameList(weaponsets), weaponsetSelectedListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    89
        themeSpinner = prepareSpinner(v, R.id.spinTheme, themes, themeSelectedListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    90
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    91
        stateManager.addListener(roomStateChangeListener);
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    93
        if(stateManager.getGameStyle() != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    94
            styleSpinner.setSelection(styles.indexOf(stateManager.getGameStyle()), false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    95
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    96
        if(stateManager.getScheme() != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    97
            schemeSpinner.setSelection(getSchemePosition(schemes, stateManager.getScheme().name), false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    98
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
    99
        if(stateManager.getWeaponset() != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   100
            weaponsetSpinner.setSelection(getWeaponsetPosition(weaponsets, stateManager.getWeaponset().name), false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   101
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   102
        if(stateManager.getMapRecipe() != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   103
            themeSpinner.setSelection(themes.indexOf(stateManager.getMapRecipe().theme), false);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   104
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   105
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   106
        setChiefState(stateManager.getChiefStatus());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   107
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   108
        return v;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   109
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   110
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   111
    private static Spinner prepareSpinner(View v, int id, List<String> items, OnItemSelectedListener itemSelectedListener) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   112
        Spinner spinner = (Spinner)v.findViewById(id);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   113
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(v.getContext(), R.layout.listview_item, items);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   114
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   115
        spinner.setAdapter(adapter);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   116
        spinner.setOnItemSelectedListener(itemSelectedListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   117
        return spinner;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   118
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   119
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   120
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   121
    public void onCreate(Bundle savedInstanceState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   122
        super.onCreate(savedInstanceState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   123
        try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   124
            stateManager = ((RoomStateManager.Provider)getActivity()).getRoomStateManager();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   125
        } catch(ClassCastException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   126
            throw new RuntimeException("Hosting activity must implement RoomStateManager.Provider.", e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   127
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   128
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   129
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   130
    @Override
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   131
    public void onDestroy() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   132
        super.onDestroy();
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   133
        stateManager.removeListener(roomStateChangeListener);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   134
    }
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   135
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   136
    private static int getSchemePosition(List<Scheme> schemes, String scheme) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   137
        for(int i=0; i<schemes.size(); i++) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   138
            if(schemes.get(i).name.equals(scheme)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   139
                return i;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   140
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   141
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   142
        return -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   143
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   144
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   145
    private static int getWeaponsetPosition(List<Weaponset> weaponsets, String weaponset) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   146
        for(int i=0; i<weaponsets.size(); i++) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   147
            if(weaponsets.get(i).name.equals(weaponset)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   148
                return i;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   149
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   150
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   151
        return -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   152
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   153
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   154
    private void setChiefState(boolean chiefState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   155
        styleSpinner.setEnabled(chiefState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   156
        schemeSpinner.setEnabled(chiefState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   157
        weaponsetSpinner.setEnabled(chiefState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   158
        themeSpinner.setEnabled(chiefState);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   159
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   160
        if(chiefState) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   161
            stateManager.changeGameStyle(styles.get(styleSpinner.getSelectedItemPosition()));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   162
            stateManager.changeScheme(schemes.get(schemeSpinner.getSelectedItemPosition()));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   163
            stateManager.changeWeaponset(weaponsets.get(weaponsetSpinner.getSelectedItemPosition()));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   164
            stateManager.changeMapTheme(themes.get(themeSpinner.getSelectedItemPosition()));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   165
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   166
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   167
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   168
    private final OnItemSelectedListener styleSelectedListener = new OnItemSelectedListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   169
        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   170
            stateManager.changeGameStyle(styles.get(position));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   171
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   172
        public void onNothingSelected(AdapterView<?> arg0) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   173
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   174
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   175
    private final OnItemSelectedListener schemeSelectedListener = new OnItemSelectedListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   176
        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   177
            stateManager.changeScheme(schemes.get(position));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   178
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   179
        public void onNothingSelected(AdapterView<?> arg0) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   180
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   181
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   182
    private final OnItemSelectedListener weaponsetSelectedListener = new OnItemSelectedListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   183
        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   184
            stateManager.changeWeaponset(weaponsets.get(position));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   185
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   186
        public void onNothingSelected(AdapterView<?> arg0) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   187
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   188
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   189
    private final OnItemSelectedListener themeSelectedListener = new OnItemSelectedListener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   190
        public void onItemSelected(AdapterView<?> adapter, View v, int position, long arg3) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   191
            stateManager.changeMapTheme(themes.get(position));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   192
            String theme = themes.get(position);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   193
            try {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   194
                File iconFile = FileUtils.getDataPathFile(getActivity(), "Themes", theme, "icon@2X.png");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   195
                Drawable themeIconDrawable = Drawable.createFromPath(iconFile.getAbsolutePath());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   196
                themeIcon.setImageDrawable(themeIconDrawable);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   197
            } catch (FileNotFoundException e) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   198
                Log.e("SettingsFragment", "Unable to find preview for theme "+theme, e);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   199
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   200
        };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   201
        public void onNothingSelected(AdapterView<?> arg0) {};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   202
    };
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   203
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   204
    private final RoomStateManager.Listener roomStateChangeListener = new RoomStateManager.Listener() {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   205
        public void onWeaponsetChanged(Weaponset weaponset) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   206
            weaponsetSpinner.setSelection(getWeaponsetPosition(weaponsets, weaponset.name));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   207
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   208
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   209
        public void onTeamsChanged(Map<String, TeamInGame> teams) {}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   210
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   211
        public void onSchemeChanged(Scheme scheme) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   212
            schemeSpinner.setSelection(getSchemePosition(schemes, scheme.name));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   213
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   214
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   215
        public void onMapChanged(MapRecipe recipe) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   216
            themeSpinner.setSelection(themes.indexOf(recipe.theme));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   217
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   218
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   219
        public void onGameStyleChanged(String gameStyle) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   220
            styleSpinner.setSelection(styles.indexOf(gameStyle));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   221
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   222
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   223
        public void onChiefStatusChanged(boolean isChief) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   224
            setChiefState(isChief);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   225
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7586
diff changeset
   226
    };
7508
763d3961400b Hedgeroid: Frantic scrabbling toward the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   227
}