private void ChangeVolumeMenu() { MenuIcon musicVolumeUp = new MenuIcon(Language.Instance.GetString("MusicVolumeUp")); MenuIcon musicVolumeDown = new MenuIcon(Language.Instance.GetString("MusicVolumeDown")); MenuIcon sfxVolumeUp = new MenuIcon(Language.Instance.GetString("EffectsVolumeUp")); MenuIcon sfxVolumeDown = new MenuIcon(Language.Instance.GetString("EffectsVolumeDown")); MenuIcon empty = new MenuIcon(""); MenuIcon done = new MenuIcon(Language.Instance.GetString("Cancel"), Recellection.textureMap.GetTexture(Globals.TextureTypes.No)); List <MenuIcon> iconList = new List <MenuIcon>();; iconList.Add(musicVolumeUp); iconList.Add(empty); iconList.Add(musicVolumeDown); iconList.Add(sfxVolumeUp); iconList.Add(sfxVolumeDown); iconList.Add(done); Menu volumeMenu = new Menu(Globals.MenuLayout.NineMatrix, iconList, ""); MenuController.LoadMenu(volumeMenu); bool notFinished = true; while (notFinished) { MenuIcon response = MenuController.GetInput(); if (response == musicVolumeUp) { if (GameOptions.Instance.musicVolume <= 1.0f) { SoundsController.changeMusicVolume(GameOptions.Instance.musicVolume + 0.1f); } } else if (response == musicVolumeDown) { SoundsController.changeMusicVolume(GameOptions.Instance.musicVolume - 0.1f); } else if (response == sfxVolumeUp) { if (GameOptions.Instance.sfxVolume <= 1.0f) { SoundsController.changeEffectsVolume(GameOptions.Instance.sfxVolume + 0.1f); } } else if (response == sfxVolumeDown) { SoundsController.changeEffectsVolume(GameOptions.Instance.sfxVolume - 0.1f); } else if (response == done) { notFinished = false; } } MenuController.UnloadMenu(); }
public void ChangeOptions() { Menu optionsMenu = BuildMenu(); MenuController.LoadMenu(optionsMenu); Recellection.CurrentState = MenuView.Instance; bool notFinished = true; while (notFinished) { MenuIcon response = MenuController.GetInput(); if (response == mute) { if (GameOptions.Instance.musicMuted) { GameOptions.Instance.musicMuted = false; SoundsController.changeEffectsVolume(GameOptions.Instance.sfxVolume); SoundsController.changeMusicVolume(GameOptions.Instance.musicVolume); } else { GameOptions.Instance.musicMuted = true; SoundsController.changeEffectsVolume(0.0f); SoundsController.changeMusicVolume(0.0f); } } else if (response == volume) { ChangeVolumeMenu(); } else if (response == language) { ChangeLanguageMenu(); } else if (response == difficulty) { ChangeDifficultyMenu(); } else if (response == back) { notFinished = false; } else if (response == credits) { PlayCredits(); } } MenuController.UnloadMenu(); }
/// <summary> /// Removes a fromBuilding from the graph containing it. /// </summary> /// <param name="b">The buiding to remove.</param> public static void RemoveBuilding(Building b) { lock (b) { if (b is ResourceBuilding && GraphController.Instance.GetGraph(b).baseBuilding != null) { GraphController.Instance.GetGraph(b).baseBuilding.RateOfProduction -= ((ResourceBuilding)b).RateOfProduction; } lock (b.controlZone) { b.controlZone.First().RemoveBuilding(); GraphController.Instance.RemoveBuilding(b); // How about I exchange this: //b.Damage(Math.Max(0, b.currentHealth+1)); // Kill it! // // With this: b.Kill(); SoundsController.playSound("buildingDeath", b.position); } } }
/// <summary> /// Add a fromBuilding to the source buildings owners graph, /// the source fromBuilding will be used to find the correct graph. /// </summary> /// <param name="buildingType">The type of fromBuilding to build.</param> /// <param name="sourceBuilding">The fromBuilding used to build this fromBuilding.</param> /// <param name="targetCoordinate">The tile coordinates where the fromBuilding will be built.</param> /// <param name="world">The world to build the fromBuilding in.</param> public static bool AddBuilding(Globals.BuildingTypes buildingType, Building sourceBuilding, Vector2 targetCoordinate, World world, Player owner) { if (sourceBuilding != null && buildingType != Globals.BuildingTypes.Base && (Math.Abs(((int)sourceBuilding.position.X) - (int)targetCoordinate.X) > MAX_BUILDING_RANGE || (Math.Abs(((int)sourceBuilding.position.Y) - (int)targetCoordinate.Y) > MAX_BUILDING_RANGE))) { logger.Debug("Building position out of range"); throw new BuildingOutOfRangeException(); } uint price = owner.unitAcc.CalculateBuildingCostInflation(buildingType); if (sourceBuilding != null && (uint)sourceBuilding.CountUnits() < price) { logger.Debug("Building too expensive"); return(false); } logger.Info("Building a building at position " + targetCoordinate + " of " + buildingType + "."); lock (owner.GetGraphs()) { LinkedList <Tile> controlZone = CreateControlZone(targetCoordinate, world); //The Base building is handled in another way due to it's nature. if (buildingType == Globals.BuildingTypes.Base) { logger.Trace("Adding a Base Building and also constructing a new graph"); BaseBuilding baseBuilding = new BaseBuilding("Base Buidling", (int)targetCoordinate.X, (int)targetCoordinate.Y, owner, controlZone); world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).SetBuilding(baseBuilding); owner.AddGraph(GraphController.Instance.AddBaseBuilding(baseBuilding, sourceBuilding)); } else { //The other buildings constructs in similiar ways but they are constructed //as the specified type. Building newBuilding = null; switch (buildingType) { case Globals.BuildingTypes.Aggressive: logger.Trace("Building a new Aggressive building"); newBuilding = new AggressiveBuilding("Aggresive Building", (int)targetCoordinate.X, (int)targetCoordinate.Y, owner, GraphController.Instance.GetGraph(sourceBuilding).baseBuilding, controlZone); break; case Globals.BuildingTypes.Barrier: logger.Trace("Building a new Barrier building"); newBuilding = new BarrierBuilding("Barrier Building", (int)targetCoordinate.X, (int)targetCoordinate.Y, owner, GraphController.Instance.GetGraph(sourceBuilding).baseBuilding, controlZone); break; case Globals.BuildingTypes.Resource: logger.Trace("Building a new Resource building"); newBuilding = new ResourceBuilding("Resource Building", (int)targetCoordinate.X, (int)targetCoordinate.Y, owner, GraphController.Instance.GetGraph(sourceBuilding).baseBuilding, controlZone); break; } world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).SetBuilding(newBuilding); newBuilding.Parent = sourceBuilding; GraphController.Instance.AddBuilding(sourceBuilding, newBuilding); } if (sourceBuilding != null && world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).GetBuilding() != null) { logger.Info("The building has " + sourceBuilding.CountUnits() + " and the building costs " + price); owner.unitAcc.DestroyUnits(sourceBuilding.units, (int)price); logger.Info("The source building only got " + sourceBuilding.CountUnits() + " units left."); } else if (world.map.GetTile((int)targetCoordinate.X, (int)targetCoordinate.Y).GetBuilding() == null) { throw new Exception("A building was not placed on the tile even though it should have been."); } SoundsController.playSound("buildingPlacement"); } // Let's update the fog of war! /* * for (int i = -3; i <= 3; i++) * { * for (int j = -3; j <= 3; j++) * { * try * { * world.map.GetTile((int)targetCoordinate.X + j, (int)targetCoordinate.Y + i).MakeVisibleTo(owner); * } * catch(IndexOutOfRangeException e) * { * } * } * } */ return(true); }