void OnEnable()
 {
     if (miniMap == null)
     {
         miniMap          = WMSKMiniMap.Show(new Vector4(0, 0, 1, 1));
         miniMap.UIParent = GetComponent <RectTransform>();
     }
 }
 void OnDisable()
 {
     if (miniMap != null)
     {
         DestroyImmediate(miniMap.gameObject);
         miniMap = null;
     }
 }
Exemple #3
0
        /// <summary>
        ///	Opens the mini map at the provided normalized screen rect.
        /// </summary>
        /// <param name="screenRect">Screen rectangle in normalized coordinates (0..1)</param>
        public static WMSKMiniMap Show(Vector4 screenRect)
        {
            GameObject minimapObj = GameObject.Find(MINIMAP_NAME);

            if (minimapObj == null)
            {
                minimapObj      = Instantiate(Resources.Load <GameObject>("WMSK/Prefabs/MiniMap")) as GameObject;
                minimapObj.name = MINIMAP_NAME;
            }
            WMSKMiniMap mm = minimapObj.GetComponent <WMSKMiniMap>();

            minimapObj.transform.SetParent(mm.map.cameraMain.transform, false);
            mm.normalizedScreenRect = screenRect;
            return(mm);
        }
Exemple #4
0
        /// <summary>
        /// UI Buttons
        /// </summary>
        void OnGUI()
        {
            // Do autoresizing of GUI layer
            GUIResizer.AutoResize();

            // buttons background color
            GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f);

            // Add button to toggle Earth texture
            if (GUI.Button(new Rect(10, 10, 160, 30), "  Open Mini Map", buttonStyle))
            {
                float       left   = 0.8f;
                float       top    = 0.8f;
                float       width  = 0.2f;
                float       height = 0.2f;
                Vector4     normalizedScreenRect = new Vector4(left, top, width, height);
                WMSKMiniMap minimap = WMSKMiniMap.Show(normalizedScreenRect);
                minimap.duration  = 2f;
                minimap.zoomLevel = 0.1f;
            }

            if (WMSKMiniMap.IsVisible())
            {
                if (GUI.Button(new Rect(10, 50, 160, 30), "  Random Position", buttonStyle))
                {
                    float   left   = Random.value * 0.8f;
                    float   top    = Random.value * 0.8f;
                    float   width  = 0.2f;
                    float   height = 0.2f;
                    Vector4 normalizedScreenRect = new Vector4(left, top, width, height);
                    WMSKMiniMap.RepositionAt(normalizedScreenRect);
                }

                if (GUI.Button(new Rect(10, 90, 160, 30), "  Hide Mini Map", buttonStyle))
                {
                    WMSKMiniMap.Hide();
                }
            }
        }
Exemple #5
0
        // Use this for initialization
        void Start()
        {
            State.turn = 1;
            State.setGamePhase(MyEnum.GamePhase.adminstration);
            map = WMSK.instance;

            SelfProvinceGUI.SetActive(false);
            OtherProvinceGUI.SetActive(false);

            // WMSKMiniMap.Show();


            string nationsPath = Application.dataPath +
                                 "/StreamingAssets/Scenarios/DefaultFictional/Nations";
            string provincesPath = Application.dataPath +
                                   "/StreamingAssets/Scenarios/DefaultFictional/Provinces";



            string[] provFiles = Directory.GetFiles(provincesPath, "*.json");
            //foreach (string file in System.IO.Directory.GetFiles(provincesPath))
            foreach (string file in provFiles)
            {
                string dataAsJson = File.ReadAllText(file);

                //  Debug.Log(dataAsJson);
                //  assemblyCsharp.Province province = assemblyCsharp.Province.CreateFromJSON(dataAsJson);
                //assemblyCsharp.Province province = new assemblyCsharp.Province();
                // assemblyCsharp.Province newProvince = JsonUtility.FromJson<assemblyCsharp.Province>(dataAsJson);
                var newProvince = Newtonsoft.Json.JsonConvert.DeserializeObject <assemblyCsharp.Province>(dataAsJson);
                provinces.Add(newProvince.getIndex(), newProvince);
                // Debug.Log("Culture: " + newProvince.getCulture());

                map.GetProvince(newProvince.getIndex()).name        = newProvince.getProvName();
                map.GetProvince(newProvince.getIndex()).customLabel = newProvince.getProvName();
            }

            string[] nationFiles = Directory.GetFiles(nationsPath, "*.json");

            foreach (string file in nationFiles)
            {
                string dataAsJson = File.ReadAllText(file);
                //   Debug.Log(dataAsJson);
                var newNation = Newtonsoft.Json.JsonConvert.DeserializeObject <assemblyCsharp.Nation>(dataAsJson);
                //   Nation newNation = JsonUtility.FromJson<Nation>(dataAsJson);

                nations.Add(newNation.getIndex(), newNation);
                map.GetCountry(newNation.getIndex()).name = newNation.getNationName();
                Color color = new Color(UnityEngine.Random.Range(0.0f, 1.0f),
                                        UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f));
                newNation.setColor(color);
                // map.ToggleCountrySurface(newNation.getIndex(), true, color);
                map.GetCountry(newNation.getIndex()).customLabel = newNation.getNationName();
                map.CountryRename("Country" + newNation.getIndex(), newNation.getNationName());
            }

            map.Redraw();

            for (int k = 0; k < map.countries.Length; k++)
            {
                //Color color = new Color(UnityEngine.Random.Range(0.0f, 1.0f),
                // UnityEngine.Random.Range(0.0f, 1.0f), UnityEngine.Random.Range(0.0f, 1.0f));
                Color color = nations[k].getColor();
                //    Debug.Log("f**k: " + k + " " + color);

                map.ToggleCountrySurface(k, true, color);
            }

            float       left   = 0.78f;
            float       top    = 0.02f;
            float       width  = 0.2f;
            float       height = 0.2f;
            Vector4     normalizedScreenRect = new Vector4(left, top, width, height);
            WMSKMiniMap minimap = WMSKMiniMap.Show(normalizedScreenRect);

            // string path = Application.dataPath + "Alpha9.png";
            minimap.map.earthStyle = EARTH_STYLE.SolidColor;
            //  string absoluteImagePath = Path.Combine(Application.streamingAssetsPath, "ScenarioOne/Alpha9.png");

            //Texture2D  miniMapTexture = loadSprite(path);
            Texture2D miniMapTexture = Resources.Load("AlphaPrime.png", typeof(Texture2D)) as Texture2D;

            minimap.map.earthTexture = miniMapTexture;
            minimap.map.fillColor    = Color.blue;
            minimap.map.earthColor   = Color.blue;

            minimap.duration  = 1.5f;
            minimap.zoomLevel = 0.4f;


            for (int countryIndex = 0; countryIndex < map.countries.Length; countryIndex++)
            {
                Color color = nations[countryIndex].getColor();
                minimap.map.ToggleCountrySurface(countryIndex, true, color);
            }


            Dictionary <int, string> majorNations = NationData.majorDict;
            Dictionary <int, string> minorNations = NationData.minorDict;
            Dictionary <int, string> uncivNations = NationData.uncivDict;

            map.showProvinceNames = true;

            WorldMapStrategyKit.Province prov = map.GetProvince(45);
            Vector2 position = prov.center;

            //  Vector2 position = map.GetProvince(45, 20).center;


            army      = PlaceArmy(position);
            army.name = "first unit";
            army.GetComponent <ArmyController>().army = army;

            Vector2 position2 = map.GetProvince(32).center;

            Nation humanPlayer = nations[16];

            humanPlayer.SetHuman(true);

            //


            //Ship Click

            /*  map.OnClick += (float x, float y, int buttonIndex) => {
             *    Vector2 shipPosition = new Vector2(x, y);
             *    byte byteValue1= 0;
             *
             *    map.waterMaskLevel = byteValue1;
             *    if (map.ContainsWater(shipPosition))
             *    {
             *        Debug.Log("Water!");
             *
             *    }
             *    else
             *    {
             *        Debug.Log("Land!");
             *    }
             *    if (map.GetProvince(shipPosition) == null)
             *    {
             *        ship.MoveTo(shipPosition, 0.1f);
             *    }
             *
             * }; */


            // LaunchShip();

            //Show resources of each provinces
            //  ShowProvinceResources();

            map.OnClick += (float x, float y, int buttonIndex) =>
            {
                Vector2 provincePosition = new Vector2(x, y);
                int     clickedIndex     = map.GetProvinceIndex(provincePosition);
                assemblyCsharp.Province clickedProvince = provinces[clickedIndex];
            };
        }