diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-10 14:46:13 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-07-10 14:46:13 +0200 |
commit | e0a6d318be7570152eef053ad0dbc67608a981de (patch) | |
tree | f9818a3777ad6e513750eba33365a859e004a6eb | |
parent | ed517bbfd0e10abd9bc571131188061a7221d103 (diff) | |
download | godot-hexgrid-e0a6d318be7570152eef053ad0dbc67608a981de.zip godot-hexgrid-e0a6d318be7570152eef053ad0dbc67608a981de.tar.gz |
add check boxes
-rw-r--r-- | Main.gd | 7 | ||||
-rw-r--r-- | Main.tscn | 21 | ||||
-rw-r--r-- | Map.gd | 30 |
3 files changed, 48 insertions, 10 deletions
@@ -9,11 +9,18 @@ onready var Camera : Camera2D = $ViewportContainer/Viewport/Camera func _ready(): UI.get_node("rotate").connect("pressed", Map, "on_rotate") + UI.get_node("LOS").connect("pressed", self, "on_toggle") + UI.get_node("Move").connect("pressed", self, "on_toggle") Map.connect("configure", Camera, "on_configure") Map.connect("hex_touched", self, "on_hex_touched") Camera.window = $ViewportContainer/Viewport.size + on_toggle() Map.on_rotate() +func on_toggle() -> void: + Map.config(UI.get_node("LOS").pressed, UI.get_node("Move").pressed) + Map.update() + func on_hex_touched(pos : Vector2, hex : Hex, key : int) -> void: UI.get_node("Info").set_text("\n(%d;%d)\n -> %s\n -> %d" % [int(pos.x), int(pos.y), hex.inspect(), key]) @@ -31,6 +31,27 @@ __meta__ = { "_edit_use_anchors_": false } +[node name="LOS" type="CheckBox" parent="UI"] +margin_left = 30.0 +margin_top = 90.0 +margin_right = 83.0 +margin_bottom = 114.0 +pressed = true +text = "LOS" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Move" type="CheckBox" parent="UI"] +margin_left = 30.0 +margin_top = 140.0 +margin_right = 93.0 +margin_bottom = 164.0 +text = "Move" +__meta__ = { +"_edit_use_anchors_": false +} + [node name="ViewportContainer" type="ViewportContainer" parent="."] margin_left = 141.0 margin_top = 19.0 @@ -24,6 +24,8 @@ var p1 : Vector2 var los : Array var move : Array var unit : Unit +var show_los : bool +var show_move : bool func _ready(): board = HexBoard.new() @@ -47,6 +49,10 @@ func get_tile(coords : Vector2, k : int) -> Tile: $Hexes.add_child(hex) return hex +func config(l : bool, m : bool) -> void: + show_los = l + show_move = m + func on_rotate() -> void: texture = load(MAPH if board.v else MAPV) var ts : Vector2 = texture.get_size() @@ -74,7 +80,7 @@ func on_rotate() -> void: $Hexes.remove_child(hex) hex.queue_free() reset() - update_los() + update() func on_mouse_move() -> void: if drag != null: @@ -97,7 +103,7 @@ func on_mouse_1(pressed : bool) -> void: drag.position = board.center_of(coords) if drag == $Tank: p0 = coords else: p1 = coords - update_los() + update() else: drag.position = board.center_of(prev) drag = null @@ -109,18 +115,22 @@ func on_mouse_2(pressed : bool) -> void: var hex : Hex = board.get_tile(coords) hex.change() notify(hex, pos, coords) - update_los() + update() func notify(hex : Hex, pos : Vector2, coords : Vector2) -> void: if board.is_on_map(coords): emit_signal("hex_touched",pos, hex, board.key(coords)) else: emit_signal("hex_touched", pos, hex, -1) -func update_los() -> void: +func update() -> void: + $Los.visible = false for hex in los: hex.show_los(false) - var ct : Vector2 = board.line_of_sight(p0, p1, los) - $Los.setup($Tank.position, $Target.position, ct) - for hex in los: hex.show_los(true) + if show_los: + $Los.visible = true + var ct : Vector2 = board.line_of_sight(p0, p1, los) + $Los.setup($Tank.position, $Target.position, ct) + for hex in los: hex.show_los(true) for hex in move: hex.show_move(false) - # warning-ignore:return_value_discarded - board.possible_moves(unit, board.get_tile(p0), move) - for hex in move: hex.show_move(true) + if show_move: + # warning-ignore:return_value_discarded + board.possible_moves(unit, board.get_tile(p0), move) + for hex in move: hex.show_move(true) |