[CLOSED] prevent UI dialog from base entity?

Place to get help with not working mods / modding interface.
Post Reply
Cobaltur
Inserter
Inserter
Posts: 47
Joined: Sat Sep 24, 2016 1:33 pm
Contact:

[CLOSED] prevent UI dialog from base entity?

Post by Cobaltur »

Hi all,

I have a entity derived from constant combinator.
In the past the entity has a behavior based on its type and I just disabled the UI dialog by diabling any dialogs

Code: Select all

	entity.operable =false
	data:extend({entity})
but how I combined a set of combinators and wanted to create a settings UI.
e.g.

Code: Select all

player.gui.left.add {type = "frame", name = "mathProcessorUi", caption = "Select operation", direction = "vertical"}
but I had to set entity.operable =true and now the base dialogs appear.

1) How do I prevent the base dialog? Or how do I close it immedialty.

Code: Select all

player.gui.center.clear()
does not work.

2) Currently I have to manual close the dialog. I prefer to close the dialog with ESC? How do I achieve this?

Code: Select all

local function on_gui_click(event)
	if event.element and event.element.name == "closemathProcessorUi" then
		if player.gui.left.mathProcessorUi ~= nil then
			player.gui.left.mathProcessorUi.destroy()
		end
	end
end

Thx
Last edited by Cobaltur on Sun Nov 10, 2019 10:28 pm, edited 1 time in total.

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: prevent UI dialog from base entity?

Post by DaveMcW »

Code: Select all

script.on_event(defines.events.on_gui_opened, function(event)
  local entity = event.entity
  if not entity or not entity.valid then return end
  if entity.name == "my-combinator" then 
    local player = game.players[event.player_index]
    player.opened = nil
    player.print("TODO: create gui for "..entity.name)
  end
end)

Cobaltur
Inserter
Inserter
Posts: 47
Joined: Sat Sep 24, 2016 1:33 pm
Contact:

Re: prevent UI dialog from base entity?

Post by Cobaltur »

thx prevent base dialog perfectly.

any ideas how to support ESC key? So it closes my custom dialog like other dialogs?

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5150
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: prevent UI dialog from base entity?

Post by Klonan »

Cobaltur wrote:
Sun Nov 10, 2019 4:04 pm
thx prevent base dialog perfectly.

any ideas how to support ESC key? So it closes my custom dialog like other dialogs?
set player.opened to your custom gui element, then when the player presses esc it will fire the on_gui_closed event

Cobaltur
Inserter
Inserter
Posts: 47
Joined: Sat Sep 24, 2016 1:33 pm
Contact:

Re: prevent UI dialog from base entity?

Post by Cobaltur »

perfect.

Code: Select all

local function on_gui_closed(event)
	if event.element~=nil and event.element == lib.player.gui.center.mathProcessorUi then
		lib.player.gui.center.mathProcessorUi.destroy()
	end
end

local function on_gui_opened(event)
	if event.entity and event.entity.name == "math-allInOne" then
		....
		local ui =lib.player.gui.center.add {	....		}
		lib.player.opened = ui 
		....
	end
end


Post Reply

Return to “Modding help”