public void Start()
        {
            if (field == null)
            {
                field = GetComponent <InputField>();
            }
            if (messageKey != 0)
            {
                Message <string> valueChange = GameLink.Game.SceneComponents.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get <Message <string> >((int)messageKey);

                field.onValueChanged.AddListener(valueChange.Send);
            }
            if (setKey != 0)
            {
                fieldText = GameLink.Game.SceneComponents.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get <SubscribableObject <string> >((int)setKey);
                fieldText.Subscribe(new SimpleListener <string>((t) => RefreshText()));
                RefreshText();
            }
            if (interactableKey != 0)
            {
                interactable = GameLink.Game.SceneComponents.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get <SubscribableBool>((int)interactableKey);
                interactable.Subscribe(new SimpleListener <bool>((t) => RefreshInteractable()));
                RefreshInteractable();
            }
        }
        public ReadyButtonController(AutoController scene)
        {
            ComponentRegistry guiComps = scene.Components.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages);

            buttonEnabled = new SubscribableBool(true);
            guiComps.Register((int)GUICompKeys.ReadyBtnEnabled, buttonEnabled);
            buttonLabel = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.ReadyBtnLabel, buttonLabel);
            Message buttonClick = new Message();

            guiComps.Register((int)GUICompKeys.ReadyBtnClicked, buttonClick);
            buttonClick.Subscribe(new SimpleListener(OnButtonClick));

            selectedMod = scene.Components.GetOrRegister <SubscribableObject <string> >
                              ((int)ComponentKeys.LobbyModSelected, SubscribableObject <string> .Create);
            selectedMod.Subscribe(new SimpleListener <string>((m) => {
                RefreshButton();
            }));
            readyStatus = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.LobbyReadyStatus, SubscribableBool.Create);
            readyStatus.Subscribe(new SimpleListener <bool>((v) => RefreshButton()));

            StateMachine screen = scene.Components.Get <StateMachine>((int)ComponentKeys.LobbyScreen);

            screen.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => {
                isHost = s == (int)LobbyScreen.HostGamePrefs;
                if (s == (int)LobbyScreen.HostGamePrefs || s == (int)LobbyScreen.ClientGamePrefs)
                {
                    ScreenEnter();
                }
            }));
        }
예제 #3
0
 public BoardSpaceChooser(ChessScene scene)
 {
     actionList   = new List <int>();
     inputOffsets = new Dictionary <IntVector2, int>();
     scene.Components.GetOrRegister <Message <Board> >((int)ComponentKeys.BoardCreatedMessage, Message <Board> .Create)
     .Subscribe(new SimpleListener <Board>((b) => board = b));
     db           = scene.Game.Components.Get <GameDatabase>((int)ComponentKeys.GameDatabase);
     chooserState = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.TurnChooserState, StateMachine.Create);
     chooserState.EnterStateMessenger.Subscribe(new SimpleListener <int>(OnEnterState));
     selEvent = scene.Components.GetOrRegister <PlayerSelectionEvent>((int)ComponentKeys.PlayerSelectionChange, PlayerSelectionEvent.Create);
     selEvent.Subscribe(new SimpleListener(OnSelectionChange));
     acceptBtn = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.PlayerSelectionAcceptBtn, SubscribableBool.Create);
     acceptBtn.Subscribe(new TriggerListener(OnSelectionBtnTrigger));
     chosenAction = scene.Components.GetOrRegister <SubscribableObject <TurnAction> >
                        ((int)ComponentKeys.TurnChooserChosenAction, SubscribableObject <TurnAction> .Create);
     highlightMessage = scene.Components.GetOrRegister <Message <TurnChooserHighlight> >
                            ((int)ComponentKeys.TurnChooserHighlightChange, Message <TurnChooserHighlight> .Create);
     chosenPiece          = scene.Components.GetOrRegister <SubscribableInt>((int)ComponentKeys.TurnChooserChosenPiece, SubscribableInt.Create);
     turnOptionCalculator = scene.Components.GetOrRegister <Query <TurnOptions, TurnOptionCalculatorArgs> >
                                ((int)ComponentKeys.MoveOptionListQuery, Query <TurnOptions, TurnOptionCalculatorArgs> .Create);
     scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.PlayerSelectionCycleBtn, SubscribableBool.Create)
     .Subscribe(new TriggerListener(OnCycleButtonPress));
     scene.Components.GetOrRegister <SubscribableInt>((int)ComponentKeys.ScrollWheel, SubscribableInt.Create)
     .Subscribe(new SimpleListener <int>((s) => {
         if (s != 0)
         {
             OnScrollWheel(s);
         }
     }));
 }
예제 #4
0
 public PieceChooser(ChessScene scene)
 {
     scene.Components.GetOrRegister <Message <Board> >((int)ComponentKeys.BoardCreatedMessage, Message <Board> .Create)
     .Subscribe(new SimpleListener <Board>((b) => board = b));
     chooserState = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.TurnChooserState, StateMachine.Create);
     chooserState.EnterStateMessenger.Subscribe(new SimpleListener <int>(OnEnterState));
     selEvent = scene.Components.GetOrRegister <PlayerSelectionEvent>((int)ComponentKeys.PlayerSelectionChange, PlayerSelectionEvent.Create);
     //selEvent.Subscribe(new SimpleListener(OnSelectionChange));
     acceptBtn = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.PlayerSelectionAcceptBtn, SubscribableBool.Create);
     acceptBtn.Subscribe(new TriggerListener(OnSelectionBtnTrigger));
     chosenPiece = scene.Components.GetOrRegister <SubscribableInt>((int)ComponentKeys.TurnChooserChosenPiece, SubscribableInt.Create);
 }
예제 #5
0
 private void Start()
 {
     if (group == null)
     {
         group = GetComponent <ToggleGroup>();
     }
     if (allowAllOffKey != 0)
     {
         allowAllOff = GameLink.Game.SceneComponents.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get <SubscribableBool>((int)allowAllOffKey);
         allowAllOff.Subscribe(new SimpleListener <bool>((e) => RefreshAllOff()));
         RefreshAllOff();
     }
 }
예제 #6
0
        public void Start()
        {
            if (button == null)
            {
                button = GetComponent <Button>();
            }
            if (messageKey != 0)
            {
                Message messenger = GameLink.Game.SceneComponents.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get <Message>((int)messageKey);

                button.onClick.AddListener(messenger.Send);
            }
            if (enableKey != 0)
            {
                enabledState = GameLink.Game.SceneComponents.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get <SubscribableBool>((int)enableKey);
                enabledState.Subscribe(new SimpleListener <bool>((e) => RefreshEnabled()));
                RefreshEnabled();
            }
        }
 public void Start() {
     if(toggle == null) {
         toggle = GetComponent<Toggle>();
     }
     if(changeKey != 0) {
         Message<bool> messenger = GameLink.Game.SceneComponents.Get<ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get<Message<bool>>((int)changeKey);
         toggle.onValueChanged.AddListener(messenger.Send);
     }
     if(enableKey != 0) {
         enabledState = GameLink.Game.SceneComponents.Get<ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get<SubscribableBool>((int)enableKey);
         enabledState.Subscribe(new SimpleListener<bool>((e) => RefreshEnabled()));
         RefreshEnabled();
     }
     if(setKey != 0) {
         selectedState = GameLink.Game.SceneComponents.Get<ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages).Get<SubscribableBool>((int)setKey);
         selectedState.Subscribe(new SimpleListener<bool>((e) => RefreshSelected()));
         RefreshSelected();
     }
 }
        public LobbyBackButton(AutoController scene)
        {
            ComponentRegistry guiComps = scene.Components.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages);

            onClick = new Message();
            guiComps.Register((int)GUICompKeys.BackButtonClicked, onClick);
            onClick.Subscribe(new SimpleListener(OnButtonClicked));

            buttonInteractable = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.BackButtonInteractable, buttonInteractable);

            connHelper = scene.Game.Components.Get <ConnectionHelper>((int)ComponentKeys.ConnectionHelper);
            scene.ActivatableList.Add(new ListenerJanitor <IListener <int> >(
                                          connHelper.Connection.EnterStateMessenger,
                                          new SimpleListener <int>((s) => CheckDisconnect())));

            readyStatus = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.LobbyReadyStatus, SubscribableBool.Create);
            readyStatus.Subscribe(new SimpleListener <bool>(OnReadyStatusChange));

            screen = scene.Components.Get <StateMachine>((int)ComponentKeys.LobbyScreen);
            screen.EnterStateMessenger.Subscribe(new SimpleListener <int>(OnEnterScreen));
        }
        public LobbyExitController(AutoController scene)
        {
            game = (ModdableChessGame)scene.Game;

            choices = scene.Game.Components.Get <LobbyChoices>((int)ComponentKeys.LobbyChoices);

            state = new StateMachine(0);
            state.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnStateChange()));

            readyStatus = scene.Components.GetOrRegister((int)ComponentKeys.LobbyReadyStatus, SubscribableBool.Create);
            readyStatus.Subscribe(new SimpleListener <bool>((v) => OnReadyStatusChange()));
            readyStatus.Value = false;

            notifyServerReady = scene.Game.Components.Get <Command <bool> >((int)ComponentKeys.LobbyReadyNoticeSendRequest);

            scene.ActivatableList.Add(new ListenerJanitor <IListener <LobbyExitState> >(
                                          scene.Game.Components.Get <IMessage <LobbyExitState> >((int)ComponentKeys.LobbyExitMessageReceived),
                                          new SimpleListener <LobbyExitState>(OnAllReadyReceived)));

            scene.Components.GetOrRegister <SubscribableObject <string> >((int)ComponentKeys.LobbyModSelected, SubscribableObject <string> .Create)
            .Subscribe(new SimpleListener <string>(OnModChange));

            initStatus = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.LobbyInitStatus, StateMachine.Create);
            initStatus.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnInitStatusChange()));

            getModFolder = scene.Components.GetOrRegister <Query <string, string> >((int)ComponentKeys.GetCachedModFolder, Query <string, string> .Create);

            screen = scene.Components.Get <StateMachine>((int)ComponentKeys.LobbyScreen);
            screen.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => {
                state.State       = 0;
                readyStatus.Value = false;
                if (s == (int)LobbyScreen.HostGamePrefs || s == (int)LobbyScreen.ClientGamePrefs)
                {
                    SendReadyStatus();
                }
            }));
        }
예제 #10
0
        public TurnChooser(ChessScene scene)
        {
            //scene.Components.GetOrRegister<Message<Board>>((int)ComponentKeys.BoardCreatedMessage, Message<Board>.Create)
            //    .Subscribe(new SimpleListener<Board>((b) => board = b));
            //db = scene.Game.Components.Get<GameDatabase>((int)ComponentKeys.GameDatabase);

            tickHelper = new TickingJanitor(scene.Game, this);
            tickHelper.ForceInactive = true;
            scene.ActivatableList.Add(tickHelper);

            states = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.TurnChooserState, StateMachine.Create);
            states.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnEnterChoosingState()));

            backBtn = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.PlayerSelectionCancelBtn, SubscribableBool.Create);
            backBtn.Subscribe(new TriggerListener(OnBackBtnTrigger));
            choiceMadeEvent = scene.Components.GetOrRegister <Message <TurnAction> >((int)ComponentKeys.MoveChoiceMadeEvent, Message <TurnAction> .Create);
            chosenPiece     = scene.Components.GetOrRegister <SubscribableInt>((int)ComponentKeys.TurnChooserChosenPiece, SubscribableInt.Create);
            chosenPiece.Subscribe(new SimpleListener <int>(OnPieceChosen));
            chosenAction = scene.Components.GetOrRegister <SubscribableObject <TurnAction> >
                               ((int)ComponentKeys.TurnChooserChosenAction, SubscribableObject <TurnAction> .Create);
            chosenAction.Subscribe(new SimpleListener <TurnAction>(OnActionChosen));

            scene.Components.GetOrRegister <Command>((int)ComponentKeys.StartTurnChoosingCommand, Command.Create)
            .Handler = ChoosingStartCommand;
            scene.Components.GetOrRegister <Command>((int)ComponentKeys.StopTurnChoosingCommand, Command.Create)
            .Handler = ChoosingStopCommand;
            scene.Components.GetOrRegister <Command>((int)ComponentKeys.ForfeitGame, Command.Create)
            .Handler = ForfeitGameCommand;

            requestSendAction = scene.Game.Components.Get <Command <TurnAction> >((int)ComponentKeys.SendTurnAction);

            connectionState = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.ReconnectionState, StateMachine.Create);
            connectionState.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => OnConnectionStateChange()));

            new PieceChooser(scene);
            new BoardSpaceChooser(scene);
        }
        public ModListController(AutoController scene)
        {
            statusSortOrder = new Dictionary <int, int>();
            statusSortOrder[(int)ModNetworkStatus.Playable]        = 0;
            statusSortOrder[(int)ModNetworkStatus.HostOutOfDate]   = 1;
            statusSortOrder[(int)ModNetworkStatus.ClientOutOfDate] = 1;
            statusSortOrder[(int)ModNetworkStatus.OnlyHost]        = 2;
            statusSortOrder[(int)ModNetworkStatus.OnlyClient]      = 3;
            statusSortOrder[(int)ModNetworkStatus.Unknown]         = 4;
            localMods        = new List <LocalModInfo>();
            networkMods      = new List <NetworkModInfo>();
            allMods          = new List <ComboModInfo>();
            showNotLocalMods = true;

            prevChoices = scene.Game.Components.Get <LobbyChoices>((int)ComponentKeys.LobbyChoices);

            ComponentRegistry guiComps = scene.Components.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages);

            modButtons = new ModList();
            guiComps.Register((int)GUICompKeys.ModList, modButtons);
            modButtons.OnButtonClick.Subscribe(new SimpleListener <int>(OnModButtonClick));
            pickedLabelTop = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.ModListLabelTop, pickedLabelTop);
            pickedLabelBottom = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.ModListLabelBottom, pickedLabelBottom);
            pickedModTop = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.ModListPickedTop, pickedModTop);
            pickedModBottom = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.ModListPickedBottom, pickedModBottom);
            Message reloadBtnPressed = new Message();

            guiComps.Register((int)GUICompKeys.ModListReloadBtnPress, reloadBtnPressed);
            reloadBtnPressed.Subscribe(new SimpleListener(OnReloadButton));
            Message hideBtnPressed = new Message();

            guiComps.Register((int)GUICompKeys.ModListHideBtnPress, hideBtnPressed);
            hideBtnPressed.Subscribe(new SimpleListener(OnHideButton));

            reqSendNetworkModList = scene.Game.Components.Get <Command <List <LocalModInfo> > >((int)ComponentKeys.NetworkModListSendRequest);
            scene.ActivatableList.Add(new ListenerJanitor <IListener <List <NetworkModInfo> > >(
                                          scene.Game.Components.Get <Message <List <NetworkModInfo> > >((int)ComponentKeys.NetworkModListReceived),
                                          new SimpleListener <List <NetworkModInfo> >(OnNetworkModListReceived)));

            reqSendPickedMod = scene.Game.Components.Get <Command <bool, string> >((int)ComponentKeys.NetworkPickedModSendRequest);
            scene.ActivatableList.Add(new ListenerJanitor <IListener <bool, string> > (
                                          scene.Game.Components.Get <Message <bool, string> >((int)ComponentKeys.NetworkPickedModReceived),
                                          new SimpleListener <bool, string>(OnNetworkPickedModReceived)));

            selectedModName = scene.Components.GetOrRegister((int)ComponentKeys.LobbyModSelected, SubscribableObject <string> .Create);

            modSearcher = scene.Components.GetOrRegister <Query <List <LocalModInfo>, string> >
                              ((int)ComponentKeys.SearchModFolderRequest, Query <List <LocalModInfo>, string> .Create);

            localInfo = scene.Game.Components.Get <LocalPlayerInformation>((int)ComponentKeys.LocalPlayerInformation);

            initState = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.LobbyInitStatus, StateMachine.Create);
            initState.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => InitStatusChange()));

            scene.Components.GetOrRegister <Query <string, string> >((int)ComponentKeys.GetCachedModFolder, Query <string, string> .Create)
            .Handler = GetCachedModFolder;

            readyStatus = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.LobbyReadyStatus, SubscribableBool.Create);
            readyStatus.Subscribe(new SimpleListener <bool>((v) => OnReadyStatusChange()));

            screen = scene.Components.Get <StateMachine>((int)ComponentKeys.LobbyScreen);
            screen.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => {
                switch ((LobbyScreen)s)
                {
                case LobbyScreen.ClientGamePrefs:
                case LobbyScreen.HostGamePrefs:
                    OnEnterScreen();
                    break;
                }
            }));
        }
        public TurnOrderSelectionController(AutoController scene)
        {
            tickHelper        = new TickingJanitor(scene.Game, this);
            tickHelper.Active = false;

            ComponentRegistry guiComps = scene.Components.Get <ComponentRegistry>((int)ComponentKeys.LobbyGUIMessages);

            btnsInteractable       = guiComps.GetOrRegister <SubscribableBool>((int)GUICompKeys.TOSInteractable, SubscribableBool.Create);
            btnsInteractable.Value = true;

            toggleValues    = new SubscribableBool[3];
            toggleValues[0] = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSOpt1Set, toggleValues[0]);
            toggleValues[1] = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSOpt2Set, toggleValues[1]);
            toggleValues[2] = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSOpt3Set, toggleValues[2]);

            Message <bool>[] toggleChanges = new Message <bool> [3];
            toggleChanges[0] = new Message <bool>();
            guiComps.Register((int)GUICompKeys.TOSOpt1Change, toggleChanges[0]);
            toggleChanges[1] = new Message <bool>();
            guiComps.Register((int)GUICompKeys.TOSOpt2Change, toggleChanges[1]);
            toggleChanges[2] = new Message <bool>();
            guiComps.Register((int)GUICompKeys.TOSOpt3Change, toggleChanges[2]);
            for (int i = 0; i < toggleChanges.Length; i++)
            {
                int index = i;
                toggleChanges[i].Subscribe(new SimpleListener <bool>((v) => OnToggleChange(index, v)));
            }

            choiceBtnIndex = new Dictionary <LobbyTurnOrderChoice, int>();
            choiceBtnIndex[LobbyTurnOrderChoice.HostIsFirst]   = 0;
            choiceBtnIndex[LobbyTurnOrderChoice.ClientIsFirst] = 1;
            choiceBtnIndex[LobbyTurnOrderChoice.Random]        = 2;
            choiceBtnIndex[LobbyTurnOrderChoice.None]          = -1;

            otherSelLabel = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.TOSOtherSelectionLabel, otherSelLabel);
            otherSelValue = new SubscribableObject <string>("");
            guiComps.Register((int)GUICompKeys.TOSOtherSelectionValue, otherSelValue);

            allowTogglesOff = new SubscribableBool(false);
            guiComps.Register((int)GUICompKeys.TOSAllowAllTogglesOff, allowTogglesOff);

            prevChoices = scene.Game.Components.Get <LobbyChoices>((int)ComponentKeys.LobbyChoices);

            selected = new SubscribableInt(0);
            //scene.SceneComponents.Register((int)ComponentKeys.LobbyTurnOrderSelected, selected);

            initStatus = scene.Components.GetOrRegister <StateMachine>((int)ComponentKeys.LobbyInitStatus, StateMachine.Create);
            initStatus.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => InitStatusChange()));

            reqSendPick = scene.Game.Components.Get <Command <LobbyTurnOrderChoice> >((int)ComponentKeys.LobbyTurnOrderChoiceNotify);
            scene.ActivatableList.Add(new ListenerJanitor <IListener <LobbyTurnOrderChoice> >(
                                          scene.Game.Components.Get <IMessage <LobbyTurnOrderChoice> >((int)ComponentKeys.LobbyTurnOrderChoiceReceived),
                                          new SimpleListener <LobbyTurnOrderChoice>(OnNetworkPickReceived)));

            readyStatus = scene.Components.GetOrRegister <SubscribableBool>((int)ComponentKeys.LobbyReadyStatus, SubscribableBool.Create);
            readyStatus.Subscribe(new SimpleListener <bool>((v) => OnReadyStatusChange()));

            screen = scene.Components.Get <StateMachine>((int)ComponentKeys.LobbyScreen);
            screen.EnterStateMessenger.Subscribe(new SimpleListener <int>((s) => {
                isHost = s == (int)LobbyScreen.HostGamePrefs;
                if (s == (int)LobbyScreen.HostGamePrefs || s == (int)LobbyScreen.ClientGamePrefs)
                {
                    ScreenEnter();
                }
            }));
        }