|
1 local function open_gui(event) |
|
2 local player = game.players[event.player_index] |
|
3 if not player.gui.goal["set-goal"] |
|
4 then |
|
5 local frame = player.gui.goal.add{ |
|
6 type = "frame", |
|
7 name = "set-goal", |
|
8 caption = {"set-goal-gui.title"}, |
|
9 direction = "vertical" |
|
10 } |
|
11 frame.add{ |
|
12 type = "text-box", |
|
13 text = player.get_goal_description(), |
|
14 name = "goal-description", |
|
15 style = "set-goal-gui-textbox", |
|
16 icon_selector = true, |
|
17 } |
|
18 local buttons_flow = frame.add{ |
|
19 type = "flow", |
|
20 name = "buttons-flow", |
|
21 direction = "horizontal", |
|
22 } |
|
23 buttons_flow.add{ |
|
24 type = "sprite-button", |
|
25 tooltip = {"set-goal-gui.close-tooltip"}, |
|
26 style = "tool_button_red", |
|
27 sprite = 'utility.close', |
|
28 name = "close-button", |
|
29 tags = {["owner-mod"] = "set-goal", action="close"}, |
|
30 } |
|
31 buttons_flow.add{ |
|
32 type = "sprite-button", |
|
33 tooltip = {"set-goal-gui.confirm-tooltip"}, |
|
34 style = "confirm_button", |
|
35 name = "confirm-button", |
|
36 sprite = "utility.confirm_slot", |
|
37 tags = {["owner-mod"] = "set-goal", action="confirm"}, |
|
38 } |
|
39 else |
|
40 player.gui.goal["set-goal"].destroy() |
|
41 end |
|
42 end |
|
43 |
|
44 script.on_event(defines.events.on_gui_click, |
|
45 function(event) |
|
46 local player = game.players[event.player_index] |
|
47 if player.gui.goal["set-goal"] |
|
48 and event.element.tags |
|
49 and event.element.tags["owner-mod"] == "set-goal" |
|
50 then |
|
51 if event.element.tags.action == "confirm" |
|
52 then |
|
53 player.set_goal_description(player.gui.goal["set-goal"]["goal-description"].text) |
|
54 player.gui.goal["set-goal"].destroy() |
|
55 elseif event.element.tags.action == "close" |
|
56 then |
|
57 player.gui.goal["set-goal"].destroy() |
|
58 end |
|
59 end |
|
60 end |
|
61 ) |
|
62 |
|
63 script.on_event("open-set-goal-gui", open_gui) |
|
64 |
|
65 script.on_event(defines.events.on_lua_shortcut, |
|
66 function(event) |
|
67 if event.prototype_name == "open-set-goal-gui" |
|
68 then |
|
69 open_gui(event) |
|
70 end |
|
71 end |
|
72 ) |