void SetupWorld(int width, int height) { jobQueue = new JobQueue(); // Set the current world to be this world. // TODO: Do we need to do any cleanup of the old world? current = this; Width = width; Height = height; tiles = new Tile[Width, Height]; rooms = new List <Room>(); rooms.Add(new Room()); // Create the outside? for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { tiles[x, y] = new Tile(x, y); tiles[x, y].cbTileChanged += OnTileChanged; tiles[x, y].room = GetOutsideRoom(); // Rooms 0 is always going to be outside, and that is our default room } } Debug.Log("World created with " + (Width * Height) + " tiles."); CreateFurniturePrototypes(); characters = new List <Character>(); furnitures = new List <Furniture>(); inventoryManager = new InventoryManager(); powerSystem = new PowerSystem(); }
// Use this for initialization protected void Start() { _grid = FindObjectOfType <Grid>(); _powerSystem = FindObjectOfType <PowerSystem>(); _renderer = GetComponent <SpriteRenderer>(); SoundPlayer = GetComponent <AudioSource>(); }
// Use this for initialization void Start() { totalCash = 1000; InvokeRepeating("Heartbeat", 2, heartbeatTimer); powersystem = FindObjectOfType <PowerSystem>(); moonManSpawner = FindObjectOfType <MoonManSpawner> ().GetComponent <MoonManSpawner> (); }
/// /// \brief Called every frame /// /// \return No return value /// /// \details Updates the Displayed text. /// public void update() { int np = PowerSystem.getRoom(name); tb.text = string.Format("{0}\n{1}/{2}", displayName, np, minPower); tb.color = np < minPower ? Color.red : powered; }
public static void ImportPostfix(PowerSystem __instance, ref BinaryReader r) { //Debug.Log("Planet --------- " + __instance.planet.displayName); if (__instance == null) { return; } if (__instance.genPool != null && __instance.genPool.Length > 0 && EnergyManager_Generators_Plugin.GenModDict != null && EnergyManager_Generators_Plugin.GenModDict.Count > 0 && EnergyManager_Generators_Plugin.EditExisting ) { EnergyManager_Generators_Plugin.logger.LogMessage("Editing Existing Generator Pool in Powersystem of Planet \"" + __instance.planet.displayName + "\""); int tmpCount = 0; for (int i = 0; i < __instance.genPool.Length; i++) { int ItemID = __instance.factory.entityPool[__instance.genPool[i].entityId].protoId; if (EnergyManager_Generators_Plugin.GenModDict.ContainsKey(ItemID)) { __instance.genPool[i].genEnergyPerTick = Convert.ToInt64(Math.Round(EnergyManager_Generators_Plugin.GenModDict[ItemID] * kwMultiplier)); tmpCount++; } } EnergyManager_Generators_Plugin.logger.LogMessage("Edited " + tmpCount + " Generator/s on Planet \"" + __instance.planet.displayName + "\""); } }
///Sets the rod value and the rod text public void SetRod(float rod) { ///sets the rod value to be the current instances of rod. this.rod = rod; /// sets the power units to 100 - rod. powerUnits = (int)(100 - rod) / 2; ///Sets the current draw in the power system to be the power units. PowerSystem.setPower(powerUnits); }
/// <summary>Copy constructor.</summary> public PowerSystem(PowerSystem src) { energyCapacity = src.energyCapacity; energyRecharge = src.energyRecharge; reservedEnergy = src.reservedEnergy; currentEnergy = src.currentEnergy; damage = src.damage; overclock = src.overclock; }
/// /// \brief Used for initialization /// /// \return No return value /// /// \details Gets and sets the color form the powerUI object. Gets the text component. Gets the minimum power. Sets the initial display text. /// void Start() { powered = GetComponentInParent <powerUI>().powered; tb = GetComponent <Text>(); int np = PowerSystem.getRoom(name); minPower = PowerSystem.getMin(name); tb.text = string.Format("{0}\n{1}/{2}", displayName, np, minPower); tb.color = np < minPower ? Color.red : powered; }
/// /// \brief Called when the button is clicked /// /// \param [in] eventData Unity's auto-passed mouse data /// \return No return value /// /// \details Will increase the power on click, decrease on any other click type (Right, centre) /// public void OnPointerClick(PointerEventData eventData) { int np = PowerSystem.changeRoom(this.name, eventData.button == PointerEventData.InputButton.Left); tb.text = string.Format("{0}\n{1}/{2}", displayName, np, minPower); tb.color = np < minPower ? Color.red : powered; if (np == -1) { Debug.LogError("Error in PowerChange at " + name); } }
void ContextSwitched() { usermode = false; //get current system PowerSystem system = GetCurrentSystem(); //update UI if (system.on) { controller.Controls.toggle1.SetValue(true); if (system.WarmedUp) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; } else { controller.Controls.greenLight.Lit = false; controller.Controls.yellowLight.Lit = true; } controller.Controls.redLight.Lit = false; } else { controller.Controls.toggle1.SetValue(false); controller.Controls.greenLight.Lit = false; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = true; } if (controller.Controls.toggle2.isOn) { controller.Controls.meter2.Value = system.power; controller.Controls.meter3.Value = 0; controller.Controls.toggle2.SetLabel("Power"); controller.Controls.meter1.SetLabel("Total Power"); controller.Controls.meter2.SetLabel("System Power"); controller.Controls.meter3.SetLabel(); } else { controller.Controls.meter2.Value = system.initialCurrent; controller.Controls.meter3.Value = system.runningCurrent; controller.Controls.toggle2.SetLabel("Current"); controller.Controls.meter1.SetLabel("Total Current"); controller.Controls.meter2.SetLabel("Initial Current"); controller.Controls.meter3.SetLabel("Running Current"); } controller.Controls.setting2.SetLabel(system.backupName); usermode = true; }
public static void PowerTickPrefix(ref PowerSystem __instance, ref PowerConsumerComponent[] __state) { __state = new PowerConsumerComponent[__instance.consumerPool.Length]; __instance.consumerPool.CopyTo(__state, 0); for (int i = 0; i < __instance.consumerPool.Length; i++) { __instance.consumerPool[i].idleEnergyPerTick = 0; __instance.consumerPool[i].workEnergyPerTick = 0; __instance.consumerPool[i].requiredEnergy = 0; } }
public static bool RemoveNodeComponent(PowerSystem __instance, int id) { if (Multiplayer.IsActive) { // as the destruct is synced accross players this event is too // and as such we can safely remove power demand for every player PowerNodeComponent pComp = __instance.nodePool[id]; Multiplayer.Session.PowerTowers.RemExtraDemand(__instance.planet.id, pComp.networkId, id); } return(true); }
public static bool RemoveNodeComponent(PowerSystem __instance, int id) { if (SimulatedWorld.Initialized) { // as the destruct is synced accross players this event is too // and as such we can safely remove power demand for every player PowerNodeComponent pComp = __instance.nodePool[id]; PowerTowerManager.RemExtraDemand(__instance.planet.id, pComp.networkId, id); } return(true); }
public static void RemExtraDemand(int PlanetId, int NetId, int NodeId) { if (Energy.TryGetValue(PlanetId, out var mapping)) { for (int i = 0; i < mapping.Count; i++) { if (mapping[i].NetId == NetId) { PlanetFactory factory = GameMain.galaxy.PlanetById(PlanetId).factory; PowerSystem pSystem = factory?.powerSystem; if (Monitor.TryEnter(mapping, 100)) { try { for (int j = 0; j < mapping[i].NodeId.Count; j++) { if (mapping[i].NodeId[j] == NodeId) { if (factory != null && pSystem != null) { mapping[i].ExtraPower -= pSystem.nodePool[NodeId].workEnergyPerTick; } else { mapping[i].ExtraPower -= mapping[i].ExtraPower / mapping[i].NodeId.Count; } mapping[i].Activated[j]--; AddRequested(PlanetId, NetId, NodeId, false, true); break; } } } finally { Monitor.Exit(mapping); } } else { Log.Warn($"PowerTower: cant wait longer for threading lock, PowerTowers will be desynced!"); } if (mapping[i].ExtraPower < 0) { mapping[i].ExtraPower = 0; } } } } }
public static void PowerSystem_GameTick_Postfix(PowerSystem __instance, long time, bool isActive, bool isMultithreadMode) { if (Multiplayer.IsActive) { for (int i = 1; i < __instance.netCursor; i++) { PowerNetwork pNet = __instance.netPool[i]; pNet.energyRequired += Multiplayer.Session.PowerTowers.GetExtraDemand(__instance.planet.id, i); } Multiplayer.Session.PowerTowers.GivePlayerPower(); Multiplayer.Session.PowerTowers.UpdateAllAnimations(__instance.planet.id); } }
/// /// \brief Called on initial creation of the object /// /// \return No return value /// /// \details Used to set the static powerSystem object and make it singular by self deleting if one is already set /// void Awake() { if (powersystem == null) { //Debug.Log("Added Powersystem at: " + gameObject.name); powersystem = this; } else { Debug.LogError("Multiple PowerSystems"); Destroy(transform.gameObject); } }
public static void PowerSystem_GameTick_Postfix(PowerSystem __instance, long time, bool isActive, bool isMultithreadMode) { if (SimulatedWorld.Initialized) { for (int i = 1; i < __instance.netCursor; i++) { PowerNetwork pNet = __instance.netPool[i]; pNet.energyRequired += PowerTowerManager.GetExtraDemand(__instance.planet.id, i); } PowerTowerManager.GivePlayerPower(); PowerTowerManager.UpdateAllAnimations(__instance.planet.id); } }
public static bool NewConsumerComponentPrefix(PowerSystem __instance, ref int entityId, ref long work, ref long idle) { var x = LDB.items.Select(__instance.factory.entityPool[entityId].protoId).ID; if (x != GigaStationsPlugin.ils.ID && x != GigaStationsPlugin.pls.ID) { return(true); } work = 1000000; return(true); }
void SetupWorld(int width, int height) { // Setup furniture actions before any other things are loaded. new FurnitureActions(); jobQueue = new JobQueue(); jobWaitingQueue = new JobQueue(); // Set the current world to be this world. // TODO: Do we need to do any cleanup of the old world? current = this; Width = width; Height = height; TileType.LoadTileTypes(); tiles = new Tile[Width, Height]; rooms = new List <Room>(); rooms.Add(new Room()); // Create the outside? for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { tiles[x, y] = new Tile(x, y); tiles[x, y].TileChanged += OnTileChanged; tiles[x, y].Room = GetOutsideRoom(); // Rooms 0 is always going to be outside, and that is our default room } } CreateFurniturePrototypes(); CreateNeedPrototypes(); CreateInventoryPrototypes(); CreateTraderPrototypes(); CreateQuests(); characters = new List <Character>(); furnitures = new List <Furniture>(); inventoryManager = new InventoryManager(); powerSystem = new PowerSystem(); temperature = new Temperature(Width, Height); LoadSkybox(); }
/// This function executes when the reactor needs to power up. settings all the ui elements and calls restore on the power system, so the power units can be allocated again. /// updates the boolean online to true to let the script know to heat things up again. public void powerUP() { ///when the power lines are fixed and the temp is 0. if (temp <= 0 && PowerLines.getFixed()) { ///restores the power system and sets the power units avaiable to be what they were. powerUnits = PowerSystem.restore(); /// sets the reactor to online online = true; ///Sets the restart button to not be interactable RecUI.restart.interactable = false; ///Sets the shutdown button to be interactable. RecUI.shutdown.interactable = true; ///Sets the controlRod to be interactable, RecUI.controlRod.interactable = true; } }
// Use this for initialization void Start() { powerSystem = GameObject.FindObjectOfType <PowerSystem>(); generator = GameObject.FindObjectOfType <Generator>(); elapsedWeekTimer = new System.Timers.Timer(); elapsedWeekTimer.Elapsed += new ElapsedEventHandler(SpaceDateClockCalculator); elapsedWeekTimer.Interval = SpaceDateWeekMillis; elapsedWeekTimer.Enabled = true; if (Tabs.Length > 0) { selectedTab = Tabs[0]; } cities = Grid.GetCities(); MeteorAlert.color = new Color(MeteorAlert.color.r, MeteorAlert.color.g, MeteorAlert.color.b, .4f); SetGeneratorPower(); }
// Use this for initialization void Start() { anim = GetComponent <Animator>(); powersystem = FindObjectOfType <PowerSystem>(); //Set the level and the ID for the room digLevel = FindObjectOfType <DigAndDebug>(); roomID = currentRoomID; currentRoomID += 1; roomLevel = digLevel.currentLevel; //Set up the backups productivityCapabilitybackup = productivityCapability; tourismCapabilitybackup = tourismCapability; powerGenerationbackup = powerGeneration; powerUsebackup = powerUse; LivingSpacesbackup = LivingSpaces; openWorkingSpacesbackup = openWorkingSpaces; openTourismSpacesbackup = openTourismSpaces; miningCapabilitybackup = miningCapability; powerGenerationbackup = powerGeneration; //Some other totaling stuff that will probably be overwritten totalMiningCapability += miningCapability; totalTourismCapability += tourismCapability; totalProductivityCapability += productivityCapability; if (powerGeneration != 0) { powersystem.totalPowerAvailable += powerGeneration; } if (powersystem.totalPowerUse + powerUse > powersystem.totalPowerAvailable && powerUse != 0) { shutDownRoom(); } else { isActive = true; } }
public static void RemExtraDemand(int PlanetId, int NetId, int NodeId) { if (Energy.TryGetValue(PlanetId, out var mapping)) { for (int i = 0; i < mapping.Count; i++) { if (mapping[i].NetId == NetId) { PlanetFactory factory = GameMain.galaxy.PlanetById(PlanetId).factory; PowerSystem pSystem = factory?.powerSystem; for (int j = 0; j < mapping[i].NodeId.Count; j++) { if (mapping[i].NodeId[j] == NodeId) { if (factory != null && pSystem != null) { mapping[i].ExtraPower -= pSystem.nodePool[NodeId].workEnergyPerTick; } else { mapping[i].ExtraPower -= mapping[i].ExtraPower / mapping[i].NodeId.Count; } mapping[i].Activated[j] = false; } } if (mapping[i].ExtraPower < 0) { mapping[i].ExtraPower = 0; } } } } }
/// this funtion executes when the reactor powers down for any reason, through a restart or a overload. public void powerDown(bool crash) { ///when the reactor crashes send a message of what it has done. if (crash) { ///sends the message to the top of the players screen Toast.addToast("Reactor overload\n Powering Down", 3); PowerLines.onBreak(); ///breaks the powerlines. } ///sets the overload to crash, being true. overload = crash; ///Sets reactor to offline online = false; ///calls set rod with the value 100 SetRod(100); ///sets the powerunits to what the should be when crashes. powerUnits = PowerSystem.crash(); /// Sets the reatart to be interactable RecUI.restart.interactable = true; ///sets the controlRod to not be interactable. RecUI.controlRod.interactable = false; ///sets the shutdown to not be interactable. RecUI.shutdown.interactable = false; }
public static void UpdateTotalChargedEnergy(ref long num2, int targetIndex) { num2 = 0L; //Total Stored Energy for "Entire Star Cluster" if (targetIndex == -1) { //For the host and singleplayer, use normal calculation. For the clients, use Data from the server if (SimulatedWorld.Initialized && !LocalPlayer.IsMasterClient) { for (int i = 0; i < PowerEnergyStoredData.Length; i++) { num2 += PowerEnergyStoredData[i]; } } else { for (int i = 0; i < GameMain.data.factoryCount; i++) { PowerSystem powerSystem = GameMain.data.factories[i].powerSystem; int netCursor = powerSystem.netCursor; PowerNetwork[] netPool = powerSystem.netPool; for (int j = 1; j < netCursor; j++) { num2 += netPool[j].energyStored; } } } } //Total Stored Energy for "Local Planet" else if (targetIndex == 0) { if (SimulatedWorld.Initialized && !LocalPlayer.IsMasterClient) { num2 = GameMain.data.localPlanet.factoryIndex != -1 ? PowerEnergyStoredData[GameMain.data.localPlanet.factoryIndex] : 0; } else { PowerSystem powerSystem2 = GameMain.data.localPlanet?.factory?.powerSystem; int netCursor2 = powerSystem2.netCursor; PowerNetwork[] netPool2 = powerSystem2.netPool; for (int l = 1; l < netCursor2; l++) { num2 += netPool2[l].energyStored; } } } //Total Stored Energy for "Picking specific planet" else if (targetIndex % 100 > 0) { if (SimulatedWorld.Initialized && !LocalPlayer.IsMasterClient) { for (int i = 0; i < GameMain.data.factoryCount; i++) { if (targetIndex == GameMain.data.factories[i].planetId) { num2 = PowerEnergyStoredData[i]; break; } } } else { PlanetData planetData = GameMain.data.galaxy.PlanetById(targetIndex); PowerSystem powerSystem3 = planetData.factory.powerSystem; int netCursor3 = powerSystem3.netCursor; PowerNetwork[] netPool3 = powerSystem3.netPool; for (int m = 1; m < netCursor3; m++) { num2 += netPool3[m].energyStored; } Debug.Log(num2); } } //Total Stored Energy for "Picking Star System" else if (targetIndex % 100 == 0) { int starId = targetIndex / 100; StarData starData = GameMain.data.galaxy.StarById(starId); for (int n = 0; n < starData.planetCount; n++) { if (SimulatedWorld.Initialized && !LocalPlayer.IsMasterClient) { if (starData.planets[n].factoryIndex != -1) { num2 += PowerEnergyStoredData[starData.planets[n].factoryIndex]; } } else if (starData.planets[n].factory != null) { PowerSystem powerSystem4 = starData.planets[n].factory.powerSystem; int netCursor4 = powerSystem4.netCursor; PowerNetwork[] netPool4 = powerSystem4.netPool; for (int num9 = 1; num9 < netCursor4; num9++) { num2 += netPool4[num9].energyStored; } } } } }
// Use this for initialization void Start() { displayText = GetComponent <Text>(); valueTracker = GameObject.FindObjectOfType <ValueTracker>(); powersystem = FindObjectOfType <PowerSystem>(); }
public LDCOPFModelSolver(PowerSystem powerSystem, LoadDurationCurveByBlocks durationCurveBlocks) : base(powerSystem) { this.DurationCurveBlocks = durationCurveBlocks; }
public override void RunUpdate() { //update all system timers and the current current = 0; power = startingPower; PowerSystem curSys = GetCurrentSystem(); bool level1enabled = false; foreach (PowerSystem sys in level1systems) { if (sys.on) { bool notWarm = false; if (!sys.WarmedUp) { notWarm = true; sys.warmUpTimer -= Time.deltaTime; } if (sys.WarmedUp) { level1enabled = true; current += sys.runningCurrent; if (notWarm && sys == curSys) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = false; //tutorial if (curState == TutState.YellowLight) { tut.YellowLightHint.SetActive(false); tut.GreenLightHint.SetActive(true); tut.ExplainMeter1c.SetActive(true); curState = TutState.ExplainMeter1c; } } } else { current += sys.initialCurrent; } power -= sys.power; } } bool level2enabled = false; foreach (PowerSystem sys in level2systems) { if (sys.on) { bool notWarm = false; if (!sys.WarmedUp) { notWarm = true; sys.warmUpTimer -= Time.deltaTime; } if (sys.WarmedUp) { level2enabled = true; current += sys.runningCurrent; if (notWarm && sys == curSys) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = false; //tutorial if (curState == TutState.YellowLight) { tut.YellowLightHint.SetActive(false); tut.GreenLightHint.SetActive(true); tut.ExplainMeter1c.SetActive(true); curState = TutState.ExplainMeter1c; } } } else { current += sys.initialCurrent; } power -= sys.power; } } bool level3enabled = false; foreach (PowerSystem sys in level3systems) { if (sys.on) { bool notWarm = false; if (!sys.WarmedUp) { notWarm = true; sys.warmUpTimer -= Time.deltaTime; } if (sys.WarmedUp) { level3enabled = true; current += sys.runningCurrent; if (notWarm && sys == curSys) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = false; //tutorial if (curState == TutState.YellowLight) { tut.YellowLightHint.SetActive(false); tut.GreenLightHint.SetActive(true); tut.ExplainMeter1c.SetActive(true); curState = TutState.ExplainMeter1c; } } } else { current += sys.initialCurrent; } power -= sys.power; } } //update UI for current if (controller.Controls.toggle2.isOn) { controller.Controls.meter1.Value = (power < 0 ? 0 : power); } else { controller.Controls.meter1.Value = current; } if (level1enabled) { controller.Controls.button1.ToggleButton(true); } else { controller.Controls.button1.ToggleButton(false); } if (level2enabled) { controller.Controls.button2.ToggleButton(true); } else { controller.Controls.button2.ToggleButton(false); } if (level3enabled) { controller.Controls.button3.ToggleButton(true); } else { controller.Controls.button3.ToggleButton(false); } if (current > currentLimit || power < 0) // failed { ResetUI(); EndProcedure(false); } else if (level1enabled && level2enabled && level3enabled) // success { ResetUI(); EndProcedure(true); } }
//Update function runs every frame public override void RunUpdate() { if (!stopped) { //update all system timers and the current current = 0; power = startingPower; PowerSystem curSys = GetCurrentSystem(); bool level1enabled = false; foreach (PowerSystem sys in level1systems) { if (sys.on) { bool notWarm = false; if (!sys.WarmedUp) { notWarm = true; sys.warmUpTimer -= Time.deltaTime; } if (sys.WarmedUp) { level1enabled = true; current += sys.runningCurrent; if (notWarm && sys == curSys) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = false; } } else { current += sys.initialCurrent; } power -= sys.power; } } bool level2enabled = false; foreach (PowerSystem sys in level2systems) { if (sys.on) { bool notWarm = false; if (!sys.WarmedUp) { notWarm = true; sys.warmUpTimer -= Time.deltaTime; } if (sys.WarmedUp) { level2enabled = true; current += sys.runningCurrent; if (notWarm && sys == curSys) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = false; } } else { current += sys.initialCurrent; } power -= sys.power; } } bool level3enabled = false; foreach (PowerSystem sys in level3systems) { if (sys.on) { bool notWarm = false; if (!sys.WarmedUp) { notWarm = true; sys.warmUpTimer -= Time.deltaTime; } if (sys.WarmedUp) { level3enabled = true; current += sys.runningCurrent; if (notWarm && sys == curSys) { controller.Controls.greenLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.redLight.Lit = false; } } else { current += sys.initialCurrent; } power -= sys.power; } } //update UI for current if (controller.Controls.toggle2.isOn) { controller.Controls.meter1.Value = power; } else { controller.Controls.meter1.Value = current; } if (level1enabled) { controller.Controls.button1.ToggleButton(true); } else { controller.Controls.button1.ToggleButton(false); } if (level2enabled) { controller.Controls.button2.ToggleButton(true); } else { controller.Controls.button2.ToggleButton(false); } if (level3enabled) { controller.Controls.button3.ToggleButton(true); } else { controller.Controls.button3.ToggleButton(false); } if (current > currentLimit || power < 0) { controller.Controls.UnsubscribeToAllControls(Handler); ResetUI(); UnsetUILabels(); EndProcedure(false); } else if (level1enabled && level2enabled && level3enabled) { controller.Controls.UnsubscribeToAllControls(Handler); ResetUI(); UnsetUILabels(); EndProcedure(true); } } }
//Handler captures usage of controls void Handler(BaseControl control) { if (usermode) { if (control == controller.Controls.setting1 || control == controller.Controls.setting2 || control == controller.Controls.toggle2) { ContextSwitched(); } else if (control == controller.Controls.toggle1) { PowerSystem system = GetCurrentSystem(); system.on = !system.on; if (system.on) { controller.Controls.yellowLight.Lit = true; controller.Controls.redLight.Lit = false; } else { controller.Controls.redLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.greenLight.Lit = false; system.ResetTimer(); } } //light up buttons if (control == controller.Controls.button1) { int ii = 0; bool found = false; for (ii = 0; ii < level1systems.Count && !found; ++ii) { if (level1systems[ii].on && level1systems[ii].WarmedUp) { found = true; } } if (found) { controller.Controls.setting1.option1.isOn = true; switch (--ii) { case 0: controller.Controls.setting2.option1.isOn = true; break; case 1: controller.Controls.setting2.option2.isOn = true; break; case 2: controller.Controls.setting2.option3.isOn = true; break; } ContextSwitched(); } } else if (control == controller.Controls.button2) { int ii = 0; bool found = false; for (ii = 0; ii < level2systems.Count && !found; ++ii) { if (level2systems[ii].on && level2systems[ii].WarmedUp) { found = true; } } if (found) { controller.Controls.setting1.option2.isOn = true; switch (--ii) { case 0: controller.Controls.setting2.option1.isOn = true; break; case 1: controller.Controls.setting2.option2.isOn = true; break; case 2: controller.Controls.setting2.option3.isOn = true; break; } ContextSwitched(); } } else if (control == controller.Controls.button3) { int ii = 0; bool found = false; for (ii = 0; ii < level1systems.Count && !found; ++ii) { if (level3systems[ii].on && level3systems[ii].WarmedUp) { found = true; } } if (found) { controller.Controls.setting1.option3.isOn = true; switch (--ii) { case 0: controller.Controls.setting2.option1.isOn = true; break; case 1: controller.Controls.setting2.option2.isOn = true; break; case 2: controller.Controls.setting2.option3.isOn = true; break; } ContextSwitched(); } } } }
void Handler(BaseControl control) { if (usermode && !tutWait) { //tutorial stuff if (curState == TutState.WaitForToggle2 && control == controller.Controls.toggle2) { tutWait = true; tut.Toggle2Hinta.SetActive(false); tut.ExplainMeter1b.SetActive(true); curState = TutState.ExplainMeter1b; } if (curState == TutState.ExplainSetting2c && control == controller.Controls.setting2) { tut.ExplainSetting2c.GetComponentInChildren <Button>(true).gameObject.SetActive(true); } if (curState == TutState.WaitForToggle1 && control == controller.Controls.toggle1) { tutWait = true; tut.Toggle1Hinta.SetActive(false); tut.RedLightHint.SetActive(false); tut.YellowLightHint.SetActive(true); curState = TutState.YellowLight; } if (curState == TutState.WaitForSetting1 && control == controller.Controls.setting1) { tut.Setting1Hint.SetActive(false); tut.Setting2Hint.SetActive(true); curState = TutState.WaitForSetting2; } if (curState == TutState.WaitForSetting2 && control == controller.Controls.setting2) { tut.Setting2Hint.SetActive(false); tut.Toggle1Hintb.SetActive(true); curState = TutState.WaitForToggle1b; } if (curState == TutState.WaitForToggle1b && control == controller.Controls.toggle1) { tut.Toggle1Hintb.SetActive(false); tut.ExplainEnding.SetActive(true); curState = TutState.ExplainEnding; } //main logic if (control == controller.Controls.setting1 || control == controller.Controls.setting2 || control == controller.Controls.toggle2) { ContextSwitched(); } else if (control == controller.Controls.toggle1) { PowerSystem system = GetCurrentSystem(); system.on = !system.on; if (system.on) { controller.Controls.yellowLight.Lit = true; controller.Controls.redLight.Lit = false; } else { controller.Controls.redLight.Lit = true; controller.Controls.yellowLight.Lit = false; controller.Controls.greenLight.Lit = false; system.ResetTimer(); } } //light up buttons if (control == controller.Controls.button1) { int ii = 0; bool found = false; for (ii = 0; ii < level1systems.Count && !found; ++ii) { if (level1systems[ii].on && level1systems[ii].WarmedUp) { found = true; } } if (found) { controller.Controls.setting1.option1.isOn = true; switch (--ii) { case 0: controller.Controls.setting2.option1.isOn = true; break; case 1: controller.Controls.setting2.option2.isOn = true; break; case 2: controller.Controls.setting2.option3.isOn = true; break; } ContextSwitched(); } } else if (control == controller.Controls.button2) { int ii = 0; bool found = false; for (ii = 0; ii < level2systems.Count && !found; ++ii) { if (level2systems[ii].on && level2systems[ii].WarmedUp) { found = true; } } if (found) { controller.Controls.setting1.option2.isOn = true; switch (--ii) { case 0: controller.Controls.setting2.option1.isOn = true; break; case 1: controller.Controls.setting2.option2.isOn = true; break; case 2: controller.Controls.setting2.option3.isOn = true; break; } ContextSwitched(); } } else if (control == controller.Controls.button3) { int ii = 0; bool found = false; for (ii = 0; ii < level1systems.Count && !found; ++ii) { if (level3systems[ii].on && level3systems[ii].WarmedUp) { found = true; } } if (found) { controller.Controls.setting1.option3.isOn = true; switch (--ii) { case 0: controller.Controls.setting2.option1.isOn = true; break; case 1: controller.Controls.setting2.option2.isOn = true; break; case 2: controller.Controls.setting2.option3.isOn = true; break; } ContextSwitched(); } } } }