public override void ShowDialog()
 {
     base.ShowDialog();
     if (events.HasEvent("OnShow") == true)
     {
         events.Trigger("OnShow", this);
     }
 }
    /// <summary>
    /// This function is called to update the furniture. This will also trigger EventsActions.
    /// This checks if the furniture is a PowerConsumer, and if it does not have power it cancels its job.
    /// </summary>
    /// <param name="deltaTime">The time since the last update was called.</param>
    public void Update(float deltaTime)
    {
        if (PowerConnection != null && PowerConnection.IsPowerConsumer && HasPower() == false)
        {
            if (JobCount() > 0)
            {
                PauseJobs();
            }

            return;
        }

        if (pausedJobs.Count > 0)
        {
            ResumeJobs();
        }

        // TODO: some weird thing happens
        if (EventActions != null)
        {
            // updateActions(this, deltaTime);
            EventActions.Trigger("OnUpdate", this, deltaTime);
        }

        if (IsWorkshop)
        {
            workshop.Update(deltaTime);
        }

        if (Animation != null)
        {
            Animation.Update(deltaTime);
        }
    }
Exemple #3
0
 /// <summary>
 /// This function is called to update the room behavior. This will also trigger EventsActions.
 /// </summary>
 /// <param name="deltaTime">The time since the last update was called.</param>
 public void Update(float deltaTime)
 {
     if (EventActions != null)
     {
         // updateActions(this, deltaTime);
         EventActions.Trigger("OnUpdate", this, deltaTime);
     }
 }
Exemple #4
0
 public void Update(float deltaTime)
 {
     // TODO: some weird thing happens
     if (EventActions != null)
     {
         // updateActions(this, deltaTime);
         EventActions.Trigger("OnUpdate", this, deltaTime);
     }
 }
    /// <summary>
    /// This function is called to update the furniture. This will also trigger EventsActions.
    /// This checks if the furniture is a PowerConsumer, and if it does not have power it cancels its job.
    /// </summary>
    /// <param name="deltaTime">The time since the last update was called.</param>
    public void FixedFrequencyUpdate(float deltaTime)
    {
        // requirements from components (gas, ...)
        bool canFunction = true;

        BuildableComponent.Requirements newRequirements = BuildableComponent.Requirements.None;
        foreach (BuildableComponent component in components)
        {
            bool componentCanFunction = component.CanFunction();
            canFunction &= componentCanFunction;

            // if it can't function, collect all stuff it needs (power, gas, ...) for icon signalization
            if (!componentCanFunction)
            {
                newRequirements |= component.Needs;
            }
        }

        // requirements were changed, force update of status icons
        if (Requirements != newRequirements)
        {
            Requirements = newRequirements;
            OnIsOperatingChanged(this);
        }

        IsOperating = canFunction;

        if (canFunction == false)
        {
            if (prevUpdatePowerOn)
            {
                EventActions.Trigger("OnPowerOff", this, deltaTime);
            }

            Jobs.PauseAll();
            prevUpdatePowerOn = false;
            return;
        }

        prevUpdatePowerOn = true;
        Jobs.ResumeAll();

        if (EventActions != null)
        {
            EventActions.Trigger("OnUpdate", this, deltaTime);
        }

        foreach (BuildableComponent component in components)
        {
            component.FixedFrequencyUpdate(deltaTime);
        }

        if (Animation != null)
        {
            Animation.Update(deltaTime);
        }
    }
Exemple #6
0
    /// <summary>
    /// Deconstructs the utility.
    /// </summary>
    public void Deconstruct()
    {
        if (Tile.Utilities != null)
        {
            Jobs.CancelAll();
        }

        // Just unregister our grid, it will get reregistered if there are any other utilities on this grid
        World.Current.PowerNetwork.RemoveGrid(Grid);

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);
        Tile.UnplaceUtility(this);

        if (Removed != null)
        {
            Removed(this);
        }

        Deconstruct deconstructOrder = GetOrderAction <Deconstruct>();

        if (deconstructOrder != null)
        {
            foreach (KeyValuePair <string, int> inv in deconstructOrder.Inventory)
            {
                World.Current.InventoryManager.PlaceInventoryAround(Tile, new Inventory(inv.Key, inv.Value));
            }
        }

        // We should inform our neighbours that they have just lost a neighbour.
        // Just trigger their OnChangedCallback.
        foreach (Tile neighbor in Tile.GetNeighbours())
        {
            if (neighbor.Utilities != null && neighbor.Utilities.ContainsKey(this.Type))
            {
                Utility neighborUtility = neighbor.Utilities[this.Type];
                if (neighborUtility.Changed != null)
                {
                    neighborUtility.Changed(neighborUtility);
                }

                if (neighborUtility.Grid == this.Grid)
                {
                    neighborUtility.Grid = new UtilityGrid();
                }

                neighborUtility.UpdateGrid(neighborUtility);
                neighborUtility.Grid.Split();
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
    /// <summary>
    /// This function is called to update the furniture animation in lua.
    /// This will be called every frame and should be used carefully.
    /// </summary>
    /// <param name="deltaTime">The time since the last update was called.</param>
    public void EveryFrameUpdate(float deltaTime)
    {
        if (EventActions != null)
        {
            EventActions.Trigger("OnFastUpdate", this, deltaTime);
        }

        foreach (BuildableComponent component in components)
        {
            component.EveryFrameUpdate(deltaTime);
        }
    }
Exemple #8
0
    /// <summary>
    /// This function is called to update the furniture animation in lua.
    /// This will be called every frame and should be used carefully.
    /// </summary>
    /// <param name="deltaTime">The time since the last update was called.</param>
    public void EveryFrameUpdate(float deltaTime)
    {
        if (EventActions != null)
        {
            EventActions.Trigger("OnFastUpdate", this, deltaTime);
        }

        foreach (var cmp in components)
        {
            cmp.EveryFrameUpdate(deltaTime);
        }
    }
Exemple #9
0
    /// <summary>
    /// Deconstructs the utility.
    /// </summary>
    public void Deconstruct()
    {
        int x = Tile.X;
        int y = Tile.Y;

        if (Tile.Utilities != null)
        {
            Jobs.CancelAll();
        }

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);
        Tile.UnplaceUtility(this);

        if (Removed != null)
        {
            Removed(this);
        }

        if (deconstructInventory != null)
        {
            foreach (Inventory inv in deconstructInventory)
            {
                inv.MaxStackSize = PrototypeManager.Inventory.Get(inv.Type).maxStackSize;
                World.Current.InventoryManager.PlaceInventoryAround(Tile, inv.Clone());
            }
        }

        // We should inform our neighbours that they have just lost a
        // neighbour regardless of type.
        // Just trigger their OnChangedCallback.
        for (int xpos = x - 1; xpos < x + 2; xpos++)
        {
            for (int ypos = y - 1; ypos < y + 2; ypos++)
            {
                Tile tileAt = World.Current.GetTileAt(xpos, ypos, Tile.Z);
                if (tileAt != null && tileAt.Utilities != null)
                {
                    foreach (Utility neighborUtility in tileAt.Utilities.Values)
                    {
                        if (neighborUtility.Changed != null)
                        {
                            neighborUtility.Changed(neighborUtility);
                        }
                    }
                }
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
Exemple #10
0
        /// <summary>
        /// Deconstructs the room behavior.
        /// </summary>
        public void Deconstruct(RoomBehavior roomBehavior)
        {
            // We call lua to decostruct
            EventActions.Trigger("OnUninstall", this);
            Room.UndesignateRoomBehavior(roomBehavior);

            if (Removed != null)
            {
                Removed(this);
            }

            // At this point, no DATA structures should be pointing to us, so we
            // should get garbage-collected.
        }
Exemple #11
0
    public void OnClicked()
    {
        // These names should actually be something like "button_my" in order to be localized.
        // However, just to make sure, we replace this to avoid any problems.
        buttonName = buttonName.Replace(" ", "_");
        EventActions dialogEvents = transform.GetComponentInParent <ModDialogBox>().events;

        Debug.ULogChannel("ModDialogBox", "Calling On" + buttonName + "Clicked function");

        if (dialogEvents.HasEvent("On" + buttonName + "Clicked") == true)
        {
            Debug.ULogChannel("ModDialogBox", "Found On" + buttonName + "Clicked event");
            dialogEvents.Trigger <ModDialogBox>("On" + buttonName + "Clicked", transform.GetComponentInParent <ModDialogBox>());
        }
    }
Exemple #12
0
    /// <summary>
    /// This function is called to update the furniture. This will also trigger EventsActions.
    /// This checks if the furniture is a PowerConsumer, and if it does not have power it cancels its job.
    /// </summary>
    /// <param name="deltaTime">The time since the last update was called.</param>
    public void FixedFrequencyUpdate(float deltaTime)
    {
        // requirements from components (gas, ...)
        bool canFunction = true;

        foreach (var cmp in components)
        {
            canFunction &= cmp.CanFunction();
        }

        IsOperating = DoesntNeedOrHasPower && canFunction;

        if ((PowerConnection != null && PowerConnection.IsPowerConsumer && DoesntNeedOrHasPower == false) ||
            canFunction == false)
        {
            if (prevUpdatePowerOn)
            {
                EventActions.Trigger("OnPowerOff", this, deltaTime);
            }

            Jobs.PauseAll();
            prevUpdatePowerOn = false;
            return;
        }

        prevUpdatePowerOn = true;
        Jobs.ResumeAll();

        // TODO: some weird thing happens
        if (EventActions != null)
        {
            EventActions.Trigger("OnUpdate", this, deltaTime);
        }

        foreach (var cmp in components)
        {
            cmp.FixedFrequencyUpdate(deltaTime);
        }

        if (Animation != null)
        {
            Animation.Update(deltaTime);
        }
    }
Exemple #13
0
        public void Control(Room room)
        {
            this.Room = room;
            HashSet <Tile> allTiles = room.GetInnerTiles();

            allTiles.UnionWith(room.GetBoundaryTiles());

            foreach (FurnitureRequirement requirement in requiredFurniture)
            {
                string furnitureKey = requirement.type ?? requirement.typeTag;
                ControlledFurniture.Add(furnitureKey, new List <Furniture>());
                foreach (Tile tile in allTiles.Where(tile => (tile.Furniture != null && (tile.Furniture.Type == requirement.type || tile.Furniture.HasTypeTag(requirement.typeTag)))))
                {
                    ControlledFurniture[furnitureKey].Add(tile.Furniture);
                }
            }

            EventActions.Trigger("OnControl", this);
        }
Exemple #14
0
    public void Update(float deltaTime)
    {
        if (PowerConnection != null && PowerConnection.IsPowerConsumer && HasPower() == false)
        {
            if (JobCount() > 0)
            {
                CancelJobs();
            }

            return;
        }

        // TODO: some weird thing happens
        if (EventActions != null)
        {
            // updateActions(this, deltaTime);
            EventActions.Trigger("OnUpdate", this, deltaTime);
        }
    }
Exemple #15
0
        public void Control(Room room) 
        {
            this.Room = room;
            List<Tile> innerTiles = room.GetInnerTiles();
            List<Tile> borderTiles = room.GetBorderingTiles();

            List<Tile> allTiles = innerTiles.Union(borderTiles).ToList();

            foreach (NestedObjectRequirement requirement in requiredNestedObject)
            {
                string nestedObjectKey = requirement.type ?? requirement.typeTag;
                ControlledNestedObject.Add(nestedObjectKey, new List<NestedObject>());
                foreach (Tile tile in allTiles.FindAll(tile => (tile.NestedObject != null && (tile.NestedObject.Type == requirement.type || tile.NestedObject.HasTypeTag(requirement.typeTag))))) 
                {
                    ControlledNestedObject[nestedObjectKey].Add(tile.NestedObject);
                }
            }

            EventActions.Trigger("OnControl", this);
        }
Exemple #16
0
        public void Control(Room room)
        {
            this.Room = room;
            List <Tile> innerTiles  = room.GetInnerTiles();
            List <Tile> borderTiles = room.GetBorderingTiles();

            List <Tile> allTiles = innerTiles.Union(borderTiles).ToList();

            foreach (FurnitureRequirement requirement in requiredFurniture)
            {
                string furnitureKey = requirement.type ?? requirement.typeTag;
                ControlledFurniture.Add(furnitureKey, new List <Furniture>());
                foreach (Tile tile in allTiles.FindAll(tile => (tile.Furniture != null && (tile.Furniture.Type == requirement.type || tile.Furniture.HasTypeTag(requirement.typeTag)))))
                {
                    ControlledFurniture[furnitureKey].Add(tile.Furniture);
                }
            }

            EventActions.Trigger("OnControl", this);
        }
Exemple #17
0
    public void Deconstruct()
    {
        int  x                = Tile.X;
        int  y                = Tile.Y;
        int  fwidth           = 1;
        int  fheight          = 1;
        bool linksToNeighbour = false;

        if (Tile.Furniture != null)
        {
            Furniture furniture = Tile.Furniture;
            fwidth           = furniture.Width;
            fheight          = furniture.Height;
            linksToNeighbour = furniture.LinksToNeighbour;
            furniture.CancelJobs();
        }

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);

        // Update thermalDiffusifity to default value
        World.Current.temperature.SetThermalDiffusivity(Tile.X, Tile.Y, Temperature.defaultThermalDiffusivity);

        Tile.UnplaceFurniture();

        if (Removed != null)
        {
            Removed(this);
        }

        // Do we need to recalculate our rooms?
        if (RoomEnclosure)
        {
            Room.DoRoomFloodFill(Tile);
        }

        ////World.current.InvalidateTileGraph();

        if (World.Current.tileGraph != null)
        {
            World.Current.tileGraph.RegenerateGraphAtTile(Tile);
        }

        // We should inform our neighbours that they have just lost a
        // neighbour regardless of objectType.
        // Just trigger their OnChangedCallback.
        if (linksToNeighbour == true)
        {
            for (int xpos = x - 1; xpos < x + fwidth + 1; xpos++)
            {
                for (int ypos = y - 1; ypos < y + fheight + 1; ypos++)
                {
                    Tile t = World.Current.GetTileAt(xpos, ypos);
                    if (t != null && t.Furniture != null && t.Furniture.Changed != null)
                    {
                        t.Furniture.Changed(t.Furniture);
                    }
                }
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
Exemple #18
0
    /// <summary>
    /// Deconstructs the furniture.
    /// </summary>
    public void Deconstruct()
    {
        int    x                = Tile.X;
        int    y                = Tile.Y;
        int    fwidth           = 1;
        int    fheight          = 1;
        string linksToNeighbour = string.Empty;

        if (Tile.Furniture != null)
        {
            Furniture furniture = Tile.Furniture;
            fwidth           = furniture.Width;
            fheight          = furniture.Height;
            linksToNeighbour = furniture.LinksToNeighbours;
            furniture.Jobs.CancelAll();
        }

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);

        // Let our workspot tile know it is no longer reserved for us
        World.Current.UnreserveTileAsWorkSpot(this);

        Tile.UnplaceFurniture();

        Deconstruct deconstructOrder = GetOrderAction <Deconstruct>();

        if (deconstructOrder != null)
        {
            foreach (KeyValuePair <string, int> inv in deconstructOrder.Inventory)
            {
                World.Current.InventoryManager.PlaceInventoryAround(Tile, new Inventory(inv.Key, inv.Value));
            }
        }

        if (Removed != null)
        {
            Removed(this);
        }

        // Do we need to recalculate our rooms?
        if (EnclosesRoom)
        {
            World.Current.RoomManager.DoRoomFloodFill(Tile, false);
        }

        ////World.current.InvalidateTileGraph();

        if (World.Current.tileGraph != null)
        {
            World.Current.tileGraph.RegenerateGraphAtTile(Tile);
        }

        // We should inform our neighbours that they have just lost a
        // neighbour regardless of type.
        // Just trigger their OnChangedCallback.
        if (linksToNeighbour != string.Empty)
        {
            for (int xpos = x - 1; xpos < x + fwidth + 1; xpos++)
            {
                for (int ypos = y - 1; ypos < y + fheight + 1; ypos++)
                {
                    Tile t = World.Current.GetTileAt(xpos, ypos, Tile.Z);
                    if (t != null && t.Furniture != null && t.Furniture.Changed != null)
                    {
                        t.Furniture.Changed(t.Furniture);
                    }
                }
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
Exemple #19
0
    /// <summary>
    /// Deconstructs the furniture.
    /// </summary>
    public void Deconstruct()
    {
        int    x                = Tile.X;
        int    y                = Tile.Y;
        int    fwidth           = 1;
        int    fheight          = 1;
        string linksToNeighbour = string.Empty;

        if (Tile.Furniture != null)
        {
            Furniture furniture = Tile.Furniture;
            fwidth           = furniture.Width;
            fheight          = furniture.Height;
            linksToNeighbour = furniture.LinksToNeighbour;
            furniture.Jobs.CancelAll();
        }

        // We call lua to decostruct
        EventActions.Trigger("OnUninstall", this);

        // Update thermalDiffusifity to default value
        World.Current.temperature.SetThermalDiffusivity(Tile.X, Tile.Y, Tile.Z, Temperature.defaultThermalDiffusivity);

        // Let our workspot tile know it is no longer reserved for us
        World.Current.UnreserveTileAsWorkSpot(this);

        Tile.UnplaceFurniture();

        if (deconstructInventory != null)
        {
            foreach (Inventory inv in deconstructInventory)
            {
                inv.MaxStackSize = PrototypeManager.Inventory.Get(inv.Type).maxStackSize;
                World.Current.InventoryManager.PlaceInventoryAround(Tile, inv.Clone());
            }
        }

        if (Removed != null)
        {
            Removed(this);
        }

        // Do we need to recalculate our rooms?
        if (RoomEnclosure)
        {
            World.Current.RoomManager.DoRoomFloodFill(Tile, false);
        }

        ////World.current.InvalidateTileGraph();

        if (World.Current.tileGraph != null)
        {
            World.Current.tileGraph.RegenerateGraphAtTile(Tile);
        }

        // We should inform our neighbours that they have just lost a
        // neighbour regardless of type.
        // Just trigger their OnChangedCallback.
        if (linksToNeighbour != string.Empty)
        {
            for (int xpos = x - 1; xpos < x + fwidth + 1; xpos++)
            {
                for (int ypos = y - 1; ypos < y + fheight + 1; ypos++)
                {
                    Tile t = World.Current.GetTileAt(xpos, ypos, Tile.Z);
                    if (t != null && t.Furniture != null && t.Furniture.Changed != null)
                    {
                        t.Furniture.Changed(t.Furniture);
                    }
                }
            }
        }

        // At this point, no DATA structures should be pointing to us, so we
        // should get garbage-collected.
    }
Exemple #20
0
 private void CallEventAction(string actionName, params object[] parameters)
 {
     EventActions.Trigger(actionName, this, parameters);
 }