Created
July 28, 2021 14:15
-
-
Save cbilski/ccaece37e7303103bfddcf6ac0ef731b to your computer and use it in GitHub Desktop.
A work in progress level objective dialog for Helicorps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LevelObjectiveWidget | |
# | |
# Initialize Widget | |
# | |
def initialize | |
@finished = false | |
end | |
# | |
# Process input from args | |
# | |
def handle_input(args) | |
end | |
# | |
# Update logic (perform any time based logic that doesn't require rendering) | |
# | |
def track(args) | |
end | |
# | |
# Lazy implementation of word wrapping for our render pipeline | |
# | |
def render_text(args, pipeline, rect, text, font_size, font) | |
work = "" | |
len = text.length | |
font_h = args.gtk.calcstringbox(text, font_size, font).y | |
y_offset = 0 | |
x_offset = 8 | |
i = 0 | |
while i < len | |
x_len = args.gtk.calcstringbox(work + text[i], font_size, font).x | |
if (x_len >= rect.w || text[i] == "\n") | |
pipeline << { | |
x: rect.x + x_offset, y: (rect.y + rect.h) - y_offset, | |
text: work, size_enum: font_size, | |
alignment_enum: 0, vertical_alignment_enum: 2, | |
font: font, | |
r: 0, g: 255, b: 0, | |
}.label | |
work = text[i] | |
y_offset += font_h | |
else | |
work += text[i] | |
end | |
i += 1 | |
end | |
if (work.length > 0) | |
pipeline << { | |
x: rect.x + x_offset, y: (rect.y + rect.h) - y_offset, | |
text: work, size_enum: font_size, | |
alignment_enum: 0, vertical_alignment_enum: 2, | |
font: font, | |
r: 0, g: 255, b: 0, | |
}.label | |
end | |
end | |
# | |
# Core render functionality (layout logic embedded in here currently) | |
# | |
def render(args, pipeline) | |
# layout into 24x12 grid | |
rect = args.layout.rect(row: 2, col: 5, w: 14, h: 9.25, dx: 0, dy: 0) # outer border | |
pipeline << { x: rect[:x], y: rect[:y], w: rect[:w], h: rect[:h], r: 191, g: 190, b: 189 }.solid | |
pipeline << { x: rect[:x], y: rect[:y], w: rect[:w], h: rect[:h], r: 0, g: 0, b: 255 }.border | |
rect = args.layout.rect(row: 1.25, col: 9, w: 6, h: 1.5, dx: 0, dy: 0) # MISSION | |
pipeline << { x: rect[:x], y: rect[:y], w: rect[:w], h: rect[:h], r: 191, g: 190, b: 189 }.solid | |
pipeline << { x: rect.x, y: rect.y, w: rect.w, h: rect.h, r: 0, g: 0, b: 255 }.border | |
pipeline << { | |
x: rect.x + (rect.w / 2), y: rect.y + (rect.h / 1.8), | |
text: "MISSION", size_enum: args.layout.font_size_sm, | |
alignment_enum: 1, vertical_alignment_enum: 1, | |
font: "/fonts/PixeloidSans.ttf", | |
}.label | |
rect = args.layout.rect(row: 3, col: 6, w: 6, h: 3, dx: 0, dy: 0) # INTEL | |
pipeline << { x: rect[:x], y: rect[:y], w: rect[:w], h: rect[:h], r: 0, g: 0, b: 0 }.solid | |
pipeline << { **rect, r: 0, g: 0, b: 255 }.border | |
pipeline << { | |
x: rect.x, y: rect.y + rect.h, | |
text: " INTEL", size_enum: 1, | |
alignment_enum: 0, vertical_alignment_enum: 2, | |
font: "/fonts/PixeloidSans.ttf", | |
r: 0, g: 255, b: 0, | |
}.label | |
rect = args.layout.rect(row: 6, col: 6, w: 6, h: 4, dx: 0, dy: 0) # ENEMIES | |
pipeline << { x: rect[:x], y: rect[:y], w: rect[:w], h: rect[:h], r: 0, g: 0, b: 0 }.solid | |
pipeline << { **rect, r: 0, g: 0, b: 255 }.border | |
pipeline << { | |
x: rect.x, y: rect.y + rect.h, | |
text: " ENEMIES", size_enum: 1, | |
alignment_enum: 0, vertical_alignment_enum: 2, | |
font: "/fonts/PixeloidSans.ttf", | |
r: 0, g: 255, b: 0, | |
}.label | |
rect = args.layout.rect(row: 3, col: 12, w: 6, h: 7, dx: 0, dy: 0) # OBJECTIVE | |
pipeline << { x: rect[:x], y: rect[:y], w: rect[:w], h: rect[:h], r: 0, g: 0, b: 0 }.solid | |
pipeline << { **rect, r: 0, g: 0, b: 255 }.border | |
objective_text = "OBJECTIVE:\n\nHELIpost Gamma-II has\nreported UNREST.\n\nCITIZENS are under threat from MECHs:\n\n● Transport CITIZENS to\n safety.\n● Defeat MECHs." | |
render_text(args, pipeline, rect, objective_text, 1, "/fonts/PixeloidSans.ttf") | |
rect = args.layout.rect(row: 10, col: 9, w: 3, h: 1, dx: 0, dy: 0) # BACK | |
pipeline << { **rect, r: 0, g: 0, b: 255 }.border | |
pipeline << { | |
x: rect.x + (rect.w / 2), y: rect.y + (rect.h / 2), | |
text: "< BACK", size_enum: 1, | |
alignment_enum: 1, vertical_alignment_enum: 1, | |
font: "/fonts/PixeloidSans.ttf", | |
}.label | |
rect = args.layout.rect(row: 10, col: 12, w: 3, h: 1, dx: 0, dy: 0) # NEXT | |
pipeline << { **rect, r: 0, g: 0, b: 255 }.border | |
pipeline << { | |
x: rect.x + (rect.w / 2), y: rect.y + (rect.h / 2), | |
text: "NEXT > ", size_enum: 1, | |
alignment_enum: 1, vertical_alignment_enum: 1, | |
font: "/fonts/PixeloidSans.ttf", | |
}.label | |
end | |
# | |
# Return true when this widget is done (parent can clean up afterward) | |
# | |
def finished? | |
@finished | |
end | |
# | |
# Return true if the parent's game loop should be paused while this is active | |
# | |
def modal? | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment