From ac408c6e2b00c157112ffc4b6f03299bc0a43fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Tue, 26 Jul 2022 10:53:33 +0200 Subject: [PATCH] Added examples menu --- example/controller.collection | 178 ++++++++ example/controller.gui | 133 ++++++ example/controller.gui_script | 19 + example/controller.script | 24 + example/menu.collection | 37 ++ example/menu.gui | 734 ++++++++++++++++++++++++++++++ example/menu.gui_script | 30 ++ example/shared/fonts/example.font | 3 + example/zoom/zoom.collection | 152 +++++++ example/zoom/zoom.script | 45 ++ game.project | 3 +- 11 files changed, 1357 insertions(+), 1 deletion(-) create mode 100644 example/controller.collection create mode 100644 example/controller.gui create mode 100644 example/controller.gui_script create mode 100644 example/controller.script create mode 100644 example/menu.collection create mode 100644 example/menu.gui create mode 100644 example/menu.gui_script create mode 100644 example/shared/fonts/example.font create mode 100644 example/zoom/zoom.collection create mode 100644 example/zoom/zoom.script diff --git a/example/controller.collection b/example/controller.collection new file mode 100644 index 0000000..2f516b9 --- /dev/null +++ b/example/controller.collection @@ -0,0 +1,178 @@ +name: "controller" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"controller\"\n" + " component: \"/example/controller.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "components {\n" + " id: \"back\"\n" + " component: \"/example/controller.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"menu\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/menu.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"dragtoscroll\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/dragtoscroll/dragtoscroll.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"multicamera\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/multicamera/multicamera.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"bounds\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/bounds/bounds.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"basics\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/basics/basics.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"allfeatures\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/allfeatures/allfeatures.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"zoom\"\n" + " type: \"collectionproxy\"\n" + " data: \"collection: \\\"/example/zoom/zoom.collection\\\"\\n" + "exclude: false\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/controller.gui b/example/controller.gui new file mode 100644 index 0000000..08a3e21 --- /dev/null +++ b/example/controller.gui @@ -0,0 +1,133 @@ +script: "/example/controller.gui_script" +fonts { + name: "example" + font: "/example/shared/fonts/example.font" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 117.0 + y: 672.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 100.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "backbutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 100.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "BACK" + font: "example" + id: "backtext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "backbutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/example/controller.gui_script b/example/controller.gui_script new file mode 100644 index 0000000..95c1d0b --- /dev/null +++ b/example/controller.gui_script @@ -0,0 +1,19 @@ +local gooey = require "gooey.gooey" + +function init(self) + gooey.acquire_input() +end + +function on_input(self, action_id, action) + local group = gooey.group("controller", function() + gooey.button("backbutton", action_id, action, function() + msg.post("controller:/go", "show" , { id = "menu" }) + end) + end) + return group.consumed +end + +function on_reload(self) + -- Add input-handling code here + -- Remove this function if not needed +end diff --git a/example/controller.script b/example/controller.script new file mode 100644 index 0000000..aaa9da5 --- /dev/null +++ b/example/controller.script @@ -0,0 +1,24 @@ +local function show(self, proxy) + if self.current_proxy then + msg.post(self.current_proxy, "unload") + end + msg.post(proxy, "async_load") +end + +function init(self) + msg.post(".", "acquire_input_focus") + msg.post("#", "show", { id = "menu" }) + msg.post("@render:", "clear_color", { color = vmath.vector4(0.15, 0.15, 0.15, 1.0) }) +end + +function on_message(self, message_id, message, sender) + if message_id == hash("proxy_loaded") then + self.current_proxy = sender + msg.post(sender, "enable") + elseif message_id == hash("show") then + local id = message.id + show(self, "#" .. id) + else + print(message_id) + end +end diff --git a/example/menu.collection b/example/menu.collection new file mode 100644 index 0000000..fe2aa46 --- /dev/null +++ b/example/menu.collection @@ -0,0 +1,37 @@ +name: "menu" +scale_along_z: 0 +embedded_instances { + id: "go" + data: "components {\n" + " id: \"menu\"\n" + " component: \"/example/menu.gui\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/menu.gui b/example/menu.gui new file mode 100644 index 0000000..4ec324c --- /dev/null +++ b/example/menu.gui @@ -0,0 +1,734 @@ +script: "/example/menu.gui_script" +fonts { + name: "example" + font: "/example/shared/fonts/example.font" +} +background_color { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 +} +nodes { + position { + x: 320.0 + y: 400.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "boundsbutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "BOUNDS" + font: "example" + id: "boundstext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "boundsbutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 320.0 + y: 340.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "dragtoscrollbutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "DRAG TO SCROLL" + font: "example" + id: "dragtoscrollbuttontext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "dragtoscrollbutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 320.0 + y: 462.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "multicamerabutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "MULTICAMERA" + font: "example" + id: "multtcameratext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "multicamerabutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 320.0 + y: 523.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "basicsbutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "BASICS" + font: "example" + id: "basicstext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "basicsbutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 320.0 + y: 278.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "allfeaturesbutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "ALL FEATURES" + font: "example" + id: "allfeaturestext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "allfeaturesbutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +nodes { + position { + x: 533.0 + y: 523.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + type: TYPE_BOX + blend_mode: BLEND_MODE_ALPHA + texture: "" + id: "zoombutton" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + adjust_mode: ADJUST_MODE_FIT + layer: "" + inherit_alpha: true + slice9 { + x: 0.0 + y: 0.0 + z: 0.0 + w: 0.0 + } + clipping_mode: CLIPPING_MODE_NONE + clipping_visible: true + clipping_inverted: false + alpha: 1.0 + template_node_child: false + size_mode: SIZE_MODE_MANUAL + custom_type: 0 +} +nodes { + position { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + size { + x: 200.0 + y: 50.0 + z: 0.0 + w: 1.0 + } + color { + x: 0.2 + y: 0.2 + z: 0.2 + w: 1.0 + } + type: TYPE_TEXT + blend_mode: BLEND_MODE_ALPHA + text: "ZOOM" + font: "example" + id: "zoomtext" + xanchor: XANCHOR_NONE + yanchor: YANCHOR_NONE + pivot: PIVOT_CENTER + outline { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + shadow { + x: 1.0 + y: 1.0 + z: 1.0 + w: 1.0 + } + adjust_mode: ADJUST_MODE_FIT + line_break: false + parent: "zoombutton" + layer: "" + inherit_alpha: true + alpha: 1.0 + outline_alpha: 1.0 + shadow_alpha: 1.0 + template_node_child: false + text_leading: 1.0 + text_tracking: 0.0 + custom_type: 0 +} +layers { + name: "below" +} +layers { + name: "text" +} +material: "/builtins/materials/gui.material" +adjust_reference: ADJUST_REFERENCE_PARENT +max_nodes: 512 diff --git a/example/menu.gui_script b/example/menu.gui_script new file mode 100644 index 0000000..1d3bb50 --- /dev/null +++ b/example/menu.gui_script @@ -0,0 +1,30 @@ +local gooey = require "gooey.gooey" + +function init(self) + gooey.acquire_input() +end + +local BUTTONS = { + "basics", + "bounds", + "dragtoscroll", + "multicamera", + "allfeatures", + "zoom", +} + +function on_input(self, action_id, action) + local group = gooey.group("group1", function() + for _,id in ipairs(BUTTONS) do + gooey.button(id .. "button", action_id, action, function() + msg.post("controller:/go", "show" , { id = id }) + end) + end + end) + return group.consumed +end + +function on_reload(self) + -- Add input-handling code here + -- Remove this function if not needed +end diff --git a/example/shared/fonts/example.font b/example/shared/fonts/example.font new file mode 100644 index 0000000..4929518 --- /dev/null +++ b/example/shared/fonts/example.font @@ -0,0 +1,3 @@ +font: "/builtins/fonts/vera_mo_bd.ttf" +material: "/builtins/fonts/font.material" +size: 15 diff --git a/example/zoom/zoom.collection b/example/zoom/zoom.collection new file mode 100644 index 0000000..cdd6e32 --- /dev/null +++ b/example/zoom/zoom.collection @@ -0,0 +1,152 @@ +name: "zoom" +scale_along_z: 0 +embedded_instances { + id: "level" + data: "components {\n" + " id: \"top_down\"\n" + " component: \"/example/allfeatures/top_down.tilemap\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: -1.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} +embedded_instances { + id: "zoom" + data: "components {\n" + " id: \"zoom\"\n" + " component: \"/example/zoom/zoom.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"sprite\"\n" + " type: \"sprite\"\n" + " data: \"tile_set: \\\"/example/shared/examples.atlas\\\"\\n" + "default_animation: \\\"crosshair_outline_large\\\"\\n" + "material: \\\"/builtins/materials/sprite.material\\\"\\n" + "blend_mode: BLEND_MODE_ALPHA\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} +embedded_instances { + id: "camera" + data: "components {\n" + " id: \"camera\"\n" + " component: \"/orthographic/camera.script\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + " properties {\n" + " id: \"projection\"\n" + " value: \"FIXED_ZOOM\"\n" + " type: PROPERTY_TYPE_HASH\n" + " }\n" + "}\n" + "embedded_components {\n" + " id: \"sprite\"\n" + " type: \"sprite\"\n" + " data: \"tile_set: \\\"/builtins/graphics/particle_blob.tilesource\\\"\\n" + "default_animation: \\\"anim\\\"\\n" + "material: \\\"/builtins/materials/sprite.material\\\"\\n" + "blend_mode: BLEND_MODE_ALPHA\\n" + "\"\n" + " position {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " }\n" + " rotation {\n" + " x: 0.0\n" + " y: 0.0\n" + " z: 0.0\n" + " w: 1.0\n" + " }\n" + "}\n" + "" + position { + x: 0.0 + y: 0.0 + z: 0.0 + } + rotation { + x: 0.0 + y: 0.0 + z: 0.0 + w: 1.0 + } + scale3 { + x: 1.0 + y: 1.0 + z: 1.0 + } +} diff --git a/example/zoom/zoom.script b/example/zoom/zoom.script new file mode 100644 index 0000000..d088b06 --- /dev/null +++ b/example/zoom/zoom.script @@ -0,0 +1,45 @@ +local camera = require "orthographic.camera" + +local CAMERA_ID = hash("/camera") + +function init(self) + msg.post(".", "acquire_input_focus") +end + +function on_input(self, action_id, action) + + local action_pos = vmath.vector3(action.x, action.y, 0) + local action_world_pos = camera.screen_to_world(CAMERA_ID, action_pos) + local camera_pos = go.get_position(CAMERA_ID) + local zoom = camera.get_zoom(CAMERA_ID) + + go.set_position(action_world_pos, "zoom") + + if not action_id then + local delta = vmath.vector3(action.dx, action.dy, 0) + delta = delta / zoom + camera_pos = camera_pos + delta + go.set_position(camera_pos, CAMERA_ID) + else + if action_id == hash("zoom_in") then + zoom = math.min(4, zoom + 0.05) + camera.set_zoom(CAMERA_ID, zoom) + elseif action_id == hash("zoom_out") then + zoom = math.max(0.2, zoom - 0.05) + camera.set_zoom(CAMERA_ID, zoom) + end + + local new_action_pos = camera.world_to_screen(CAMERA_ID, action_world_pos) + local diff = new_action_pos - action_pos + diff = diff / zoom + camera_pos = camera_pos + diff + go.set_position(camera_pos, CAMERA_ID) + end + +end + +function on_reload(self) + -- Add reload-handling code here + -- Learn more: https://defold.com/manuals/hot-reload/ + -- Remove this function if not needed +end diff --git a/game.project b/game.project index 7f5e448..a844f17 100644 --- a/game.project +++ b/game.project @@ -3,9 +3,10 @@ title = Orthographic version = 0.9 dependencies#0 = https://github.com/subsoap/defos/archive/v2.3.1.zip dependencies#1 = https://github.com/britzl/deftest/archive/2.7.0.zip +dependencies#2 = https://github.com/britzl/gooey/archive/refs/tags/10.4.0.zip [bootstrap] -main_collection = /example/allfeatures/allfeatures.collectionc +main_collection = /example/controller.collectionc render = /orthographic/render/orthographic.renderc [input]