// ======================== PRIVATE METHODS
 private void Awake()
 {
     if (_currentObserver != null)
     {
         Destroy(this);
     }
     _currentObserver = this;
 }
Esempio n. 2
0
        public static bool TeleportToGlobalMapPoint(BlueprintGlobalMapPoint destination)
        {
            if (GlobalMapView.Instance != null)
            {
                var            globalMapController = Game.Instance.GlobalMapController;
                GlobalMapUI    globalMapUI         = Game.Instance.UI.GlobalMapUI;
                GlobalMapView  globalMapView       = GlobalMapView.Instance;
                GlobalMapState globalMapState      = Game.Instance.Player.GetGlobalMap(destination.GlobalMap);

                GlobalMapPointState pointState = Game.Instance.Player.GetGlobalMap(destination.GlobalMap).GetPointState(destination);
                pointState.EdgesOpened = true;
                pointState.Reveal();
                GlobalMapPointView pointView = globalMapView.GetPointView(destination);
                if ((bool)(UnityEngine.Object)globalMapView)
                {
                    if ((bool)(UnityEngine.Object)pointView)
                    {
                        globalMapView.RevealLocation(pointView);
                    }
                }
                foreach (var edge in pointState.Edges)
                {
                    edge.UpdateExplored(1f, 1);
                    globalMapView.GetEdgeView(edge.Blueprint).UpdateRenderers();
                }
                globalMapController.StartTravels();
                EventBus.RaiseEvent <IGlobalMapPlayerTravelHandler>((Action <IGlobalMapPlayerTravelHandler>)(h => h.HandleGlobalMapPlayerTravelStarted((IGlobalMapTraveler)globalMapView.State.Player)));
                globalMapView.State.Player.SetCurrentPosition(new GlobalMapPosition(destination));
                globalMapView.GetPointView(destination)?.OpenOutgoingEdges((GlobalMapPointView)null);
                globalMapView.UpdatePawnPosition();
                globalMapController.Stop();
                EventBus.RaiseEvent <IGlobalMapPlayerTravelHandler>((Action <IGlobalMapPlayerTravelHandler>)(h => h.HandleGlobalMapPlayerTravelStopped((IGlobalMapTraveler)globalMapView.State.Player)));
                globalMapView.PlayerPawn.m_Compass.TryClear();
                globalMapView.PlayerPawn.m_Compass.TrySet();
#if false
                globalMapView.TeleportParty(globalMapPoint);
                globalMapUI.HandleGlobalMapPlayerTravelStopped(globalMapState.Player);
                GlobalMapPointState pointState = Game.Instance.Player.GlobalMap.GetPointState(globalMapPoint);
                pointState.EdgesOpened = true;
                pointState.Reveal();
                GlobalMapPointView pointView = globalMapView.GetPointView(globalMapPoint);
                pointView?.OpenOutgoingEdges((GlobalMapPointView)null);
                globalMapView.RevealLocation(pointView);
                if ((bool)(UnityEngine.Object)globalMapView)
                {
                    if ((bool)(UnityEngine.Object)pointView)
                    {
                        globalMapView.RevealLocation(pointView);
                    }
                }
                globalMapView.UpdatePawnPosition();
                pointState.LastVisited = Game.Instance.TimeController.GameTime;
#endif
                return(true);
            }
            return(false);
        }
    public void ExpeditionsButtonsRedraw()
    {
        var elist = Expedition.expeditionsList;
        var c     = elist.Count;

        if (c > 0)
        {
            int        i = 0, l = expeditionsFastButtons.Length;
            Button     b;
            Expedition e;
            if (c != l)
            {
                if (c > l)
                { //увеличение списка
                    var nb = new Button[c];
                    for (; i < l; i++)
                    {
                        b = expeditionsFastButtons[i];
                        b.onClick.RemoveAllListeners();
                        e = elist[i];
                        int id = e.ID;
                        b.onClick.AddListener(() => this.SelectExpedition(id));
                        b.transform.GetChild(0).GetComponent <RawImage>().uvRect =
                            GlobalMapUI.GetMarkerRect(e.GetDestinationIcon());
                        b.gameObject.SetActive(true);
                        nb[i] = b;
                    }
                    RectTransform rt = null;
                    for (; i < c; i++)
                    {
                        b                   = Instantiate(expeditionsFastButtons[0], expeditionFastButtonsPanel);
                        rt                  = b.GetComponent <RectTransform>();
                        rt.anchorMin        = new Vector2(0f, 0.95f - 0.05f * i);
                        rt.anchorMax        = new Vector2(0f, 1f - i * 0.05f);
                        rt.anchoredPosition = new Vector2(rt.sizeDelta.x / 2f, 0f);
                        b.onClick.RemoveAllListeners();
                        e = elist[i];
                        int id = e.ID;
                        b.onClick.AddListener(() => this.SelectExpedition(id));
                        b.transform.GetChild(0).GetComponent <RawImage>().uvRect = GlobalMapUI.GetMarkerRect(e.GetDestinationIcon());
                        b.gameObject.SetActive(true);
                        nb[i] = b;
                    }
                    expeditionsFastButtons = nb;
                }
                else
                { // сужение списка
                    for (i = 0; i < c; i++)
                    {
                        b = expeditionsFastButtons[i];
                        b.onClick.RemoveAllListeners();
                        e = elist[i];
                        int id = e.ID;
                        b.onClick.AddListener(() => this.SelectExpedition(id));
                        b.transform.GetChild(0).GetComponent <RawImage>().uvRect =
                            GlobalMapUI.GetMarkerRect(e.GetDestinationIcon());
                        b.gameObject.SetActive(true);
                    }
                    for (; i < l; i++)
                    {
                        expeditionsFastButtons[i].gameObject.SetActive(false);
                    }
                }
            }
            else
            { // просто перезапись
                for (i = 0; i < l; i++)
                {
                    b = expeditionsFastButtons[i];
                    b.onClick.RemoveAllListeners();
                    e = elist[i];
                    int id = e.ID;
                    b.onClick.AddListener(() => this.SelectExpedition(id));
                    b.transform.GetChild(0).GetComponent <RawImage>().uvRect = GetMarkerRect(e.GetDestinationIcon());
                    b.gameObject.SetActive(true);
                }
            }
            expeditionFastButtonsPanel.gameObject.SetActive(true);
        }
        else
        {
            expeditionFastButtonsPanel.gameObject.SetActive(false);
        }
        needExpeditionsRedraw = false;
    }
Esempio n. 4
0
    private void RedrawWindow()
    {
        int        statedCrystalsCount = 0, statedSuppliesCount = Expedition.MIN_SUPPLIES_COUNT;
        Color      redcolor = Color.red, whitecolor = Color.white;
        GameObject g;

        if (showingExpedition == null)
        {
            //подготовка новой экспедиции
            expLabel.text = Localization.GetExpeditionName(selectedDestination);
            bool readyToStart = true;

            PrepareCrewDropdown();
            if (selectedCrew != null)
            {
                readyToStart = selectedCrew.atHome;
                crewButton.SetActive(true);
            }
            else
            {
                readyToStart = false;
                crewButton.SetActive(false);
            }
            if (!crewDropdown.gameObject.activeSelf)
            {
                crewDropdown.gameObject.SetActive(true);
                crewStableName.enabled = false;
            }
            //supplies
            suppliesSlider.value = statedSuppliesCount;
            OnSuppliesSliderChanged(statedSuppliesCount);
            if (preparingMode != true)
            {
                suppliesSlider.gameObject.SetActive(true);
                suppliesStableValue.gameObject.SetActive(false);
            }
            //crystals
            crystalsSlider.value = statedCrystalsCount;
            OnCrystalsSliderChanged(statedCrystalsCount);
            if (preparingMode != true)
            {
                crystalsSlider.gameObject.SetActive(true);
                crystalsStableValue.gameObject.SetActive(false);
            }
            //transmitters:
            int c = QuantumTransmitter.GetFreeTransmittersCount();
            if (c > 0)
            {
                transmitterMarker.uvRect = UIController.GetIconUVRect(Icons.TaskCompleted);
                transmitterLabel.text    = Localization.GetPhrase(LocalizedPhrase.FreeTransmitters) + c.ToString();
                transmitterLabel.color   = whitecolor;
            }
            else
            {
                transmitterMarker.uvRect = UIController.GetIconUVRect(Icons.TaskFailed);
                transmitterLabel.text    = Localization.GetPhrase(LocalizedPhrase.NoTransmitters);
                transmitterLabel.color   = redcolor;
                readyToStart             = false;
            }
            //shuttles:
            c = Hangar.GetFreeShuttlesCount();
            if (c > 0)
            {
                shuttleMarker.uvRect = UIController.GetIconUVRect(Icons.TaskCompleted);
                shuttleLabel.text    = Localization.GetPhrase(LocalizedPhrase.FreeShuttles) + c.ToString();
                shuttleLabel.color   = whitecolor;
            }
            else
            {
                shuttleMarker.uvRect = UIController.GetIconUVRect(Icons.TaskFailed);
                shuttleLabel.text    = Localization.GetPhrase(LocalizedPhrase.NoShuttles);
                shuttleLabel.color   = redcolor;
                readyToStart         = false;
            }
            lastShuttlesListMarker = Hangar.listChangesMarkerValue;
            //fuel:
            if (FuelCheck() == false)
            {
                readyToStart = false;
            }
            if (preparingMode != true)
            {
                shuttleLine.gameObject.SetActive(true);
                fuelLine.gameObject.SetActive(true);
                minigameButton.SetActive(false);
            }
            //launch button
            launchButtonLabel.text    = Localization.GetWord(LocalizedWord.Launch);
            launchButton.interactable = readyToStart;
            launchButton.GetComponent <Image>().color = readyToStart ? lightcyan : Color.grey;
            launchButton.gameObject.SetActive(true);
            //
            preparingMode = true;
        }
        else
        {
            // отрисовка существующей
            expLabel.text          = Localization.GetExpeditionName(showingExpedition);
            statedCrystalsCount    = showingExpedition.crystalsCollected;
            statedSuppliesCount    = showingExpedition.suppliesCount;
            lastChangesMarkerValue = showingExpedition.changesMarkerValue;

            crewStableName.text = showingExpedition.crew.name;
            if (crewDropdown.gameObject.activeSelf)
            {
                crewDropdown.gameObject.SetActive(false);
                crewStableName.enabled = true;
            }
            //supplies
            suppliesStableValue.text  = statedSuppliesCount.ToString();
            suppliesStableValue.color = statedSuppliesCount > 0 ? whitecolor : redcolor;
            if (preparingMode != false)
            {
                suppliesSlider.gameObject.SetActive(false);
                suppliesStableValue.gameObject.SetActive(true);
            }
            //crystals
            crystalsStableValue.text = statedCrystalsCount.ToString();
            if (preparingMode != false)
            {
                crystalsSlider.gameObject.SetActive(false);
                crystalsStableValue.gameObject.SetActive(true);
            }
            //transmitter:
            if (showingExpedition.hasConnection)
            {
                transmitterMarker.uvRect = UIController.GetIconUVRect(Icons.TaskCompleted);
                transmitterLabel.text    = Localization.GetPhrase(LocalizedPhrase.ConnectionOK);
                transmitterLabel.color   = whitecolor;
            }
            else
            {
                transmitterMarker.uvRect = UIController.GetIconUVRect(Icons.TaskFailed);
                transmitterLabel.text    = Localization.GetPhrase(LocalizedPhrase.ConnectionLost);
                transmitterLabel.color   = redcolor;
            }
            //shuttle & fuel
            if (preparingMode != false)
            {
                shuttleLine.gameObject.SetActive(false);
                fuelLine.gameObject.SetActive(false);
            }
            //launchbutton
            if (showingExpedition.stage == Expedition.ExpeditionStage.OnMission | showingExpedition.stage == Expedition.ExpeditionStage.WayIn)
            {
                launchButtonLabel.text = Localization.GetPhrase(LocalizedPhrase.StopMission);
                launchButton.GetComponent <Image>().color = halfred;
                launchButton.interactable = true;
                launchButton.gameObject.SetActive(true);
            }
            else
            {
                launchButton.gameObject.SetActive(false);
            }

            minigameButton.SetActive(showingExpedition.stage == Expedition.ExpeditionStage.OnMission);

            preparingMode = false;
        }

        var edb = expDestinationButton;

        if (selectedDestination != null)
        {
            edb.transform.GetChild(0).GetComponent <RawImage>().uvRect = GlobalMapUI.GetMarkerRect(selectedDestination.type);
            edb.SetActive(workOnMainCanvas);
        }
        else
        {
            if (edb.activeSelf)
            {
                edb.SetActive(false);
            }
        }
    }
Esempio n. 5
0
    private void RedrawMap()
    {
        if (!prepared)
        {
            return;
        }
        else
        {
            mapPoints = globalMap.mapPoints;
            int n = mapPoints.Count;
            //print(n);
            int c = mapMarkers.Count;
            if (n > 0)
            {
                mapRect.gameObject.SetActive(false);
                if (c != n)
                {
                    if (c > n)
                    {
                        for (int i = c - 1; i >= n; i--)
                        {
                            int a = mapMarkers.Count - 1;
                            Destroy(mapMarkers[a].gameObject);
                            mapMarkers.RemoveAt(a);
                        }
                    }
                    else
                    {
                        for (int i = c; i < n; i++)
                        {
                            mapMarkers.Add(Instantiate(exampleMarker, mapRect).GetComponent <RectTransform>());
                        }
                    }
                }
                RectTransform rt;
                MapPoint      mp;
                Vector3       dir = Vector3.back, up = Vector3.up * mapRect.rect.height / 2f;
                bool          checkForChosen = (chosenPoint != null);
                for (int i = 0; i < n; i++)
                {
                    mp = mapPoints[i];
                    rt = mapMarkers[i];
                    if (checkForChosen && mp == chosenPoint)
                    {
                        rt.GetComponent <Image>().color = chosenColor;
                    }
                    else
                    {
                        rt.GetComponent <Image>().color = mp is PointOfInterest ? interactableColor : notInteractableColor;
                    }
                    rt.GetChild(0).GetComponent <RawImage>().uvRect = GetMarkerRect(mp.type);
                    Button b = rt.GetComponent <Button>();;
                    b.onClick.RemoveAllListeners();
                    MapPoint mpLink = mp;
                    b.onClick.AddListener(() => { this.SelectPoint(mpLink); }); // переписываем каждый раз, поскольку массив видимых точек соответствует массиву всех точек по индексам

                    rt.localPosition = Quaternion.AngleAxis(mapPoints[i].angle, dir) * (up * mapPoints[i].height);

                    if (!rt.gameObject.activeSelf)
                    {
                        rt.gameObject.SetActive(true);
                    }
                }
                mapRect.gameObject.SetActive(true);
                //
                var elist = Expedition.expeditionsList;
                c = elist.Count;
                if (c > 0)
                {
                    int        i = 0, l = expeditionsFastButtons.Length;
                    Button     b;
                    Expedition e;
                    if (c != l)
                    {
                        if (c > l)
                        { //увеличение списка
                            var nb = new Button[c];
                            for (; i < l; i++)
                            {
                                b = expeditionsFastButtons[i];
                                b.onClick.RemoveAllListeners();
                                e = elist[i];
                                int id = e.ID;
                                b.onClick.AddListener(() => this.SelectExpedition(id));
                                b.transform.GetChild(0).GetComponent <RawImage>().uvRect =
                                    GlobalMapUI.GetMarkerRect(e.stage == Expedition.ExpeditionStage.OnMission ? e.destination.type : MapMarkerType.FlyingExpedition);
                                b.gameObject.SetActive(true);
                                nb[i] = b;
                            }
                            for (; i < c; i++)
                            {
                                b                   = Instantiate(expeditionsFastButtons[0], expeditionFastButtonsPanel);
                                rt                  = b.GetComponent <RectTransform>();
                                rt.anchorMin        = new Vector2(0f, 0.95f - 0.05f * i);
                                rt.anchorMax        = new Vector2(0f, 1f - i * 0.05f);
                                rt.anchoredPosition = new Vector2(rt.sizeDelta.x / 2f, 0f);
                                b.onClick.RemoveAllListeners();
                                e = elist[i];
                                int id = e.ID;
                                b.onClick.AddListener(() => this.SelectExpedition(id));
                                b.transform.GetChild(0).GetComponent <RawImage>().uvRect = GlobalMapUI.GetMarkerRect(e.destination.type);
                                b.gameObject.SetActive(true);
                                nb[i] = b;
                            }
                            expeditionsFastButtons = nb;
                        }
                        else
                        { // сужение списка
                            for (i = 0; i < c; i++)
                            {
                                b = expeditionsFastButtons[i];
                                b.onClick.RemoveAllListeners();
                                e = elist[i];
                                int id = e.ID;
                                b.onClick.AddListener(() => this.SelectExpedition(id));
                                b.transform.GetChild(0).GetComponent <RawImage>().uvRect =
                                    GlobalMapUI.GetMarkerRect(e.stage == Expedition.ExpeditionStage.OnMission ? e.destination.type : MapMarkerType.FlyingExpedition);
                                b.gameObject.SetActive(true);
                            }
                            for (; i < l; i++)
                            {
                                expeditionsFastButtons[i].gameObject.SetActive(false);
                            }
                        }
                    }
                    else
                    { // просто перезапись
                        for (i = 0; i < l; i++)
                        {
                            b = expeditionsFastButtons[i];
                            b.onClick.RemoveAllListeners();
                            e = elist[i];
                            int id = e.ID;
                            b.onClick.AddListener(() => this.SelectExpedition(id));
                            b.transform.GetChild(0).GetComponent <RawImage>().uvRect = GlobalMapUI.GetMarkerRect(e.destination.type);
                            b.gameObject.SetActive(true);
                        }
                    }
                    expeditionFastButtonsPanel.gameObject.SetActive(true);
                }
                else
                {
                    expeditionFastButtonsPanel.gameObject.SetActive(false);
                }
            }
            else
            {
                if (mapMarkers.Count > 0)
                {
                    for (int i = 0; i < c; i++)
                    {
                        Destroy(mapMarkers[0].gameObject);
                        mapMarkers.RemoveAt(0);
                    }
                }
                expeditionFastButtonsPanel.gameObject.SetActive(false);
            }

            RingSector[] sectorsData = globalMap.mapSectors;
            for (int i = 0; i < sectorsData.Length; i++)
            {
                if (sectorsData[i] != null)
                {
                    var mp = sectorsData[i].centralPoint;
                    if (mp.type != MapMarkerType.Star)
                    {
                        sectorsImages[i].color = sectorsData[i].environment.GetMapColor();
                    }
                    else
                    {
                        sectorsImages[i].color = (mp as SunPoint).color;
                    }
                }
                else
                {
                    sectorsImages[i].color = inactiveSectorColor;
                }
            }

            lastDrawnStateHash = globalMap.actionsHash;
        }
    }