UI and other changes
This commit is contained in:
parent
87b5c11fcf
commit
215e24e246
79 changed files with 70023 additions and 2201 deletions
114
game/resources/pixel_outline.gdshader
Normal file
114
game/resources/pixel_outline.gdshader
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
shader_type spatial;
|
||||
render_mode unshaded;
|
||||
|
||||
// MIT License. Made by Leo Peltola
|
||||
// Inspired by https://threejs.org/examples/webgl_postprocessing_pixel.html
|
||||
//
|
||||
// Drawn by ToonLook on a 2 x 2 quad that vertex() pins to the screen (it never culls, so one quad
|
||||
// outlines whatever camera is current). Needs the Forward+ renderer (the normal-roughness
|
||||
// buffer). The material draws first among the transparent things, so the effects drawn over the
|
||||
// farm (zone tints, beams, flames, rings) aren't outlined or painted over.
|
||||
|
||||
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear_mipmap;
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
|
||||
uniform sampler2D NORMAL_TEXTURE : hint_normal_roughness_texture, filter_nearest;
|
||||
|
||||
uniform bool shadows_enabled = true;
|
||||
uniform bool highlights_enabled = true;
|
||||
uniform float shadow_strength : hint_range(0.0, 1.0, 0.01) = 0.4;
|
||||
uniform float highlight_strength : hint_range(0.0, 1.0, 0.01) = 0.1;
|
||||
uniform vec3 highlight_color : source_color = vec3(1.);
|
||||
uniform vec3 shadow_color : source_color = vec3(0.0);
|
||||
|
||||
varying mat4 model_view_matrix;
|
||||
|
||||
|
||||
float getDepth(vec2 screen_uv, sampler2D depth_texture, mat4 inv_projection_matrix){
|
||||
// Credit: https://godotshaders.com/shader/depth-modulated-pixel-outline-in-screen-space/
|
||||
float raw_depth = texture(depth_texture, screen_uv)[0];
|
||||
vec3 normalized_device_coordinates = vec3(screen_uv * 2.0 - 1.0, raw_depth);
|
||||
vec4 view_space = inv_projection_matrix * vec4(normalized_device_coordinates, 1.0);
|
||||
view_space.xyz /= view_space.w;
|
||||
return -view_space.z;
|
||||
}
|
||||
|
||||
vec3 getPos(float depth, mat4 mvm, mat4 ipm, vec2 suv, mat4 wm, mat4 icm){
|
||||
vec4 pos = inverse(mvm) * ipm * vec4((suv * 2.0 - 1.0), depth * 2.0 - 1.0, 1.0);
|
||||
pos.xyz /= (pos.w+0.0001*(1.-abs(sign(pos.w))));
|
||||
return (pos*icm).xyz+wm[3].xyz;
|
||||
}
|
||||
|
||||
float normalIndicator(vec3 normalEdgeBias, vec3 baseNormal, vec3 newNormal, float depth_diff){
|
||||
// Credit: https://threejs.org/examples/webgl_postprocessing_pixel.html
|
||||
float normalDiff = dot(baseNormal - newNormal, normalEdgeBias);
|
||||
float normalIndicator = clamp(smoothstep(-.01, .01, normalDiff), 0.0, 1.0);
|
||||
float depthIndicator = clamp(sign(depth_diff * .25 + .0025), 0.0, 1.0);
|
||||
return (1.0 - dot(baseNormal, newNormal)) * depthIndicator * normalIndicator;
|
||||
}
|
||||
|
||||
void vertex(){
|
||||
// Full screen, at the near plane (reverse Z), for any camera.
|
||||
POSITION = vec4(VERTEX.xy, 1.0, 1.0);
|
||||
model_view_matrix = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 e = vec2(1./VIEWPORT_SIZE.xy);
|
||||
|
||||
// Shadows
|
||||
float depth_diff = 0.0;
|
||||
float neg_depth_diff = .5;
|
||||
if (shadows_enabled) {
|
||||
float depth = getDepth(SCREEN_UV, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
|
||||
float du = getDepth(SCREEN_UV+vec2(0., -1.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
|
||||
float dr = getDepth(SCREEN_UV+vec2(1., 0.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
|
||||
float dd = getDepth(SCREEN_UV+vec2(0., 1.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
|
||||
float dl = getDepth(SCREEN_UV+vec2(-1., 0.)*e, DEPTH_TEXTURE, INV_PROJECTION_MATRIX);
|
||||
depth_diff += clamp(du - depth, 0., 1.);
|
||||
depth_diff += clamp(dd - depth, 0., 1.);
|
||||
depth_diff += clamp(dr - depth, 0., 1.);
|
||||
depth_diff += clamp(dl - depth, 0., 1.);
|
||||
neg_depth_diff += depth - du;
|
||||
neg_depth_diff += depth - dd;
|
||||
neg_depth_diff += depth - dr;
|
||||
neg_depth_diff += depth - dl;
|
||||
neg_depth_diff = clamp(neg_depth_diff, 0., 1.);
|
||||
neg_depth_diff = clamp(smoothstep(0.5, 0.5, neg_depth_diff)*10., 0., 1.);
|
||||
depth_diff = smoothstep(0.2, 0.3, depth_diff);
|
||||
// ALBEDO = vec3(neg_depth_diff);
|
||||
}
|
||||
|
||||
// Highlights
|
||||
float normal_diff = 0.;
|
||||
if (highlights_enabled) {
|
||||
vec3 normal = texture(NORMAL_TEXTURE, SCREEN_UV).rgb * 2.0 - 1.0;
|
||||
vec3 nu = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(0., -1.)*e).rgb * 2.0 - 1.0;
|
||||
vec3 nr = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(1., 0.)*e).rgb * 2.0 - 1.0;
|
||||
vec3 nd = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(0., 1.)*e).rgb * 2.0 - 1.0;
|
||||
vec3 nl = texture(NORMAL_TEXTURE, SCREEN_UV+vec2(-1., 0.)*e).rgb * 2.0 - 1.0;
|
||||
vec3 normal_edge_bias = (vec3(1., 1., 1.));
|
||||
normal_diff += normalIndicator(normal_edge_bias, normal, nu, depth_diff);
|
||||
normal_diff += normalIndicator(normal_edge_bias, normal, nr, depth_diff);
|
||||
normal_diff += normalIndicator(normal_edge_bias, normal, nd, depth_diff);
|
||||
normal_diff += normalIndicator(normal_edge_bias, normal, nl, depth_diff);
|
||||
normal_diff = smoothstep(0.2, 0.8, normal_diff);
|
||||
normal_diff = clamp(normal_diff-neg_depth_diff, 0., 1.);
|
||||
// ALBEDO = vec3(normal_diff);
|
||||
}
|
||||
|
||||
|
||||
vec3 original_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb;
|
||||
vec3 final_highlight_color = mix(original_color, highlight_color, highlight_strength);
|
||||
vec3 final_shadow_color = mix(original_color, shadow_color, shadow_strength);
|
||||
vec3 final = original_color;
|
||||
if (highlights_enabled) {
|
||||
final = mix(final, final_highlight_color, normal_diff);
|
||||
}
|
||||
if (shadows_enabled) {
|
||||
final = mix(final, final_shadow_color, depth_diff);
|
||||
}
|
||||
ALBEDO = final;
|
||||
|
||||
float alpha_mask = depth_diff * float(shadows_enabled) + normal_diff * float(highlights_enabled);
|
||||
ALPHA = clamp((alpha_mask) * 5., 0., 1.);
|
||||
}
|
||||
1
game/resources/pixel_outline.gdshader.uid
Normal file
1
game/resources/pixel_outline.gdshader.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b4dor4pwrfaxw
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
shader_type spatial;
|
||||
// Shared enemy material (one MultiMesh batch), from the prototype's bird shader: wings (local
|
||||
// |x|) flap with a per-enemy phase from INSTANCE_CUSTOM.r, and a hit flashes the enemy white
|
||||
// through INSTANCE_CUSTOM.g (1 on the hit, fading). Rim light keeps the near-black crow
|
||||
// readable against the grass and crops, and night_glow (set by DayNight) adds a faint purple glow
|
||||
// at night.
|
||||
// through INSTANCE_CUSTOM.g (1 on the hit, fading). Lit like the rest of the farm
|
||||
// (toon_light.gdshaderinc), whose rim light keeps the near-black crow readable against the grass
|
||||
// and crops, and night_glow (set by DayNight) adds a faint purple glow at night.
|
||||
render_mode cull_disabled;
|
||||
|
||||
#include "res://game/resources/toon_light.gdshaderinc"
|
||||
|
||||
uniform vec3 base_color : source_color = vec3(0.07, 0.07, 0.09);
|
||||
uniform float flap_speed = 11.0;
|
||||
uniform float flap_amount = 0.55;
|
||||
|
|
@ -25,6 +27,4 @@ void fragment() {
|
|||
EMISSION = vec3(1.0, 0.9, 0.8) * flash * 0.6 + vec3(0.5, 0.28, 0.75) * night_glow * 0.35;
|
||||
ROUGHNESS = 0.55;
|
||||
SPECULAR = 0.4;
|
||||
RIM = 0.8;
|
||||
RIM_TINT = 0.3;
|
||||
}
|
||||
|
|
|
|||
4
game/resources/toon.gdshader
Normal file
4
game/resources/toon.gdshader
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
shader_type spatial;
|
||||
// Toon material (ToonLook): see toon_surface.gdshaderinc and toon_light.gdshaderinc.
|
||||
|
||||
#include "res://game/resources/toon_surface.gdshaderinc"
|
||||
1
game/resources/toon.gdshader.uid
Normal file
1
game/resources/toon.gdshader.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cp1pd2g4f3yps
|
||||
6
game/resources/toon_double_sided.gdshader
Normal file
6
game/resources/toon_double_sided.gdshader
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
shader_type spatial;
|
||||
// Toon material (ToonLook) for double-sided source materials, e.g. the ithappy farm pack's: see
|
||||
// toon_surface.gdshaderinc and toon_light.gdshaderinc.
|
||||
render_mode cull_disabled;
|
||||
|
||||
#include "res://game/resources/toon_surface.gdshaderinc"
|
||||
1
game/resources/toon_double_sided.gdshader.uid
Normal file
1
game/resources/toon_double_sided.gdshader.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dikxn4x402j5h
|
||||
90
game/resources/toon_light.gdshaderinc
Normal file
90
game/resources/toon_light.gdshaderinc
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
// Toon lighting, shared by toon.gdshader (ToonLook's converted materials) and the enemy shaders
|
||||
// (thief.gdshader, ufo.gdshader): diffuse light cut into bands, a hard specular spot, and a rim
|
||||
// light. The Godot 3 toon shader ported to Godot 4: source_color hints, ATTENUATION is a float,
|
||||
// PI is built in, and LIGHT_COLOR already carries the PI that the "/ PI" divides back out. Omni
|
||||
// and spot lights fade their rim with distance (a directional light's rim stays whole), and the
|
||||
// specular and rim powers clamp their base so back faces and grazing angles can't go negative.
|
||||
|
||||
uniform bool clamp_diffuse_to_max = false;
|
||||
|
||||
uniform int cuts : hint_range(1, 8) = 3;
|
||||
uniform float wrap : hint_range(-2.0f, 2.0f) = 0.0f;
|
||||
uniform float steepness : hint_range(1.0f, 8.0f) = 1.0f;
|
||||
|
||||
uniform bool use_attenuation = true;
|
||||
|
||||
uniform bool use_specular = true;
|
||||
uniform float specular_strength : hint_range(0.0f, 1.0f) = 1.0f;
|
||||
uniform float specular_shininess : hint_range(0.0f, 32.0f) = 16.0f;
|
||||
uniform sampler2D specular_map : source_color;
|
||||
|
||||
uniform bool use_rim = true;
|
||||
uniform float rim_width : hint_range(0.0f, 16.0f) = 8.0f;
|
||||
uniform vec4 rim_color : source_color = vec4(1.0f);
|
||||
|
||||
uniform bool use_ramp = false;
|
||||
uniform sampler2D ramp : source_color;
|
||||
|
||||
uniform bool use_borders = false;
|
||||
uniform float border_width = 0.01f;
|
||||
|
||||
float split_specular(float specular) {
|
||||
return step(0.5f, specular);
|
||||
}
|
||||
|
||||
void light() {
|
||||
// Attenuation.
|
||||
float attenuation = 1.0f;
|
||||
if (use_attenuation) {
|
||||
attenuation = ATTENUATION;
|
||||
}
|
||||
|
||||
// Diffuse lighting.
|
||||
float NdotL = dot(NORMAL, LIGHT);
|
||||
float diffuse_amount = NdotL + (attenuation - 1.0) + wrap;
|
||||
diffuse_amount *= steepness;
|
||||
float cuts_inv = 1.0f / float(cuts);
|
||||
float diffuse_stepped = clamp(diffuse_amount + mod(1.0f - diffuse_amount, cuts_inv), 0.0f, 1.0f);
|
||||
|
||||
// Calculate borders.
|
||||
float border = 0.0f;
|
||||
if (use_borders) {
|
||||
float corr_border_width = length(cross(NORMAL, LIGHT)) * border_width * steepness;
|
||||
border = step(diffuse_stepped - corr_border_width, diffuse_amount)
|
||||
- step(1.0 - corr_border_width, diffuse_amount);
|
||||
}
|
||||
|
||||
// Apply diffuse result to different styles.
|
||||
vec3 diffuse = ALBEDO.rgb * LIGHT_COLOR / PI;
|
||||
if (use_ramp) {
|
||||
diffuse *= texture(ramp, vec2(diffuse_stepped * (1.0f - border), 0.0f)).rgb;
|
||||
} else {
|
||||
diffuse *= diffuse_stepped * (1.0f - border);
|
||||
}
|
||||
|
||||
if (clamp_diffuse_to_max) {
|
||||
// Clamp diffuse to max for multiple light sources.
|
||||
DIFFUSE_LIGHT = max(DIFFUSE_LIGHT, diffuse);
|
||||
} else {
|
||||
DIFFUSE_LIGHT += diffuse;
|
||||
}
|
||||
|
||||
// Specular lighting.
|
||||
if (use_specular) {
|
||||
vec3 H = normalize(LIGHT + VIEW);
|
||||
float NdotH = max(dot(NORMAL, H), 0.0f);
|
||||
float specular_amount = pow(NdotH, specular_shininess * specular_shininess)
|
||||
* texture(specular_map, UV).r
|
||||
* attenuation;
|
||||
specular_amount = split_specular(specular_amount);
|
||||
SPECULAR_LIGHT += specular_strength * specular_amount * LIGHT_COLOR;
|
||||
}
|
||||
|
||||
// Simple rim lighting.
|
||||
if (use_rim) {
|
||||
float NdotV = dot(NORMAL, VIEW);
|
||||
float rim_light = pow(clamp(1.0 - NdotV, 0.0f, 1.0f), rim_width);
|
||||
float rim_fade = LIGHT_IS_DIRECTIONAL ? 1.0f : attenuation;
|
||||
DIFFUSE_LIGHT += rim_light * rim_fade * rim_color.rgb * rim_color.a * LIGHT_COLOR / PI;
|
||||
}
|
||||
}
|
||||
1
game/resources/toon_light.gdshaderinc.uid
Normal file
1
game/resources/toon_light.gdshaderinc.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b7jx3r74b5mgk
|
||||
23
game/resources/toon_surface.gdshaderinc
Normal file
23
game/resources/toon_surface.gdshaderinc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// The surface half of ToonLook's converted materials (toon.gdshader, toon_double_sided.gdshader):
|
||||
// albedo color times albedo texture (times the vertex color when the source material used it),
|
||||
// lit by toon_light.gdshaderinc. ToonLook copies these from each StandardMaterial3D it replaces.
|
||||
|
||||
uniform vec4 albedo : source_color = vec4(1.0f);
|
||||
uniform sampler2D albedo_texture : source_color, filter_linear_mipmap, repeat_enable;
|
||||
uniform bool use_vertex_color = false;
|
||||
uniform vec3 uv1_scale = vec3(1.0f);
|
||||
uniform vec3 uv1_offset = vec3(0.0f);
|
||||
|
||||
#include "res://game/resources/toon_light.gdshaderinc"
|
||||
|
||||
void vertex() {
|
||||
UV = UV * uv1_scale.xy + uv1_offset.xy;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec3 color = albedo.rgb * texture(albedo_texture, UV).rgb;
|
||||
if (use_vertex_color) {
|
||||
color *= COLOR.rgb;
|
||||
}
|
||||
ALBEDO = color;
|
||||
}
|
||||
1
game/resources/toon_surface.gdshaderinc.uid
Normal file
1
game/resources/toon_surface.gdshaderinc.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://rewmnv65ptqi
|
||||
|
|
@ -3,9 +3,12 @@ shader_type spatial;
|
|||
// EnemySystem.build_ufo_mesh(): each part's color comes from the vertex COLOR, and its glow and
|
||||
// metalness from UV (x, y). No flap: the saucer turns slowly about its axis and bobs a little,
|
||||
// with a per-enemy phase from INSTANCE_CUSTOM.r, and the rim lights (glow 1) pulse in a chase
|
||||
// around the ring. As in thief.gdshader, a hit flashes it white through INSTANCE_CUSTOM.g (1 on
|
||||
// the hit, fading), a rim light keeps it readable, and night_glow (set by DayNight) adds a faint
|
||||
// purple glow at night; the lights and the dome glow brighter in the dark.
|
||||
// around the ring. As in thief.gdshader, it's lit like the rest of the farm
|
||||
// (toon_light.gdshaderinc), a hit flashes it white through INSTANCE_CUSTOM.g (1 on the hit,
|
||||
// fading), and night_glow (set by DayNight) adds a faint purple glow at night; the lights and the
|
||||
// dome glow brighter in the dark.
|
||||
|
||||
#include "res://game/resources/toon_light.gdshaderinc"
|
||||
|
||||
uniform float spin_speed = 1.2;
|
||||
uniform float bob_amount = 0.05;
|
||||
|
|
@ -43,6 +46,4 @@ void fragment() {
|
|||
// The night's purple sits on the hull; the glowing parts keep their own color.
|
||||
EMISSION = base * glow * glow_energy * (1.0 + night_glow) + vec3(1.0, 0.9, 0.8) * f * 0.6
|
||||
+ vec3(0.5, 0.28, 0.75) * night_glow * 0.35 * (1.0 - glow);
|
||||
RIM = 0.6;
|
||||
RIM_TINT = 0.4;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
2424
game/scenes/forest.tscn
Normal file
2424
game/scenes/forest.tscn
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,89 +0,0 @@
|
|||
class_name AssetHud
|
||||
extends Control
|
||||
## Top-center readout of what's left to protect: "Crops 28/30 · Animals 7/8 · Supplies 23" (the
|
||||
## shed's stock plus any sacks still on the farm), each in its category's color. A count flashes
|
||||
## red when it drops and green when it rises. Categories not in play are left out.
|
||||
|
||||
const FLASH_TIME := 1.2
|
||||
const LOSS := Color(1.0, 0.3, 0.25)
|
||||
const GAIN := Color(0.5, 1.0, 0.45)
|
||||
|
||||
var campaign: CampaignController
|
||||
|
||||
var _box: HBoxContainer
|
||||
var _panel: PanelContainer
|
||||
var _labels: Array[Label] = []
|
||||
var _last := PackedInt32Array([-1, -1, -1])
|
||||
var _flash := PackedFloat32Array([0.0, 0.0, 0.0])
|
||||
var _flash_color: Array[Color] = [Color.WHITE, Color.WHITE, Color.WHITE]
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
campaign = p_campaign
|
||||
_last = _counts()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_panel = PanelContainer.new()
|
||||
var bg := StyleBoxFlat.new()
|
||||
bg.bg_color = Color(0.0, 0.0, 0.0, 0.42)
|
||||
bg.content_margin_left = 18.0
|
||||
bg.content_margin_right = 18.0
|
||||
bg.content_margin_top = 4.0
|
||||
bg.content_margin_bottom = 4.0
|
||||
_panel.add_theme_stylebox_override("panel", bg)
|
||||
_panel.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_panel)
|
||||
_box = HBoxContainer.new()
|
||||
_box.add_theme_constant_override("separation", 28)
|
||||
_box.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_panel.add_child(_box)
|
||||
for c in 3:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", 24)
|
||||
l.add_theme_color_override("font_color", LootSystem.CATEGORY_COLORS[c])
|
||||
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
l.add_theme_constant_override("outline_size", 6)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_box.add_child(l)
|
||||
_labels.append(l)
|
||||
|
||||
|
||||
## "Crops 28/30 · Animals 7/8 · Supplies 23", as the HUD shows it (also used by tests).
|
||||
func describe() -> String:
|
||||
var parts: Array[String] = []
|
||||
for l in _labels:
|
||||
if l.visible:
|
||||
parts.append(l.text)
|
||||
return " · ".join(parts)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var s := campaign.state
|
||||
var now := _counts()
|
||||
var texts := ["Crops %d/%d" % [s.crops, s.crops_total], "Animals %d/%d" % [s.animals, s.animals_total],
|
||||
"Supplies %d" % s.supplies]
|
||||
var in_play := [s.crops_total > 0, s.animals_total > 0, s.supplies_total > 0]
|
||||
for c in 3:
|
||||
var l := _labels[c]
|
||||
l.visible = in_play[c]
|
||||
l.text = texts[c]
|
||||
if _last[c] >= 0 and now[c] != _last[c]:
|
||||
_flash[c] = FLASH_TIME
|
||||
_flash_color[c] = LOSS if now[c] < _last[c] else GAIN
|
||||
_last[c] = now[c]
|
||||
_flash[c] = maxf(_flash[c] - delta, 0.0)
|
||||
var k := _flash[c] / FLASH_TIME
|
||||
var pulse := (0.5 + 0.5 * sin(_flash[c] * 18.0)) * k
|
||||
l.modulate = Color.WHITE.lerp(_flash_color[c] * 1.4, pulse)
|
||||
_panel.reset_size()
|
||||
_panel.position = Vector2((size.x - _panel.size.x) * 0.5, 14.0)
|
||||
|
||||
|
||||
func _counts() -> PackedInt32Array:
|
||||
var s := campaign.state
|
||||
return PackedInt32Array([s.crops, s.animals, s.supplies])
|
||||
|
|
@ -1 +0,0 @@
|
|||
uid://cdhho7exq5x3s
|
||||
|
|
@ -1,19 +1,22 @@
|
|||
class_name BuildHud
|
||||
extends Control
|
||||
## The build hotbar, shown in build mode: one slot per buildable with its key, name, and cost
|
||||
## (red when the builder can't afford it from their own pouch and the shed), the selected one
|
||||
## highlighted, the controls, and how many structures stand on the farm.
|
||||
## The build bar, shown in build mode in the weapons hotbar's place (ScarecrowHud), hand-drawn
|
||||
## like the HUD's pouch panel (Sketch): "Build" over a pen rule with how many structures stand on
|
||||
## the farm, one slot per buildable with its key, name, and cost (red when the builder can't
|
||||
## afford it from their own pouch and the shed), the selected one lifted in a gold frame, and the
|
||||
## controls in dim text under them.
|
||||
|
||||
const SLOT := Vector2(230.0, 76.0)
|
||||
const SLOT := Vector2(250.0, 80.0)
|
||||
const GAP := 12.0
|
||||
const PAD := 18.0
|
||||
const HEAD := 52.0
|
||||
const HELP := 32.0
|
||||
const BOTTOM := 22.0
|
||||
const SHORT := Color(1.0, 0.45, 0.4)
|
||||
|
||||
var build: BuildMode
|
||||
var campaign: CampaignController
|
||||
|
||||
var _names: Array[Label] = []
|
||||
var _costs: Array[Label] = []
|
||||
var _help: Label
|
||||
|
||||
|
||||
func setup(p_build: BuildMode, p_campaign: CampaignController) -> void:
|
||||
build = p_build
|
||||
|
|
@ -23,55 +26,47 @@ func setup(p_build: BuildMode, p_campaign: CampaignController) -> void:
|
|||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
for i in StructureSystem.ORDER.size():
|
||||
_names.append(_label(22))
|
||||
_costs.append(_label(18))
|
||||
_help = _label(19)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
visible = build != null and build.active
|
||||
if not visible:
|
||||
return
|
||||
var r := campaign.state.resources
|
||||
var slot := build.kit.slot if build.kit != null else 0
|
||||
var origin := _origin()
|
||||
for i in StructureSystem.ORDER.size():
|
||||
var t: String = StructureSystem.ORDER[i]
|
||||
var cost: Dictionary = campaign.config.costs.get(t, {})
|
||||
var pos := origin + Vector2(i * (SLOT.x + GAP), 0.0)
|
||||
_names[i].text = "%d %s" % [i + 1, StructureSystem.NAMES[t]]
|
||||
_names[i].position = pos + Vector2(12.0, 8.0)
|
||||
_costs[i].text = ResourceStore.describe(cost)
|
||||
_costs[i].position = pos + Vector2(12.0, 42.0)
|
||||
_costs[i].add_theme_color_override("font_color", Color(0.9, 0.95, 0.9) if r.can_afford(cost, slot) else Color(1.0, 0.45, 0.4))
|
||||
_help.text = "Build mode · LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave · %d built" % \
|
||||
build.structures.count()
|
||||
_help.position = origin + Vector2(0.0, -34.0)
|
||||
queue_redraw()
|
||||
if visible:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## The controls line, as shown.
|
||||
func help_text() -> String:
|
||||
return "LMB / RT build · Z C / d-pad rotate · 1-4 / Tab pick · RMB / B dismantle or leave"
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if build == null or not build.active:
|
||||
return
|
||||
var origin := _origin()
|
||||
for i in StructureSystem.ORDER.size():
|
||||
var rect := Rect2(origin + Vector2(i * (SLOT.x + GAP), 0.0), SLOT)
|
||||
draw_rect(rect, Color(0.0, 0.0, 0.0, 0.55))
|
||||
draw_rect(rect, Color(1.0, 0.9, 0.4) if i == build.selected else Color(1.0, 1.0, 1.0, 0.25), false, 3.0 if i == build.selected else 1.5)
|
||||
|
||||
|
||||
func _origin() -> Vector2:
|
||||
var r := campaign.state.resources
|
||||
var slot := build.kit.slot if build.kit != null else 0
|
||||
var n := StructureSystem.ORDER.size()
|
||||
var width := n * SLOT.x + (n - 1) * GAP
|
||||
return Vector2((size.x - width) * 0.5, size.y - SLOT.y - 28.0)
|
||||
|
||||
|
||||
func _label(font_size: int) -> Label:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
l.add_theme_constant_override("outline_size", 6)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(l)
|
||||
return l
|
||||
var width := n * SLOT.x + (n - 1) * GAP + PAD * 2.0
|
||||
var height := HEAD + SLOT.y + HELP + PAD
|
||||
var panel := Rect2(Vector2((size.x - width) * 0.5, size.y - BOTTOM - height), Vector2(width, height))
|
||||
Sketch.panel(self, panel, 801.0)
|
||||
Sketch.text(self, panel.position + Vector2(PAD, 6.0), "Build", 32)
|
||||
Sketch.text(self, Vector2(panel.end.x - PAD - 8.0, panel.position.y + 12.0), "%d built" % build.structures.count(), 24,
|
||||
Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
Sketch.rule(self, panel.position.x + 14.0, panel.end.x - 14.0, panel.position.y + 48.0, 802.0)
|
||||
for i in n:
|
||||
var t: String = StructureSystem.ORDER[i]
|
||||
var cost: Dictionary = campaign.config.costs.get(t, {})
|
||||
var rect := Rect2(panel.position + Vector2(PAD + i * (SLOT.x + GAP), HEAD + 4.0), SLOT)
|
||||
var picked := i == build.selected
|
||||
if picked:
|
||||
rect = rect.grow(3.0)
|
||||
rect.position.y -= 4.0
|
||||
Sketch.box(self, rect, Sketch.SLOT, Sketch.INK, 2.5, 810.0 + i * 3.0)
|
||||
if picked:
|
||||
Sketch.box(self, rect.grow(2.0), Color(0, 0, 0, 0), Sketch.GOLD, 3.5, 830.0 + i)
|
||||
Sketch.text(self, rect.position + Vector2(12.0, 4.0), "%d %s" % [i + 1, StructureSystem.NAMES[t]], 28, Sketch.TEXT,
|
||||
HORIZONTAL_ALIGNMENT_LEFT, 6)
|
||||
Sketch.text(self, rect.position + Vector2(12.0, 42.0), ResourceStore.describe(cost), 22,
|
||||
Sketch.TEXT if r.can_afford(cost, slot) else SHORT, HORIZONTAL_ALIGNMENT_LEFT, 6)
|
||||
Sketch.text(self, Vector2(panel.get_center().x, panel.end.y - PAD - 22.0), help_text(), 22, Sketch.DIM,
|
||||
HORIZONTAL_ALIGNMENT_CENTER, 6)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func morning_snapshot() -> Dictionary:
|
|||
return _morning_snapshot.duplicate(true)
|
||||
|
||||
|
||||
## The farm as it is now becomes this morning's snapshot, the one a retry goes back to (debug: F8
|
||||
## The farm as it is now becomes this morning's snapshot, the one a retry goes back to (debug: F4
|
||||
## in the morning review, so a retry keeps what it unlocked). Nothing is saved.
|
||||
func retake_morning_snapshot() -> void:
|
||||
_morning_snapshot = state.to_dict()
|
||||
|
|
|
|||
|
|
@ -6,12 +6,13 @@ extends CanvasLayer
|
|||
## pairs, then all three; game/resources/scenarios/) and back to the real one
|
||||
## F3 / Shift+F3 in the morning review: jump to the next / previous day's morning, farm as
|
||||
## it is (jump_morning; debug builds only, not on a co-op partner's machine)
|
||||
## F4 unlock everything: every upgrade and shop item at its last level, free
|
||||
## (unlock_all; debug builds only, not on a co-op partner's machine). Not
|
||||
## F8: run from the editor, Godot stops the game on F8 (its Stop shortcut)
|
||||
## N start the night early (only when GameConfig.allow_early_night is on)
|
||||
## R after Game Over: retry the night; after the farmers return: new vacation
|
||||
## F6 end the current phase now
|
||||
## F7 cycle game speed 1x / 5x / 20x
|
||||
## F8 unlock everything: every upgrade and shop item at its last level, free
|
||||
## (unlock_all; debug builds only, not on a co-op partner's machine)
|
||||
## F9 debug: scarecrow to 0 HP
|
||||
## F10 debug: strip every farm asset
|
||||
## T / G / H debug: send in a thief / a crow / a fence breaker (FarmSim)
|
||||
|
|
@ -68,6 +69,8 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
cycle_scenario()
|
||||
KEY_F3:
|
||||
jump_morning(-1 if key.shift_pressed else 1)
|
||||
KEY_F4:
|
||||
unlock_all()
|
||||
KEY_N:
|
||||
campaign.start_night_early()
|
||||
KEY_F6:
|
||||
|
|
@ -75,8 +78,6 @@ func _unhandled_input(event: InputEvent) -> void:
|
|||
KEY_F7:
|
||||
_speed_index = (_speed_index + 1) % SPEEDS.size()
|
||||
Engine.time_scale = SPEEDS[_speed_index]
|
||||
KEY_F8:
|
||||
unlock_all()
|
||||
KEY_F9:
|
||||
s.scarecrow_hp = 0
|
||||
KEY_F10:
|
||||
|
|
@ -168,5 +169,5 @@ func _describe() -> String:
|
|||
lines.append("[N] start the night early")
|
||||
if sim != null and sim.waves.debug_plan != null:
|
||||
lines.append("Scenario: %s (F2 next)" % sim.waves.debug_plan.title)
|
||||
lines.append("F1 hide · F2 scenario · F3 / Shift+F3 next / previous morning · F6 next phase · F7 speed · F8 unlock everything · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker")
|
||||
lines.append("F1 hide · F2 scenario · F3 / Shift+F3 next / previous morning · F4 unlock everything · F6 next phase · F7 speed · F9 scarecrow to 0 HP · F10 strip farm · T/G/H thief/crow/breaker")
|
||||
return "\n".join(lines)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
class_name ConfirmBox
|
||||
extends CenterContainer
|
||||
## A yes / no question over the menus (Main): the message, the confirming button, and Cancel
|
||||
## (focused, so a stray Enter / A never throws progress away). Escape / B cancels.
|
||||
## (focused, so a stray Enter / A never throws progress away). Escape / B cancels. Hand-drawn like
|
||||
## the pause menu it mostly opens from (UiTheme.sketch).
|
||||
|
||||
var message: Label
|
||||
var yes_button: Button
|
||||
|
|
@ -13,11 +14,13 @@ var _on_yes: Callable
|
|||
|
||||
func _ready() -> void:
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
theme = UiTheme.sketch()
|
||||
var panel := PanelContainer.new()
|
||||
panel.theme_type_variation = &"SolidPanel" # over the pause menu: none of it shows through
|
||||
add_child(panel)
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 30)
|
||||
margin.add_theme_constant_override("margin_" + side, 14)
|
||||
panel.add_child(margin)
|
||||
var box := VBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 22)
|
||||
|
|
@ -26,7 +29,7 @@ func _ready() -> void:
|
|||
message.custom_minimum_size = Vector2(560.0, 0.0)
|
||||
message.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
message.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
message.add_theme_font_size_override("font_size", 24)
|
||||
message.add_theme_font_size_override("font_size", 30)
|
||||
box.add_child(message)
|
||||
var row := HBoxContainer.new()
|
||||
row.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
|
|
@ -34,11 +37,13 @@ func _ready() -> void:
|
|||
box.add_child(row)
|
||||
yes_button = Button.new()
|
||||
yes_button.custom_minimum_size = Vector2(240.0, 54.0)
|
||||
yes_button.add_theme_font_size_override("font_size", 30)
|
||||
yes_button.pressed.connect(_yes)
|
||||
row.add_child(yes_button)
|
||||
no_button = Button.new()
|
||||
no_button.text = "Cancel"
|
||||
no_button.custom_minimum_size = Vector2(200.0, 54.0)
|
||||
no_button.add_theme_font_size_override("font_size", 30)
|
||||
no_button.pressed.connect(close)
|
||||
row.add_child(no_button)
|
||||
visible = false
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class_name CoopHud
|
||||
extends Control
|
||||
## The co-op part of the HUD (Main adds it to the farm's HUD layer):
|
||||
## * the partner panel, above your own health: their name in their color (P1 gold, P2 blue),
|
||||
## * the partner panel, under your own portrait and health: their name in their color (P1 gold, P2 blue),
|
||||
## their health pips, what they're doing (down until morning, patching, gathering, fear
|
||||
## ready), a speaker mark while their voice comes through, and the ping; plus your
|
||||
## microphone (on / muted, [M])
|
||||
|
|
@ -9,7 +9,7 @@ extends Control
|
|||
## * the lobby's status while hosting with nobody in yet ("Waiting for a friend to join ...")
|
||||
## Both scarecrows also wear name tags (PlayerCharacter.set_tag).
|
||||
|
||||
const PANEL := Rect2(22.0, -318.0, 336.0, 104.0) # from the bottom left
|
||||
const PANEL := Rect2(22.0, 150.0, 336.0, 104.0) # from the top left
|
||||
const PIP := Vector2(14.0, 9.0)
|
||||
const ARROW_MARGIN := 60.0
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ func _process(delta: float) -> void:
|
|||
_arrow_label.visible = false
|
||||
if other == null:
|
||||
return
|
||||
var base := Vector2(PANEL.position.x, size.y + PANEL.position.y)
|
||||
var base := PANEL.position
|
||||
_name.text = other.label()
|
||||
_name.add_theme_color_override("font_color", other.color())
|
||||
_name.position = base + Vector2(14.0, 6.0)
|
||||
|
|
@ -129,9 +129,9 @@ func _draw() -> void:
|
|||
if session == null or not session.is_active() or sim == null or sim.partner == null:
|
||||
return
|
||||
var other := sim.avatars[0] if session.is_client() else sim.partner
|
||||
var base := Vector2(PANEL.position.x, size.y + PANEL.position.y)
|
||||
draw_rect(Rect2(base, PANEL.size), Color(0.0, 0.0, 0.0, 0.45))
|
||||
draw_rect(Rect2(base, Vector2(5.0, PANEL.size.y)), other.color())
|
||||
var base := PANEL.position
|
||||
Sketch.box(self, Rect2(base, PANEL.size), Sketch.WASH, Color(0, 0, 0, 0), 0.0, 601.0)
|
||||
Sketch.line(self, base + Vector2(3.0, 4.0), base + Vector2(3.0, PANEL.size.y - 4.0), other.color(), 5.0, 602.0)
|
||||
var hp := other.kit.hp()
|
||||
var top := other.kit.max_hp()
|
||||
for i in top:
|
||||
|
|
@ -162,9 +162,7 @@ func _measure_ping() -> void:
|
|||
|
||||
func _label(font_size: int) -> Label:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
l.add_theme_constant_override("outline_size", 6)
|
||||
Sketch.style(l, font_size + 2, Sketch.TEXT, 6)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
l.visible = false
|
||||
add_child(l)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ extends Node
|
|||
## WaveDirector), sunrise makes them retreat (carriers keep running), the end of the dawn grace
|
||||
## sends the rest off the farm with whatever they carry, returns dropped loot (and the animals
|
||||
## still following the scarecrow) home, and regrows the gather points, and every new morning (also after a retry) resets the
|
||||
## theft state from the farm state. DayNight lights the phases; PhaseHud, AssetHud, ReviewPanel,
|
||||
## and the other HUD parts show them. Co-op (CoopSession): a second scarecrow (add_partner) is
|
||||
## theft state from the farm state. DayNight lights the phases; PhaseHud, ReviewPanel, and the
|
||||
## other HUD parts show them. Co-op (CoopSession): a second scarecrow (add_partner) is
|
||||
## simulated alongside the first, and on the partner's machine the farm is a replica: nothing is
|
||||
## simulated there, the host's state is applied instead (replica = true), and player, scarecrow,
|
||||
## combat, and interactions are that machine's own scarecrow's (player 2's).
|
||||
|
|
@ -42,7 +42,6 @@ const NIGHT_PLAN_PATH := "res://game/resources/nights/night_%d.tres"
|
|||
@export var resource_hud: ResourceHud
|
||||
@export var build_hud: BuildHud
|
||||
@export var phase_hud: PhaseHud
|
||||
@export var asset_hud: AssetHud
|
||||
@export var review_panel: ReviewPanel
|
||||
@export var upgrade_panel: UpgradePanel
|
||||
@export var shed_panel: UpgradePanel
|
||||
|
|
@ -146,7 +145,7 @@ func _ready() -> void:
|
|||
shed_stock = ShedStock.new()
|
||||
shed_stock.name = "ShedStock"
|
||||
add_child(shed_stock)
|
||||
shed_stock.setup(campaign, shed_zone, player) # every pile prop in place for the navigation
|
||||
shed_stock.setup(campaign, shed_zone) # every pile prop in place for the navigation
|
||||
nav.build(get_parent(), zones.playable.grow(5.0), config.nav_cell_size, config.enemy_radius + config.nav_inflate_margin)
|
||||
shed_stock.refresh()
|
||||
# #13: three CROP_FIELD zones (the original field, lettuce/cabbage, corn). #20: each keeps its
|
||||
|
|
@ -293,13 +292,10 @@ func _ready() -> void:
|
|||
combat.equip(w))
|
||||
if resource_hud != null:
|
||||
resource_hud.setup(campaign)
|
||||
resource_hud.structures = structures
|
||||
if build_hud != null:
|
||||
build_hud.setup(build, campaign)
|
||||
if phase_hud != null:
|
||||
phase_hud.setup(campaign, waves, enemies)
|
||||
if asset_hud != null:
|
||||
asset_hud.setup(campaign)
|
||||
if review_panel != null:
|
||||
review_panel.setup(campaign, structures)
|
||||
review_panel.animals = animals
|
||||
|
|
@ -307,6 +303,7 @@ func _ready() -> void:
|
|||
review_panel.refresh()
|
||||
if hud != null:
|
||||
hud.setup(scarecrow, campaign, combat)
|
||||
hud.build = build
|
||||
if hud != null and hud.get_parent() != null:
|
||||
var radar_hud := RadarHud.new()
|
||||
radar_hud.name = "RadarHud"
|
||||
|
|
@ -561,7 +558,6 @@ func set_local(a: Avatar) -> void:
|
|||
audio.focus = a.body
|
||||
if alerts != null:
|
||||
alerts.player = a.body
|
||||
shed_stock.player = a.body
|
||||
|
||||
|
||||
## Restarts every flow-field job for the current structure layout.
|
||||
|
|
|
|||
|
|
@ -6,7 +6,9 @@ extends RefCounted
|
|||
## * Controls: the dead zones of the move stick (the move_* actions) and the aim stick
|
||||
## (GameConfig.aim_dead_zone). Mouse aim follows the cursor directly, so it has no
|
||||
## sensitivity to set.
|
||||
## * Display: fullscreen, VSync, and the 3D resolution scale (the HUD stays sharp).
|
||||
## * Display: fullscreen, VSync, the pixel size (the 3D view renders that many times smaller
|
||||
## and scales back up with sharp pixels, for ToonLook's pixel-art look; 1 = off), and the 3D
|
||||
## resolution scale, used when the pixel size is 1 (the HUD stays sharp either way).
|
||||
## * Gameplay: whether the tips show on the first day and night (Tutorial).
|
||||
## * Co-op: your player name, and whether your microphone is sent in voice chat.
|
||||
## Values missing from the file or out of range fall back to the defaults, so an old or
|
||||
|
|
@ -17,12 +19,14 @@ const BUSES: Array[String] = ["Master", "Music", "SFX", "Ambience", "Voice"]
|
|||
const BUS_NAMES := {"Master": "Master volume", "Music": "Music and stingers", "SFX": "Sound effects", "Ambience": "Ambience",
|
||||
"Voice": "Voice chat (your friend)"}
|
||||
const DEFAULT_VOLUME := {"Master": 0.8, "Music": 0.7, "SFX": 0.8, "Ambience": 0.6, "Voice": 1.0}
|
||||
const MAX_PIXEL_SIZE := 8
|
||||
|
||||
var volume := DEFAULT_VOLUME.duplicate()
|
||||
var move_dead_zone := 0.2
|
||||
var aim_dead_zone := 0.3
|
||||
var fullscreen := false
|
||||
var vsync := true
|
||||
var pixel_size := 4
|
||||
var resolution_scale := 1.0
|
||||
var show_tips := true
|
||||
## Co-op: your name for the lobby and the name tag, and whether your microphone is sent.
|
||||
|
|
@ -41,6 +45,7 @@ static func load_from(path: String = PATH) -> GameSettings:
|
|||
g.aim_dead_zone = _number(f.get_value("controls", "aim_dead_zone", g.aim_dead_zone), 0.05, 0.9, g.aim_dead_zone)
|
||||
g.fullscreen = _flag(f.get_value("display", "fullscreen", g.fullscreen), g.fullscreen)
|
||||
g.vsync = _flag(f.get_value("display", "vsync", g.vsync), g.vsync)
|
||||
g.pixel_size = roundi(_number(f.get_value("display", "pixel_size", g.pixel_size), 1.0, MAX_PIXEL_SIZE, g.pixel_size))
|
||||
g.resolution_scale = _number(f.get_value("display", "resolution_scale", g.resolution_scale), 0.5, 1.0, g.resolution_scale)
|
||||
g.show_tips = _flag(f.get_value("gameplay", "show_tips", g.show_tips), g.show_tips)
|
||||
var n: Variant = f.get_value("coop", "player_name", "")
|
||||
|
|
@ -57,6 +62,7 @@ func save_to(path: String = PATH) -> Error:
|
|||
f.set_value("controls", "aim_dead_zone", aim_dead_zone)
|
||||
f.set_value("display", "fullscreen", fullscreen)
|
||||
f.set_value("display", "vsync", vsync)
|
||||
f.set_value("display", "pixel_size", pixel_size)
|
||||
f.set_value("display", "resolution_scale", resolution_scale)
|
||||
f.set_value("gameplay", "show_tips", show_tips)
|
||||
f.set_value("coop", "player_name", player_name)
|
||||
|
|
@ -80,7 +86,7 @@ func apply(viewport: Viewport, config: GameConfig = null) -> void:
|
|||
if config != null:
|
||||
config.aim_dead_zone = aim_dead_zone
|
||||
if viewport != null:
|
||||
viewport.scaling_3d_scale = resolution_scale
|
||||
apply_pixels(viewport)
|
||||
if DisplayServer.get_name() == "headless":
|
||||
return
|
||||
var mode := DisplayServer.window_get_mode()
|
||||
|
|
@ -91,6 +97,20 @@ func apply(viewport: Viewport, config: GameConfig = null) -> void:
|
|||
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED if vsync else DisplayServer.VSYNC_DISABLED)
|
||||
|
||||
|
||||
## The 3D view's size: pixel_size > 1 renders it that many times smaller with sharp (nearest)
|
||||
## upscaling and no MSAA, so each art pixel is a clean block; 1 renders it at resolution_scale
|
||||
## with the project's MSAA.
|
||||
func apply_pixels(viewport: Viewport) -> void:
|
||||
if pixel_size > 1:
|
||||
viewport.scaling_3d_mode = Viewport.SCALING_3D_MODE_NEAREST
|
||||
viewport.scaling_3d_scale = 1.0 / pixel_size
|
||||
viewport.msaa_3d = Viewport.MSAA_DISABLED
|
||||
else:
|
||||
viewport.scaling_3d_mode = Viewport.SCALING_3D_MODE_BILINEAR
|
||||
viewport.scaling_3d_scale = resolution_scale
|
||||
viewport.msaa_3d = ProjectSettings.get_setting("rendering/anti_aliasing/quality/msaa_3d", Viewport.MSAA_DISABLED)
|
||||
|
||||
|
||||
static func _number(v: Variant, lo: float, hi: float, fallback: float) -> float:
|
||||
if not (v is float or v is int):
|
||||
return fallback
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@ func _ready() -> void:
|
|||
farm.process_mode = Node.PROCESS_MODE_PAUSABLE
|
||||
settings = GameSettings.load_from(settings_path)
|
||||
settings.apply(get_viewport(), sim.config)
|
||||
var look := ToonLook.new() # toon shading and pixel outlines on the farm
|
||||
look.name = "ToonLook"
|
||||
add_child(look)
|
||||
sim.campaign.save_path = save_path
|
||||
if sim.end_panel != null:
|
||||
sim.end_panel.has_menu = true
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
class_name PauseMenu
|
||||
extends CenterContainer
|
||||
## Escape / Start during play (Main pauses the tree): where you are, then Resume, Restart the
|
||||
## night, Settings, Save & quit to the menu, and Quit the game, with a reminder of what Continue
|
||||
## picks up (the vacation is saved every morning).
|
||||
## Escape / Start during play (Main pauses the tree), hand-drawn like the HUD's pouch panel
|
||||
## (UiTheme.sketch): where you are and what's left to protect
|
||||
## (crops, animals, supplies; asset_counts), then Resume, Restart the night, Settings, Save & quit
|
||||
## to the menu, and Quit the game, with a reminder of what Continue picks up (the vacation is
|
||||
## saved every morning).
|
||||
|
||||
signal resume_requested
|
||||
signal restart_requested
|
||||
|
|
@ -17,15 +19,17 @@ var menu_button: Button
|
|||
var quit_button: Button
|
||||
var _where: Label
|
||||
var _note: Label
|
||||
var _assets: Array[Label] = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
theme = UiTheme.sketch()
|
||||
var panel := PanelContainer.new()
|
||||
add_child(panel)
|
||||
var margin := MarginContainer.new()
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 32)
|
||||
margin.add_theme_constant_override("margin_" + side, 14)
|
||||
panel.add_child(margin)
|
||||
var box := VBoxContainer.new()
|
||||
box.add_theme_constant_override("separation", 14)
|
||||
|
|
@ -33,13 +37,24 @@ func _ready() -> void:
|
|||
var title := Label.new()
|
||||
title.text = "Paused"
|
||||
title.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
title.add_theme_font_size_override("font_size", 48)
|
||||
title.add_theme_color_override("font_color", UiTheme.GOLD)
|
||||
title.add_theme_font_size_override("font_size", 56)
|
||||
box.add_child(title)
|
||||
box.add_child(HSeparator.new())
|
||||
_where = Label.new()
|
||||
_where.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_where.add_theme_font_size_override("font_size", 22)
|
||||
_where.add_theme_font_size_override("font_size", 28)
|
||||
_where.add_theme_color_override("font_color", Sketch.DIM)
|
||||
box.add_child(_where)
|
||||
var assets := HBoxContainer.new()
|
||||
assets.alignment = BoxContainer.ALIGNMENT_CENTER
|
||||
assets.add_theme_constant_override("separation", 30)
|
||||
box.add_child(assets)
|
||||
for c in 3:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", 30)
|
||||
l.add_theme_color_override("font_color", LootSystem.CATEGORY_COLORS[c])
|
||||
assets.add_child(l)
|
||||
_assets.append(l)
|
||||
resume_button = _button(box, "Resume")
|
||||
resume_button.pressed.connect(func() -> void: resume_requested.emit())
|
||||
restart_button = _button(box, "Restart the night")
|
||||
|
|
@ -54,8 +69,8 @@ func _ready() -> void:
|
|||
_note.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_note.custom_minimum_size = Vector2(520.0, 0.0)
|
||||
_note.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_note.add_theme_font_size_override("font_size", 18)
|
||||
_note.add_theme_color_override("font_color", Color(0.72, 0.74, 0.68))
|
||||
_note.add_theme_font_size_override("font_size", 22)
|
||||
_note.add_theme_color_override("font_color", Sketch.DIM)
|
||||
box.add_child(_note)
|
||||
visible = false
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
|
@ -66,6 +81,10 @@ func open(campaign: CampaignController, coop: int = 0) -> void:
|
|||
var s := campaign.state
|
||||
var phase: String = CampaignController.Phase.keys()[s.phase]
|
||||
_where.text = "Night %d of %d · %s" % [s.night, campaign.config.campaign_nights, phase.replace("_", " ").capitalize()]
|
||||
var counts := asset_counts(s)
|
||||
for c in 3:
|
||||
_assets[c].text = counts[c]
|
||||
_assets[c].visible = counts[c] != ""
|
||||
var over := campaign.outcome == CampaignController.Outcome.VACATION_COMPLETE
|
||||
restart_button.disabled = over or coop == 2
|
||||
menu_button.text = "Leave the game" if coop == 2 else "Save & quit to menu"
|
||||
|
|
@ -80,6 +99,23 @@ func open(campaign: CampaignController, coop: int = 0) -> void:
|
|||
resume_button.grab_focus.call_deferred()
|
||||
|
||||
|
||||
## "Crops 28/30", "Animals 7/8", "Supplies 23" (the shed's stock plus any sacks still on the
|
||||
## farm): what's left to protect, "" for a category not in play.
|
||||
static func asset_counts(s: FarmState) -> PackedStringArray:
|
||||
return PackedStringArray(["Crops %d/%d" % [s.crops, s.crops_total] if s.crops_total > 0 else "",
|
||||
"Animals %d/%d" % [s.animals, s.animals_total] if s.animals_total > 0 else "",
|
||||
"Supplies %d" % s.supplies if s.supplies_total > 0 else ""])
|
||||
|
||||
|
||||
## The assets line as shown: "Crops 28/30 · Animals 7/8 · Supplies 23" (tests).
|
||||
func describe_assets() -> String:
|
||||
var parts := PackedStringArray()
|
||||
for l in _assets:
|
||||
if l.visible:
|
||||
parts.append(l.text)
|
||||
return " · ".join(parts)
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
draw_rect(Rect2(Vector2.ZERO, size), Color(0.0, 0.0, 0.0, 0.4)) # dims what's behind
|
||||
|
||||
|
|
@ -93,6 +129,6 @@ func _button(parent: Control, text: String) -> Button:
|
|||
var b := Button.new()
|
||||
b.text = text
|
||||
b.custom_minimum_size = Vector2(420.0, 56.0)
|
||||
b.add_theme_font_size_override("font_size", 24)
|
||||
b.add_theme_font_size_override("font_size", 30)
|
||||
parent.add_child(b)
|
||||
return b
|
||||
|
|
|
|||
|
|
@ -1,22 +1,27 @@
|
|||
class_name PhaseHud
|
||||
extends Control
|
||||
## Top-left phase indicator: a dial whose ring fills over the current phase with a sun (day), a
|
||||
## setting sun (dusk), a moon (night), or a rising sun (dawn) in it; "Night N of M"; the phase
|
||||
## and its time left; and a hint line (what tonight brings at dusk, thieves on the farm at night, the
|
||||
## early-night key when allowed). Each phase also announces itself with a banner that fades;
|
||||
## from dusk into the night, tonight's dusk hint (NightPlan.dusk_hint) shows under it.
|
||||
## Top-right day and time, hand-drawn (Sketch): a sun by day (a moon at night) on a light wash,
|
||||
## "Day N of M", the time left in the phase ("1:42 until Dusk"), and a thin teal line filling
|
||||
## over the phase; under it, a hint when there is one (what tonight brings at dusk, who's on the
|
||||
## farm at night, the early-night key when allowed). Each phase also announces itself with a
|
||||
## banner that fades; from dusk into the night, tonight's dusk hint (NightPlan.dusk_hint) shows
|
||||
## under it.
|
||||
|
||||
const DIAL_CENTER := Vector2(62.0, 64.0)
|
||||
const DIAL_RADIUS := 34.0
|
||||
const BANNER_TIME := 3.0
|
||||
const WIDGET := Vector2(430.0, 112.0)
|
||||
const MARGIN := Vector2(24.0, 18.0)
|
||||
const PROGRESS := Color(0.3, 0.82, 0.8)
|
||||
const HINT_SIZE := 22
|
||||
const HINT_LINE := 28.0
|
||||
|
||||
var campaign: CampaignController
|
||||
var waves: WaveDirector
|
||||
var enemies: EnemySystem
|
||||
|
||||
var _title: Label
|
||||
var _sub: Label
|
||||
var _hint: Label
|
||||
## What the widget shows: "Day 2 of 30", "1:42 until Dusk", and the hint ("" for none).
|
||||
var title := ""
|
||||
var sub := ""
|
||||
var hint := ""
|
||||
var _banner: Label
|
||||
var _banner_left: float = 0.0
|
||||
var _dusk_hint: Label
|
||||
|
|
@ -33,38 +38,40 @@ func setup(p_campaign: CampaignController, p_waves: WaveDirector, p_enemies: Ene
|
|||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_title = _label(28, Vector2(112.0, 26.0))
|
||||
_sub = _label(22, Vector2(112.0, 62.0))
|
||||
_hint = _label(19, Vector2(112.0, 92.0))
|
||||
_banner = Label.new()
|
||||
_banner.set_anchors_preset(Control.PRESET_TOP_WIDE)
|
||||
_banner.offset_top = 250.0
|
||||
_banner.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_banner.add_theme_font_size_override("font_size", 52)
|
||||
_banner.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
_banner.add_theme_constant_override("outline_size", 12)
|
||||
Sketch.style(_banner, 60, Sketch.TEXT, 14)
|
||||
_banner.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_banner.modulate.a = 0.0
|
||||
add_child(_banner)
|
||||
_dusk_hint = Label.new()
|
||||
_dusk_hint.set_anchors_preset(Control.PRESET_CENTER_TOP)
|
||||
_dusk_hint.offset_top = 330.0
|
||||
_dusk_hint.offset_top = 336.0
|
||||
_dusk_hint.offset_left = -520.0
|
||||
_dusk_hint.offset_right = 520.0
|
||||
_dusk_hint.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
||||
_dusk_hint.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_dusk_hint.add_theme_font_size_override("font_size", 26)
|
||||
_dusk_hint.add_theme_color_override("font_color", Color(1.0, 0.88, 0.7))
|
||||
_dusk_hint.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
_dusk_hint.add_theme_constant_override("outline_size", 8)
|
||||
Sketch.style(_dusk_hint, 30, Color(1.0, 0.88, 0.7), 10)
|
||||
_dusk_hint.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_dusk_hint.visible = false
|
||||
add_child(_dusk_hint)
|
||||
|
||||
|
||||
## "Night 1 of 5 · Day · 2:34 left", as the HUD shows it (also used by tests).
|
||||
## "Day 1 of 5 · 2:34 until Dusk", as the HUD shows it (also used by tests).
|
||||
func describe() -> String:
|
||||
return "%s · %s" % [_title.text, _sub.text]
|
||||
return "%s · %s" % [title, sub]
|
||||
|
||||
|
||||
## The widget's rect (canvas), and the bottom of it and its hint (RadarHud sits under that).
|
||||
func widget_rect() -> Rect2:
|
||||
return Rect2(Vector2(size.x - MARGIN.x - WIDGET.x, MARGIN.y), WIDGET)
|
||||
|
||||
|
||||
func bottom() -> float:
|
||||
var lines := hint.count("\n") + 1 if hint != "" else 0
|
||||
return widget_rect().end.y + 10.0 + lines * HINT_LINE
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
|
@ -72,29 +79,28 @@ func _process(delta: float) -> void:
|
|||
return
|
||||
var s := campaign.state
|
||||
var cfg := campaign.config
|
||||
_title.text = "Night %d of %d" % [s.night, cfg.campaign_nights]
|
||||
title = "Day %d of %d" % [s.night, cfg.campaign_nights]
|
||||
var left := _clock(s.phase_time_left)
|
||||
var hint := ""
|
||||
hint = ""
|
||||
match s.phase:
|
||||
CampaignController.Phase.MORNING:
|
||||
_sub.text = "Morning"
|
||||
sub = "Morning"
|
||||
CampaignController.Phase.DAY:
|
||||
_sub.text = "Day · %s left" % left
|
||||
sub = "%s until Dusk" % left
|
||||
if campaign.can_start_night_early():
|
||||
hint = "[N] start the night early"
|
||||
CampaignController.Phase.DUSK:
|
||||
_sub.text = "Dusk · nightfall in %s" % left
|
||||
sub = "%s until Nightfall" % left
|
||||
hint = "\n".join(waves.tonight_warning()) if waves != null else ""
|
||||
CampaignController.Phase.NIGHT:
|
||||
_sub.text = "Night · sunrise in %s" % left
|
||||
sub = "%s until Dawn" % left
|
||||
hint = on_the_farm(enemies)
|
||||
CampaignController.Phase.DAWN:
|
||||
_sub.text = "Dawn · the aliens are fleeing (%s)" % left
|
||||
sub = "%s until Morning" % left
|
||||
CampaignController.Phase.FARMERS_RETURN:
|
||||
_sub.text = "The farmers are back"
|
||||
sub = "The farmers are back"
|
||||
CampaignController.Phase.GAME_OVER:
|
||||
_sub.text = "Game over"
|
||||
_hint.text = hint
|
||||
sub = "Game over"
|
||||
var plan := waves.tonight() if waves != null else null
|
||||
_dusk_hint.visible = plan != null and plan.dusk_hint != "" and waves.warning_active()
|
||||
if _dusk_hint.visible:
|
||||
|
|
@ -109,25 +115,21 @@ func _draw() -> void:
|
|||
return
|
||||
var s := campaign.state
|
||||
var length := campaign.phase_length(s.phase)
|
||||
var frac := 1.0 - s.phase_time_left / length if is_finite(length) and length > 0.0 else 0.0
|
||||
var phase := s.phase
|
||||
var night := phase == CampaignController.Phase.NIGHT
|
||||
var hint_size := _hint.get_minimum_size() if _hint.text != "" else Vector2.ZERO
|
||||
var box := Vector2(maxf(430.0, 112.0 + hint_size.x + 18.0), maxf(104.0, 92.0 + hint_size.y - 14.0 + 22.0))
|
||||
draw_rect(Rect2(Vector2(14.0, 14.0), box), Color(0.0, 0.0, 0.0, 0.42))
|
||||
draw_circle(DIAL_CENTER, DIAL_RADIUS, Color(0.08, 0.1, 0.18, 0.95) if night else Color(0.25, 0.45, 0.7, 0.95))
|
||||
var ring := Color(0.6, 0.7, 1.0) if night else Color(1.0, 0.85, 0.4)
|
||||
draw_arc(DIAL_CENTER, DIAL_RADIUS - 4.0, -PI * 0.5, -PI * 0.5 + TAU * frac, 48, ring, 5.0)
|
||||
match phase:
|
||||
CampaignController.Phase.NIGHT:
|
||||
draw_circle(DIAL_CENTER, 15.0, Color(0.93, 0.95, 1.0))
|
||||
draw_circle(DIAL_CENTER + Vector2(7.0, -5.0), 13.0, Color(0.08, 0.1, 0.18))
|
||||
CampaignController.Phase.DUSK, CampaignController.Phase.DAWN:
|
||||
var c := DIAL_CENTER + Vector2(0.0, 8.0)
|
||||
draw_circle(c, 15.0, Color(1.0, 0.55, 0.3) if phase == CampaignController.Phase.DUSK else Color(1.0, 0.72, 0.6))
|
||||
draw_rect(Rect2(c + Vector2(-20.0, 4.0), Vector2(40.0, 16.0)), Color(0.12, 0.2, 0.12))
|
||||
_:
|
||||
draw_circle(DIAL_CENTER, 15.0, Color(1.0, 0.88, 0.35))
|
||||
var frac := clampf(1.0 - s.phase_time_left / length, 0.0, 1.0) if is_finite(length) and length > 0.0 else 0.0
|
||||
var r := widget_rect()
|
||||
Sketch.box(self, r, Sketch.WASH, Color(0, 0, 0, 0), 0.0, 301.0)
|
||||
Sketch.icon(self, "moon" if s.phase == CampaignController.Phase.NIGHT else "sun", Rect2(r.position + Vector2(4.0, 4.0), Vector2(104.0, 104.0)))
|
||||
var right := r.end.x - 18.0
|
||||
Sketch.text(self, Vector2(right, r.position.y + 6.0), title, 40, Sketch.TEXT, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
Sketch.text(self, Vector2(right, r.position.y + 54.0), sub, 36, Sketch.TEXT, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
var y := r.end.y + 1.0
|
||||
Sketch.line(self, Vector2(r.position.x + 6.0, y), Vector2(r.end.x - 6.0, y), Color(PROGRESS, 0.25), 4.0, 302.0, 0.8)
|
||||
if frac > 0.0:
|
||||
Sketch.line(self, Vector2(r.position.x + 6.0, y), Vector2(r.position.x + 6.0 + (r.size.x - 12.0) * frac, y), PROGRESS, 4.0, 302.0, 0.8)
|
||||
var lines := hint.split("\n", false)
|
||||
for i in lines.size():
|
||||
Sketch.text(self, Vector2(right, r.end.y + 10.0 + i * HINT_LINE), lines[i], HINT_SIZE, Color(1.0, 0.93, 0.75),
|
||||
HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
|
||||
|
||||
func _on_phase_changed(phase: CampaignController.Phase, _previous: CampaignController.Phase) -> void:
|
||||
|
|
@ -183,13 +185,3 @@ static func join_words(words: PackedStringArray) -> String:
|
|||
return "".join(words)
|
||||
return ", ".join(words.slice(0, words.size() - 1)) + " and " + words[words.size() - 1]
|
||||
|
||||
|
||||
func _label(font_size: int, at: Vector2) -> Label:
|
||||
var l := Label.new()
|
||||
l.position = at
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
l.add_theme_constant_override("outline_size", 6)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(l)
|
||||
return l
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class_name RadarHud
|
||||
extends Control
|
||||
## Top-right minimap, under ResourceHud's materials readout (Task #8): the playable farm's
|
||||
## Top-right minimap, under PhaseHud's day and time (Task #8): the playable farm's
|
||||
## outline scaled into a small panel, a white dot for the local scarecrow, and one dot per alive
|
||||
## enemy within GameConfig.radar_range meters of it, colored by type. Hidden unless the Radar
|
||||
## upgrade is bought (Upgrades.owned(state, "radar")); like the Alien Ray, it's a hidden shed item
|
||||
|
|
@ -8,12 +8,11 @@ extends Control
|
|||
## GameConfig.radar_refresh seconds rather than every frame, matching the "sweep" feel of a radar
|
||||
## rather than a live camera.
|
||||
|
||||
## Panel size, and its offset from the screen's top-right corner (below ResourceHud, which uses
|
||||
## roughly the top 120 px of that corner: PhaseHud/AssetHud/ScarecrowHud/CoopHud leave the rest of
|
||||
## the right side clear).
|
||||
## Panel size, and its offset from the screen's top-right corner (MARGIN_TOP when there's no
|
||||
## PhaseHud; else just under its widget and hint, PhaseHud.bottom()).
|
||||
const MAP_SIZE := Vector2(190.0, 190.0)
|
||||
const MARGIN_RIGHT := 24.0
|
||||
const MARGIN_TOP := 140.0
|
||||
const MARGIN_TOP := 150.0
|
||||
const DOT_RADIUS := 4.0
|
||||
const PLAYER_RADIUS := 5.0
|
||||
## thief (alien), crow, breaker (alien robot), ufo: EnemySystem.TYPE_*.
|
||||
|
|
@ -40,9 +39,7 @@ func _ready() -> void:
|
|||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_title = Label.new()
|
||||
_title.text = "Radar"
|
||||
_title.add_theme_font_size_override("font_size", 18)
|
||||
_title.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
_title.add_theme_constant_override("outline_size", 6)
|
||||
Sketch.style(_title, 22, Sketch.TEXT, 6)
|
||||
_title.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_title)
|
||||
|
||||
|
|
@ -51,7 +48,10 @@ func _process(delta: float) -> void:
|
|||
visible = sim != null and sim.campaign != null and Upgrades.owned(sim.campaign.state, "radar")
|
||||
if not visible:
|
||||
return
|
||||
_title.position = _rect().position + Vector2(10.0, 6.0)
|
||||
var at := _rect().position + Vector2(10.0, 0.0)
|
||||
if at != _title.position:
|
||||
_title.position = at
|
||||
queue_redraw() # moved with PhaseHud's hint
|
||||
_refresh_left -= delta
|
||||
if _refresh_left <= 0.0:
|
||||
_refresh()
|
||||
|
|
@ -87,10 +87,9 @@ func _draw() -> void:
|
|||
if not visible:
|
||||
return
|
||||
var r := _rect()
|
||||
draw_rect(r, Color(0.0, 0.0, 0.0, 0.42))
|
||||
Sketch.box(self, r, Sketch.WASH, Color(0, 0, 0, 0), 0.0, 501.0)
|
||||
var inner := Rect2(r.position + Vector2(10.0, 30.0), r.size - Vector2(20.0, 40.0))
|
||||
draw_rect(inner, Color(0.08, 0.14, 0.08, 0.85))
|
||||
draw_rect(inner, Color(0.5, 0.7, 0.5, 0.6), false, 1.5)
|
||||
Sketch.box(self, inner, Color(0.08, 0.14, 0.08, 0.85), Color(0.6, 0.8, 0.6, 0.7), 2.0, 502.0)
|
||||
if sim == null or sim.zones == null:
|
||||
return
|
||||
var playable: Rect2 = sim.zones.playable
|
||||
|
|
@ -111,4 +110,5 @@ static func _to_map(inner: Rect2, playable: Rect2, world: Vector2) -> Vector2:
|
|||
|
||||
|
||||
func _rect() -> Rect2:
|
||||
return Rect2(Vector2(size.x - MARGIN_RIGHT - MAP_SIZE.x, MARGIN_TOP), MAP_SIZE)
|
||||
var top := sim.phase_hud.bottom() + 8.0 if sim != null and sim.phase_hud != null else MARGIN_TOP
|
||||
return Rect2(Vector2(size.x - MARGIN_RIGHT - MAP_SIZE.x, top), MAP_SIZE)
|
||||
|
|
|
|||
|
|
@ -1,79 +1,111 @@
|
|||
class_name ResourceHud
|
||||
extends Control
|
||||
## Top-right materials readout: what the supply shed holds, and what this machine's scarecrow
|
||||
## carries in its own pouch (with its capacity). A line flashes when its numbers change.
|
||||
## Bottom-left backpack, hand-drawn (Sketch): this machine's scarecrow's pouch, "used/capacity"
|
||||
## beside it, and a red dot once something new has gone into it since it was last opened (gone
|
||||
## again when the pouch is emptied). The pouch action (I / R3) opens the pouch panel over it, and
|
||||
## closes it again: each material carried, and how much of each the supply shed holds.
|
||||
|
||||
## The backpack icon, from the screen's bottom-left corner.
|
||||
const ICON := Rect2(26.0, -136.0, 108.0, 108.0)
|
||||
const PANEL_WIDTH := 410.0
|
||||
const ROW := 46.0
|
||||
const DOT := Color(0.92, 0.12, 0.1)
|
||||
const SHED := Color(1.0, 0.9, 0.62)
|
||||
|
||||
var campaign: CampaignController
|
||||
## The avatar slot whose pouch is shown (FarmSim.set_local: the partner's machine shows P2's).
|
||||
var slot: int = 0
|
||||
## The pouch panel is open.
|
||||
var open := false
|
||||
## Something went into the pouch since it was last opened.
|
||||
var new_items := false
|
||||
|
||||
## Set by FarmSim: shows how many structures stand.
|
||||
var structures: StructureSystem
|
||||
|
||||
var _shed: RichTextLabel
|
||||
var _pouch: RichTextLabel
|
||||
var _built: RichTextLabel
|
||||
var _last_shed := ""
|
||||
var _last_pouch := ""
|
||||
var _flash_shed: float = 0.0
|
||||
var _flash_pouch: float = 0.0
|
||||
var _last := {}
|
||||
|
||||
|
||||
func setup(p_campaign: CampaignController) -> void:
|
||||
campaign = p_campaign
|
||||
_last = campaign.state.resources.pouch_of(slot).duplicate()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
_shed = _line(20.0)
|
||||
_pouch = _line(52.0)
|
||||
_built = _line(84.0)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if campaign != null and is_visible_in_tree() and event.is_action_pressed("pouch", false):
|
||||
toggle()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func toggle() -> void:
|
||||
open = not open
|
||||
if open:
|
||||
new_items = false
|
||||
|
||||
|
||||
## "6/15": what the pouch holds, of what it can.
|
||||
func count_text() -> String:
|
||||
var r := campaign.state.resources
|
||||
return "%d/%d" % [r.pouch_total(slot), r.pouch_capacity]
|
||||
|
||||
|
||||
## The pouch panel's rows: {material, pouch, shed}, one per material (ResourceStore.MATERIALS).
|
||||
func rows() -> Array[Dictionary]:
|
||||
var out: Array[Dictionary] = []
|
||||
var r := campaign.state.resources
|
||||
var p := r.pouch_of(slot)
|
||||
for m in ResourceStore.MATERIALS:
|
||||
out.append({"material": m, "pouch": int(p.get(m, 0)), "shed": int(r.shed.get(m, 0))})
|
||||
return out
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var r := campaign.state.resources
|
||||
var shed := "Shed %s" % _amounts(r.shed)
|
||||
var total := r.pouch_total(slot)
|
||||
var pouch := "Pouch %d/%d %s" % [total, r.pouch_capacity, _amounts(r.pouch_of(slot)) if total > 0 else "empty"]
|
||||
if shed != _last_shed:
|
||||
_last_shed = shed
|
||||
_shed.text = shed
|
||||
_flash_shed = 1.0
|
||||
if pouch != _last_pouch:
|
||||
_last_pouch = pouch
|
||||
_pouch.text = pouch
|
||||
_flash_pouch = 1.0
|
||||
_flash_shed = maxf(_flash_shed - delta * 2.0, 0.0)
|
||||
_flash_pouch = maxf(_flash_pouch - delta * 2.0, 0.0)
|
||||
if structures != null:
|
||||
_built.text = "Built %d structures [B] build" % structures.count()
|
||||
_shed.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_shed)
|
||||
_pouch.modulate = Color.WHITE.lerp(Color(1.0, 1.0, 0.55), _flash_pouch)
|
||||
|
||||
|
||||
func _amounts(d: Dictionary) -> String:
|
||||
var parts: Array[String] = []
|
||||
var p := r.pouch_of(slot)
|
||||
for m in ResourceStore.MATERIALS:
|
||||
parts.append("[color=#%s]%s %d[/color]" % [GatherNode.COLORS[m].to_html(false), m.capitalize(), int(d.get(m, 0))])
|
||||
return " ".join(parts)
|
||||
if int(p.get(m, 0)) > int(_last.get(m, 0)) and not open:
|
||||
new_items = true
|
||||
_last = p.duplicate()
|
||||
if r.pouch_total(slot) == 0:
|
||||
new_items = false
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _line(y: float) -> RichTextLabel:
|
||||
var l := RichTextLabel.new()
|
||||
l.bbcode_enabled = true
|
||||
l.fit_content = true
|
||||
l.scroll_active = false
|
||||
l.autowrap_mode = TextServer.AUTOWRAP_OFF
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
l.add_theme_font_size_override("normal_font_size", 22)
|
||||
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
l.add_theme_constant_override("outline_size", 6)
|
||||
l.set_anchors_preset(Control.PRESET_TOP_RIGHT)
|
||||
l.offset_left = -520.0
|
||||
l.offset_right = -24.0
|
||||
l.offset_top = y
|
||||
add_child(l)
|
||||
return l
|
||||
func _draw() -> void:
|
||||
if campaign == null:
|
||||
return
|
||||
var icon := Rect2(Vector2(ICON.position.x, size.y + ICON.position.y), ICON.size)
|
||||
Sketch.icon(self, "backpack", icon)
|
||||
if new_items:
|
||||
var at := icon.position + Vector2(icon.size.x - 16.0, 16.0)
|
||||
draw_colored_polygon(Sketch.blob(at, 11.0, 11.0, 401.0, 0.04, 20), DOT)
|
||||
Sketch.circle(self, at, 11.5, Sketch.INK, 2.0, 402.0)
|
||||
Sketch.text(self, Vector2(icon.end.x + 4.0, icon.get_center().y - 18.0), count_text(), 42)
|
||||
if open:
|
||||
_draw_panel(icon)
|
||||
|
||||
|
||||
func _draw_panel(icon: Rect2) -> void:
|
||||
var list := rows()
|
||||
var height := 52.0 + list.size() * ROW + 12.0
|
||||
var r := Rect2(Vector2(icon.position.x - 4.0, icon.position.y - 14.0 - height), Vector2(PANEL_WIDTH, height))
|
||||
Sketch.panel(self, r, 411.0)
|
||||
var pouch_x := r.position.x + 290.0
|
||||
var shed_x := r.end.x - 26.0
|
||||
Sketch.text(self, r.position + Vector2(18.0, 8.0), "Pouch", 32)
|
||||
Sketch.text(self, Vector2(pouch_x, r.position.y + 14.0), "Carried", 24, Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
Sketch.text(self, Vector2(shed_x, r.position.y + 14.0), "Shed", 24, Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT, 6)
|
||||
Sketch.rule(self, r.position.x + 14.0, r.end.x - 14.0, r.position.y + 50.0, 412.0)
|
||||
for i in list.size():
|
||||
var row: Dictionary = list[i]
|
||||
var m: String = row["material"]
|
||||
var y := r.position.y + 56.0 + i * ROW
|
||||
Sketch.icon(self, m, Rect2(Vector2(r.position.x + 14.0, y), Vector2(40.0, 40.0)))
|
||||
Sketch.text(self, Vector2(r.position.x + 62.0, y + 2.0), m.capitalize(), 30, GatherNode.COLORS[m])
|
||||
var carried: int = row["pouch"]
|
||||
Sketch.text(self, Vector2(pouch_x, y + 2.0), str(carried), 30, Sketch.TEXT if carried > 0 else Sketch.DIM, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
Sketch.text(self, Vector2(shed_x, y + 2.0), str(row["shed"]), 30, SHED, HORIZONTAL_ALIGNMENT_RIGHT)
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ func refresh() -> void:
|
|||
_title.text = "The farmers are away"
|
||||
lines.append("Keep the farm safe for %d nights until they come home: the crops, the animals in the pen, and the supplies in the shed." % nights)
|
||||
lines.append("By day, gather wood, scrap, and straw (hold E), store them at the barn, and build defenses (B). There's more to gather off the farm, to the north, east, and south.")
|
||||
lines.append("At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or 1-2), and more weapons arrive there over the days.")
|
||||
lines.append("At night, stab aliens with your pitchfork (left mouse), scare them off (Q), and pick up anything they drop. Animals roam loose until you lead them into the pen: walk up to one and it follows you. The supply shed sells a corn shooter (switch weapons with Tab or the number keys), and more weapons arrive there over the days.")
|
||||
else:
|
||||
var e: Dictionary = s.night_log[s.night_log.size() - 1]
|
||||
_title.text = "Morning of day %d of %d" % [s.night, nights]
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ extends Node3D
|
|||
## scarecrow's from the start; or the corn shooter, Potato Cannon, Shurikens, Propane Torch, or
|
||||
## Alien Ray, every one bought at the supply shed, Upgrades.shop_of "shed"), and pumpkin bombs
|
||||
## in the off-hand (the left, also shed-bought). weapon_next (Tab / d-pad down) cycles through
|
||||
## the main weapons owned; weapon_1..2 (1-2) pick the first two only (Task #7 added more main
|
||||
## weapons than there are number keys — the rest are Tab-cycle only), both only outside build
|
||||
## mode (where those keys pick structures) and with no menu open. The off-hand holds the
|
||||
## the main weapons owned; weapon_1..6 (1-6) pick the first, second, ... of the ones owned
|
||||
## (owned_main: the HUD's hotbar slots, numbered the same way), both only outside build mode
|
||||
## (where those keys pick structures) and with no menu open. The off-hand holds the
|
||||
## off-hand weapon owned (OFFHAND_WEAPONS; there's no pick while there's only one). A main
|
||||
## weapon no longer owned (a retry from before it was bought) goes back to the pitchfork, an
|
||||
## off-hand one out of the hand. The Alien Ray stays hidden (GameConfig "hidden") until enough
|
||||
|
|
@ -85,13 +85,14 @@ const WEAPON_IDS: Array[String] = ["pitchfork", "corn_shooter", "pumpkin_bomb",
|
|||
"propane_torch", "alien_ray"]
|
||||
const WEAPON_NAMES: Array[String] = ["Pitchfork", "Corn shooter", "Pumpkin bombs", "Potato cannon", "Shurikens",
|
||||
"Propane torch", "Alien ray"]
|
||||
## The main weapons (Weapon), in the order weapon_next cycles them, and the off-hand ones.
|
||||
## weapon_1.. only picks the first SWITCH_ACTIONS.size() - 1 of MAIN_WEAPONS directly (no new
|
||||
## number-key actions were added for Task #7's four); the rest are reached by cycling.
|
||||
## The main weapons (Weapon), in the order weapon_next cycles them and the hotbar shows them, and
|
||||
## the off-hand ones. weapon_k picks the k-th main weapon owned (owned_main), one number key per
|
||||
## main weapon.
|
||||
const MAIN_WEAPONS: Array[int] = [Weapon.PITCHFORK, Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS,
|
||||
Weapon.PROPANE_TORCH, Weapon.ALIEN_RAY]
|
||||
const OFFHAND_WEAPONS: Array[int] = [Weapon.PUMPKIN_BOMB]
|
||||
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2"]
|
||||
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2", &"weapon_3", &"weapon_4",
|
||||
&"weapon_5", &"weapon_6"]
|
||||
## Main weapons that fire from the muzzle (SIDE_OFFSET/muzzle_distance), so aiming at a target
|
||||
## needs the same muzzle correction as the corn shooter's (attack_toward, the mouse in _update_aim).
|
||||
## The Propane Torch's band runs along the gun's line too (#17), and the Alien Ray's beam (#18).
|
||||
|
|
@ -199,6 +200,16 @@ func owns(w: int) -> bool:
|
|||
return w > 0 and w < WEAPON_IDS.size() and campaign != null and Upgrades.owned(campaign.state, WEAPON_IDS[w])
|
||||
|
||||
|
||||
## The main weapons this scarecrow owns, in MAIN_WEAPONS order: the hotbar's slots, weapon_k
|
||||
## picking the k-th.
|
||||
func owned_main() -> Array[int]:
|
||||
var out: Array[int] = []
|
||||
for w in MAIN_WEAPONS:
|
||||
if owns(w):
|
||||
out.append(w)
|
||||
return out
|
||||
|
||||
|
||||
## Takes the weapon up if it's owned: a main weapon into the hand, an off-hand one into the
|
||||
## off-hand. Returns whether it's there now.
|
||||
func equip(w: int) -> bool:
|
||||
|
|
@ -277,11 +288,10 @@ func tick(dt: float, can_switch: bool) -> void:
|
|||
return
|
||||
if p[&"weapon_next"]:
|
||||
cycle()
|
||||
# Only the first SWITCH_ACTIONS.size() - 1 main weapons have a number key (Task #7 added more
|
||||
# MAIN_WEAPONS than keys; the rest are Tab-cycle only).
|
||||
for k in mini(MAIN_WEAPONS.size(), SWITCH_ACTIONS.size() - 1):
|
||||
var owned := owned_main()
|
||||
for k in mini(owned.size(), SWITCH_ACTIONS.size() - 1):
|
||||
if p[SWITCH_ACTIONS[k + 1]]:
|
||||
equip(MAIN_WEAPONS[k])
|
||||
equip(owned[k])
|
||||
|
||||
|
||||
## One physics tick while the scarecrow can attack: update the aim, then attack with the main
|
||||
|
|
|
|||
|
|
@ -1,42 +1,49 @@
|
|||
class_name ScarecrowHud
|
||||
extends Control
|
||||
## Bottom-left status for the scarecrow: health as pips, the fear ability as a circle that
|
||||
## sweeps full while it cools down and flashes when it is ready again, the patch hint with its
|
||||
## progress, and once the Sprint upgrade is bought a sprint line (ready, seconds left, or
|
||||
## recharging); plus a red screen tint when the scarecrow is hit. Bottom-right, the weapons:
|
||||
## the main ones by number, the one in hand marked, and how to switch; under them the off-hand
|
||||
## (pumpkin bombs, marked when one is ready, else its recharge) and its button. The ones not
|
||||
## bought yet are greyed out (with where to buy them: Upgrades.shop_of).
|
||||
## The scarecrow's part of the HUD, hand-drawn (Sketch):
|
||||
## * Top-left: its portrait in a ring that is the fear ability's charge: a dim ring with a blue
|
||||
## arc sweeping round while fear recharges, glowing blue when it's ready (a flash as it
|
||||
## becomes ready); greyed out while the scarecrow is down. Beside it the health bar, one
|
||||
## segment per point of max health (red filled, grey empty; while patching, the segments the
|
||||
## patch will fill fill in), and under it, once the Sprint upgrade is bought, a thin green
|
||||
## bar: the sprint's stamina (draining while sprinting, filling back while it recharges).
|
||||
## * Bottom-center: the hotbar, one slot per main weapon owned (locked ones aren't shown),
|
||||
## numbered by the key that picks it (ScarecrowCombat.owned_main: weapon_k picks slot k), the
|
||||
## one in hand highlighted; then past a divider the off-hand weapons owned (pumpkin bombs), in a
|
||||
## bolder frame, darkened from the top while a bomb recharges. Hidden in build mode (BuildHud
|
||||
## has the bottom then).
|
||||
## * A red tint over the screen when the scarecrow is hit.
|
||||
|
||||
const PIP := Vector2(22.0, 16.0)
|
||||
const PIP_GAP := 5.0
|
||||
const FEAR_RADIUS := 26.0
|
||||
## Extra height of the panel for the sprint line.
|
||||
const SPRINT_ROW := 30.0
|
||||
## The weapon panel, from the bottom-right corner: its row height, and its width (its height grows
|
||||
## with ScarecrowCombat.MAIN_WEAPONS / OFFHAND_WEAPONS, see _weapons_rect / _offhand_top).
|
||||
const WEAPON_PANEL_WIDTH := 320.0
|
||||
const WEAPON_ROW := 30.0
|
||||
const PORTRAIT_CENTER := Vector2(78.0, 76.0)
|
||||
const PORTRAIT_RADIUS := 50.0
|
||||
const FEAR_COLOR := Color(0.36, 0.74, 1.0)
|
||||
const BAR_ORIGIN := Vector2(146.0, 32.0)
|
||||
const SEGMENT := Vector2(54.0, 22.0)
|
||||
const SEGMENT_GAP := 8.0
|
||||
const SEGMENT_SKEW := 7.0
|
||||
## The health bar grows a segment per point of max health up to this width, then its segments
|
||||
## get narrower.
|
||||
const BAR_MAX_WIDTH := 360.0
|
||||
const STAMINA_HEIGHT := 6.0
|
||||
const HEALTH := Color(0.88, 0.14, 0.12)
|
||||
const EMPTY := Color(0.62, 0.62, 0.6, 0.85)
|
||||
const STAMINA := Color(0.3, 0.9, 0.25)
|
||||
const SLOT := Vector2(78.0, 72.0)
|
||||
const SLOT_GAP := 16.0
|
||||
const DIVIDER_GAP := 30.0
|
||||
const HOTBAR_BOTTOM := 22.0
|
||||
|
||||
var kit: Scarecrow
|
||||
## This machine's scarecrow's weapons.
|
||||
var combat: ScarecrowCombat
|
||||
var campaign: CampaignController
|
||||
## The health line's name ("Scarecrow"; in co-op "P1 Scarecrow" / "P2 Scarecrow").
|
||||
var label := "Scarecrow"
|
||||
## Set by FarmSim: the hotbar hides in build mode.
|
||||
var build: BuildMode
|
||||
|
||||
var _tint: ColorRect
|
||||
var _hp_label: Label
|
||||
var _fear_label: Label
|
||||
var _patch_label: Label
|
||||
var _sprint_label: Label
|
||||
var _weapon_title: Label
|
||||
var _weapon_rows: Array[Label] = []
|
||||
var _weapon_hint: Label
|
||||
var _offhand_title: Label
|
||||
var _offhand_rows: Array[Label] = []
|
||||
var _hit: float = 0.0
|
||||
var _ready_flash: float = 0.0
|
||||
var _time: float = 0.0
|
||||
|
||||
|
||||
func setup(p_kit: Scarecrow, p_campaign: CampaignController, p_combat: ScarecrowCombat = null) -> void:
|
||||
|
|
@ -71,102 +78,48 @@ func _ready() -> void:
|
|||
_tint.color = Color(0.85, 0.05, 0.0, 0.0)
|
||||
_tint.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(_tint)
|
||||
_hp_label = _label(22)
|
||||
_fear_label = _label(20)
|
||||
_patch_label = _label(20)
|
||||
_sprint_label = _label(20)
|
||||
_weapon_title = _label(18)
|
||||
_weapon_title.text = "Main weapon"
|
||||
for i in ScarecrowCombat.MAIN_WEAPONS.size():
|
||||
_weapon_rows.append(_label(20))
|
||||
_weapon_hint = _label(16)
|
||||
_weapon_hint.text = "Switch: Tab / 1-2 / d-pad down"
|
||||
_offhand_title = _label(18)
|
||||
_offhand_title.text = "Off-hand right mouse / LT"
|
||||
for i in ScarecrowCombat.OFFHAND_WEAPONS.size():
|
||||
_offhand_rows.append(_label(20))
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
_time += delta
|
||||
_hit = maxf(_hit - delta * 2.5, 0.0)
|
||||
_ready_flash = maxf(_ready_flash - delta * 2.0, 0.0)
|
||||
_tint.color.a = 0.22 * _hit
|
||||
if kit == null:
|
||||
return
|
||||
var base := _base()
|
||||
var s := campaign.state
|
||||
_hp_label.text = "%s %d/%d" % [label, kit.hp(), kit.max_hp()]
|
||||
_hp_label.position = base + Vector2(0.0, -34.0)
|
||||
if not kit.alive:
|
||||
_fear_label.text = "Fear"
|
||||
elif kit.fear_left == 0.0:
|
||||
_fear_label.text = "Fear Q / LB"
|
||||
else:
|
||||
_fear_label.text = "Fear %.0f s" % ceilf(kit.fear_left)
|
||||
_fear_label.position = base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 34.0)
|
||||
if not kit.alive:
|
||||
_patch_label.text = "Patch"
|
||||
elif kit.patching:
|
||||
_patch_label.text = "Patching up..."
|
||||
elif kit.hp() >= kit.max_hp():
|
||||
_patch_label.text = "Patch (full health)"
|
||||
else:
|
||||
_patch_label.text = "Patch hold F / Y (%s)" % ResourceStore.describe(kit.config.costs.get("patch", {}))
|
||||
_patch_label.position = base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 62.0)
|
||||
var body := kit.player
|
||||
_sprint_label.visible = _sprint_shown()
|
||||
if _sprint_label.visible:
|
||||
if not kit.alive:
|
||||
_sprint_label.text = "Sprint"
|
||||
elif body.sprinting:
|
||||
_sprint_label.text = "Sprinting %.1f s" % body.sprint_left
|
||||
elif body.sprint_recharge > 0.0:
|
||||
_sprint_label.text = "Sprint %.0f s" % ceilf(body.sprint_recharge)
|
||||
else:
|
||||
_sprint_label.text = "Sprint hold Shift / L3"
|
||||
_sprint_label.position = base + Vector2(0.0, 100.0)
|
||||
_update_weapons()
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _update_weapons() -> void:
|
||||
var shown := combat != null
|
||||
for l: Label in [_weapon_title, _weapon_hint, _offhand_title] + _weapon_rows + _offhand_rows:
|
||||
l.visible = shown
|
||||
if not shown:
|
||||
return
|
||||
var at := _weapons_rect().position
|
||||
_weapon_title.position = at + Vector2(12.0, 6.0)
|
||||
# weapon_1.. only picks the first SWITCH_ACTIONS.size() - 1 (Task #7 added more main weapons
|
||||
# than there are number keys): only those rows get a number, the rest just their name.
|
||||
var keyed := ScarecrowCombat.SWITCH_ACTIONS.size() - 1
|
||||
for k in _weapon_rows.size():
|
||||
var w := ScarecrowCombat.MAIN_WEAPONS[k]
|
||||
var text := "%d %s" % [k + 1, ScarecrowCombat.WEAPON_NAMES[w]] if k < keyed else ScarecrowCombat.WEAPON_NAMES[w]
|
||||
_weapon_row(_weapon_rows[k], text, w, w == combat.weapon)
|
||||
_weapon_rows[k].position = at + Vector2(30.0, 30.0 + k * WEAPON_ROW)
|
||||
_weapon_hint.position = at + Vector2(12.0, 30.0 + _weapon_rows.size() * WEAPON_ROW + 2.0)
|
||||
_offhand_title.position = at + Vector2(12.0, _offhand_top() + 6.0)
|
||||
for k in _offhand_rows.size():
|
||||
var w := ScarecrowCombat.OFFHAND_WEAPONS[k]
|
||||
var text := ScarecrowCombat.WEAPON_NAMES[w]
|
||||
if w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.owns(w) and combat.bomb_left > 0.0:
|
||||
text += " %.0f s" % ceilf(combat.bomb_left)
|
||||
_weapon_row(_offhand_rows[k], text, w, _offhand_lit(w))
|
||||
_offhand_rows[k].position = at + Vector2(30.0, _offhand_top() + 30.0 + k * WEAPON_ROW)
|
||||
## Whether the green stamina bar shows: only once the Sprint upgrade is bought.
|
||||
func stamina_shown() -> bool:
|
||||
var body := kit.player if kit != null else null
|
||||
return body != null and body.config != null and body.can_sprint()
|
||||
|
||||
|
||||
## A weapon's row: greyed out until it's bought, gold when it's in hand (lit).
|
||||
func _weapon_row(l: Label, text: String, w: int, lit: bool) -> void:
|
||||
var color := Color(0.95, 0.95, 0.95)
|
||||
if not combat.owns(w):
|
||||
var shop := Upgrades.shop_of(campaign.config, ScarecrowCombat.WEAPON_IDS[w]) if campaign != null else "workbench"
|
||||
text += " (%s)" % ("supply shed" if shop == "shed" else "workbench")
|
||||
color = Color(0.55, 0.55, 0.55)
|
||||
elif lit:
|
||||
color = Color(1.0, 0.85, 0.3)
|
||||
l.text = text
|
||||
l.add_theme_color_override("font_color", color)
|
||||
## The green bar's fill, 0..1: the sprint left while sprinting, its recharge after, else full.
|
||||
func stamina() -> float:
|
||||
if not stamina_shown():
|
||||
return 1.0
|
||||
var body := kit.player
|
||||
if body.sprinting:
|
||||
return clampf(body.sprint_left / maxf(body.config.sprint_time, 0.001), 0.0, 1.0)
|
||||
if body.sprint_recharge > 0.0:
|
||||
return clampf(1.0 - body.sprint_recharge / maxf(body.config.sprint_cooldown, 0.001), 0.0, 1.0)
|
||||
return 1.0
|
||||
|
||||
|
||||
## The hotbar's slots as shown, left to right: {weapon, key (the number that picks it; 0 for
|
||||
## the off-hand), offhand, selected}. Empty while it's hidden (build mode, no weapons).
|
||||
func slots() -> Array[Dictionary]:
|
||||
var out: Array[Dictionary] = []
|
||||
if combat == null or (build != null and build.active):
|
||||
return out
|
||||
var owned := combat.owned_main()
|
||||
for k in owned.size():
|
||||
out.append({"weapon": owned[k], "key": k + 1 if k < ScarecrowCombat.SWITCH_ACTIONS.size() - 1 else 0,
|
||||
"offhand": false, "selected": owned[k] == combat.weapon})
|
||||
for w in ScarecrowCombat.OFFHAND_WEAPONS:
|
||||
if combat.owns(w):
|
||||
out.append({"weapon": w, "key": 0, "offhand": true, "selected": _offhand_lit(w)})
|
||||
return out
|
||||
|
||||
|
||||
## Whether the off-hand weapon is in the off-hand and ready (a pumpkin bomb not recharging).
|
||||
|
|
@ -174,73 +127,110 @@ func _offhand_lit(w: int) -> bool:
|
|||
return w == combat.offhand and not (w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.bomb_left > 0.0)
|
||||
|
||||
|
||||
## Top of the off-hand section, under the main weapon rows and the switch hint (grows with
|
||||
## ScarecrowCombat.MAIN_WEAPONS.size()).
|
||||
func _offhand_top() -> float:
|
||||
return 30.0 + ScarecrowCombat.MAIN_WEAPONS.size() * WEAPON_ROW + 32.0
|
||||
|
||||
|
||||
func _weapons_rect() -> Rect2:
|
||||
var height := _offhand_top() + 30.0 + ScarecrowCombat.OFFHAND_WEAPONS.size() * WEAPON_ROW + 12.0
|
||||
return Rect2(size - Vector2(WEAPON_PANEL_WIDTH + 36.0, height + 26.0), Vector2(WEAPON_PANEL_WIDTH, height))
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
if kit == null:
|
||||
return
|
||||
var base := _base()
|
||||
var s := campaign.state
|
||||
var height := 146.0 + (SPRINT_ROW if _sprint_shown() else 0.0)
|
||||
draw_rect(Rect2(base - Vector2(14.0, 46.0), Vector2(340.0, height)), Color(0.0, 0.0, 0.0, 0.42))
|
||||
var frac := float(kit.hp()) / float(maxi(kit.max_hp(), 1))
|
||||
var full := Color(0.45, 0.9, 0.35) if frac > 0.5 else (Color(1.0, 0.8, 0.2) if frac > 0.25 else Color(1.0, 0.3, 0.2))
|
||||
full = full.lerp(Color.WHITE, _hit * 0.6)
|
||||
for i in kit.max_hp():
|
||||
var r := Rect2(base + Vector2(i * (PIP.x + PIP_GAP), 0.0), PIP)
|
||||
draw_rect(r, full if i < kit.hp() else Color(0.15, 0.15, 0.15, 0.8))
|
||||
draw_rect(r, Color(0.0, 0.0, 0.0, 0.9), false, 2.0)
|
||||
# Fear: dark disc, a sweep that fills while cooling down, bright when ready.
|
||||
var c := base + Vector2(FEAR_RADIUS, 32.0 + FEAR_RADIUS)
|
||||
_draw_portrait()
|
||||
_draw_health()
|
||||
_draw_hotbar()
|
||||
|
||||
|
||||
func _draw_portrait() -> void:
|
||||
var c := PORTRAIT_CENTER
|
||||
var r := PORTRAIT_RADIUS
|
||||
var box := Rect2(c - Vector2(r, r) * 0.98, Vector2(r, r) * 1.96)
|
||||
Sketch.icon(self, "portrait", box)
|
||||
if not kit.alive:
|
||||
draw_circle(c, r - 3.0, Color(0.16, 0.16, 0.16, 0.6))
|
||||
var ready := kit.fear_left == 0.0 and kit.alive
|
||||
draw_circle(c, FEAR_RADIUS, Color(0.08, 0.1, 0.14, 0.9))
|
||||
if ready:
|
||||
draw_circle(c, FEAR_RADIUS - 5.0, Color(0.55, 0.85, 1.0).lerp(Color.WHITE, _ready_flash))
|
||||
var pulse := 0.75 + 0.25 * sin(_time * 3.2)
|
||||
for k in 4:
|
||||
Sketch.circle(self, c, r + 3.0 + k * 3.5, Color(FEAR_COLOR, (0.32 - k * 0.07) * pulse), 4.5, 3.0 + k)
|
||||
Sketch.circle(self, c, r, Color(0.62, 0.9, 1.0).lerp(Color.WHITE, _ready_flash), 5.0, 1.0)
|
||||
else:
|
||||
draw_arc(c, FEAR_RADIUS - 8.0, -PI * 0.5, -PI * 0.5 + TAU * kit.fear_charge(), 48, Color(0.4, 0.6, 0.75), 9.0)
|
||||
draw_arc(c, FEAR_RADIUS + 3.0 + _ready_flash * 10.0, 0.0, TAU, 48, Color(1.0, 1.0, 1.0, 0.25 + 0.75 * _ready_flash), 2.5)
|
||||
if combat != null:
|
||||
var w := _weapons_rect()
|
||||
draw_rect(w, Color(0.0, 0.0, 0.0, 0.42))
|
||||
_draw_lit_row(w, 32.0 + ScarecrowCombat.MAIN_WEAPONS.find(combat.weapon) * WEAPON_ROW)
|
||||
var off := ScarecrowCombat.OFFHAND_WEAPONS.find(combat.offhand)
|
||||
if off >= 0 and _offhand_lit(combat.offhand):
|
||||
_draw_lit_row(w, _offhand_top() + 32.0 + off * WEAPON_ROW)
|
||||
Sketch.circle(self, c, r, Color(0.32, 0.42, 0.5, 0.85) if kit.alive else Color(0.4, 0.4, 0.4, 0.85), 5.0, 1.0)
|
||||
if kit.alive:
|
||||
Sketch.circle(self, c, r, FEAR_COLOR, 5.0, 2.0, -PI * 0.5, -PI * 0.5 + TAU * kit.fear_charge())
|
||||
if _ready_flash > 0.0:
|
||||
Sketch.circle(self, c, r + 6.0 + (1.0 - _ready_flash) * 18.0, Color(0.8, 0.95, 1.0, _ready_flash), 3.0, 4.0)
|
||||
Sketch.circle(self, c, r + 2.8, Color(Sketch.INK, 0.8), 1.5, 5.0)
|
||||
Sketch.circle(self, c, r - 2.8, Color(Sketch.INK, 0.8), 1.5, 6.0)
|
||||
|
||||
|
||||
func _draw_health() -> void:
|
||||
var top := maxi(kit.max_hp(), 1)
|
||||
var hp := kit.hp()
|
||||
var step := minf(SEGMENT.x + SEGMENT_GAP, (BAR_MAX_WIDTH + SEGMENT_GAP) / top)
|
||||
var seg := Vector2(maxf(step - SEGMENT_GAP, 4.0), SEGMENT.y)
|
||||
var width := step * top - SEGMENT_GAP
|
||||
var healing := 0
|
||||
var heal_frac := 0.0
|
||||
if kit.patching:
|
||||
var bar := Rect2(base + Vector2(FEAR_RADIUS * 2.0 + 14.0, 92.0), Vector2(210.0, 8.0))
|
||||
draw_rect(bar, Color(0.1, 0.1, 0.1, 0.9))
|
||||
draw_rect(Rect2(bar.position, Vector2(bar.size.x * kit.patch_elapsed / kit.config.patch_time, bar.size.y)), Color(0.45, 1.0, 0.4))
|
||||
healing = mini(kit.config.patch_heal, top - hp)
|
||||
heal_frac = clampf(kit.patch_elapsed / maxf(kit.config.patch_time, 0.001), 0.0, 1.0)
|
||||
var full := HEALTH.lerp(Color.WHITE, _hit * 0.6)
|
||||
for i in top:
|
||||
var at := BAR_ORIGIN + Vector2(i * step, 0.0)
|
||||
var pts := _segment(at, seg, 20.0 + i)
|
||||
draw_colored_polygon(pts, full if i < hp else EMPTY)
|
||||
if i >= hp and i < hp + healing:
|
||||
draw_colored_polygon(_segment(at, Vector2(seg.x * heal_frac, seg.y), 40.0 + i), Color(HEALTH.lightened(0.35), 0.85))
|
||||
if i < hp: # a darker stroke along the bottom, like paint pooling
|
||||
Sketch.line(self, at + Vector2(3.0, seg.y - 4.0), at + Vector2(seg.x - 3.0, seg.y - 4.0), full.darkened(0.3), 3.0, 60.0 + i, 0.6)
|
||||
Sketch.outline(self, pts, Color(Sketch.INK, 0.55), 1.5, 80.0 + i, 0.8, 1)
|
||||
if not stamina_shown():
|
||||
return
|
||||
# The stamina bar, as wide as the health bar.
|
||||
var bar := Rect2(BAR_ORIGIN + Vector2(0.0, SEGMENT.y + 12.0), Vector2(maxf(width, 120.0), STAMINA_HEIGHT))
|
||||
var y := bar.get_center().y
|
||||
Sketch.line(self, Vector2(bar.position.x, y), Vector2(bar.end.x, y), Color(Sketch.INK, 0.6), STAMINA_HEIGHT + 3.0, 101.0, 0.6)
|
||||
Sketch.line(self, Vector2(bar.position.x, y), Vector2(bar.end.x, y), Color(0.16, 0.3, 0.14, 0.9), STAMINA_HEIGHT, 101.0, 0.6)
|
||||
var fill := stamina()
|
||||
if fill > 0.0:
|
||||
Sketch.line(self, Vector2(bar.position.x, y), Vector2(bar.position.x + bar.size.x * fill, y), STAMINA, STAMINA_HEIGHT, 102.0, 0.6)
|
||||
|
||||
|
||||
## The marked row of the weapon panel w, top pixels down.
|
||||
func _draw_lit_row(w: Rect2, top: float) -> void:
|
||||
var row := Rect2(w.position + Vector2(6.0, top), Vector2(w.size.x - 12.0, WEAPON_ROW - 2.0))
|
||||
draw_rect(row, Color(1.0, 0.85, 0.3, 0.18))
|
||||
draw_rect(Rect2(row.position, Vector2(4.0, row.size.y)), Color(1.0, 0.85, 0.3))
|
||||
## A health segment: a slanted brush stroke.
|
||||
func _segment(at: Vector2, seg: Vector2, seed: float) -> PackedVector2Array:
|
||||
var w := 1.2
|
||||
return PackedVector2Array([at + Vector2(SEGMENT_SKEW, 0.0) + Sketch.jitter(seed, w),
|
||||
at + Vector2(SEGMENT_SKEW + seg.x, 1.5) + Sketch.jitter(seed + 1.0, w),
|
||||
at + Vector2(seg.x, seg.y) + Sketch.jitter(seed + 2.0, w), at + Vector2(0.0, seg.y - 1.0) + Sketch.jitter(seed + 3.0, w)])
|
||||
|
||||
|
||||
func _base() -> Vector2:
|
||||
return Vector2(36.0, size.y - 126.0 - (SPRINT_ROW if _sprint_shown() else 0.0))
|
||||
|
||||
|
||||
func _sprint_shown() -> bool:
|
||||
return kit != null and kit.player != null and kit.player.can_sprint()
|
||||
|
||||
|
||||
func _label(font_size: int) -> Label:
|
||||
var l := Label.new()
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_outline_color", Color.BLACK)
|
||||
l.add_theme_constant_override("outline_size", 6)
|
||||
l.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
add_child(l)
|
||||
return l
|
||||
func _draw_hotbar() -> void:
|
||||
var list := slots()
|
||||
if list.is_empty():
|
||||
return
|
||||
var mains := 0
|
||||
for s in list:
|
||||
if not s["offhand"]:
|
||||
mains += 1
|
||||
var width := list.size() * SLOT.x + (list.size() - 1) * SLOT_GAP + (DIVIDER_GAP * 2.0 - SLOT_GAP if mains < list.size() else 0.0)
|
||||
var x := (size.x - width) * 0.5
|
||||
var y := size.y - HOTBAR_BOTTOM - SLOT.y
|
||||
for i in list.size():
|
||||
var s: Dictionary = list[i]
|
||||
var w: int = s["weapon"]
|
||||
if i == mains and i > 0:
|
||||
var div := x - SLOT_GAP + DIVIDER_GAP
|
||||
Sketch.line(self, Vector2(div, y - 10.0), Vector2(div, y + SLOT.y + 12.0), Sketch.INK, 3.0, 200.0, 1.5)
|
||||
x += DIVIDER_GAP * 2.0 - SLOT_GAP
|
||||
var r := Rect2(Vector2(x, y), SLOT)
|
||||
var lit: bool = s["selected"] and not s["offhand"] # the off-hand's ready shows by not being darkened
|
||||
if lit:
|
||||
r = r.grow(3.0)
|
||||
r.position.y -= 4.0
|
||||
Sketch.box(self, r, Sketch.SLOT, Sketch.INK, 4.5 if s["offhand"] else 2.5, 210.0 + i * 3.0)
|
||||
Sketch.icon(self, ScarecrowCombat.WEAPON_IDS[w], Rect2(r.get_center() - Vector2(38.0, 36.0), Vector2(76.0, 76.0)))
|
||||
var cooldown := campaign.config.bomb_cooldown if campaign != null else 0.0
|
||||
if w == ScarecrowCombat.Weapon.PUMPKIN_BOMB and combat.bomb_left > 0.0 and cooldown > 0.0:
|
||||
var left := clampf(combat.bomb_left / cooldown, 0.0, 1.0)
|
||||
draw_colored_polygon(Sketch.corners(Rect2(r.position, Vector2(r.size.x, r.size.y * left)).grow(-2.0), 230.0 + i),
|
||||
Color(0.04, 0.05, 0.04, 0.6))
|
||||
if lit:
|
||||
Sketch.box(self, r.grow(2.0), Color(0, 0, 0, 0), Sketch.GOLD, 3.5, 240.0 + i)
|
||||
if int(s["key"]) > 0:
|
||||
Sketch.text(self, r.position + Vector2(7.0, 1.0), str(s["key"]), 20, Sketch.TEXT, HORIZONTAL_ALIGNMENT_LEFT, 6)
|
||||
x += SLOT.x + SLOT_GAP
|
||||
|
|
|
|||
108
game/scripts/screen_labels.gd
Normal file
108
game/scripts/screen_labels.gd
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
class_name ScreenLabels
|
||||
extends Control
|
||||
## Draws the farm's Label3Ds as flat text over the 3D view, so they stay sharp and readable when
|
||||
## the 3D view is pixelated (GameSettings.pixel_size). ToonLook tracks every Label3D; a tracked
|
||||
## label stops rendering in 3D (layers 0) and is drawn here instead, centered on where it projects,
|
||||
## with its text, colors, and outline (in the HUD's handwritten font, Sketch, unless it has its own
|
||||
## font), at the size it would have on screen but never smaller than
|
||||
## MIN_SIZE (far-off ones, under HIDE_BELOW, aren't drawn at all). Labels that would overlap are
|
||||
## nudged apart: the lowest on screen keeps its place and the ones over it move up clear of it.
|
||||
## The game's labels are all
|
||||
## billboards drawn over the scene (no_depth_test), so nothing is lost by drawing them flat, and
|
||||
## game code keeps using the Label3Ds as before (text, modulate, visible, position). Sits on a
|
||||
## CanvasLayer under the HUD and the menus.
|
||||
|
||||
const MIN_SIZE := 16.0 # canvas pixels (1080 high): smaller labels are drawn at this size...
|
||||
const HIDE_BELOW := 6.0 # ...unless they'd be this small on screen, when they're not drawn
|
||||
const GAP := 2.0 # canvas pixels between labels nudged apart
|
||||
|
||||
var _labels: Array = [] # Label3D; untyped, so freed ones can be dropped
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
|
||||
func track(label: Label3D) -> void:
|
||||
if _labels.has(label):
|
||||
return
|
||||
label.layers = 0 # drawn here instead
|
||||
_labels.append(label)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
queue_redraw()
|
||||
|
||||
|
||||
## What to draw this frame, one entry per shown label in front of the camera: label, text, font,
|
||||
## font_size, outline_size, color, outline_color, and rect (canvas: the text and its outline,
|
||||
## after nudging overlapping labels apart).
|
||||
func entries() -> Array[Dictionary]:
|
||||
var out: Array[Dictionary] = []
|
||||
_labels = _labels.filter(func(l: Variant) -> bool: return is_instance_valid(l))
|
||||
var cam := get_viewport().get_camera_3d()
|
||||
if cam == null:
|
||||
return out
|
||||
var up := cam.global_basis.y
|
||||
var fallback := Sketch.font()
|
||||
for l: Label3D in _labels:
|
||||
if l.text == "" or not l.is_visible_in_tree():
|
||||
continue
|
||||
var world := l.get_global_transform_interpolated().origin
|
||||
if cam.is_position_behind(world):
|
||||
continue
|
||||
var at := cam.unproject_position(world) # already in canvas units (the stretched 1080-high view)
|
||||
var tall := at.distance_to(cam.unproject_position(world + up * l.font_size * l.pixel_size))
|
||||
if tall < HIDE_BELOW:
|
||||
continue
|
||||
var scale := maxf(tall, MIN_SIZE) / l.font_size
|
||||
var outline := l.outline_modulate
|
||||
outline.a *= l.modulate.a
|
||||
var font: Font = l.font if l.font != null else fallback
|
||||
var size := roundi(l.font_size * scale)
|
||||
var outline_size := roundi(l.outline_size * scale)
|
||||
var box := font.get_multiline_string_size(l.text, HORIZONTAL_ALIGNMENT_CENTER, -1, size) + Vector2.ONE * outline_size
|
||||
var center := at + Vector2(l.offset.x, -l.offset.y) * scale
|
||||
out.append({"label": l, "text": l.text, "font": font, "font_size": size, "outline_size": outline_size,
|
||||
"color": l.modulate, "outline_color": outline, "rect": Rect2(center - box * 0.5, box)})
|
||||
_separate(out)
|
||||
return out
|
||||
|
||||
|
||||
## Nudges overlapping labels apart: from the lowest on screen up, each label that overlaps one
|
||||
## already placed moves up until it clears it.
|
||||
static func _separate(list: Array[Dictionary]) -> void:
|
||||
list.sort_custom(func(a: Dictionary, b: Dictionary) -> bool:
|
||||
var ya: float = (a["rect"] as Rect2).get_center().y
|
||||
var yb: float = (b["rect"] as Rect2).get_center().y
|
||||
if ya != yb:
|
||||
return ya > yb
|
||||
return (a["label"] as Object).get_instance_id() < (b["label"] as Object).get_instance_id())
|
||||
var placed: Array[Rect2] = []
|
||||
for e in list:
|
||||
var r: Rect2 = e["rect"]
|
||||
var moved := true
|
||||
while moved:
|
||||
moved = false
|
||||
for p in placed:
|
||||
if r.intersects(p):
|
||||
r.position.y = p.position.y - r.size.y - GAP
|
||||
moved = true
|
||||
placed.append(r)
|
||||
e["rect"] = r
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
for e in entries():
|
||||
var font: Font = e["font"]
|
||||
var text: String = e["text"]
|
||||
var size: int = e["font_size"]
|
||||
var outline_size: int = e["outline_size"]
|
||||
var rect: Rect2 = e["rect"]
|
||||
var pos := rect.position + Vector2(outline_size * 0.5, outline_size * 0.5 + font.get_ascent(size))
|
||||
var width := rect.size.x - outline_size
|
||||
if outline_size > 0:
|
||||
draw_multiline_string_outline(font, pos, text, HORIZONTAL_ALIGNMENT_CENTER, width, size, -1,
|
||||
outline_size, e["outline_color"])
|
||||
draw_multiline_string(font, pos, text, HORIZONTAL_ALIGNMENT_CENTER, width, size, -1, e["color"])
|
||||
1
game/scripts/screen_labels.gd.uid
Normal file
1
game/scripts/screen_labels.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bqyaq20hq8ek5
|
||||
|
|
@ -19,7 +19,7 @@ const BINDINGS := [
|
|||
["Aim", []],
|
||||
["Attack (main weapon)", ["fire"]],
|
||||
["Throw a pumpkin bomb (off-hand)", ["offhand"]],
|
||||
["Switch main weapon", ["weapon_1", "weapon_2", "weapon_next"]],
|
||||
["Switch main weapon", ["weapon_1", "weapon_2", "weapon_3", "weapon_4", "weapon_5", "weapon_6", "weapon_next"]],
|
||||
["Fear", ["fear"]],
|
||||
["Patch up (hold)", ["patch"]],
|
||||
["Gather / repair / workbench", ["interact"]],
|
||||
|
|
@ -27,6 +27,7 @@ const BINDINGS := [
|
|||
["Pick a buildable", ["build_1", "build_2", "build_3", "build_4", "build_next"]],
|
||||
["Rotate", ["rotate_left", "rotate_right"]],
|
||||
["Dismantle / leave build mode", ["cancel"]],
|
||||
["Pouch (what you carry, the shed's stock)", ["pouch"]],
|
||||
["Pause", ["pause"]],
|
||||
["Hide tips", ["hide_tips"]],
|
||||
["Microphone on / off (co-op)", ["toggle_mic"]],
|
||||
|
|
@ -87,7 +88,9 @@ func _ready() -> void:
|
|||
_head("Display")
|
||||
_check("fullscreen", "Fullscreen")
|
||||
_check("vsync", "VSync")
|
||||
_slider("pixel_size", "Pixel size", 1.0, GameSettings.MAX_PIXEL_SIZE, 1.0)
|
||||
_slider("resolution_scale", "3D resolution scale", 0.5, 1.0, 0.05)
|
||||
_note("Pixel size 1 turns the pixel look off; the resolution scale is used only then.")
|
||||
_head("Gameplay")
|
||||
_check("show_tips", "Tips on the first day and night")
|
||||
_head("Co-op")
|
||||
|
|
@ -106,7 +109,7 @@ func _ready() -> void:
|
|||
reset.custom_minimum_size = Vector2(280.0, 54.0)
|
||||
reset.pressed.connect(func() -> void:
|
||||
var fresh := GameSettings.new()
|
||||
for key in ["volume", "move_dead_zone", "aim_dead_zone", "fullscreen", "vsync", "resolution_scale", "show_tips"]:
|
||||
for key in ["volume", "move_dead_zone", "aim_dead_zone", "fullscreen", "vsync", "pixel_size", "resolution_scale", "show_tips"]:
|
||||
settings.set(key, fresh.get(key))
|
||||
_load()
|
||||
changed.emit())
|
||||
|
|
@ -196,14 +199,18 @@ func _apply_value(key: String, v: Variant) -> void:
|
|||
if key.begins_with("volume/"):
|
||||
settings.volume[key.trim_prefix("volume/")] = float(v)
|
||||
else:
|
||||
settings.set(key, v)
|
||||
settings.set(key, roundi(v) if key == "pixel_size" else v)
|
||||
if v is float:
|
||||
_show_value(key, v)
|
||||
changed.emit()
|
||||
|
||||
|
||||
func _show_value(key: String, v: float) -> void:
|
||||
if _values.has(key):
|
||||
if not _values.has(key):
|
||||
return
|
||||
if key == "pixel_size":
|
||||
(_values[key] as Label).text = "Off" if roundi(v) <= 1 else "%d×" % roundi(v)
|
||||
else:
|
||||
(_values[key] as Label).text = "%d%%" % roundi(v * 100.0)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@ extends Node3D
|
|||
## the rest added here); a pile shows one prop per `per` units, up to all of them. Every prop has
|
||||
## collision, and all of them are in place when the farm's navigation is built, so a pile's
|
||||
## footprint never changes for enemies; a hidden prop only stops colliding for the scarecrow and
|
||||
## shots. Each pile has a spot in front of it where supply thieves stand to fill their sacks, and a
|
||||
## label with the amount while the scarecrow is nearby.
|
||||
## shots. Each pile has a spot in front of it where supply thieves stand to fill their sacks. (How
|
||||
## much the shed holds shows in the HUD's pouch panel, ResourceHud.)
|
||||
|
||||
const PREF := "res://assets/farm/ithappy/farm/prefabs/assets/"
|
||||
const LABEL_RANGE := 9.0
|
||||
## material -> adopt (scene props under the shed zone, in fill order), extra ([prefab, world
|
||||
## position, yaw in degrees, scale]), per (units per prop), front (thieves' spot), label (world).
|
||||
## position, yaw in degrees, scale]), per (units per prop), front (thieves' spot).
|
||||
const PILES := {
|
||||
"wood": {
|
||||
"adopt": ["firewood_010_1", "firewood_010_2"],
|
||||
|
|
@ -24,7 +23,6 @@ const PILES := {
|
|||
],
|
||||
"per": 4,
|
||||
"front": Vector2(2.6, -18.6),
|
||||
"label": Vector3(4.2, 2.2, -18.7),
|
||||
},
|
||||
"scrap": {
|
||||
"adopt": ["box_004_1", "box_004_2", "case_001_1", "box_004_3"],
|
||||
|
|
@ -38,7 +36,6 @@ const PILES := {
|
|||
],
|
||||
"per": 3,
|
||||
"front": Vector2(-3.0, -15.1),
|
||||
"label": Vector3(-3.4, 2.8, -18.6),
|
||||
},
|
||||
"straw": {
|
||||
"adopt": ["hay_001_1"],
|
||||
|
|
@ -51,9 +48,8 @@ const PILES := {
|
|||
],
|
||||
"per": 4,
|
||||
"front": Vector2(6.75, -16.25),
|
||||
"label": Vector3(6.2, 3.2, -18.4),
|
||||
},
|
||||
## No pile of its own yet (placeholder: it never shows props), but it needs a real front/label
|
||||
## No pile of its own yet (placeholder: it never shows props), but it needs a real front
|
||||
## spot so a supply thief sent for it (once it's the shed's most-stocked material) has
|
||||
## somewhere reachable to stand; the wood pile's spot is already proven walkable.
|
||||
"alien_goop": {
|
||||
|
|
@ -61,26 +57,22 @@ const PILES := {
|
|||
"extra": [],
|
||||
"per": 1,
|
||||
"front": Vector2(2.6, -18.6),
|
||||
"label": Vector3(4.2, 2.6, -18.3),
|
||||
},
|
||||
}
|
||||
|
||||
var campaign: CampaignController
|
||||
var player: Node3D
|
||||
## material -> Array[Node3D], in fill order.
|
||||
var slots := {}
|
||||
var shown := {}
|
||||
|
||||
var _labels := {}
|
||||
var _bodies := {} # material -> Array (per slot: Array[CollisionObject3D])
|
||||
var _last := {}
|
||||
|
||||
|
||||
## Before the navigation is built: adopts the scene's piles and adds the extra props (every prop
|
||||
## present and colliding).
|
||||
func setup(p_campaign: CampaignController, shed_zone: Node3D, p_player: Node3D) -> void:
|
||||
func setup(p_campaign: CampaignController, shed_zone: Node3D) -> void:
|
||||
campaign = p_campaign
|
||||
player = p_player
|
||||
for m: String in PILES:
|
||||
var pile: Dictionary = PILES[m]
|
||||
var list: Array[Node3D] = []
|
||||
|
|
@ -99,18 +91,6 @@ func setup(p_campaign: CampaignController, shed_zone: Node3D, p_player: Node3D)
|
|||
for n in list:
|
||||
bodies.append(n.find_children("*", "CollisionObject3D", true, false))
|
||||
_bodies[m] = bodies
|
||||
var l := Label3D.new()
|
||||
l.billboard = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
l.no_depth_test = true
|
||||
l.shaded = false
|
||||
l.font_size = 44
|
||||
l.outline_size = 10
|
||||
l.pixel_size = 0.0075
|
||||
l.modulate = GatherNode.COLORS[m]
|
||||
l.visible = false
|
||||
add_child(l)
|
||||
l.global_position = pile["label"]
|
||||
_labels[m] = l
|
||||
|
||||
|
||||
## Where supply thieves stand to take this material.
|
||||
|
|
@ -148,10 +128,3 @@ func _process(_delta: float) -> void:
|
|||
if int(shed.get(m, 0)) != int(_last.get(m, -1)):
|
||||
refresh()
|
||||
break
|
||||
var near := player != null
|
||||
for m: String in _labels:
|
||||
var l := _labels[m] as Label3D
|
||||
var at: Vector3 = PILES[m]["label"]
|
||||
l.visible = near and Vector2(player.global_position.x - at.x, player.global_position.z - at.z).length() < LABEL_RANGE
|
||||
if l.visible:
|
||||
l.text = "%s %d" % [m.capitalize(), int(shed.get(m, 0))]
|
||||
|
|
|
|||
367
game/scripts/sketch.gd
Normal file
367
game/scripts/sketch.gd
Normal file
|
|
@ -0,0 +1,367 @@
|
|||
class_name Sketch
|
||||
extends RefCounted
|
||||
## The HUD's hand-drawn look, drawn into any CanvasItem from its _draw() (lines, outlines, and
|
||||
## boxes also into a canvas item RID, for SketchBox, the look's StyleBox): a handwritten font
|
||||
## (Gochi Hand, assets/fonts, SIL OFL) with a dark outline so text reads over the farm, wobbly
|
||||
## sketched outlines (each edge drawn twice, slightly off, overshooting its corners), painted
|
||||
## fills (a flat color, a lighter dab, a darker rim), and painted icons for the weapons, the
|
||||
## materials, the backpack, the sun and moon, and the scarecrow's portrait. Every wobble comes
|
||||
## from a hash of a seed, so a shape is drawn the same way each frame (no flicker).
|
||||
## Icons are designed in a 100 x 100 box and scaled to the rect they're drawn in.
|
||||
|
||||
const FONT_PATH := "res://assets/fonts/GochiHand-Regular.ttf"
|
||||
const INK := Color(0.07, 0.06, 0.05)
|
||||
const TEXT := Color(0.98, 0.97, 0.92)
|
||||
## The few panels left: a light wash, not a solid block.
|
||||
const WASH := Color(0.06, 0.08, 0.06, 0.4)
|
||||
## A panel with things to read in it (the pouch panel, the build bar, the menus over the farm):
|
||||
## a darker wash in a sketched ink frame (panel()), its heading in TEXT, a pen rule under it,
|
||||
## its column headings and hints in DIM.
|
||||
const PANEL := Color(0.06, 0.08, 0.06, 0.86)
|
||||
const PANEL_INK := 3.0
|
||||
const DIM := Color(0.7, 0.7, 0.66)
|
||||
const RULE := Color(0.98, 0.97, 0.92, 0.35)
|
||||
## A slot or button in a panel or the hotbar, and the gold of the one picked (in hand, focused).
|
||||
const SLOT := Color(0.1, 0.24, 0.1, 0.62)
|
||||
const GOLD := Color(1.0, 0.86, 0.35)
|
||||
const TEXT_OUTLINE := 8
|
||||
## Icon ids (icon()): ScarecrowCombat.WEAPON_IDS, ResourceStore.MATERIALS, and these.
|
||||
const ICONS: Array[String] = ["pitchfork", "corn_shooter", "pumpkin_bomb", "potato_cannon", "shurikens",
|
||||
"propane_torch", "alien_ray", "wood", "scrap", "straw", "alien_goop", "backpack", "sun", "moon", "portrait"]
|
||||
|
||||
static var _font: Font
|
||||
|
||||
|
||||
static func font() -> Font:
|
||||
if _font == null:
|
||||
_font = load(FONT_PATH) as Font
|
||||
if _font == null:
|
||||
_font = ThemeDB.fallback_font
|
||||
return _font
|
||||
|
||||
|
||||
## Gives a code-built Label the HUD's handwritten look.
|
||||
static func style(l: Label, font_size: int, color: Color = TEXT, outline: int = TEXT_OUTLINE) -> void:
|
||||
l.add_theme_font_override("font", font())
|
||||
l.add_theme_font_size_override("font_size", font_size)
|
||||
l.add_theme_color_override("font_color", color)
|
||||
l.add_theme_color_override("font_outline_color", INK)
|
||||
l.add_theme_constant_override("outline_size", outline)
|
||||
|
||||
|
||||
## Outlined handwritten text with its top at pos.y; pos.x is its left edge, center, or right
|
||||
## edge (align). Returns its width.
|
||||
static func text(ci: CanvasItem, pos: Vector2, s: String, size: int, color: Color = TEXT,
|
||||
align: HorizontalAlignment = HORIZONTAL_ALIGNMENT_LEFT, outline: int = TEXT_OUTLINE) -> float:
|
||||
var f := font()
|
||||
var w := f.get_string_size(s, HORIZONTAL_ALIGNMENT_LEFT, -1, size).x
|
||||
var x := pos.x
|
||||
if align == HORIZONTAL_ALIGNMENT_RIGHT:
|
||||
x -= w
|
||||
elif align == HORIZONTAL_ALIGNMENT_CENTER:
|
||||
x -= w * 0.5
|
||||
var base := Vector2(x, pos.y + f.get_ascent(size))
|
||||
if outline > 0:
|
||||
ci.draw_string_outline(f, base, s, HORIZONTAL_ALIGNMENT_LEFT, -1, size, outline, Color(INK, INK.a * color.a))
|
||||
ci.draw_string(f, base, s, HORIZONTAL_ALIGNMENT_LEFT, -1, size, color)
|
||||
return w
|
||||
|
||||
|
||||
static func text_width(s: String, size: int) -> float:
|
||||
return font().get_string_size(s, HORIZONTAL_ALIGNMENT_LEFT, -1, size).x
|
||||
|
||||
|
||||
## A repeatable pseudo-random value in -1..1 for a seed.
|
||||
static func noise(seed: float) -> float:
|
||||
var x := sin(seed * 12.9898 + 78.233) * 43758.5453
|
||||
return (x - floorf(x)) * 2.0 - 1.0
|
||||
|
||||
|
||||
static func jitter(seed: float, amount: float) -> Vector2:
|
||||
return Vector2(noise(seed), noise(seed + 0.37)) * amount
|
||||
|
||||
|
||||
## One pen stroke from a to b: slightly bowed, a little shaky, running past both ends. ci is a
|
||||
## CanvasItem (in its _draw()) or a canvas item RID (a StyleBox's _draw()), as for outline() and
|
||||
## box().
|
||||
static func line(ci: Variant, a: Vector2, b: Vector2, color: Color, width: float, seed: float, wobble: float = 1.4) -> void:
|
||||
var pts := line_points(a, b, seed, wobble)
|
||||
if not pts.is_empty():
|
||||
_polyline(ci, pts, color, width)
|
||||
|
||||
|
||||
## The points of line()'s stroke (empty when a and b meet).
|
||||
static func line_points(a: Vector2, b: Vector2, seed: float, wobble: float = 1.4) -> PackedVector2Array:
|
||||
var d := b - a
|
||||
var length := d.length()
|
||||
if length < 0.01:
|
||||
return PackedVector2Array()
|
||||
var dir := d / length
|
||||
var n := dir.orthogonal()
|
||||
var bow := noise(seed) * wobble
|
||||
var steps := clampi(int(length / 16.0) + 2, 2, 14)
|
||||
var pts := PackedVector2Array()
|
||||
for i in steps + 1:
|
||||
var t := float(i) / steps
|
||||
pts.append(a.lerp(b, t) + n * (bow * sin(PI * t) + noise(seed + 1.3 + i) * wobble * 0.3))
|
||||
pts[0] -= dir * wobble * (0.8 + 0.6 * noise(seed + 9.1))
|
||||
pts[steps] += dir * wobble * (0.8 + 0.6 * noise(seed + 9.7))
|
||||
return pts
|
||||
|
||||
|
||||
static func _polyline(ci: Variant, pts: PackedVector2Array, color: Color, width: float) -> void:
|
||||
if ci is RID:
|
||||
RenderingServer.canvas_item_add_polyline(ci, pts, PackedColorArray([color]), width, true)
|
||||
else:
|
||||
(ci as CanvasItem).draw_polyline(pts, color, width, true)
|
||||
|
||||
|
||||
static func _polygon(ci: Variant, pts: PackedVector2Array, color: Color) -> void:
|
||||
if ci is RID:
|
||||
RenderingServer.canvas_item_add_polygon(ci, pts, PackedColorArray([color]))
|
||||
else:
|
||||
(ci as CanvasItem).draw_colored_polygon(pts, color)
|
||||
|
||||
|
||||
## A sketched outline around a closed shape: every edge stroked twice (the second lighter).
|
||||
static func outline(ci: Variant, pts: PackedVector2Array, color: Color, width: float, seed: float,
|
||||
wobble: float = 1.6, passes: int = 2) -> void:
|
||||
var n := pts.size()
|
||||
for p in passes:
|
||||
var c := color if p == 0 else Color(color, color.a * 0.5)
|
||||
for i in n:
|
||||
line(ci, pts[i], pts[(i + 1) % n], c, width if p == 0 else maxf(width * 0.6, 1.0), seed + p * 31.0 + i * 7.0, wobble)
|
||||
|
||||
|
||||
## A rect's corners, each nudged off true.
|
||||
static func corners(r: Rect2, seed: float, wobble: float = 2.0) -> PackedVector2Array:
|
||||
return PackedVector2Array([r.position + jitter(seed, wobble), Vector2(r.end.x, r.position.y) + jitter(seed + 1.0, wobble),
|
||||
r.end + jitter(seed + 2.0, wobble), Vector2(r.position.x, r.end.y) + jitter(seed + 3.0, wobble)])
|
||||
|
||||
|
||||
## A hand-drawn box: a wobbly fill (skipped when transparent) and a sketched outline (skipped
|
||||
## when width is 0).
|
||||
static func box(ci: Variant, r: Rect2, fill: Color, ink: Color = INK, width: float = 2.5, seed: float = 1.0) -> void:
|
||||
var c := corners(r, seed)
|
||||
if fill.a > 0.0:
|
||||
_polygon(ci, c, fill)
|
||||
if width > 0.0 and ink.a > 0.0:
|
||||
outline(ci, c, ink, width, seed + 5.0)
|
||||
|
||||
|
||||
## A panel to read things in (PANEL in a sketched ink frame).
|
||||
static func panel(ci: Variant, r: Rect2, seed: float = 1.0) -> void:
|
||||
box(ci, r, PANEL, INK, PANEL_INK, seed)
|
||||
|
||||
|
||||
## The pen rule under a panel's heading, from x0 to x1 at y.
|
||||
static func rule(ci: Variant, x0: float, x1: float, y: float, seed: float = 1.0) -> void:
|
||||
line(ci, Vector2(x0, y), Vector2(x1, y), RULE, 2.0, seed)
|
||||
|
||||
|
||||
## Points around a wobbly ellipse (radii rx, ry), turned by rot.
|
||||
static func blob(center: Vector2, rx: float, ry: float, seed: float, wobble: float = 0.05, n: int = 28, rot: float = 0.0) -> PackedVector2Array:
|
||||
var pts := PackedVector2Array()
|
||||
for i in n:
|
||||
var a := TAU * i / n
|
||||
var k := 1.0 + noise(seed + i * 0.71) * wobble
|
||||
pts.append(center + Vector2(cos(a) * rx * k, sin(a) * ry * k).rotated(rot))
|
||||
return pts
|
||||
|
||||
|
||||
## A wobbly circle outline (or arc, from..to radians, clockwise on screen from the right).
|
||||
static func circle(ci: CanvasItem, c: Vector2, r: float, color: Color, width: float, seed: float,
|
||||
from: float = 0.0, to: float = TAU, wobble: float = 0.025) -> void:
|
||||
var span := to - from
|
||||
if absf(span) < 0.001:
|
||||
return
|
||||
var n := maxi(int(absf(span) / TAU * 64.0), 3)
|
||||
var pts := PackedVector2Array()
|
||||
for i in n + 1:
|
||||
var a := from + span * i / n
|
||||
pts.append(c + Vector2(cos(a), sin(a)) * r * (1.0 + wobble * (sin(a * 3.0 + seed) * 0.6 + sin(a * 7.0 + seed * 1.7) * 0.4)))
|
||||
ci.draw_polyline(pts, color, width, true)
|
||||
|
||||
|
||||
## A painted shape: its color, a lighter dab toward the top-left, and a darker rim.
|
||||
static func paint(ci: CanvasItem, pts: PackedVector2Array, color: Color, seed: float, rim: float = 3.0) -> void:
|
||||
ci.draw_colored_polygon(pts, color)
|
||||
var center := Vector2.ZERO
|
||||
for p in pts:
|
||||
center += p
|
||||
center /= pts.size()
|
||||
var size := Vector2.ZERO
|
||||
for p in pts:
|
||||
size = size.max((p - center).abs())
|
||||
var dab := PackedVector2Array()
|
||||
for p in pts:
|
||||
dab.append(center + (p - center) * 0.55 - size * Vector2(0.18, 0.22))
|
||||
ci.draw_colored_polygon(dab, Color(color.lightened(0.28), 0.55))
|
||||
if rim > 0.0:
|
||||
outline(ci, pts, Color(color.darkened(0.62), 0.95), rim, seed, 0.8, 1)
|
||||
|
||||
|
||||
## A thick inked stroke: dark under, color on top.
|
||||
static func stroke(ci: CanvasItem, a: Vector2, b: Vector2, color: Color, width: float, seed: float) -> void:
|
||||
line(ci, a, b, INK, width + 4.0, seed, 0.8)
|
||||
line(ci, a, b, color, width, seed, 0.8)
|
||||
|
||||
|
||||
static func _bezier(a: Vector2, q: Vector2, b: Vector2, n: int) -> PackedVector2Array:
|
||||
var pts := PackedVector2Array()
|
||||
for i in n + 1:
|
||||
var t := float(i) / n
|
||||
pts.append(a.lerp(q, t).lerp(q.lerp(b, t), t))
|
||||
return pts
|
||||
|
||||
|
||||
## Draws an icon (ICONS) into rect r.
|
||||
static func icon(ci: CanvasItem, id: String, r: Rect2) -> void:
|
||||
ci.draw_set_transform(r.position, 0.0, r.size / 100.0)
|
||||
_icon(ci, id)
|
||||
ci.draw_set_transform_matrix(Transform2D.IDENTITY)
|
||||
|
||||
|
||||
static func _icon(ci: CanvasItem, id: String) -> void:
|
||||
match id:
|
||||
"pitchfork":
|
||||
stroke(ci, Vector2(14.0, 90.0), Vector2(60.0, 44.0), Color(0.6, 0.4, 0.22), 8.0, 11.0)
|
||||
var metal := Color(0.74, 0.76, 0.8)
|
||||
stroke(ci, Vector2(48.7, 32.7), Vector2(71.3, 55.3), metal, 6.0, 12.0)
|
||||
for k: float in [-14.0, 0.0, 14.0]:
|
||||
var root := Vector2(60.0, 44.0) + Vector2(0.707, 0.707) * k
|
||||
stroke(ci, root, root + Vector2(0.707, -0.707) * 30.0, metal, 5.0, 13.0 + k)
|
||||
"corn_shooter":
|
||||
var green := Color(0.24, 0.55, 0.22)
|
||||
paint(ci, PackedVector2Array([Vector2(26, 52), Vector2(44, 52), Vector2(38, 84), Vector2(22, 82)]), green.darkened(0.15), 21.0)
|
||||
paint(ci, PackedVector2Array([Vector2(14, 42), Vector2(82, 40), Vector2(84, 58), Vector2(16, 60)]), green, 22.0)
|
||||
paint(ci, blob(Vector2(88, 49), 5.0, 10.0, 23.0), green.darkened(0.3), 24.0, 2.0)
|
||||
paint(ci, blob(Vector2(52, 30), 24.0, 10.0, 25.0, 0.04, 24, -0.08), Color(0.98, 0.84, 0.24), 26.0)
|
||||
for i in 6:
|
||||
ci.draw_circle(Vector2(36.0 + i * 6.5, 27.0 + (i % 2) * 5.0), 2.2, Color(0.85, 0.62, 0.1))
|
||||
paint(ci, PackedVector2Array([Vector2(26, 30), Vector2(40, 20), Vector2(38, 34)]), Color(0.45, 0.75, 0.3), 27.0, 2.0)
|
||||
"potato_cannon":
|
||||
stroke(ci, Vector2(16.0, 82.0), Vector2(44.0, 58.0), Color(0.3, 0.32, 0.35), 22.0, 31.0)
|
||||
paint(ci, blob(Vector2(16, 82), 8.0, 8.0, 32.0), Color(0.22, 0.23, 0.25), 33.0, 2.0)
|
||||
var potato := blob(Vector2(62, 38), 27.0, 19.0, 34.0, 0.07, 26, -0.45)
|
||||
paint(ci, potato, Color(0.8, 0.62, 0.36), 35.0)
|
||||
for p: Vector2 in [Vector2(54, 32), Vector2(68, 44), Vector2(71, 28)]:
|
||||
ci.draw_circle(p, 2.6, Color(0.5, 0.36, 0.18))
|
||||
"shurikens":
|
||||
var star := PackedVector2Array()
|
||||
for i in 8:
|
||||
var a := TAU * i / 8.0 + 0.35
|
||||
star.append(Vector2(50, 50) + Vector2(cos(a), sin(a)) * (40.0 if i % 2 == 0 else 12.0) + jitter(41.0 + i, 1.5))
|
||||
paint(ci, star, Color(0.63, 0.67, 0.72), 42.0)
|
||||
ci.draw_circle(Vector2(50, 50), 6.0, INK)
|
||||
"propane_torch":
|
||||
paint(ci, PackedVector2Array([Vector2(22, 44), Vector2(56, 42), Vector2(58, 88), Vector2(22, 90)]), Color(0.92, 0.9, 0.84), 51.0)
|
||||
paint(ci, blob(Vector2(39, 44), 17.0, 8.0, 52.0), Color(0.92, 0.9, 0.84), 53.0, 0.0)
|
||||
paint(ci, PackedVector2Array([Vector2(22, 60), Vector2(57, 59), Vector2(57, 68), Vector2(22, 69)]), Color(0.85, 0.25, 0.2), 54.0, 2.0)
|
||||
paint(ci, PackedVector2Array([Vector2(33, 26), Vector2(45, 26), Vector2(46, 40), Vector2(32, 40)]), Color(0.78, 0.62, 0.25), 55.0, 2.0)
|
||||
stroke(ci, Vector2(44.0, 30.0), Vector2(70.0, 24.0), Color(0.6, 0.6, 0.62), 4.0, 56.0)
|
||||
var flame := PackedVector2Array([Vector2(70, 16), Vector2(86, 14), Vector2(97, 22), Vector2(86, 31), Vector2(70, 31)])
|
||||
paint(ci, flame, Color(1.0, 0.55, 0.15), 57.0, 2.0)
|
||||
ci.draw_colored_polygon(PackedVector2Array([Vector2(72, 20), Vector2(84, 19), Vector2(90, 23), Vector2(83, 27), Vector2(72, 27)]), Color(1.0, 0.88, 0.4))
|
||||
"alien_ray":
|
||||
var body := Color(0.42, 0.7, 0.74)
|
||||
paint(ci, PackedVector2Array([Vector2(30, 54), Vector2(44, 54), Vector2(40, 82), Vector2(28, 80)]), body.darkened(0.2), 61.0)
|
||||
paint(ci, PackedVector2Array([Vector2(16, 46), Vector2(70, 40), Vector2(72, 60), Vector2(16, 58)]), body, 62.0)
|
||||
for i in 3:
|
||||
paint(ci, blob(Vector2(74.0 + i * 8.0, 50.0), 4.0, 12.0 - i * 3.0, 63.0 + i), Color(0.55, 0.95, 0.35), 64.0 + i, 2.0)
|
||||
paint(ci, blob(Vector2(40, 36), 11.0, 11.0, 66.0), Color(0.55, 0.95, 0.35), 67.0)
|
||||
ci.draw_circle(Vector2(36, 32), 3.0, Color(0.9, 1.0, 0.8))
|
||||
"pumpkin_bomb":
|
||||
var orange := Color(0.95, 0.52, 0.12)
|
||||
paint(ci, blob(Vector2(34, 60), 18.0, 25.0, 71.0), orange.darkened(0.1), 72.0)
|
||||
paint(ci, blob(Vector2(66, 60), 18.0, 25.0, 73.0), orange.darkened(0.1), 74.0)
|
||||
paint(ci, blob(Vector2(50, 60), 22.0, 27.0, 75.0), orange, 76.0)
|
||||
paint(ci, PackedVector2Array([Vector2(46, 36), Vector2(54, 35), Vector2(57, 20), Vector2(49, 19)]), Color(0.3, 0.55, 0.2), 77.0, 2.0)
|
||||
ci.draw_polyline(_bezier(Vector2(56, 22), Vector2(68, 8), Vector2(78, 18), 8), INK, 3.0, true)
|
||||
ci.draw_circle(Vector2(79, 18), 4.0, Color(1.0, 0.85, 0.3))
|
||||
"wood":
|
||||
paint(ci, PackedVector2Array([Vector2(16, 36), Vector2(78, 34), Vector2(80, 68), Vector2(18, 70)]), Color(0.6, 0.38, 0.2), 81.0)
|
||||
for k in 2:
|
||||
line(ci, Vector2(24, 46.0 + k * 12.0), Vector2(68, 45.0 + k * 12.0), Color(0.4, 0.24, 0.12), 2.0, 82.0 + k)
|
||||
paint(ci, blob(Vector2(79, 51), 10.0, 17.0, 83.0), Color(0.88, 0.68, 0.42), 84.0)
|
||||
circle(ci, Vector2(79, 51), 6.0, Color(0.6, 0.42, 0.24), 2.0, 85.0)
|
||||
"scrap":
|
||||
paint(ci, PackedVector2Array([Vector2(20, 38), Vector2(66, 26), Vector2(82, 58), Vector2(42, 76), Vector2(16, 60)]), Color(0.6, 0.68, 0.76), 91.0)
|
||||
for p: Vector2 in [Vector2(36, 46), Vector2(60, 56)]:
|
||||
paint(ci, blob(p, 6.0, 6.0, 92.0 + p.x), Color(0.42, 0.46, 0.52), 93.0, 1.5)
|
||||
"straw":
|
||||
for i in 9:
|
||||
var x := 36.0 + i * 3.5
|
||||
line(ci, Vector2(x, 86.0), Vector2(18.0 + i * 8.0, 20.0 + absf(i - 4.0) * 3.0), Color(0.98, 0.86, 0.38), 4.0, 101.0 + i, 1.0)
|
||||
for i in 9:
|
||||
line(ci, Vector2(37.0 + i * 3.5, 86.0), Vector2(20.0 + i * 8.0, 24.0 + absf(i - 4.0) * 3.0), Color(0.8, 0.62, 0.2), 1.5, 111.0 + i, 1.0)
|
||||
paint(ci, PackedVector2Array([Vector2(32, 58), Vector2(70, 58), Vector2(70, 66), Vector2(32, 66)]), Color(0.55, 0.35, 0.18), 121.0, 2.0)
|
||||
"alien_goop":
|
||||
var drop := PackedVector2Array([Vector2(50, 14)])
|
||||
for i in 15:
|
||||
var a := lerpf(-0.3, PI + 0.3, i / 14.0) # round the bottom, right to left
|
||||
drop.append(Vector2(50, 62) + Vector2(cos(a), sin(a)) * 26.0 + jitter(131.0 + i, 1.2))
|
||||
paint(ci, drop, Color(0.5, 0.92, 0.3), 132.0)
|
||||
ci.draw_circle(Vector2(42, 58), 5.0, Color(0.85, 1.0, 0.75, 0.9))
|
||||
"backpack":
|
||||
var leather := Color(0.82, 0.46, 0.14)
|
||||
circle(ci, Vector2(50, 26), 11.0, leather.darkened(0.45), 5.0, 141.0, PI, TAU)
|
||||
paint(ci, PackedVector2Array([Vector2(10, 54), Vector2(26, 52), Vector2(27, 84), Vector2(12, 84)]), leather.darkened(0.15), 142.0)
|
||||
paint(ci, PackedVector2Array([Vector2(22, 30), Vector2(78, 28), Vector2(82, 92), Vector2(20, 94)]), leather, 143.0)
|
||||
paint(ci, PackedVector2Array([Vector2(18, 26), Vector2(82, 25), Vector2(80, 52), Vector2(20, 54)]), leather.darkened(0.22), 144.0)
|
||||
paint(ci, PackedVector2Array([Vector2(34, 64), Vector2(66, 63), Vector2(66, 86), Vector2(34, 87)]), leather.darkened(0.12), 145.0, 2.0)
|
||||
paint(ci, PackedVector2Array([Vector2(46, 48), Vector2(54, 48), Vector2(54, 60), Vector2(46, 60)]), Color(0.9, 0.78, 0.4), 146.0, 1.5)
|
||||
"sun":
|
||||
var sun := PackedVector2Array()
|
||||
for i in 54:
|
||||
var a := TAU * i / 54.0
|
||||
sun.append(Vector2(50, 50) + Vector2(cos(a), sin(a)) * (34.0 + 7.0 * sin(a * 9.0) + noise(151.0 + i) * 1.5))
|
||||
paint(ci, sun, Color(0.98, 0.74, 0.22), 152.0, 2.0)
|
||||
ci.draw_colored_polygon(blob(Vector2(48, 47), 18.0, 18.0, 153.0), Color(1.0, 0.86, 0.42))
|
||||
"moon":
|
||||
# The part of one circle outside another, offset up and to the right.
|
||||
var c1 := Vector2(50, 50)
|
||||
var c2 := c1 + Vector2(0.8, -0.6) * 12.0
|
||||
var moon := _arc_through(c1, 32.0, c2, 30.0, c1 * 2.0 - c2)
|
||||
moon.append_array(_arc_through(c2, 30.0, c1, 32.0, c1).slice(1, -1))
|
||||
paint(ci, moon, Color(0.92, 0.93, 0.82), 161.0, 2.0)
|
||||
ci.draw_circle(Vector2(30, 52), 3.0, Color(0.78, 0.79, 0.68))
|
||||
ci.draw_circle(Vector2(38, 70), 2.5, Color(0.78, 0.79, 0.68))
|
||||
"portrait":
|
||||
ci.draw_colored_polygon(blob(Vector2(50, 50), 46.0, 46.0, 171.0, 0.01, 40), Color(0.64, 0.8, 0.82))
|
||||
var straw := Color(0.96, 0.82, 0.36)
|
||||
for i in 5:
|
||||
line(ci, Vector2(26.0 + i * 3.0, 50.0), Vector2(12.0 + i * 2.0, 68.0 + i * 2.0), straw, 3.5, 172.0 + i, 1.0)
|
||||
line(ci, Vector2(74.0 - i * 3.0, 50.0), Vector2(88.0 - i * 2.0, 68.0 + i * 2.0), straw, 3.5, 178.0 + i, 1.0)
|
||||
paint(ci, blob(Vector2(50, 64), 29.0, 30.0, 184.0, 0.04), Color(0.84, 0.76, 0.36), 185.0)
|
||||
for k: float in [-1.0, 1.0]:
|
||||
var e := Vector2(50.0 + 12.0 * k, 62.0)
|
||||
line(ci, e + Vector2(-6, -6), e + Vector2(6, 6), INK, 4.0, 186.0 + k, 0.6)
|
||||
line(ci, e + Vector2(6, -6), e + Vector2(-6, 6), INK, 4.0, 188.0 + k, 0.6)
|
||||
var mouth := _bezier(Vector2(35, 79), Vector2(50, 86), Vector2(65, 78), 8)
|
||||
ci.draw_polyline(mouth, INK, 3.0, true)
|
||||
for i in range(1, 8, 2):
|
||||
ci.draw_line(mouth[i] + Vector2(0, -4.0), mouth[i] + Vector2(0, 4.0), INK, 2.2, true)
|
||||
paint(ci, PackedVector2Array([Vector2(31, 42), Vector2(69, 41), Vector2(65, 11), Vector2(35, 12)]), Color(0.62, 0.42, 0.22), 190.0)
|
||||
paint(ci, PackedVector2Array([Vector2(32, 35), Vector2(68, 34), Vector2(68, 41), Vector2(32, 42)]), Color(0.42, 0.26, 0.14), 191.0, 0.0)
|
||||
paint(ci, blob(Vector2(50, 43), 44.0, 8.0, 192.0, 0.03, 28, -0.06), Color(0.72, 0.52, 0.28), 193.0)
|
||||
|
||||
|
||||
## Points along a circle (center c, radius r) between where it crosses another circle (o, ro),
|
||||
## taking the way round that passes nearest to the point toward.
|
||||
static func _arc_through(c: Vector2, r: float, o: Vector2, ro: float, toward: Vector2) -> PackedVector2Array:
|
||||
var d := c.distance_to(o)
|
||||
var a := (r * r - ro * ro + d * d) / (2.0 * d)
|
||||
var h := sqrt(maxf(r * r - a * a, 0.0))
|
||||
var u := (o - c) / d
|
||||
var mid := c + u * a
|
||||
var from := (mid + u.orthogonal() * h - c).angle()
|
||||
var to := (mid - u.orthogonal() * h - c).angle()
|
||||
var sweep := wrapf(to - from, 0.0, TAU)
|
||||
if wrapf((toward - c).angle() - from, 0.0, TAU) > sweep:
|
||||
sweep -= TAU
|
||||
var pts := PackedVector2Array()
|
||||
for i in 25:
|
||||
var t := from + sweep * i / 24.0
|
||||
pts.append(c + Vector2(cos(t), sin(t)) * r)
|
||||
return pts
|
||||
1
game/scripts/sketch.gd.uid
Normal file
1
game/scripts/sketch.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cyj812m7bxr3w
|
||||
30
game/scripts/sketch_box.gd
Normal file
30
game/scripts/sketch_box.gd
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
class_name SketchBox
|
||||
extends StyleBox
|
||||
## A StyleBox in the HUD's hand-drawn look (Sketch), for the menus built from Controls
|
||||
## (UiTheme.sketch): a wobbly fill and a sketched outline (either can be left out), or, as a rule,
|
||||
## one pen line across the middle (an HSeparator's). Each box's wobble is seeded from its rect,
|
||||
## so boxes differ from each other and each stays put.
|
||||
|
||||
var fill := Color(0, 0, 0, 0)
|
||||
var ink := Sketch.INK
|
||||
var width := 2.5
|
||||
var as_rule := false
|
||||
## How far past the rect it's drawn (a focus frame around a button).
|
||||
var grow := 0.0
|
||||
|
||||
|
||||
func _init(p_fill: Color = Color(0, 0, 0, 0), p_ink: Color = Sketch.INK, p_width: float = 2.5, p_rule: bool = false) -> void:
|
||||
fill = p_fill
|
||||
ink = p_ink
|
||||
width = p_width
|
||||
as_rule = p_rule
|
||||
|
||||
|
||||
func _draw(to_canvas_item: RID, p_rect: Rect2) -> void:
|
||||
var rect := p_rect.grow(grow)
|
||||
var seed := fmod(rect.position.x * 0.013 + rect.position.y * 0.007 + rect.size.x * 0.011, 97.0)
|
||||
if as_rule:
|
||||
var y := rect.get_center().y
|
||||
Sketch.line(to_canvas_item, Vector2(rect.position.x, y), Vector2(rect.end.x, y), ink, width, seed)
|
||||
return
|
||||
Sketch.box(to_canvas_item, rect, fill, ink, width, seed)
|
||||
1
game/scripts/sketch_box.gd.uid
Normal file
1
game/scripts/sketch_box.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ewfhmslc1j5q
|
||||
148
game/scripts/toon_look.gd
Normal file
148
game/scripts/toon_look.gd
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
class_name ToonLook
|
||||
extends Node
|
||||
## The game's look: toon shading and pixel outlines on everything 3D. Main adds one at start.
|
||||
## * Every lit, opaque StandardMaterial3D in the scene tree is swapped for a toon ShaderMaterial
|
||||
## (toon.gdshader; toon_double_sided.gdshader for double-sided ones) with the same color,
|
||||
## texture, and vertex-color use: the farm's imported props, the KayKit characters, the
|
||||
## weapons, and the primitives built in code. Unshaded or transparent materials (effects and
|
||||
## indicators: beams, flames, rings, zone tints, ghosts) are left alone, as are ShaderMaterials
|
||||
## (the crows' and UFOs' shaders include the toon lighting themselves).
|
||||
## * The swap goes on the nodes (material_override, or a surface override per surface), so the
|
||||
## asset files never change. Nodes added later (enemy pools, the partner's scarecrow, debris,
|
||||
## the farmers' return) are swapped at the end of the frame they arrive in, after the code that
|
||||
## built them has set and tinted their materials.
|
||||
## * A full-screen quad (pixel_outline.gdshader) darkens depth edges and lightens creases for
|
||||
## whatever camera is current. It needs the Forward+ renderer.
|
||||
## * Label3Ds aren't rendered in 3D (they'd be pixelated): ScreenLabels draws them as sharp text
|
||||
## over the 3D view, under the HUD.
|
||||
## The pixel size (rendering the 3D view small and scaling it up with sharp pixels) is a display
|
||||
## setting: GameSettings.pixel_size.
|
||||
|
||||
const TOON := preload("res://game/resources/toon.gdshader")
|
||||
const TOON_DOUBLE_SIDED := preload("res://game/resources/toon_double_sided.gdshader")
|
||||
const OUTLINE := preload("res://game/resources/pixel_outline.gdshader")
|
||||
|
||||
var outline: MeshInstance3D
|
||||
var labels: ScreenLabels
|
||||
## Source material -> its toon material (shared materials, like the farm pack's, convert once).
|
||||
var _swapped := {}
|
||||
var _pending: Array = [] # untyped: a node may be freed before the flush
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
outline = make_outline()
|
||||
add_child(outline)
|
||||
var layer := CanvasLayer.new()
|
||||
layer.name = "Labels"
|
||||
layer.layer = -1 # over the 3D view, under the HUD (1) and the menus (10)
|
||||
add_child(layer)
|
||||
labels = ScreenLabels.new()
|
||||
labels.name = "ScreenLabels"
|
||||
layer.add_child(labels)
|
||||
get_tree().node_added.connect(_on_node_added)
|
||||
apply_to(get_tree().root)
|
||||
|
||||
|
||||
## Swaps the materials of root and everything under it (and hands its Label3Ds to ScreenLabels).
|
||||
func apply_to(root: Node) -> void:
|
||||
if root is GeometryInstance3D:
|
||||
_take(root as GeometryInstance3D)
|
||||
for node in root.find_children("*", "GeometryInstance3D", true, false):
|
||||
_take(node as GeometryInstance3D)
|
||||
|
||||
|
||||
## Swaps one node's materials: its material override, else each surface of its mesh (a
|
||||
## MeshInstance3D), else the single surface of a particle or MultiMesh mesh (as an override).
|
||||
func swap_node(g: GeometryInstance3D) -> void:
|
||||
if g.material_override != null:
|
||||
g.material_override = toon_material(g.material_override)
|
||||
return
|
||||
var mi := g as MeshInstance3D
|
||||
if mi != null:
|
||||
if mi.mesh == null:
|
||||
return
|
||||
for i in mi.get_surface_override_material_count():
|
||||
var src := mi.get_active_material(i)
|
||||
if src == null:
|
||||
continue
|
||||
var toon := toon_material(src)
|
||||
if toon != src:
|
||||
mi.set_surface_override_material(i, toon)
|
||||
return
|
||||
var mesh: Mesh = null
|
||||
if g is CPUParticles3D:
|
||||
mesh = (g as CPUParticles3D).mesh
|
||||
elif g is MultiMeshInstance3D and (g as MultiMeshInstance3D).multimesh != null:
|
||||
mesh = (g as MultiMeshInstance3D).multimesh.mesh
|
||||
if mesh != null and mesh.get_surface_count() == 1 and mesh.surface_get_material(0) != null:
|
||||
var src := mesh.surface_get_material(0)
|
||||
var toon := toon_material(src)
|
||||
if toon != src:
|
||||
g.material_override = toon
|
||||
|
||||
|
||||
## The toon material that replaces src (one per source material), or src itself when it stays.
|
||||
func toon_material(src: Material) -> Material:
|
||||
if _swapped.has(src):
|
||||
return _swapped[src]
|
||||
var m := src as BaseMaterial3D
|
||||
if m == null or not swappable(m):
|
||||
return src
|
||||
var toon := ShaderMaterial.new()
|
||||
toon.resource_name = m.resource_name
|
||||
toon.shader = TOON_DOUBLE_SIDED if m.cull_mode == BaseMaterial3D.CULL_DISABLED else TOON
|
||||
toon.render_priority = m.render_priority
|
||||
toon.next_pass = m.next_pass
|
||||
toon.set_shader_parameter("albedo", m.albedo_color)
|
||||
toon.set_shader_parameter("albedo_texture", m.albedo_texture)
|
||||
toon.set_shader_parameter("use_vertex_color", m.vertex_color_use_as_albedo)
|
||||
toon.set_shader_parameter("uv1_scale", m.uv1_scale)
|
||||
toon.set_shader_parameter("uv1_offset", m.uv1_offset)
|
||||
_swapped[src] = toon
|
||||
return toon
|
||||
|
||||
|
||||
## Whether a material takes the toon look: lit, opaque, depth-tested, not a billboard.
|
||||
static func swappable(m: BaseMaterial3D) -> bool:
|
||||
return m.shading_mode != BaseMaterial3D.SHADING_MODE_UNSHADED \
|
||||
and m.transparency == BaseMaterial3D.TRANSPARENCY_DISABLED \
|
||||
and m.billboard_mode == BaseMaterial3D.BILLBOARD_DISABLED \
|
||||
and not m.no_depth_test
|
||||
|
||||
|
||||
## The outline pass: a quad that pixel_outline.gdshader pins over the whole screen.
|
||||
static func make_outline() -> MeshInstance3D:
|
||||
var quad := QuadMesh.new()
|
||||
quad.size = Vector2(2.0, 2.0)
|
||||
var mat := ShaderMaterial.new()
|
||||
mat.shader = OUTLINE
|
||||
mat.render_priority = Material.RENDER_PRIORITY_MIN # under the transparent effects
|
||||
var mi := MeshInstance3D.new()
|
||||
mi.name = "Outline"
|
||||
mi.mesh = quad
|
||||
mi.material_override = mat
|
||||
mi.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
mi.gi_mode = GeometryInstance3D.GI_MODE_DISABLED
|
||||
mi.extra_cull_margin = 16384.0 # the screen pins it; never let the camera's frustum cull it
|
||||
return mi
|
||||
|
||||
|
||||
func _on_node_added(node: Node) -> void:
|
||||
if node is GeometryInstance3D:
|
||||
if _pending.is_empty():
|
||||
_flush.call_deferred()
|
||||
_pending.append(node)
|
||||
|
||||
|
||||
func _flush() -> void:
|
||||
for g: Variant in _pending:
|
||||
if is_instance_valid(g) and (g as Node).is_inside_tree():
|
||||
_take(g as GeometryInstance3D)
|
||||
_pending.clear()
|
||||
|
||||
|
||||
func _take(g: GeometryInstance3D) -> void:
|
||||
if g is Label3D:
|
||||
labels.track(g as Label3D)
|
||||
else:
|
||||
swap_node(g)
|
||||
1
game/scripts/toon_look.gd.uid
Normal file
1
game/scripts/toon_look.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://wosfneqkuepf
|
||||
|
|
@ -14,10 +14,10 @@ extends Control
|
|||
const TEXT := {
|
||||
"move": "Move with [W A S D] or the left stick. You're the scarecrow: keep the farm safe until the farmers are back.",
|
||||
"gather": "Hold [E / X] at a dead tree, the haystacks, or the scrap heap to gather wood, straw, and scrap.",
|
||||
"store": "Your pouch only holds so much: walk onto the barn's apron (the Supply Shed) to store what you carry.",
|
||||
"store": "Your pouch only holds so much ([I] shows what's in it): walk onto the barn's apron (the Supply Shed) to store what you carry.",
|
||||
"build": "Press [B / d-pad up] to build. Pick a fence [1], place it with left mouse / RT. Aliens have to break through fences.",
|
||||
"dusk": "Dusk: aliens come at nightfall, from every side of the farm.",
|
||||
"shoot": "Aim with the mouse or the right stick and hold left mouse / RT to stab with your pitchfork. The supply shed sells a corn shooter (switch with [Tab / 1-2]); more weapons arrive there over the days, like pumpkin bombs for your off-hand (throw them with [right mouse / LT]).",
|
||||
"shoot": "Aim with the mouse or the right stick and hold left mouse / RT to stab with your pitchfork. The supply shed sells a corn shooter (switch with [Tab / the number keys]); more weapons arrive there over the days, like pumpkin bombs for your off-hand (throw them with [right mouse / LT]).",
|
||||
"fear": "Crowded? [Q / LB] Fear scares off everything nearby, and they drop what they carry.",
|
||||
"recover": "Something was dropped! Walk over it to bring it home. A dropped animal follows you back to the pen.",
|
||||
"patch": "Hurt? Hold [F / Y] to patch up with straw. Health carries over to the next night.",
|
||||
|
|
|
|||
|
|
@ -5,11 +5,74 @@ extends RefCounted
|
|||
## dark straw-trimmed panels, buttons that light up gold on hover and show a thick gold ring
|
||||
## when focused (keyboard and gamepad players always see where they are), sliders, check
|
||||
## boxes, and tabs to match. Labels keep the default look; the HUD sets its own sizes.
|
||||
## sketch() is the hand-drawn theme the in-game panels use instead (the pause menu and its
|
||||
## questions, the workbench and shed shops), to match the HUD's pouch panel (Sketch).
|
||||
|
||||
const TEXT := Color(0.95, 0.93, 0.85)
|
||||
const GOLD := Color(0.95, 0.82, 0.45)
|
||||
const DIM := Color(0.5, 0.5, 0.45)
|
||||
|
||||
static var _sketch: Theme
|
||||
|
||||
|
||||
## The hand-drawn theme (Sketch, SketchBox), set as a panel's theme: the handwritten font with a
|
||||
## dark outline on every label and button; panels in the pouch panel's dark wash and sketched ink
|
||||
## frame; buttons as hotbar slots that light up on hover, with the hotbar's gold frame when
|
||||
## focused; HSeparators as a pen rule; and SolidPanel, a PanelContainer variation without the
|
||||
## see-through wash. Anything it leaves out (sliders, check boxes) falls back
|
||||
## to the project's theme.
|
||||
static func sketch() -> Theme:
|
||||
if _sketch != null:
|
||||
return _sketch
|
||||
var t := Theme.new()
|
||||
t.default_font = Sketch.font()
|
||||
t.default_font_size = 28
|
||||
var panel := SketchBox.new(Sketch.PANEL, Sketch.INK, Sketch.PANEL_INK)
|
||||
_margins(panel, 26.0, 20.0)
|
||||
t.set_stylebox("panel", "PanelContainer", panel)
|
||||
t.set_stylebox("panel", "Panel", panel)
|
||||
# The same panel without the see-through wash, for a question over another panel.
|
||||
var solid := SketchBox.new(Color(Sketch.PANEL, 1.0), Sketch.INK, Sketch.PANEL_INK)
|
||||
_margins(solid, 26.0, 20.0)
|
||||
t.set_type_variation(&"SolidPanel", &"PanelContainer")
|
||||
t.set_stylebox("panel", "SolidPanel", solid)
|
||||
t.set_color("font_color", "Label", Sketch.TEXT)
|
||||
t.set_color("font_outline_color", "Label", Sketch.INK)
|
||||
t.set_constant("outline_size", "Label", 6)
|
||||
var hover := Color(Sketch.SLOT.lightened(0.12), 0.8)
|
||||
var styles := {
|
||||
"normal": SketchBox.new(Sketch.SLOT, Sketch.INK, 2.5),
|
||||
"hover": SketchBox.new(hover, Sketch.INK, 2.5),
|
||||
"pressed": SketchBox.new(Color(Sketch.SLOT.darkened(0.3), 0.8), Sketch.GOLD, 2.5),
|
||||
"disabled": SketchBox.new(Color(0.12, 0.12, 0.11, 0.5), Color(Sketch.INK, 0.6), 2.0),
|
||||
"focus": SketchBox.new(Color(0, 0, 0, 0), Sketch.GOLD, 3.5),
|
||||
}
|
||||
for key: String in styles:
|
||||
var b: SketchBox = styles[key]
|
||||
_margins(b, 18.0, 6.0)
|
||||
if key == "focus":
|
||||
b.grow = 3.0
|
||||
t.set_stylebox(key, "Button", b)
|
||||
t.set_color("font_color", "Button", Sketch.TEXT)
|
||||
t.set_color("font_hover_color", "Button", Color(1.0, 0.95, 0.7))
|
||||
t.set_color("font_focus_color", "Button", Color(1.0, 0.95, 0.7))
|
||||
t.set_color("font_hover_pressed_color", "Button", Sketch.GOLD)
|
||||
t.set_color("font_pressed_color", "Button", Sketch.GOLD)
|
||||
t.set_color("font_disabled_color", "Button", Sketch.DIM)
|
||||
t.set_color("font_outline_color", "Button", Sketch.INK)
|
||||
t.set_constant("outline_size", "Button", 6)
|
||||
t.set_stylebox("separator", "HSeparator", SketchBox.new(Color(0, 0, 0, 0), Sketch.RULE, 2.0, true))
|
||||
t.set_constant("separation", "HSeparator", 12)
|
||||
_sketch = t
|
||||
return t
|
||||
|
||||
|
||||
static func _margins(s: StyleBox, x: float, y: float) -> void:
|
||||
s.content_margin_left = x
|
||||
s.content_margin_right = x
|
||||
s.content_margin_top = y
|
||||
s.content_margin_bottom = y
|
||||
|
||||
|
||||
static func build() -> Theme:
|
||||
var t := Theme.new()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ extends CenterContainer
|
|||
## (shop "shed": weapons and other purchasable items) opens with interact at the shed's counter by
|
||||
## day (Interactions). Buy with a click, or the arrows / d-pad and Enter / A. Close it with Close,
|
||||
## Escape / B, interact again, by walking off, or at nightfall. The scarecrow stands still and
|
||||
## can't shoot while either is open.
|
||||
## can't shoot while either is open. Hand-drawn like the HUD's pouch panel (UiTheme.sketch): the
|
||||
## title over a pen rule, the tracks' names dim like the pouch's column headings, a slot per row.
|
||||
|
||||
## A purchase's result text. Nothing shows it on screen since #23 (the rows say what's missing);
|
||||
## tests listen to it.
|
||||
|
|
@ -49,20 +50,20 @@ func setup(p_campaign: CampaignController, p_structures: StructureSystem, p_play
|
|||
track = String(u.get("track", ""))
|
||||
var head := Label.new()
|
||||
head.text = track
|
||||
head.add_theme_font_size_override("font_size", 20)
|
||||
head.add_theme_color_override("font_color", Color(0.75, 0.85, 0.75))
|
||||
head.add_theme_font_size_override("font_size", 24)
|
||||
head.add_theme_color_override("font_color", Sketch.DIM)
|
||||
box.add_child(head)
|
||||
var b := Button.new()
|
||||
b.alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
b.custom_minimum_size = Vector2(720.0, 44.0)
|
||||
b.add_theme_font_size_override("font_size", 20)
|
||||
b.custom_minimum_size = Vector2(860.0, 46.0)
|
||||
b.add_theme_font_size_override("font_size", 25)
|
||||
b.pressed.connect(func() -> void: _buy(id))
|
||||
box.add_child(b)
|
||||
_rows[id] = b
|
||||
_close = Button.new()
|
||||
_close.text = "Close"
|
||||
_close.custom_minimum_size = Vector2(200.0, 48.0)
|
||||
_close.add_theme_font_size_override("font_size", 22)
|
||||
_close.add_theme_font_size_override("font_size", 28)
|
||||
_close.size_flags_horizontal = Control.SIZE_SHRINK_CENTER
|
||||
_close.pressed.connect(close)
|
||||
box.add_child(_close)
|
||||
|
|
@ -70,22 +71,23 @@ func setup(p_campaign: CampaignController, p_structures: StructureSystem, p_play
|
|||
|
||||
func _ready() -> void:
|
||||
set_anchors_preset(Control.PRESET_FULL_RECT)
|
||||
theme = UiTheme.sketch()
|
||||
var panel := PanelContainer.new()
|
||||
panel.name = "Panel"
|
||||
panel.add_theme_stylebox_override("panel", ReviewPanel.backing())
|
||||
add_child(panel)
|
||||
var margin := MarginContainer.new()
|
||||
margin.name = "Margin"
|
||||
for side in ["left", "right", "top", "bottom"]:
|
||||
margin.add_theme_constant_override("margin_" + side, 24)
|
||||
margin.add_theme_constant_override("margin_" + side, 8)
|
||||
panel.add_child(margin)
|
||||
var box := VBoxContainer.new()
|
||||
box.name = "Box"
|
||||
box.add_theme_constant_override("separation", 6)
|
||||
margin.add_child(box)
|
||||
_title = Label.new()
|
||||
_title.add_theme_font_size_override("font_size", 32)
|
||||
_title.add_theme_font_size_override("font_size", 36)
|
||||
box.add_child(_title)
|
||||
box.add_child(HSeparator.new())
|
||||
visible = false
|
||||
mouse_filter = Control.MOUSE_FILTER_IGNORE
|
||||
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ static func level_up(campaign: CampaignController, id: String, structures: Struc
|
|||
s.resources.pouch_capacity += add
|
||||
|
||||
|
||||
## Debug (CampaignDebug, F8): every upgrade and shop item to its last level, free, whatever the
|
||||
## Debug (CampaignDebug, F4): every upgrade and shop item to its last level, free, whatever the
|
||||
## day, the goop, or "requires" say, each level's effect applied as if bought. Not counted as
|
||||
## bought in the night record. Returns how many levels it added.
|
||||
static func grant_all(campaign: CampaignController, structures: StructureSystem = null) -> int:
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ const SUITES := [
|
|||
"res://game/tests/test_cycle.gd",
|
||||
"res://game/tests/test_flow.gd",
|
||||
"res://game/tests/test_coop.gd",
|
||||
"res://game/tests/test_look.gd",
|
||||
]
|
||||
const TICK := 1.0 / 60.0
|
||||
## Points on the farm's edge (FarmZones.edge) for tests that send an enemy in from a known side:
|
||||
|
|
|
|||
|
|
@ -28,9 +28,8 @@ func run(r: GameTestRunner) -> void:
|
|||
# counts this test tracks across night 1 (it isn't about the Workbench itself)
|
||||
var review := farm.get_node("Hud/ReviewPanel") as ReviewPanel
|
||||
var hud := farm.get_node("Hud/PhaseHud") as PhaseHud
|
||||
var assets := farm.get_node("Hud/AssetHud") as AssetHud
|
||||
assets._process(0.0)
|
||||
r.check(assets.describe() == "Crops 30/30 · Animals 8/8 · Supplies 10", "the asset HUD reads '%s'" % assets.describe())
|
||||
var assets := " · ".join(PauseMenu.asset_counts(sim.campaign.state))
|
||||
r.check(assets == "Crops 30/30 · Animals 8/8 · Supplies 10", "the pause menu's assets read '%s'" % assets)
|
||||
sim.structures.destroyed.connect(func(_id: int, _t: String, _at: Vector3) -> void: _broken.append(1))
|
||||
_morning(r, sim, review, hud)
|
||||
_day(r, sim, player, hud)
|
||||
|
|
@ -47,7 +46,7 @@ func _morning(r: GameTestRunner, sim: FarmSim, review: ReviewPanel, hud: PhaseHu
|
|||
r.check(sim.campaign.state.phase == P.MORNING and review.visible and review._title.text == "The farmers are away",
|
||||
"the first morning shows the review panel with the introduction")
|
||||
hud._process(0.0)
|
||||
r.check(hud.describe() == "Night 1 of %d · Morning" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
|
||||
r.check(hud.describe() == "Day 1 of %d · Morning" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
|
||||
sim.day_night.snap()
|
||||
var day_energy := sim.sun.light_energy
|
||||
r.check(sim.day_night.lantern.light_energy < 0.6 and day_energy > 0.8, "morning light: bright sun, lantern nearly off")
|
||||
|
|
@ -59,7 +58,7 @@ func _day(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: PhaseHu
|
|||
var c := sim.campaign
|
||||
var s := c.state
|
||||
hud._process(0.0)
|
||||
r.check(hud.describe() == "Night 1 of %d · Day · 3:00 left" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
|
||||
r.check(hud.describe() == "Day 1 of %d · 3:00 until Dusk" % sim.config.campaign_nights, "the phase HUD reads '%s'" % hud.describe())
|
||||
sim.day_night.snap()
|
||||
r.check(is_equal_approx(sim.day_night.lantern.light_energy, 0.0) and sim.sun.light_energy > 1.0, "daylight: full sun, no lantern")
|
||||
# A day's work: gather into the pouch, build, take some damage, patch up.
|
||||
|
|
@ -96,7 +95,7 @@ func _dusk(r: GameTestRunner, sim: FarmSim, hud: PhaseHud) -> void:
|
|||
r.check(w.warning_active() and w.tonight_entries() == [[EnemySystem.TYPE_CROW, LootSystem.Category.CROP]], "dusk warns of what tonight brings: %s" % [w.tonight_entries()])
|
||||
hud._process(0.0)
|
||||
var warning := "Tonight, from every side: crows"
|
||||
r.check(hud._hint.text == warning, "the HUD warns, by target: '%s'" % hud._hint.text.replace("\n", " / "))
|
||||
r.check(hud.hint == warning, "the HUD warns, by target: '%s'" % hud.hint.replace("\n", " / "))
|
||||
var marked := w.get_children().filter(func(n: Node) -> bool: return n is Node3D and (n as Node3D).visible)
|
||||
r.check(marked.is_empty() and sim.alerts.collect().is_empty(), "nothing marks tonight's arrivals on the farm or at the screen edge")
|
||||
r.check(hud._dusk_hint.visible and hud._dusk_hint.text == plan.dusk_hint and hud._banner.text == "Dusk: %s" % plan.title,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ extends RefCounted
|
|||
## supply shed's own shop (#6): weapons (corn_shooter, pumpkin_bomb) bought at its counter
|
||||
## (ShedCounter), not the workbench, with the walk-in pouch deposit unaffected. And a pouch per
|
||||
## scarecrow (#16): filled, deposited, and spent from by its own avatar slot, one shared capacity.
|
||||
## And upgrade levels and timed shed stock (#26, _tiers and _stock).
|
||||
## And upgrade levels and timed shed stock (#26, _tiers and _stock). And the HUD's backpack and
|
||||
## pouch panel (ResourceHud).
|
||||
|
||||
const P := CampaignController.Phase
|
||||
const DT := 1.0 / 60.0
|
||||
|
|
@ -38,6 +39,7 @@ func run(r: GameTestRunner) -> void:
|
|||
sim.waves.enabled = false
|
||||
var player := farm.get_node("Player") as PlayerCharacter
|
||||
_layout(r, sim)
|
||||
_pouch_hud(r, farm, sim)
|
||||
_gathering(r, sim, player)
|
||||
_deposit_and_night(r, sim, player)
|
||||
_patch_cost(r, sim)
|
||||
|
|
@ -384,7 +386,7 @@ func _tiers(r: GameTestRunner) -> void:
|
|||
## Timed shed stock (#26): each shed item arrives on its day ("from_day"; day N is the day before
|
||||
## night N) and can't be bought before it. Its row shows just its name, greyed, and "Arrives on
|
||||
## day N"; a hidden one shows "?" and its day until it arrives, then the bare "?" until revealed.
|
||||
## Debug F8 (CampaignDebug.unlock_all): on day 1, every upgrade and shop item goes to its last
|
||||
## Debug F4 (CampaignDebug.unlock_all): on day 1, every upgrade and shop item goes to its last
|
||||
## level for free, each level's effect applied; a retry from the morning review keeps it, one from
|
||||
## later in the day goes back to the morning without it.
|
||||
func _unlock_all(r: GameTestRunner) -> void:
|
||||
|
|
@ -400,14 +402,14 @@ func _unlock_all(r: GameTestRunner) -> void:
|
|||
var shed: Dictionary = s.resources.shed.duplicate()
|
||||
var damage := Upgrades.value(cfg, s, "shot_damage")
|
||||
var key := InputEventKey.new()
|
||||
key.physical_keycode = KEY_F8
|
||||
key.physical_keycode = KEY_F4
|
||||
key.pressed = true
|
||||
debug._unhandled_input(key)
|
||||
var all_max := true
|
||||
for id: String in cfg.upgrades:
|
||||
all_max = all_max and Upgrades.maxed(cfg, s, id) and Upgrades.blocker(c, id) == "Done"
|
||||
r.check(all_max and s.night == 1 and Upgrades.levels_bought(cfg, s) == Upgrades.levels_total(cfg),
|
||||
"F8 on the first morning: every upgrade and shop item at its last level (%d levels), hidden and not-yet-arrived ones too"
|
||||
"F4 on the first morning: every upgrade and shop item at its last level (%d levels), hidden and not-yet-arrived ones too"
|
||||
% Upgrades.levels_bought(cfg, s))
|
||||
r.check(s.resources.shed == shed and int(s.night_events.get("upgrades_bought", 0)) == 0, "free, and not counted as bought")
|
||||
r.check(s.scarecrow_max_hp == hp + 6 and s.scarecrow_hp == hp + 6 and s.resources.pouch_capacity == pouch + 16
|
||||
|
|
@ -576,6 +578,44 @@ func _gathering(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> voi
|
|||
_step(sim, 1)
|
||||
|
||||
|
||||
## The HUD's backpack: "used/capacity", a red dot once something new is carried (gone once the pouch
|
||||
## is opened, or emptied), and the pouch panel (I / R3) with what's carried and what the shed holds.
|
||||
func _pouch_hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
|
||||
var hud := farm.get_node("Hud/ResourceHud") as ResourceHud
|
||||
var res := sim.campaign.state.resources
|
||||
var keep_shed: Dictionary = res.shed.duplicate()
|
||||
var keep_pouch: Dictionary = res.pouch.duplicate()
|
||||
for m in ResourceStore.MATERIALS:
|
||||
res.pouch[m] = 0
|
||||
hud._process(0.0)
|
||||
hud.open = false
|
||||
r.check(not hud.new_items and hud.count_text() == "0/%d" % res.pouch_capacity, "an empty pouch: '%s', no dot" % hud.count_text())
|
||||
res.add_to_pouch("wood", 3)
|
||||
res.shed["scrap"] = 7
|
||||
hud._process(0.0)
|
||||
r.check(hud.count_text() == "3/%d" % res.pouch_capacity and hud.new_items, "the backpack counts what's carried ('%s'), with a dot for the new wood" % hud.count_text())
|
||||
var press := InputEventAction.new()
|
||||
press.action = &"pouch"
|
||||
press.pressed = true
|
||||
hud._unhandled_input(press)
|
||||
var rows := hud.rows()
|
||||
r.check(hud.open and not hud.new_items and rows.size() == ResourceStore.MATERIALS.size()
|
||||
and rows[0] == {"material": "wood", "pouch": 3, "shed": int(res.shed["wood"])} and int(rows[1]["shed"]) == 7,
|
||||
"I opens the pouch: what's carried and the shed's stock of each, and the dot goes: %s" % [rows])
|
||||
hud._unhandled_input(press)
|
||||
r.check(not hud.open, "and closes it again")
|
||||
res.add_to_pouch("straw", 1)
|
||||
hud._process(0.0)
|
||||
var dot := hud.new_items
|
||||
res.deposit()
|
||||
hud._process(0.0)
|
||||
r.check(dot and not hud.new_items, "emptying the pouch clears the dot")
|
||||
for m in ResourceStore.MATERIALS:
|
||||
res.shed[m] = int(keep_shed.get(m, 0))
|
||||
res.pouch[m] = int(keep_pouch.get(m, 0))
|
||||
hud._process(0.0)
|
||||
|
||||
|
||||
func _deposit_and_night(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
||||
var c := sim.campaign
|
||||
var res := c.state.resources
|
||||
|
|
|
|||
|
|
@ -81,15 +81,15 @@ func _zones(r: GameTestRunner, zones: FarmZones) -> void:
|
|||
r.check(not o.rect().intersects(z.rect()), "%s and %s don't overlap" % [o.display_name, z.display_name])
|
||||
|
||||
|
||||
## #13: 20 more crop units in two later-sprouting fields (lettuce/cabbage, corn), 10 each, ids
|
||||
## 31..40 and 41..50, continuing the original field's plot numbering (7..10). GameConfig.start_crops
|
||||
## #13: 60 more crop units in two later-sprouting fields (lettuce/cabbage, corn), 30 each, ids
|
||||
## 31..60 and 61..90, continuing the original field's plot numbering (7..18). GameConfig.start_crops
|
||||
## (30) only counts the original, always-grown field; the later fields grow FarmState.crops_total
|
||||
## when they sprout (LootSystem), so it's not part of this static count.
|
||||
func _crops(r: GameTestRunner, zones: FarmZones) -> void:
|
||||
var cfg := load("res://game/resources/game_config.tres") as GameConfig
|
||||
var units := zones.crop_units()
|
||||
var fields := zones.zones_of(FarmZone.Kind.CROP_FIELD)
|
||||
r.check(units.size() == cfg.start_crops + 20, "%d crop units: %d in the original field, 20 in the two later ones" % [units.size(), cfg.start_crops])
|
||||
r.check(units.size() == cfg.start_crops + 60, "%d crop units: %d in the original field, 60 in the two later ones" % [units.size(), cfg.start_crops])
|
||||
var ids := {}
|
||||
var per_plot := {}
|
||||
var fewest := 1 << 30
|
||||
|
|
@ -104,14 +104,14 @@ func _crops(r: GameTestRunner, zones: FarmZones) -> void:
|
|||
g["count"] = int(g["count"]) + 1
|
||||
by_crop[u.crop] = g
|
||||
r.check(ids.size() == units.size() and ids.has(1) and ids.has(units.size()), "crop unit ids are unique, 1..%d" % units.size())
|
||||
r.check(per_plot.size() == 10 and per_plot.values().all(func(n: int) -> bool: return n == 5), "10 plots of 5 units (%s)" % [per_plot])
|
||||
r.check(per_plot.size() == 18 and per_plot.values().all(func(n: int) -> bool: return n == 5), "18 plots of 5 units (%s)" % [per_plot])
|
||||
r.check(fewest >= 8, "every unit is a visible cluster (fewest plants: %d)" % fewest)
|
||||
r.check(by_crop.get("sunflower", {}).get("count", 0) == cfg.start_crops and by_crop["sunflower"]["sprout_night"] == 0,
|
||||
"the original field's %d units are sunflowers, already grown" % cfg.start_crops)
|
||||
r.check(by_crop.get("lettuce", {}).get("count", 0) == 10 and by_crop["lettuce"]["sprout_night"] == 2,
|
||||
"10 lettuce/cabbage units sprout after night 2")
|
||||
r.check(by_crop.get("corn", {}).get("count", 0) == 10 and by_crop["corn"]["sprout_night"] == 4,
|
||||
"10 corn units sprout after night 4")
|
||||
r.check(by_crop.get("lettuce", {}).get("count", 0) == 30 and by_crop["lettuce"]["sprout_night"] == 2,
|
||||
"30 lettuce/cabbage units sprout after night 2")
|
||||
r.check(by_crop.get("corn", {}).get("count", 0) == 30 and by_crop["corn"]["sprout_night"] == 4,
|
||||
"30 corn units sprout after night 4")
|
||||
|
||||
|
||||
## #20: the lettuce/cabbage and corn fields grow on the bare plowed soil south of the original map
|
||||
|
|
|
|||
194
game/tests/test_look.gd
Normal file
194
game/tests/test_look.gd
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
extends RefCounted
|
||||
## The toon look (ToonLook): lit, opaque StandardMaterial3Ds become toon ShaderMaterials with the
|
||||
## same color, texture, and vertex-color use (double-sided ones get the double-sided shader), one
|
||||
## per source material; unshaded, transparent, billboard, and no-depth-test materials stay. Nodes
|
||||
## added later are swapped by the end of their frame, after their builder tinted them (the
|
||||
## co-op partner's blue scarecrow). On the real farm no lit StandardMaterial3D is left showing,
|
||||
## and the outline quad never casts a shadow and draws under the transparent effects. Label3Ds
|
||||
## stop rendering in 3D (they'd be pixelated) and ScreenLabels draws them as flat text where they
|
||||
## project, at least MIN_SIZE tall, only while shown and in front of the camera, and nudged apart
|
||||
## where they'd overlap.
|
||||
|
||||
const TOON := "res://game/resources/toon.gdshader"
|
||||
const TOON_DOUBLE_SIDED := "res://game/resources/toon_double_sided.gdshader"
|
||||
|
||||
|
||||
func run(r: GameTestRunner) -> void:
|
||||
_materials(r)
|
||||
await _farm(r)
|
||||
|
||||
|
||||
func _materials(r: GameTestRunner) -> void:
|
||||
var look := ToonLook.new()
|
||||
var lit := StandardMaterial3D.new()
|
||||
lit.albedo_color = Color(0.8, 0.3, 0.1)
|
||||
var tex := PlaceholderTexture2D.new()
|
||||
lit.albedo_texture = tex
|
||||
lit.vertex_color_use_as_albedo = true
|
||||
var toon := look.toon_material(lit) as ShaderMaterial
|
||||
r.check(toon != null and toon.shader.resource_path == TOON, "a lit, opaque material becomes a toon ShaderMaterial")
|
||||
r.check(toon != null and toon.get_shader_parameter("albedo") == lit.albedo_color
|
||||
and toon.get_shader_parameter("albedo_texture") == tex and toon.get_shader_parameter("use_vertex_color") == true,
|
||||
"with the same color, texture, and vertex-color use")
|
||||
r.check(look.toon_material(lit) == toon and look.toon_material(toon) == toon,
|
||||
"one toon material per source (and swapping again changes nothing)")
|
||||
var two_sided := StandardMaterial3D.new()
|
||||
two_sided.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
r.check((look.toon_material(two_sided) as ShaderMaterial).shader.resource_path == TOON_DOUBLE_SIDED,
|
||||
"a double-sided material gets the double-sided toon shader")
|
||||
var unshaded := StandardMaterial3D.new()
|
||||
unshaded.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
var glass := StandardMaterial3D.new()
|
||||
glass.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
var facing := StandardMaterial3D.new()
|
||||
facing.billboard_mode = BaseMaterial3D.BILLBOARD_ENABLED
|
||||
var overlay := StandardMaterial3D.new()
|
||||
overlay.no_depth_test = true
|
||||
var kept := 0
|
||||
for m: StandardMaterial3D in [unshaded, glass, facing, overlay]:
|
||||
if look.toon_material(m) == m:
|
||||
kept += 1
|
||||
r.check(kept == 4, "unshaded, transparent, billboard, and no-depth-test materials stay (%d of 4)" % kept)
|
||||
|
||||
var mesh := BoxMesh.new()
|
||||
mesh.material = lit
|
||||
var mi := MeshInstance3D.new()
|
||||
mi.mesh = mesh
|
||||
look.swap_node(mi)
|
||||
r.check(mi.get_surface_override_material(0) == toon and mesh.material == lit,
|
||||
"a mesh's own material is swapped with a surface override (the mesh resource is untouched)")
|
||||
var over := MeshInstance3D.new()
|
||||
over.mesh = mesh
|
||||
over.material_override = two_sided
|
||||
look.swap_node(over)
|
||||
r.check(over.material_override == look.toon_material(two_sided), "a material override is swapped in place")
|
||||
var debris := CPUParticles3D.new()
|
||||
debris.mesh = mesh
|
||||
look.swap_node(debris)
|
||||
r.check(debris.material_override == toon, "particles swap their mesh's material through an override")
|
||||
mi.free()
|
||||
over.free()
|
||||
debris.free()
|
||||
look.free()
|
||||
|
||||
|
||||
func _farm(r: GameTestRunner) -> void:
|
||||
var farm := (load("res://game/scenes/farm.tscn") as PackedScene).instantiate() as Node3D
|
||||
r.root.add_child(farm)
|
||||
await r.process_frame
|
||||
var sim := farm.get_node("FarmSim") as FarmSim
|
||||
sim.set_physics_process(false)
|
||||
var look := ToonLook.new()
|
||||
r.root.add_child(look)
|
||||
var left := _lit_left(farm)
|
||||
r.check(left.is_empty(), "no lit StandardMaterial3D is left showing on the farm (%d left: %s)" % [left.size(), ", ".join(left.slice(0, 5))])
|
||||
r.check(_toon_count(farm) > 100, "the farm's props, characters, and weapons are toon-shaded (%d surfaces)" % _toon_count(farm))
|
||||
|
||||
var a := sim.add_partner(false, "Ben")
|
||||
var body := a.body
|
||||
r.check(not _lit_left(body).is_empty(), "the partner's scarecrow arrives with lit materials (tinted blue)")
|
||||
await r.process_frame
|
||||
await r.process_frame
|
||||
r.check(_lit_left(body).is_empty(), "and is toon-shaded by the end of the frame it arrived in")
|
||||
var blue := false
|
||||
for mi in body.find_children("*", "MeshInstance3D", true, false):
|
||||
var m := (mi as MeshInstance3D).material_override as ShaderMaterial
|
||||
if m != null and m.get_shader_parameter("albedo") == Color(0.55, 0.75, 1.0):
|
||||
blue = true
|
||||
r.check(blue, "keeping its blue tint")
|
||||
|
||||
var label3ds := farm.find_children("*", "Label3D", true, false)
|
||||
r.check(label3ds.size() >= 5 and label3ds.all(func(l: Node) -> bool: return (l as Label3D).layers == 0),
|
||||
"the farm's %d Label3Ds don't render in 3D (ScreenLabels draws them)" % label3ds.size())
|
||||
var cam := r.root.get_camera_3d()
|
||||
var sign := Label3D.new()
|
||||
sign.text = "Wood 4"
|
||||
sign.font_size = 40
|
||||
sign.pixel_size = 0.0075
|
||||
sign.outline_size = 10
|
||||
sign.modulate = Color(1.0, 0.8, 0.3)
|
||||
farm.add_child(sign)
|
||||
sign.global_position = cam.global_position - cam.global_basis.z * 12.0
|
||||
sign.reset_physics_interpolation() # drawn where it's displayed, as in 3D
|
||||
await r.process_frame
|
||||
var drawn := look.labels.entries().filter(func(e: Dictionary) -> bool: return e["label"] == sign)
|
||||
r.check(drawn.size() == 1 and drawn[0]["text"] == "Wood 4" and drawn[0]["color"] == sign.modulate
|
||||
and drawn[0]["font_size"] >= ScreenLabels.MIN_SIZE and drawn[0]["outline_size"] > 0
|
||||
and r.root.get_visible_rect().encloses(drawn[0]["rect"]),
|
||||
"a label added later is drawn flat on screen with its text, color, and outline, readable size (%s)"
|
||||
% [drawn[0]["font_size"] if drawn.size() == 1 else "not drawn"])
|
||||
var twin := sign.duplicate() as Label3D
|
||||
twin.text = "Alien Goop 0"
|
||||
farm.add_child(twin)
|
||||
twin.global_position = sign.global_position
|
||||
twin.reset_physics_interpolation()
|
||||
await r.process_frame
|
||||
var pair := look.labels.entries().filter(func(e: Dictionary) -> bool: return e["label"] in [sign, twin])
|
||||
r.check(pair.size() == 2 and not (pair[0]["rect"] as Rect2).intersects(pair[1]["rect"]),
|
||||
"two labels at the same spot are nudged apart, so both can be read")
|
||||
twin.queue_free()
|
||||
sign.visible = false
|
||||
r.check(not look.labels.entries().any(func(e: Dictionary) -> bool: return e["label"] == sign), "but not while hidden")
|
||||
sign.visible = true
|
||||
sign.global_position = cam.global_position + cam.global_basis.z * 12.0
|
||||
sign.reset_physics_interpolation()
|
||||
await r.process_frame # (the displayed position moves with the frame)
|
||||
r.check(not look.labels.entries().any(func(e: Dictionary) -> bool: return e["label"] == sign), "or behind the camera")
|
||||
|
||||
var outline := look.outline
|
||||
var outline_mat := outline.material_override as ShaderMaterial
|
||||
r.check(outline.is_inside_tree() and outline_mat.shader.resource_path == "res://game/resources/pixel_outline.gdshader"
|
||||
and outline.cast_shadow == GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
and outline_mat.render_priority == Material.RENDER_PRIORITY_MIN,
|
||||
"the outline quad is in the world, casts no shadow, and draws under the transparent effects")
|
||||
look.queue_free()
|
||||
farm.queue_free()
|
||||
await r.process_frame
|
||||
|
||||
|
||||
## The nodes under root still showing a lit StandardMaterial3D, by name.
|
||||
static func _lit_left(root: Node) -> Array[String]:
|
||||
var out: Array[String] = []
|
||||
for node in [root] + root.find_children("*", "GeometryInstance3D", true, false):
|
||||
var g := node as GeometryInstance3D
|
||||
if g == null:
|
||||
continue
|
||||
for m in _shown(g):
|
||||
if m is BaseMaterial3D and ToonLook.swappable(m as BaseMaterial3D):
|
||||
out.append(String(g.name))
|
||||
return out
|
||||
|
||||
|
||||
static func _toon_count(root: Node) -> int:
|
||||
var n := 0
|
||||
for node in root.find_children("*", "GeometryInstance3D", true, false):
|
||||
for m in _shown(node as GeometryInstance3D):
|
||||
var s := m as ShaderMaterial
|
||||
if s != null and s.shader != null and s.shader.resource_path in [TOON, TOON_DOUBLE_SIDED]:
|
||||
n += 1
|
||||
return n
|
||||
|
||||
|
||||
## The materials a node draws with.
|
||||
static func _shown(g: GeometryInstance3D) -> Array[Material]:
|
||||
var out: Array[Material] = []
|
||||
if g.material_override != null:
|
||||
out.append(g.material_override)
|
||||
return out
|
||||
var mesh: Mesh = null
|
||||
if g is MeshInstance3D:
|
||||
var mi := g as MeshInstance3D
|
||||
if mi.mesh != null:
|
||||
for i in mi.get_surface_override_material_count():
|
||||
if mi.get_active_material(i) != null:
|
||||
out.append(mi.get_active_material(i))
|
||||
return out
|
||||
if g is CPUParticles3D:
|
||||
mesh = (g as CPUParticles3D).mesh
|
||||
elif g is MultiMeshInstance3D and (g as MultiMeshInstance3D).multimesh != null:
|
||||
mesh = (g as MultiMeshInstance3D).multimesh.mesh
|
||||
if mesh != null:
|
||||
for i in mesh.get_surface_count():
|
||||
if mesh.surface_get_material(i) != null:
|
||||
out.append(mesh.surface_get_material(i))
|
||||
return out
|
||||
1
game/tests/test_look.gd.uid
Normal file
1
game/tests/test_look.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://8pt5we4ip4pk
|
||||
|
|
@ -406,7 +406,7 @@ func _night_jump(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
|
|||
r.check(c.morning_snapshot() == s.to_dict() and sim.review_panel.visible and body.contains("Tonight: %s." % tonight),
|
||||
"the retry snapshot and the review panel are day 2's")
|
||||
debug._unhandled_input(f3)
|
||||
r.check(s.night == 3 and s.nights_survived == 2 and s.crops_total == crops + 10 and sim.loot.count(LootSystem.Status.DORMANT) == dormant - 10,
|
||||
r.check(s.night == 3 and s.nights_survived == 2 and s.crops_total == crops + 30 and sim.loot.count(LootSystem.Status.DORMANT) == dormant - 30,
|
||||
"F3 again: day 3, and the field due after night 2 sprouts (%d crops)" % s.crops_total)
|
||||
var back := f3.duplicate() as InputEventKey
|
||||
back.shift_pressed = true
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ func _settings(r: GameTestRunner) -> void:
|
|||
_clean()
|
||||
var fresh := GameSettings.load_from(SETTINGS)
|
||||
r.check(fresh.volume == GameSettings.DEFAULT_VOLUME and fresh.show_tips and fresh.vsync and not fresh.fullscreen
|
||||
and fresh.resolution_scale == 1.0, "no settings file: the defaults")
|
||||
and fresh.resolution_scale == 1.0 and fresh.pixel_size == 4, "no settings file: the defaults")
|
||||
var g := GameSettings.new()
|
||||
g.volume = {"Master": 0.5, "Music": 0.25, "SFX": 0.0, "Ambience": 1.0, "Voice": 0.6}
|
||||
g.move_dead_zone = 0.35
|
||||
|
|
@ -203,6 +203,7 @@ func _settings(r: GameTestRunner) -> void:
|
|||
g.fullscreen = true
|
||||
g.vsync = false
|
||||
g.resolution_scale = 0.75
|
||||
g.pixel_size = 2
|
||||
g.show_tips = false
|
||||
g.player_name = "Ana"
|
||||
g.microphone = false
|
||||
|
|
@ -210,16 +211,27 @@ func _settings(r: GameTestRunner) -> void:
|
|||
var back := GameSettings.load_from(SETTINGS)
|
||||
r.check(back.volume == g.volume and back.move_dead_zone == 0.35 and back.aim_dead_zone == 0.15 and back.fullscreen
|
||||
and not back.vsync and back.resolution_scale == 0.75 and not back.show_tips and back.player_name == "Ana"
|
||||
and not back.microphone, "and load back unchanged (co-op name and microphone too)")
|
||||
and not back.microphone and back.pixel_size == 2, "and load back unchanged (co-op name, microphone, pixel size too)")
|
||||
var f := ConfigFile.new()
|
||||
f.set_value("audio", "master", 7.0)
|
||||
f.set_value("audio", "music", "loud")
|
||||
f.set_value("display", "fullscreen", "yes")
|
||||
f.set_value("display", "resolution_scale", 0.1)
|
||||
f.set_value("display", "pixel_size", 40)
|
||||
f.save(SETTINGS)
|
||||
var odd := GameSettings.load_from(SETTINGS)
|
||||
r.check(odd.volume["Master"] == 1.0 and odd.volume["Music"] == GameSettings.DEFAULT_VOLUME["Music"] and not odd.fullscreen
|
||||
and odd.resolution_scale == 0.5, "out-of-range and wrong-typed values are clamped or fall back")
|
||||
and odd.resolution_scale == 0.5 and odd.pixel_size == GameSettings.MAX_PIXEL_SIZE,
|
||||
"out-of-range and wrong-typed values are clamped or fall back")
|
||||
var view := SubViewport.new()
|
||||
g.apply_pixels(view)
|
||||
r.check(view.scaling_3d_mode == Viewport.SCALING_3D_MODE_NEAREST and is_equal_approx(view.scaling_3d_scale, 0.5)
|
||||
and view.msaa_3d == Viewport.MSAA_DISABLED, "pixel size 2 renders the 3D view at half size, sharp-scaled, no MSAA")
|
||||
g.pixel_size = 1
|
||||
g.apply_pixels(view)
|
||||
r.check(view.scaling_3d_mode == Viewport.SCALING_3D_MODE_BILINEAR and is_equal_approx(view.scaling_3d_scale, 0.75),
|
||||
"pixel size 1 turns that off and uses the resolution scale")
|
||||
view.free()
|
||||
var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig
|
||||
g.apply(null, cfg)
|
||||
var music := AudioServer.get_bus_index("Music")
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: Scar
|
|||
var s := sim.campaign.state
|
||||
s.upgrades.erase("sprint")
|
||||
hud._process(0.0)
|
||||
r.check(not player.can_sprint() and not hud._sprint_label.visible, "no sprint (and no sprint line on the HUD) before the upgrade")
|
||||
r.check(not player.can_sprint() and not hud.stamina_shown(), "no sprint before the upgrade (and no stamina bar on the HUD)")
|
||||
# On the real body, over physics frames: the open ground south-west of the pen.
|
||||
player.global_position = Vector3(0.0, 0.0, 6.0)
|
||||
player.velocity = Vector3.ZERO
|
||||
|
|
@ -206,13 +206,12 @@ func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: Scar
|
|||
r.check(player.animation_player.current_animation == player.run_animation and player.animation_player.speed_scale > 1.5,
|
||||
"the run clip plays faster (x%.2f)" % player.animation_player.speed_scale)
|
||||
r.check(player.move_strength() > 1.5, "the partner's machine is told it's sprinting (strength %.2f)" % player.move_strength())
|
||||
hud._process(0.0)
|
||||
r.check(hud._sprint_label.visible and hud._sprint_label.text.begins_with("Sprinting"), "the HUD shows the sprint running: '%s'" % hud._sprint_label.text)
|
||||
r.check(hud.stamina_shown() and hud.stamina() < 1.0 and is_equal_approx(hud.stamina(), player.sprint_left / cfg.sprint_time),
|
||||
"the HUD's stamina bar appears, and drains while sprinting (%.2f)" % hud.stamina())
|
||||
Input.action_release("move_right")
|
||||
await _frames(r, 2)
|
||||
r.check(not player.sprinting and player.sprint_recharge > cfg.sprint_cooldown - 0.1, "stopping ends it, and the recharge starts")
|
||||
hud._process(0.0)
|
||||
r.check(hud._sprint_label.text == "Sprint %.0f s" % ceilf(player.sprint_recharge), "the HUD counts the recharge down: '%s'" % hud._sprint_label.text)
|
||||
r.check(hud.stamina() < 0.1, "and starts filling back as it recharges (%.2f)" % hud.stamina())
|
||||
Input.action_release("sprint")
|
||||
await _frames(r, 30)
|
||||
player.velocity = Vector3.ZERO
|
||||
|
|
@ -236,8 +235,7 @@ func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: Scar
|
|||
player.step_sprint(DT, true, false)
|
||||
r.check(not player.sprinting, "and it doesn't start standing still")
|
||||
sim.scarecrow.reset_for_morning()
|
||||
hud._process(0.0)
|
||||
r.check(player.sprint_recharge == 0.0 and hud._sprint_label.text == "Sprint hold Shift / L3", "a new morning has it ready: '%s'" % hud._sprint_label.text)
|
||||
r.check(player.sprint_recharge == 0.0 and hud.stamina() == 1.0, "a new morning has it ready (a full bar)")
|
||||
s.upgrades.erase("sprint")
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -553,15 +553,13 @@ func _fallback(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
sim.animals.sync_from_state()
|
||||
|
||||
|
||||
func _hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
|
||||
var hud := farm.get_node("Hud/AssetHud") as AssetHud
|
||||
func _hud(r: GameTestRunner, _farm: Node3D, sim: FarmSim) -> void:
|
||||
var s := sim.campaign.state
|
||||
hud._process(0.0)
|
||||
var before := hud.describe()
|
||||
var before := " · ".join(PauseMenu.asset_counts(s))
|
||||
s.lose_animal(s.animals_total if not s.is_animal_lost(s.animals_total) else 1)
|
||||
hud._process(0.05)
|
||||
r.check(hud.describe() == "Crops %d/%d · Animals %d/%d · Supplies %d" % [s.crops, s.crops_total, s.animals, s.animals_total, s.supplies]
|
||||
and hud.describe() != before and hud._flash[1] > 0.0 and hud._flash_color[1] == AssetHud.LOSS, "the asset HUD updates and flashes red on a loss: '%s'" % hud.describe())
|
||||
var after := " · ".join(PauseMenu.asset_counts(s))
|
||||
r.check(after == "Crops %d/%d · Animals %d/%d · Supplies %d" % [s.crops, s.crops_total, s.animals, s.animals_total, s.supplies]
|
||||
and after != before, "the pause menu's assets count the loss: '%s'" % after)
|
||||
|
||||
|
||||
## The farm is stripped when the last supplies are carried off with every crop and animal gone.
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ func run(r: GameTestRunner) -> void:
|
|||
sim.loot.loot_event.connect(func(kind: StringName, _id: int, _p: Vector3) -> void:
|
||||
_events[kind] = int(_events.get(kind, 0)) + 1)
|
||||
r.info("farm sim loaded in %d ms (nav %d cells)" % [sim.load_msec, sim.nav.cell_count()])
|
||||
r.check(sim.loot.unit_count == 50 and sim.loot.count(S.HOME, LootSystem.Category.CROP) == 30 and sim.campaign.state.crops == 30
|
||||
and sim.loot.count(S.DORMANT, LootSystem.Category.CROP) == 20,
|
||||
"30 crop units start at home, 20 more dormant in the two later fields (#13)")
|
||||
r.check(sim.loot.unit_count == 90 and sim.loot.count(S.HOME, LootSystem.Category.CROP) == 30 and sim.campaign.state.crops == 30
|
||||
and sim.loot.count(S.DORMANT, LootSystem.Category.CROP) == 60,
|
||||
"30 crop units start at home, 60 more dormant in the two later fields (#13)")
|
||||
# #20: the map reaches z 35 now, so its south edge (3 m out) is at z 38; z 18 is inside the map.
|
||||
var edge_cells := [Vector2(-16.0, -6.0), Vector2(20.0, 38.0), Vector2(50.0, 0.0), Vector2(-16.0, 10.0)].filter(func(p: Vector2) -> bool:
|
||||
return sim.escape_field[sim.nav.cell_of(p.x, p.y)] == 0)
|
||||
r.check(edge_cells.size() == 4 and sim.escape_field[sim.nav.cell_of(10.0, -8.0)] > 0, "the farm's edge, all around, is where carriers escape")
|
||||
r.check(sim.escape_field[sim.nav.cell_of(20.0, 18.0)] > 0, "(20, 18), where the south edge used to be, is inside the map now")
|
||||
# #20: a carried or dropped crop shows the plant of its own field.
|
||||
var tokens := [1, 31, 41].map(func(id: int) -> String: return sim.loot._tokens[id].scene_file_path.get_file().get_basename())
|
||||
var tokens := [1, 31, 61].map(func(id: int) -> String: return sim.loot._tokens[id].scene_file_path.get_file().get_basename())
|
||||
r.check(tokens == ["plant_007", "plant_004", "plant_001"], "crop tokens match their crop: sunflower, cabbage, corn (%s)" % [tokens])
|
||||
|
||||
_steal_and_drop(r, sim, player)
|
||||
|
|
@ -302,7 +302,7 @@ func _night_arrivals(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
sim.waves.enabled = false
|
||||
|
||||
|
||||
## #13: the two later fields (lettuce/cabbage, ids 31-40; corn, 41-50) start dormant -- hidden,
|
||||
## #13: the two later fields (lettuce/cabbage, ids 31-60; corn, 61-90) start dormant -- hidden,
|
||||
## not claimable, not scored -- and sprout on schedule: field A the morning after night 2, field B
|
||||
## the morning after night 4. Once sprouted a unit is a crop like any other: visible, stealable by
|
||||
## a crow, and counted in crops_total and the score.
|
||||
|
|
@ -314,15 +314,15 @@ func _staged_fields(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
_play_to_next_morning(sim)
|
||||
r.check(c.state.phase == P.MORNING and c.state.nights_survived == 2, "played to the morning after night 2")
|
||||
var a_ok := true
|
||||
for id in range(31, 41):
|
||||
for id in range(31, 61):
|
||||
a_ok = a_ok and loot.status[id] == S.HOME and loot._units[id].visible
|
||||
r.check(a_ok, "field A (lettuce/cabbage, 31..40) sprouted after night 2: visible and home")
|
||||
r.check(a_ok, "field A (lettuce/cabbage, 31..60) sprouted after night 2: visible and home")
|
||||
var b_dormant := true
|
||||
for id in range(41, 51):
|
||||
for id in range(61, 91):
|
||||
b_dormant = b_dormant and loot.status[id] == S.DORMANT and not loot._units[id].visible
|
||||
r.check(b_dormant, "field B (corn, 41..50) is still dormant: hidden, not home")
|
||||
r.check(c.state.crops_total == 30 + 10, "crops_total grew by field A's 10 units")
|
||||
r.check(not loot.recover(41) and not loot.is_claimed_by(41, -1), "a dormant unit can't be recovered or claimed")
|
||||
r.check(b_dormant, "field B (corn, 61..90) is still dormant: hidden, not home")
|
||||
r.check(c.state.crops_total == 30 + 30, "crops_total grew by field A's 30 units")
|
||||
r.check(not loot.recover(61) and not loot.is_claimed_by(61, -1), "a dormant unit can't be recovered or claimed")
|
||||
|
||||
# A crow can claim (by hand, as other tests here do), steal, and carry off a field-A crop: it
|
||||
# counts exactly like any other crop.
|
||||
|
|
@ -343,19 +343,19 @@ func _staged_fields(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
_play_to_next_morning(sim)
|
||||
r.check(c.state.phase == P.MORNING and c.state.nights_survived == 4, "played to the morning after night 4")
|
||||
var b_ok := true
|
||||
for id in range(41, 51):
|
||||
for id in range(61, 91):
|
||||
b_ok = b_ok and loot.status[id] == S.HOME and loot._units[id].visible
|
||||
r.check(b_ok, "field B (corn, 41..50) sprouted after night 4: visible and home")
|
||||
r.check(c.state.crops_total == 30 + 10 + 10, "crops_total grew by field B's 10 units too")
|
||||
r.check(b_ok, "field B (corn, 61..90) sprouted after night 4: visible and home")
|
||||
r.check(c.state.crops_total == 30 + 30 + 30, "crops_total grew by field B's 30 units too")
|
||||
|
||||
var before2 := c.state.crops
|
||||
var h2 := es.spawn(EnemySystem.TYPE_CROW, -20.0, 0.0, Vector2.RIGHT)
|
||||
var d2 := es.resolve_handle(h2)
|
||||
loot.holder[41] = h2
|
||||
r.check(loot.pick_up(41, h2), "field B crop 41 can be claimed and picked up")
|
||||
es.carry[d2] = 41
|
||||
loot.escape(41, h2)
|
||||
r.check(c.state.is_crop_lost(41) and loot.status[41] == S.LOST and c.state.crops == before2 - 1,
|
||||
loot.holder[61] = h2
|
||||
r.check(loot.pick_up(61, h2), "field B crop 61 can be claimed and picked up")
|
||||
es.carry[d2] = 61
|
||||
loot.escape(61, h2)
|
||||
r.check(c.state.is_crop_lost(61) and loot.status[61] == S.LOST and c.state.crops == before2 - 1,
|
||||
"a stolen field-B crop is lost and scored like any other")
|
||||
es.apply_hit(d2, 99)
|
||||
_step(sim, 1)
|
||||
|
|
@ -368,7 +368,7 @@ func _staged_fields(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
r.check(restored.crops_total == c.state.crops_total and restored.nights_survived == c.state.nights_survived,
|
||||
"crops_total and nights_survived survive a save/JSON round trip")
|
||||
loot.sync_from_state() # as a real load or retry would trigger
|
||||
r.check(c.state.crops_total == 50, "sync_from_state() repairs crops_total to the same, fully-sprouted total")
|
||||
r.check(c.state.crops_total == 90, "sync_from_state() repairs crops_total to the same, fully-sprouted total")
|
||||
|
||||
|
||||
## Advances from wherever the campaign is now to the next morning (one full day/night/dawn cycle),
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ extends RefCounted
|
|||
## shooter and pumpkin bombs bought at the supply shed, not the workbench (rapid fire and heavy
|
||||
## seeds, bought at the workbench, need the corn shooter first; a weapon bought goes into its
|
||||
## hand, bombs into the off-hand); switching the main
|
||||
## weapon (Tab / 1-2, owned ones only, not in build mode, never the bombs; one no longer owned
|
||||
## weapon (Tab / the number keys, owned ones only, not in build mode, never the bombs; one no longer owned
|
||||
## falls back to the pitchfork); the off-hand on its own button (right mouse / LT: with the main
|
||||
## weapon in hand, both at once, held, not with the right click that leaves build mode); a bomb's
|
||||
## throw (at the aim, its range clamped), flight, and burst (everything in its radius, crows too,
|
||||
## nothing beyond, not the scarecrow), its recharge and the morning refill; the models on the
|
||||
## scarecrow; the HUD's weapon panel; the shed's other weapons; the Propane Torch's band of
|
||||
## scarecrow; the HUD's hotbar; the shed's other weapons; the Propane Torch's band of
|
||||
## fire and its flame (#17); and the Alien Ray's beam (#18).
|
||||
|
||||
const DT := 1.0 / 60.0
|
||||
|
|
@ -172,8 +172,15 @@ func _switching(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
var first := c.weapon
|
||||
_tap(sim, "weapon_2")
|
||||
r.check(first == W.PITCHFORK and c.weapon == W.CORN_SHOOTER, "1-2 pick one")
|
||||
r.check(c.equip(W.PUMPKIN_BOMB) and c.weapon == W.CORN_SHOOTER and not InputMap.has_action("weapon_3"),
|
||||
"the bombs never take the main hand (and there's no third weapon key)")
|
||||
r.check(c.equip(W.PUMPKIN_BOMB) and c.weapon == W.CORN_SHOOTER, "the bombs never take the main hand")
|
||||
s.upgrades["shurikens"] = 1 # owned: pitchfork, corn shooter, shurikens (no potato cannon)
|
||||
_tap(sim, "weapon_3")
|
||||
var third := c.weapon
|
||||
_tap(sim, "weapon_4")
|
||||
r.check(c.owned_main() == [W.PITCHFORK, W.CORN_SHOOTER, W.SHURIKENS] and third == W.SHURIKENS and c.weapon == W.SHURIKENS,
|
||||
"a number key picks that slot of the weapons owned (3: the shurikens), one past them does nothing")
|
||||
s.upgrades.erase("shurikens")
|
||||
_step(sim, 1)
|
||||
c.equip(W.PITCHFORK)
|
||||
var east := AT + Vector2(5.0, 0.0)
|
||||
_step(sim, c.stab_ticks())
|
||||
|
|
@ -310,24 +317,28 @@ func _bombs(r: GameTestRunner, sim: FarmSim) -> void:
|
|||
func _hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
|
||||
var hud := farm.get_node("Hud/ScarecrowHud") as ScarecrowHud
|
||||
var c := sim.combat
|
||||
var cfg := sim.config
|
||||
var s := sim.campaign.state
|
||||
var shown := func() -> Array:
|
||||
return hud.slots().map(func(d: Dictionary) -> Array: return [d["weapon"], d["key"], d["offhand"], d["selected"]])
|
||||
s.upgrades.erase("corn_shooter")
|
||||
c.ready_for_morning()
|
||||
_step(sim, 1)
|
||||
hud._process(0.0)
|
||||
var charged: Array = hud._offhand_rows.map(func(l: Label) -> String: return l.text)
|
||||
var start: Array = shown.call()
|
||||
r.check(start == [[W.PITCHFORK, 1, false, true], [W.PUMPKIN_BOMB, 0, true, true]],
|
||||
"the hotbar shows only what's owned: the pitchfork on 1, in hand, then the bombs, ready: %s" % [start])
|
||||
c.offhand_toward(AT + Vector2(6.0, 0.0))
|
||||
hud._process(0.0)
|
||||
var rows: Array = hud._weapon_rows.map(func(l: Label) -> String: return l.text)
|
||||
var off: Array = hud._offhand_rows.map(func(l: Label) -> String: return l.text)
|
||||
r.check(rows == ["1 Pitchfork", "2 Corn shooter (supply shed)", "Potato cannon (supply shed)",
|
||||
"Shurikens (supply shed)", "Propane torch (supply shed)", "Alien ray (supply shed)"],
|
||||
"the HUD lists the main weapons, the first two by number (no more number keys): %s" % [rows])
|
||||
r.check(charged == ["Pumpkin bombs"] and off == ["Pumpkin bombs %.0f s" % ceilf(cfg.bomb_cooldown)],
|
||||
"and the off-hand's bombs, with their recharge: %s, %s" % [charged, off])
|
||||
r.check(hud._weapon_title.visible and hud._weapon_hint.text.contains("Tab") and hud._offhand_title.text.contains("right mouse"),
|
||||
"with how to switch, and the off-hand's button")
|
||||
r.check(not hud.slots()[1]["selected"], "a bomb recharging isn't lit")
|
||||
s.upgrades["corn_shooter"] = 1
|
||||
s.upgrades["propane_torch"] = 1
|
||||
c.equip(W.PROPANE_TORCH)
|
||||
var mains: Array = shown.call().filter(func(a: Array) -> bool: return not a[2])
|
||||
r.check(mains == [[W.PITCHFORK, 1, false, false], [W.CORN_SHOOTER, 2, false, false], [W.PROPANE_TORCH, 3, false, true]],
|
||||
"bought weapons join it in order, numbered by their key, the one in hand lit: %s" % [mains])
|
||||
sim.build.set_active(true)
|
||||
r.check(hud.slots().is_empty(), "it gives way to the build hotbar in build mode")
|
||||
sim.build.set_active(false)
|
||||
s.upgrades.erase("propane_torch")
|
||||
s.upgrades.erase("corn_shooter")
|
||||
s.upgrades.erase("pumpkin_bomb")
|
||||
_step(sim, 1)
|
||||
sim.bombs.clear()
|
||||
|
|
|
|||
|
|
@ -20,13 +20,15 @@ extends SceneTree
|
|||
## | toggle_mic | M | - | Co-op |
|
||||
## | sprint (hold)| Shift | L3 (stick) | Sprint |
|
||||
## | weapon_next | Tab | D-pad down | Weapons |
|
||||
## | weapon_1..2 | 1, 2 | - | Weapons |
|
||||
## | weapon_1..6 | 1 - 6 | - | Weapons |
|
||||
## | offhand | Right mouse | LT | Off-hand |
|
||||
## The weapon keys are build mode's (build_next, build_1..2): outside build mode they pick the
|
||||
## main weapon. offhand shares the right mouse button with cancel: in build mode it dismantles.
|
||||
## STALE actions, from earlier versions of this table, are removed.
|
||||
## | pouch | I | R3 (stick) | HUD |
|
||||
## The weapon keys share build mode's (build_next, build_1..4): outside build mode they pick the
|
||||
## main weapon (the k-th owned, ScarecrowCombat.owned_main). offhand shares the right mouse button
|
||||
## with cancel: in build mode it dismantles. STALE actions, from earlier versions of this table,
|
||||
## are removed.
|
||||
|
||||
const STALE: Array[String] = ["weapon_3"]
|
||||
const STALE: Array[String] = []
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
|
|
@ -37,7 +39,7 @@ func _initialize() -> void:
|
|||
_action("rotate_left", [_key(KEY_Z), _joy(JOY_BUTTON_DPAD_LEFT)])
|
||||
_action("rotate_right", [_key(KEY_C), _joy(JOY_BUTTON_DPAD_RIGHT)])
|
||||
_action("build_next", [_key(KEY_TAB), _joy(JOY_BUTTON_DPAD_DOWN)])
|
||||
var number_keys: Array[Key] = [KEY_1, KEY_2, KEY_3, KEY_4]
|
||||
var number_keys: Array[Key] = [KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6]
|
||||
for i in 4:
|
||||
_action("build_%d" % (i + 1), [_key(number_keys[i])])
|
||||
_action("cancel", [_mouse(MOUSE_BUTTON_RIGHT), _joy(JOY_BUTTON_B)])
|
||||
|
|
@ -46,9 +48,10 @@ func _initialize() -> void:
|
|||
_action("toggle_mic", [_key(KEY_M)])
|
||||
_action("sprint", [_key(KEY_SHIFT), _joy(JOY_BUTTON_LEFT_STICK)])
|
||||
_action("weapon_next", [_key(KEY_TAB), _joy(JOY_BUTTON_DPAD_DOWN)])
|
||||
for i in 2:
|
||||
for i in 6:
|
||||
_action("weapon_%d" % (i + 1), [_key(number_keys[i])])
|
||||
_action("offhand", [_mouse(MOUSE_BUTTON_RIGHT), _axis(JOY_AXIS_TRIGGER_LEFT)])
|
||||
_action("pouch", [_key(KEY_I), _joy(JOY_BUTTON_RIGHT_STICK)])
|
||||
for a in STALE:
|
||||
ProjectSettings.clear("input/" + a)
|
||||
var err := ProjectSettings.save()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue