示例#1
0
        private void DoAutoSignIn()
        {
            ISharedPreferences prefs    = PreferenceManager.GetDefaultSharedPreferences(this);
            string             username = prefs.GetString("username", "");
            string             pwd      = prefs.GetString("pwd", "");

            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(pwd))
            {
                DoManualLogin();
            }
            else
            {
                signinText.Text = "Signing in " + username + "...";
                PhabrikServer.Login(username, pwd, false, (theResult) =>
                {
                    if (theResult == null)
                    {
                        // login failed
                        RunOnUiThread(() => { DoManualLogin(); });
                    }
                    else
                    {
                        this.SetResult(Result.Ok, new Intent());
                        Finish();
                    }
                });
            }
        }
示例#2
0
        private void SaveSectorImage()
        {
            Bitmap.Config config = Bitmap.Config.Argb8888;

            Bitmap newBitmap = Bitmap.CreateBitmap(1000, 1000, config);
            int    cellSize  = 100;
            Canvas canvas    = new Canvas(newBitmap);
            Rect   destRect  = new Rect(0, 0, 1024, 1024);
            Bitmap bkgnd     = BitmapHelper.GetImageBitmapFromUrl(parent.pop.curSector.DefaultUrl);
            Rect   srcRect   = new Rect(0, 0, bkgnd.Width, bkgnd.Height);
            Paint  thePaint  = new Paint(PaintFlags.AntiAlias);

            canvas.DrawBitmap(bkgnd, srcRect, destRect, thePaint);
            SectorObj curSector = parent.pop.curSector;

            foreach (StructureObj curStructure in parent.pop.curSector.structures)
            {
                bkgnd    = BitmapHelper.GetImageBitmapFromUrl(curStructure.imageURL);
                srcRect  = new Rect(0, 0, bkgnd.Width, bkgnd.Height);
                destRect = new Rect(curStructure.xLoc * cellSize, curStructure.yLoc * cellSize,
                                    (curStructure.xLoc + curStructure.xSize) * cellSize,
                                    (curStructure.yLoc + curStructure.ySize) * cellSize);
                canvas.DrawBitmap(bkgnd, srcRect, destRect, thePaint);
            }
            // at this point, the bitmap should be drawn
            using (System.IO.MemoryStream photoStream = new System.IO.MemoryStream())
            {
                newBitmap.Compress(Bitmap.CompressFormat.Jpeg, 90, photoStream);
                photoStream.Flush();
                PhabrikServer.UploadImage(photoStream, "sector", (newURL) =>
                {
                    parent.UpdateSectorUrl(curSector, newURL);
                });
            }
        }
示例#3
0
        private void BuildBtn_Click(object sender, EventArgs e)
        {
            if (catalog == null)
            {
                PhabrikServer.FetchStructureCatalog((theResult) =>
                {
                    catalog = new Dictionary <string, List <StructureTypeObj> >();

                    foreach (StructureTypeObj curObj in theResult)
                    {
                        if (catalog.ContainsKey(curObj.structuretype))
                        {
                            catalog[curObj.structuretype].Add(curObj);
                        }
                        else
                        {
                            List <StructureTypeObj> newList = new List <StructureTypeObj>();
                            newList.Add(curObj);
                            catalog[curObj.structuretype] = newList;
                        }
                    }

                    this.Activity.RunOnUiThread(() =>
                    {
                        ShowCatalog();
                    });
                });
            }
            else
            {
                ShowCatalog();
            }
        }
 public void UpdateSectorUrl(SectorObj theSector, string theUrl)
 {
     theSector.sectorUrl = theUrl;
     PhabrikServer.UpdateSectorUrl(theSector, theUrl);
     if (curScale == PointOfPresenceObj.PopScale.Planet)
     {
         planetFragment.UpdateSectorURL(theSector);
     }
 }
示例#5
0
 public override void OnPause()
 {
     if (isDirty)
     {
         PhabrikServer.SaveTerrainPaint(parent.pop.curTerrain, (didIt) =>
         {
             isDirty = false;
         });
     }
     base.OnPause();
 }
示例#6
0
        private void UpdateStructureLoc(View theView, int newX, int newY)
        {
            StructureObj theStruct = StructureForView(theView);

            if (theStruct != null)
            {
                theStruct.xLoc = newX;
                theStruct.yLoc = newY;
                PhabrikServer.UpdateStructureLoc(theStruct);
                isDirty = true;
            }
        }
 public void TravelToDistantStructure(long structureId)
 {
     // todo - figure out how to get there
     PhabrikServer.FetchStructure(structureId, (theResult) =>
     {
         pop.curStructure = theResult;
         EnableBtn(structureBtn);
         Activity.RunOnUiThread(() =>
         {
             SetScale(PointOfPresenceObj.PopScale.Structure);
         });
     });
 }
示例#8
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
            base.OnCreate(savedInstanceState);

            PhabrikServer.InitServer((result) =>
            {
                if (!result)
                {
                    ShowAlert("Error", "Cannot connect to server!  Quit and try again later.");
                }
            });

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);
            bodyFace  = Typeface.CreateFromAsset(Assets, "fonts/Lato-Regular.ttf");
            titleFace = Typeface.CreateFromAsset(Assets, "fonts/Orbitron-Regular.ttf");

            // set up drawer
            mDrawerTitles = new string[] {
                Resources.GetText(Resource.String.Game_Menu),
                Resources.GetText(Resource.String.Profile_Menu),
                Resources.GetText(Resource.String.About_Menu)
            };

            mDrawerLayout = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            mDrawerList   = FindViewById <ListView>(Resource.Id.left_drawer_list);
            mDrawerView   = FindViewById <LinearLayout>(Resource.Id.left_drawer);
            // Set the adapter for the list view
            mDrawerList.Adapter = new DrawerItemAdapter <string>(this, Resource.Layout.DrawerListItem, mDrawerTitles);
            // Set the list's click listener
            mDrawerList.ItemClick += mDrawerList_ItemClick;

            mDrawerToggle = new MyDrawerToggle(this, mDrawerLayout, Resource.String.drawer_open, Resource.String.drawer_close);


            mDrawerLayout.AddDrawerListener(mDrawerToggle);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetHomeButtonEnabled(true);
            SupportActionBar.SetBackgroundDrawable(new Android.Graphics.Drawables.ColorDrawable(Resources.GetColor(Resource.Color.Phabrik_white)));


            selectItem(0);

            SupportActionBar.Show();
            MainActivity.instance = this;
            Intent firstRun = new Intent(this, typeof(LoginActivity));

            StartActivityForResult(firstRun, LOGIN_RESULT);
        }
示例#9
0
        private void AttemptSignIn()
        {
            string username   = usernameField.Text;
            string pwd        = passwordField.Text;
            string confirmpwd = confirmField.Text;
            bool   create     = createBtn.Checked;

            if (create && pwd != confirmpwd)
            {
                ShowAlert("Login Error", "Passwords don't match!", "OK");
            }
            else
            {
                signinText.Text         = "signing in " + username + "...";
                autoLayout.Visibility   = ViewStates.Visible;
                manualLayout.Visibility = ViewStates.Gone;

                PhabrikServer.Login(username, pwd, create, (theResult) =>
                {
                    if (theResult != null)
                    {
                        // user is logged in!
                        ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
                        var editor = prefs.Edit();
                        editor.PutString("username", username);
                        editor.PutString("pwd", pwd);
                        editor.Apply();
                        this.SetResult(Result.Ok, new Intent());
                        Finish();
                    }
                    else
                    {
                        RunOnUiThread(() =>
                        {
                            if (create)
                            {
                                ShowAlert("Login Error", "Account creation failed.  Make sure username is unique!", "OK");
                            }
                            else
                            {
                                ShowAlert("Login Error", "Login failed.  Check username and password.", "OK");
                            }

                            DoManualLogin();
                        });
                    }
                });
            }
        }
        public void GotoPlanet(long planetId)
        {
            // go to a planet in the current system
            if (pop.curSolSys != null)
            {
                var newPlanet = pop.curSolSys.suns[0].planets.Find(p => p.Id == planetId);
                if (newPlanet == null)
                {
                    TravelToDistantPlanet(planetId);
                }
                else
                {
                    // we are the system, we can travel normally

                    PhabrikServer.FetchTerrain(planetId, (theResult) =>
                    {
                        if (theResult != null)
                        {
                            pop.curTerrain   = theResult;
                            pop.curPlanet    = newPlanet;
                            pop.curStructure = null;
                            pop.curSector    = null;

                            pop.scale = PointOfPresenceObj.PopScale.Planet;
                            Activity.RunOnUiThread(() =>
                            {
                                EnableBtn(planetBtn);
                                SetScale(PointOfPresenceObj.PopScale.Planet);
                            });
                        }
                        else
                        {
                            // null result
                            Activity.RunOnUiThread(() =>
                            {
                                MainActivity.ShowAlert(this.Context, "Missing Data", "You have no data on this planet.  Try scanning it now.", "ok");
                            });
                        }
                    });
                }
            }
            else
            {
                TravelToDistantPlanet(planetId);
            }
        }
 public void GotoSector(long sectorId)
 {
     if (pop.curTerrain != null)
     {
         PhabrikServer.FetchSector(sectorId, (theResult) =>
         {
             pop.curSector = theResult;
             Activity.RunOnUiThread(() =>
             {
                 EnableBtn(sectorBtn);
                 SetScale(PointOfPresenceObj.PopScale.Sector);
             });
         });
     }
     else
     {
         TravelToDistantSector(sectorId);
     }
 }
示例#12
0
        private void RefreshFromServer(bool fromPullDown = false)
        {
            PhabrikServer.FetchKnownSystems((resultList) =>
            {
                resultList.Sort((obj1, obj2) =>
                {
                    int loc1 = obj1.xLoc * obj1.xLoc + obj1.yLoc * obj1.yLoc + obj1.zLoc * obj1.zLoc;
                    int loc2 = obj2.xLoc * obj2.xLoc + obj2.yLoc * obj2.yLoc + obj2.zLoc * obj2.zLoc;

                    if (loc1 < loc2)
                    {
                        return(-1);
                    }
                    else if (loc1 > loc2)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                });
                this.Activity.RunOnUiThread(() =>
                {
                    header.Text = string.Format("{0} known systems", resultList.Count);
                    if (adapter == null)
                    {
                        if (adapter == null)
                        {
                            adapter = new SolSysListAdapter(this, resultList);
                        }
                        systemList.Adapter = adapter;
                        RefreshListView();
                    }

                    if (fromPullDown)
                    {
                        systemList.OnRefreshCompleted();
                    }
                });
            });
        }
        public void ScanPlanet(long planetId)
        {
            PhabrikServer.ProbePlanet(planetId, (theTerrain) =>
            {
                Activity.RunOnUiThread(() =>
                {
                    string msgStr;
                    if (theTerrain != null)
                    {
                        msgStr = "Probe successful.  You can view the planet now.";
                    }
                    else
                    {
                        msgStr = "Probe destroyed";
                    }

                    MainActivity.ShowAlert(Context, "Probe Results", msgStr, "Ok");
                });
            });
        }
示例#14
0
        private void HandlePurchase(StructureTypeObj theObj)
        {
            System.Console.WriteLine("Purchased item " + theObj.structurename);
            StructureObj newStruct = StructureObj.Instantiate(theObj);

            if (parent.pop.curSector != null)
            {
                parent.pop.curSector.structures.Add(newStruct);
                newStruct.sectorId = parent.pop.curSector.Id;
                newStruct.ownerId  = PhabrikServer.CurrentUser.Id;
                PhabrikServer.SaveNewStructure(newStruct, (newId) =>
                {
                    View newView = AddStructureToView(newStruct, true);
                    if (newView != null)
                    {
                        isDirty = true;
                    }
                });
            }
        }
 public void GotoSolSys(long solSysId)
 {
     PhabrikServer.FetchSolSysById(solSysId, (theSys) =>
     {
         if (theSys != null)
         {
             pop.curSolSys = theSys;
             EnableBtn(solSysBtn);
             pop.scale = PointOfPresenceObj.PopScale.System;
             Activity.RunOnUiThread(() =>
             {
                 SetScale(PointOfPresenceObj.PopScale.System);
             });
         }
         else
         {
             Activity.RunOnUiThread(() =>
             {
                 MainActivity.ShowAlert(this.Context, "Missing Data", "You have no data on this system.  Try scanning it now.", "ok");
             });
         }
     });
 }
 public void InitializeNewPop(SolSysObj_callback callback)
 {
     // for now, just use an empty system
     PhabrikServer.FetchSolSys(0, 0, 0, callback);
 }