Skip to content

Commit 7924d01

Browse files
committed
Added title autofill
1 parent 6a76548 commit 7924d01

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

scripts/entity-notes/controller.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,24 @@ function this.restoreGhostNote(entity) -- restore an entity note when it got rev
521521
end
522522
end
523523

524+
function this.on_string_translated(event)
525+
local index = event.player_index
526+
local player = game.players[index]
527+
local cache = global.cache[index]
528+
529+
dlog(event)
530+
531+
if util.isValid(cache.translateTarget) and event.translated then
532+
event.name = defines.events.on_gui_text_changed
533+
event.element = cache.translateTarget
534+
event.text = event.result
535+
cache.translateTarget.text = event.result
536+
gui.on_gui_text_changed(event)
537+
cache.translateTarget.focus()
538+
cache.translateTarget.select_all()
539+
end
540+
541+
cache.translateTarget = nil
542+
end
543+
524544
return this

scripts/entity-notes/gui-templates.lua

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,24 @@ this.templates.noteWindow = {
324324
end
325325
end,
326326
onChanged = function (event, index, player, cache, entity, note)
327-
if event.element.elem_value.name then
327+
if not event.element.elem_value or event.element.elem_value.name then
328328
note.icon = event.element.elem_value
329329
else
330330
event.element.elem_value = note and note.icon
331331
end
332+
333+
if note and not note.title and note.icon then
334+
--raises event to call onChanged on title field after translation
335+
cache.translateTarget = event.element.parent.title
336+
337+
local proto = game.item_prototypes[note.icon.name] or
338+
game.entity_prototypes[note.icon.name] or
339+
game.fluid_prototypes[note.icon.name] or
340+
game.virtual_signal_prototypes[note.icon.name] or
341+
game.tile_prototypes[note.icon.name]
342+
343+
if proto then player.request_translation(proto.localised_name) end
344+
end
332345
end,
333346
},
334347
createLinkedElement{

0 commit comments

Comments
 (0)