Page 1 of 1

[CLOSED] prevent UI dialog from base entity?

Posted: Sun Nov 10, 2019 7:27 am
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

Re: prevent UI dialog from base entity?

Posted: Sun Nov 10, 2019 7:53 am
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)

Re: prevent UI dialog from base entity?

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

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

Re: prevent UI dialog from base entity?

Posted: Sun Nov 10, 2019 6:39 pm
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

Re: prevent UI dialog from base entity?

Posted: Sun Nov 10, 2019 10:28 pm
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