This commit is contained in:
2026-05-13 18:52:00 +02:00
commit 2bb1acbece
404 changed files with 33353 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="16"
height="16"
version="1.1"
id="svg285"
sodipodi:docname="icon_camera_grid.svg"
inkscape:version="1.2.2 (732a01da63, 2022-12-09)"
inkscape:export-filename="camera_icon.svg"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs289">
<inkscape:path-effect
effect="powerclip"
id="path-effect1398"
is_visible="true"
lpeversion="1"
inverse="true"
flatten="false"
hide_clip="false"
message="Use fill-rule evenodd on &lt;b&gt;fill and stroke&lt;/b&gt; dialog if no flatten result after convert clip to paths." />
<filter
id="mask-powermask-path-effect308_inverse"
inkscape:label="filtermask-powermask-path-effect308"
style="color-interpolation-filters:sRGB"
height="100"
width="100"
x="-50"
y="-50">
<feColorMatrix
id="mask-powermask-path-effect308_primitive1"
values="1"
type="saturate"
result="fbSourceGraphic" />
<feColorMatrix
id="mask-powermask-path-effect308_primitive2"
values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0 "
in="fbSourceGraphic" />
</filter>
</defs>
<sodipodi:namedview
id="namedview287"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="36.63697"
inkscape:cx="14.875684"
inkscape:cy="11.027113"
inkscape:window-width="1920"
inkscape:window-height="1009"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg285" />
<path
id="path283"
clip-path="none"
d="M 9,2 C 7.4263418,1.9956603 6.1167894,3.2080193 6,4.7773438 4.0150859,2.9760821 0.84424915,4.4836506 0.98828125,7.1601562 l 2.61399275,0 c 5.0522731,0 5.257101,1.7609413 5.257101,3.7325278 L 8.8359375,13 H 10 c 0.552285,0 1,-0.447715 1,-1 v -1 l 3,2 V 7 L 11,9 V 7.2304688 C 13.042244,5.3935412 11.746822,2.0057091 9,2 Z"
sodipodi:nodetypes="cccsccsscccccc"
style="fill:#8da5f3;fill-opacity:1" />
<path
style="fill:#8da5f3;fill-opacity:1;stroke-width:1.27522"
d="M 1.9106389,8.3249242 V 14.438967 H 3.1934961 V 8.3249242 Z"
id="path772" />
<path
style="fill:#8da5f3;fill-opacity:1;stroke-width:1.27522"
d="M 5.0917949,8.3310933 V 14.44511 H 6.3746521 V 8.3310933 Z"
id="path772-5" />
<path
style="fill:#8da5f3;fill-opacity:1;stroke-width:1.27522"
d="M 7.1921752,9.1362916 H 1.0781589 v 1.2828414 h 6.1140163 z"
id="path772-5-7" />
<path
style="fill:#8da5f3;fill-opacity:1;stroke-width:1.27522"
d="M 7.2133007,12.003537 H 1.0992844 v 1.282839 h 6.1140163 z"
id="path772-5-7-2" />
</svg>

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@@ -0,0 +1,43 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://dv3cw6mamb6rl"
path="res://.godot/imported/icon_camera_grid.svg-466e9cc8bcf9b1a9a5463aaf2cf74537.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/strategy_cam/icon_camera_grid.svg"
dest_files=["res://.godot/imported/icon_camera_grid.svg-466e9cc8bcf9b1a9a5463aaf2cf74537.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=1.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false

View File

@@ -0,0 +1,7 @@
[plugin]
name="StrategyCamera"
description="A suite of strategy game camera controls. Includes togglable mouse and keyboard controls. See the README.md on the godot-strategy-camera repository to find which inputs must be mapped in the project for the camera to function."
author="Thomas737"
version="1.0"
script="strategy_camera_autoload.gd"

View File

@@ -0,0 +1,104 @@
extends Camera2D
# See WARNING's below for detail on custom control binding. Apart from scroll zooming, every key and mouse
# press must be bound manually by the developer.
@export var allow_mouse_controls: bool = true
@export var allow_keyboard_controls: bool = true
@export_group("Keyboard Controls")
## Camera zoom speed when controlled with keys
@export var key_zoom_speed: float = 2.0
## Translation speed when controlled by keys
@export var translation_speed: float = 100.0
@export_group("Camera Zoom Variables")
## Relative zoom in every scroll wheel tick.
@export var zoom_step: float = 0.2
## Speed at which the camera reaches the next target zoom. Really funky things can happen
## if x and y are set to different values...
@export var zoom_speed: Vector2 = Vector2(10, 10)
@export_group("Directional Limits")
## Top-left limit of the camera position/movement (applied to the top-left of the camera).
## If this and limit_BR set to Vector2.ZERO, no limits will be applied
@export var limit_TL: Vector2 = Vector2.ZERO
## Bottom-right limit of the camera position/movement (applied to the bottom-right of the camera).
## If this and limit_TL set to Vector2.ZERO, no limits will be applied
@export var limit_BR: Vector2 = Vector2.ZERO
var camera_TL: Vector2 = Vector2(-576, -324)
var camera_BR: Vector2 = Vector2(576, 324)
var target_zoom: Vector2 = Vector2.ONE
func _ready() -> void:
target_zoom = zoom
_on_resolution_change()
get_viewport().size_changed.connect(_on_resolution_change)
func _on_resolution_change() -> void:
camera_TL = -get_viewport_rect().size / 2
camera_BR = get_viewport_rect().size / 2
func _unhandled_input(event: InputEvent) -> void:
if not allow_mouse_controls:
return
# Zooming by scrolling with the middle mouse button
if event is InputEventMouse:
if event.is_pressed() and not event.is_echo():
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
zoom_camera(zoom_step)
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
zoom_camera(-zoom_step)
target_zoom = target_zoom.clamp(Vector2.ONE*0.5, Vector2.INF)
# Camera translation by clicking and dragging
if event is InputEventMouseMotion:
# WARNING: The dragging control must be defined WITHIN THIS PROJECT
if Input.is_action_pressed("cam_drag"):
position -= event.relative / zoom
func _process(delta: float) -> void:
if target_zoom.length()-0.001 <= zoom.length() and zoom.length() <= target_zoom.length()+0.001:
zoom = target_zoom
else:
increment_zoom((target_zoom-zoom) * zoom_speed * delta)
var screen_centre: Vector2 = get_screen_center_position()
var actual_TL: Vector2 = screen_centre + camera_TL / target_zoom
var actual_BR: Vector2 = screen_centre + camera_BR / target_zoom
# WARNING: The keyboard controls must be defined WITHIN THIS PROJECT
if allow_keyboard_controls:
position.x += Input.get_axis("cam_left", "cam_right") * translation_speed * delta
position.y += Input.get_axis("cam_up", "cam_down") * translation_speed * delta
var camera_zoom_direction: float = Input.get_axis("cam_zoom_out", "cam_zoom_in")
if camera_zoom_direction:
zoom_camera(camera_zoom_direction * key_zoom_speed * delta)
zoom = target_zoom
if limit_BR == Vector2.ZERO and limit_TL == Vector2.ZERO:
return
# Camera limit application
if actual_TL.x < limit_TL.x:
position.x += limit_TL.x - actual_TL.x
if actual_TL.y < limit_TL.y:
position.y += limit_TL.y - actual_TL.y
if actual_BR.x > limit_BR.x:
position.x -= actual_BR.x - limit_BR.x
if actual_BR.y > limit_BR.y:
position.y -= actual_BR.y - limit_BR.y
func zoom_camera(zoom_amount: float) -> void:
target_zoom *= pow(10.0, zoom_amount)
func increment_zoom(zoom_direction: Vector2) -> void:
var previous_mouse_position: Vector2 = get_local_mouse_position()
zoom += zoom_direction
var diff: Vector2 = previous_mouse_position - get_local_mouse_position()
offset += diff

View File

@@ -0,0 +1 @@
uid://rirna2vebukw

View File

@@ -0,0 +1,10 @@
@tool
extends EditorPlugin
func _enter_tree() -> void:
add_custom_type("StrategyCamera", "Camera2D", preload("strategy_camera.gd"), preload("icon_camera_grid.svg"))
func _exit_tree() -> void:
remove_custom_type("StrategyCamera")

View File

@@ -0,0 +1 @@
uid://0wl0wfyt5w78