summaryrefslogtreecommitdiffstats
path: root/Main.gd
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2020-07-15 10:55:47 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2020-07-15 10:55:47 +0200
commit594a82b45e5d9dcd90faad8fa4f8eb42b2c981b6 (patch)
treef44fbc21362e79fb8f9c987b542406cb7d61ca71 /Main.gd
parent9274d1351f527de8ccee89eaccea1cf5dc141756 (diff)
downloadgodot-hexgrid-594a82b45e5d9dcd90faad8fa4f8eb42b2c981b6.zip
godot-hexgrid-594a82b45e5d9dcd90faad8fa4f8eb42b2c981b6.tar.gz
add zoom buttons, support one button mouse, add font
Diffstat (limited to 'Main.gd')
-rw-r--r--Main.gd23
1 files changed, 17 insertions, 6 deletions
diff --git a/Main.gd b/Main.gd
index 03c9773..5e82637 100644
--- a/Main.gd
+++ b/Main.gd
@@ -1,6 +1,7 @@
#warning-ignore-all:return_value_discarded
extends Node2D
+var moved : int = 0
var drag_map : bool = false
onready var UI : Control = $CanvasLayer/HBOX/UI
@@ -9,6 +10,8 @@ onready var Camera : Camera2D = $CanvasLayer/HBOX/ViewportContainer/Viewport/Cam
func _ready():
UI.get_node("rotate").connect("pressed", self, "on_rotate")
+ UI.get_node("zin").connect("pressed", self, "on_zoom", [true])
+ UI.get_node("zout").connect("pressed", self, "on_zoom", [false])
UI.get_node("LOS").connect("pressed", self, "on_toggle")
UI.get_node("Move").connect("pressed", self, "on_toggle")
Map.connect("hex_touched", self, "on_hex_touched")
@@ -23,6 +26,9 @@ func on_rotate() -> void:
Map.rotate_map()
on_viewport_resized()
+func on_zoom(b : bool) -> void:
+ Camera.update_camera(0, 0, -0.05 if b else 0.05)
+
func on_toggle() -> void:
Map.set_mode(UI.get_node("LOS").pressed, UI.get_node("Move").pressed)
@@ -35,17 +41,22 @@ func _unhandled_input(event : InputEvent) -> void:
if drag_map:
var dv : Vector2 = event.relative * Camera.zoom
Camera.update_camera(-dv.x, -dv.y, 0)
+ moved += 1
else:
Map.on_mouse_move()
elif event is InputEventMouseButton:
- if event.button_index == 4:
- Camera.update_camera(0, 0, -0.05)
- elif event.button_index == 5:
- Camera.update_camera(0, 0, +0.05)
+ if event.button_index == 1:
+ if moved < 5:
+ drag_map = Map.on_click(event.pressed)
+ else:
+ drag_map = false
+ moved = 0
elif event.button_index == 3:
drag_map = event.pressed
- elif event.button_index == 1:
- Map.on_click(event.pressed)
+ elif event.button_index == 4:
+ on_zoom(true)
+ elif event.button_index == 5:
+ on_zoom(false)
elif event is InputEventKey:
if event.scancode == KEY_ESCAPE:
get_tree().quit()