diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-15 10:55:47 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-15 10:55:47 +0200 |
commit | 594a82b45e5d9dcd90faad8fa4f8eb42b2c981b6 (patch) | |
tree | f44fbc21362e79fb8f9c987b542406cb7d61ca71 | |
parent | 9274d1351f527de8ccee89eaccea1cf5dc141756 (diff) | |
download | godot-hexgrid-594a82b45e5d9dcd90faad8fa4f8eb42b2c981b6.zip godot-hexgrid-594a82b45e5d9dcd90faad8fa4f8eb42b2c981b6.tar.gz |
add zoom buttons, support one button mouse, add font
-rw-r--r-- | Hex.gd | 4 | ||||
-rw-r--r-- | Main.gd | 23 | ||||
-rw-r--r-- | Main.tscn | 130 | ||||
-rw-r--r-- | Map.gd | 5 | ||||
-rw-r--r-- | assets/Anke.otf | bin | 0 -> 24364 bytes | |||
-rw-r--r-- | project.godot | 5 |
6 files changed, 110 insertions, 57 deletions
@@ -14,8 +14,8 @@ func inspect() -> String: if type == 0: s = 'city' elif type == 1: s = 'wood' elif type == 2: s = 'mountain' - elif type == 3: s = 'impracticable' - return "%s e:%d h:%d c:%d r:%d\n -> [%d;%d]\n -> (%d;%d)" % [s, elevation(), height(), cost(), roads, coords.x, coords.y, position.x, position.y] + elif type == 3: s = 'blocked' + return "[%d;%d]\n -> (%d;%d)\n -> %s\ne:%d h:%d c:%d r:%d" % [coords.x, coords.y, position.x, position.y, s, elevation(), height(), cost(), roads] func has_road(o : int) -> bool: return (o & roads) > 0 @@ -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() @@ -1,12 +1,20 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://Camera.gd" type="Script" id=1] [ext_resource path="res://Map.gd" type="Script" id=2] [ext_resource path="res://Main.gd" type="Script" id=3] [ext_resource path="res://Los.gd" type="Script" id=4] +[ext_resource path="res://assets/Anke.otf" type="DynamicFontData" id=5] [ext_resource path="res://assets/target.png" type="Texture" id=6] [ext_resource path="res://assets/tank.png" type="Texture" id=7] +[sub_resource type="DynamicFont" id=1] +size = 35 +font_data = ExtResource( 5 ) + +[sub_resource type="Theme" id=2] +default_font = SubResource( 1 ) + [node name="Main" type="Node2D"] script = ExtResource( 3 ) @@ -22,53 +30,9 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="UI" type="VBoxContainer" parent="CanvasLayer/HBOX"] -margin_right = 150.0 -margin_bottom = 600.0 -rect_min_size = Vector2( 150, 0 ) -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="rotate" type="Button" parent="CanvasLayer/HBOX/UI"] -margin_right = 150.0 -margin_bottom = 20.0 -text = "Rotate" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="LOS" type="CheckBox" parent="CanvasLayer/HBOX/UI"] -margin_top = 24.0 -margin_right = 150.0 -margin_bottom = 48.0 -pressed = true -text = "LOS" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Move" type="CheckBox" parent="CanvasLayer/HBOX/UI"] -margin_top = 52.0 -margin_right = 150.0 -margin_bottom = 76.0 -text = "Move" -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="Info" type="Label" parent="CanvasLayer/HBOX/UI"] -margin_top = 80.0 -margin_right = 150.0 -margin_bottom = 94.0 -__meta__ = { -"_edit_use_anchors_": false -} - [node name="ViewportContainer" type="ViewportContainer" parent="CanvasLayer/HBOX"] -margin_left = 154.0 -margin_right = 1024.0 -margin_bottom = 600.0 +margin_right = 1666.0 +margin_bottom = 1080.0 rect_min_size = Vector2( 100, 100 ) mouse_filter = 2 size_flags_horizontal = 3 @@ -79,7 +43,7 @@ __meta__ = { } [node name="Viewport" type="Viewport" parent="CanvasLayer/HBOX/ViewportContainer"] -size = Vector2( 870, 600 ) +size = Vector2( 1666, 1080 ) handle_input_locally = false render_target_update_mode = 3 @@ -102,3 +66,73 @@ script = ExtResource( 4 ) [node name="Camera" type="Camera2D" parent="CanvasLayer/HBOX/ViewportContainer/Viewport"] current = true script = ExtResource( 1 ) + +[node name="UI" type="VBoxContainer" parent="CanvasLayer/HBOX"] +margin_left = 1670.0 +margin_right = 1920.0 +margin_bottom = 1080.0 +rect_min_size = Vector2( 250, 0 ) +theme = SubResource( 2 ) +custom_constants/separation = 30 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="rotate" type="Button" parent="CanvasLayer/HBOX/UI"] +margin_right = 250.0 +margin_bottom = 100.0 +rect_min_size = Vector2( 0, 100 ) +size_flags_horizontal = 3 +text = "Rotate" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="zin" type="Button" parent="CanvasLayer/HBOX/UI"] +margin_top = 130.0 +margin_right = 250.0 +margin_bottom = 230.0 +rect_min_size = Vector2( 0, 100 ) +size_flags_horizontal = 3 +text = "Z IN" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="zout" type="Button" parent="CanvasLayer/HBOX/UI"] +margin_top = 260.0 +margin_right = 250.0 +margin_bottom = 360.0 +rect_min_size = Vector2( 0, 100 ) +size_flags_horizontal = 3 +text = "Z OUT" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="LOS" type="CheckBox" parent="CanvasLayer/HBOX/UI"] +margin_top = 390.0 +margin_right = 250.0 +margin_bottom = 434.0 +pressed = true +text = "LOS" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Move" type="CheckBox" parent="CanvasLayer/HBOX/UI"] +margin_top = 464.0 +margin_right = 250.0 +margin_bottom = 508.0 +text = "Move" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Info" type="Label" parent="CanvasLayer/HBOX/UI"] +margin_top = 538.0 +margin_right = 250.0 +margin_bottom = 574.0 +__meta__ = { +"_edit_use_anchors_": false +} @@ -87,7 +87,7 @@ func on_mouse_move() -> void: if drag != null: drag.position = get_local_mouse_position() -func on_click(pressed : bool) -> void: +func on_click(pressed : bool) -> bool: var pos : Vector2 = get_local_mouse_position() var coords : Vector2 = board.to_map(pos) if pressed: @@ -97,6 +97,8 @@ func on_click(pressed : bool) -> void: drag = $Tank elif board.to_map($Target.position) == coords: drag = $Target + else: + return true else: if drag: if board.is_on_map(coords): @@ -111,6 +113,7 @@ func on_click(pressed : bool) -> void: else: if coords == prev and board.is_on_map(coords): change_tile(coords, pos) + return false func change_tile(coords : Vector2, pos : Vector2) -> void: var hex : Hex = board.get_tile(coords) diff --git a/assets/Anke.otf b/assets/Anke.otf Binary files differnew file mode 100644 index 0000000..c577d63 --- /dev/null +++ b/assets/Anke.otf diff --git a/project.godot b/project.godot index 03a9823..657540a 100644 --- a/project.godot +++ b/project.godot @@ -47,3 +47,8 @@ _global_script_class_icons={ config/name="hexgrid_demo" run/main_scene="res://Main.tscn" config/icon="res://icon.png" + +[display] + +window/size/width=1920 +window/size/height=1080 |