From 0d449b93757f416812c1e272302e01e85eac083e Mon Sep 17 00:00:00 2001 From: cyberarm Date: Wed, 6 Jan 2021 10:31:57 -0600 Subject: [PATCH] Added replaced sidebar label buttons with images, added 'radar' (currently static map image) --- lib/components/sidebar_actions.rb | 6 +++++ lib/entities/buildings/barracks.rb | 12 +++++---- lib/entities/buildings/construction_yard.rb | 14 +++++----- lib/entities/buildings/helipad.rb | 16 ++++++----- lib/entities/buildings/power_plant.rb | 9 ++++--- lib/entities/buildings/refinery.rb | 4 ++- lib/entities/buildings/war_factory.rb | 20 +++++++------- lib/entities/units/construction_worker.rb | 12 +++++---- lib/entity.rb | 6 ++++- lib/states/game.rb | 30 +++++++++++++-------- lib/team_colors.rb | 1 + lib/tools/entity_controller.rb | 5 +++- 12 files changed, 85 insertions(+), 50 deletions(-) diff --git a/lib/components/sidebar_actions.rb b/lib/components/sidebar_actions.rb index 79c8b15..b79c51a 100644 --- a/lib/components/sidebar_actions.rb +++ b/lib/components/sidebar_actions.rb @@ -15,7 +15,10 @@ class IMICRTS ent = IMICRTS::Entity.get(data[:entity]) raise "Failed to find entity: #{data[:entity].inspect}" unless ent + entity = Entity.new(name: ent.name, player: @parent, id: 0, position: CyberarmEngine::Vector.new, angle: 0, director: nil, proto_entity: true) + action.label = ent.name.to_s.split("_").map{ |s| s.capitalize }.join(" ") + action.image = entity.render action.description = "#{action.label}\nCost: #{ent.cost}\n#{ent.description}" action.block = proc do @parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT, @parent.player.id, @parent.id, data[:entity]) @@ -25,7 +28,10 @@ class IMICRTS ent = IMICRTS::Entity.get(data[:entity]) raise "Failed to find entity: #{data[:entity].inspect}" unless ent + entity = Entity.new(name: ent.name, player: @parent, id: 0, position: CyberarmEngine::Vector.new, angle: 0, director: nil, proto_entity: true) + action.label = ent.name.to_s.split("_").map { |s| s.capitalize }.join(" ") + action.image = entity.render action.description = "#{action.label}\nCost: #{ent.cost}\n#{ent.description}" action.block = proc { @parent.director.game.set_tool(data[:tool], data) } diff --git a/lib/entities/buildings/barracks.rb b/lib/entities/buildings/barracks.rb index 42abb25..82e9adf 100644 --- a/lib/entities/buildings/barracks.rb +++ b/lib/entities/buildings/barracks.rb @@ -6,11 +6,13 @@ tiles = [ [false, :path, :path, :path, false], ] -IMICRTS::Entity.define_entity(:barracks, :building, 400, 40, "Builds and soldiers", tiles) do |entity| - entity.has(:building) - entity.has(:waypoint) - entity.has(:spawner) - entity.has(:build_queue) +IMICRTS::Entity.define_entity(:barracks, :building, 400, 40, "Builds and heals soldiers", tiles) do |entity| + unless entity.proto_entity + entity.has(:building) + entity.has(:waypoint) + entity.has(:spawner) + entity.has(:build_queue) + end entity.radius = 44 entity.max_health = 100.0 diff --git a/lib/entities/buildings/construction_yard.rb b/lib/entities/buildings/construction_yard.rb index 342bd1f..393ecd1 100644 --- a/lib/entities/buildings/construction_yard.rb +++ b/lib/entities/buildings/construction_yard.rb @@ -7,12 +7,14 @@ tiles = [ ] IMICRTS::Entity.define_entity(:construction_yard, :building, 2_000, 310, "Provides radar and builds construction workers", tiles) do |entity| - entity.has(:building) - entity.has(:waypoint) - entity.has(:spawner) - entity.has(:build_queue) - entity.has(:sidebar_actions) - entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :construction_worker }) + unless entity.proto_entity + entity.has(:building) + entity.has(:waypoint) + entity.has(:spawner) + entity.has(:build_queue) + entity.has(:sidebar_actions) + entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :construction_worker }) + end entity.radius = 40 entity.max_health = 100.0 diff --git a/lib/entities/buildings/helipad.rb b/lib/entities/buildings/helipad.rb index 364eef3..2c24344 100644 --- a/lib/entities/buildings/helipad.rb +++ b/lib/entities/buildings/helipad.rb @@ -6,13 +6,15 @@ tiles = [ [false, false, false, false, false], ] -IMICRTS::Entity.define_entity(:helipad, :building, 1_000, 100, "Builds and rearms helicopters", tiles) do |entity| - entity.has(:building) - entity.has(:waypoint) - entity.has(:spawner) - entity.has(:build_queue) - entity.has(:sidebar_actions) - entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :helicopter }) +IMICRTS::Entity.define_entity(:helipad, :building, 1_000, 100, "Builds and rearms aircraft", tiles) do |entity| + unless entity.proto_entity + entity.has(:building) + entity.has(:waypoint) + entity.has(:spawner) + entity.has(:build_queue) + entity.has(:sidebar_actions) + entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :helicopter }) + end entity.radius = 26 entity.max_health = 100.0 diff --git a/lib/entities/buildings/power_plant.rb b/lib/entities/buildings/power_plant.rb index 9db641c..0b22190 100644 --- a/lib/entities/buildings/power_plant.rb +++ b/lib/entities/buildings/power_plant.rb @@ -7,7 +7,9 @@ tiles = [ ] IMICRTS::Entity.define_entity(:power_plant, :building, 800, 45, "Generates power", tiles) do |entity| - entity.has(:building) + unless entity.proto_entity + entity.has(:building) + end entity.radius = 24 entity.max_health = 100.0 @@ -29,14 +31,13 @@ IMICRTS::Entity.define_entity(:power_plant, :building, 800, 45, "Generates power emitters.each do |pos| - entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: pos) + entity.particle_emitters << IMICRTS::SmokeEmitter.new(position: pos, emitting: false) end entity.on_tick do # entity.produce_power - if entity.component(:building).data.state == :idle - + if entity.component(:building).construction_complete? entity.particle_emitters.each do |emitter| emitter.emitting = true end diff --git a/lib/entities/buildings/refinery.rb b/lib/entities/buildings/refinery.rb index 12e6ebf..103daa9 100644 --- a/lib/entities/buildings/refinery.rb +++ b/lib/entities/buildings/refinery.rb @@ -7,7 +7,9 @@ tiles = [ ] IMICRTS::Entity.define_entity(:refinery, :building, 1_400, 200, "Generates credits", tiles) do |entity| - entity.has(:building) + unless entity.proto_entity + entity.has(:building) + end entity.radius = 44 entity.max_health = 100.0 diff --git a/lib/entities/buildings/war_factory.rb b/lib/entities/buildings/war_factory.rb index fb2c8f2..23d559d 100644 --- a/lib/entities/buildings/war_factory.rb +++ b/lib/entities/buildings/war_factory.rb @@ -6,15 +6,17 @@ tiles = [ [false, :path, :path, :path, false], ] -IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, 310, "Builds units", tiles) do |entity| - entity.has(:building) - entity.has(:waypoint) - entity.has(:spawner) - entity.has(:build_queue) - entity.has(:sidebar_actions) - entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :jeep }) - entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :tank }) - entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :harvester }) +IMICRTS::Entity.define_entity(:war_factory, :building, 2_000, 310, "Builds and repairs ground vehicles", tiles) do |entity| + unless entity.proto_entity + entity.has(:building) + entity.has(:waypoint) + entity.has(:spawner) + entity.has(:build_queue) + entity.has(:sidebar_actions) + entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :jeep }) + entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :tank }) + entity.component(:sidebar_actions).add(:add_to_build_queue, { entity: :harvester }) + end entity.radius = 48 entity.max_health = 100.0 diff --git a/lib/entities/units/construction_worker.rb b/lib/entities/units/construction_worker.rb index 6da8d18..1729593 100644 --- a/lib/entities/units/construction_worker.rb +++ b/lib/entities/units/construction_worker.rb @@ -1,9 +1,11 @@ IMICRTS::Entity.define_entity(:construction_worker, :unit, 1000, 75, "Constructs buildings") do |entity| - entity.has(:movement) - entity.has(:build_queue) - entity.has(:sidebar_actions) - [:power_plant, :refinery, :barracks, :war_factory, :helipad, :construction_yard].each do |ent| - entity.component(:sidebar_actions).add(:set_tool, { tool: :place_entity, entity: ent, construction_worker: entity }) + unless entity.proto_entity + entity.has(:movement) + entity.has(:build_queue) + entity.has(:sidebar_actions) + [:power_plant, :refinery, :barracks, :war_factory, :helipad, :construction_yard].each do |ent| + entity.component(:sidebar_actions).add(:set_tool, { tool: :place_entity, entity: ent, construction_worker: entity }) + end end entity.radius = 14 diff --git a/lib/entity.rb b/lib/entity.rb index 038f810..39d2c9f 100644 --- a/lib/entity.rb +++ b/lib/entity.rb @@ -14,7 +14,7 @@ class IMICRTS @entities[name] = Stub.new(name, type, cost, build_steps, description, tiles, block) end - attr_reader :director, :player, :id, :name, :type, :data + attr_reader :director, :player, :id, :name, :type, :data, :proto_entity attr_accessor :position, :angle, :radius, :target, :state, :movement, :health, :max_health, :speed, :turret, :center, :particle_emitters, :color @@ -123,10 +123,14 @@ class IMICRTS end def render + turret = component(:turret).render if component(:turret) && @proto_entity + @render = Gosu.render(@shell_image.width, @shell_image.height, retro: true) do @body_image.draw(0, 0, 0) if @body_image @shell_image.draw(0, 0, 0, 1, 1, @player.color) @overlay_image.draw(0, 0, 0) if @overlay_image + + turret.draw(0, 0, 2) if component(:turret) && @proto_entity end end diff --git a/lib/states/game.rb b/lib/states/game.rb index 4b7dec0..be06a86 100644 --- a/lib/states/game.rb +++ b/lib/states/game.rb @@ -2,7 +2,7 @@ class IMICRTS class Game < CyberarmEngine::GuiState Overlay = Struct.new(:image, :position, :angle, :alpha) - attr_reader :sidebar, :sidebar_actions, :overlays, :director + attr_reader :sidebar, :sidebar_title, :sidebar_actions, :overlays, :director attr_accessor :selected_entities def setup @@ -23,11 +23,6 @@ class IMICRTS @director.add_player(player) end - # @player = Player.new(id: 0, spawnpoint: @director.map.spawnpoints.last) - # @player2 = Player.new(id: 1, spawnpoint: @director.map.spawnpoints.first) - # @director.add_player(@player) - # @director.add_player(@player2) - @selected_entities = [] @tool = set_tool(:entity_controller) @overlays = [] @@ -35,12 +30,21 @@ class IMICRTS @debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200)) @sidebar = stack(width: IMICRTS::MENU_WIDTH, height: 1.0, padding: IMICRTS::MENU_PADDING) do - background [0x55555555, 0x55666666] + background [0xff555555, 0xff666666] - banner "SIDEBAR", margin_bottom: 20 + @sidebar_radar = stack(width: 1.0) do + image @director.map.render_preview, width: 1.0 + end + + flow(width: 1.0) do + para "$10,000", width: 0.49 + para "Power 250/250", width: 0.49, text_align: :right + end + + @sidebar_title = title "" flow(width: 1.0, height: 1.0) do - @sidebar_actions = stack(width: 0.9) do + @sidebar_actions = flow(width: 0.9) do end # Power meter @@ -69,13 +73,13 @@ class IMICRTS position: CyberarmEngine::Vector.new(player.spawnpoint.x - 64, player.spawnpoint.y + 64, ZOrder::GROUND_VEHICLE) ) end + + button_down(Gosu::KB_H) if @player end def draw super - # Gosu.draw_rect(0, 0, window.width, window.height, Gosu::Color.rgb(10, 175, 35)) - @player.camera.draw do @director.map.draw(@player.camera) @director.entities.each(&:draw) @@ -122,6 +126,10 @@ class IMICRTS ).lines.map { |line| line.strip }.join("\n") @debug_info.x = @sidebar.width + 20 + + # entity = @director.players.map { |pl| pl.entities.find { |ent| mouse.distance(ent.position) <= ent.radius } }.first + # @tip.value = "#{entity.player.name}: #{entity.name}" if entity + # @tip.value = "" unless entity end def button_down(id) diff --git a/lib/team_colors.rb b/lib/team_colors.rb index 3b4f94c..a9d5922 100644 --- a/lib/team_colors.rb +++ b/lib/team_colors.rb @@ -4,6 +4,7 @@ class IMICRTS red: Gosu::Color::RED, lightblue: Gosu::Color.rgb(100, 100, 255), blue: Gosu::Color::BLUE, + purple: Gosu::Color::FUCHSIA, lime: Gosu::Color::GREEN, lightgreen: Gosu::Color.rgb(50, 200, 50), green: Gosu::Color.rgb(0, 200, 0), diff --git a/lib/tools/entity_controller.rb b/lib/tools/entity_controller.rb index 49b3988..053581f 100644 --- a/lib/tools/entity_controller.rb +++ b/lib/tools/entity_controller.rb @@ -70,6 +70,7 @@ class IMICRTS diff = (@player.selected_entities - @game.selected_entities) @game.sidebar_actions.clear + @game.sidebar_title.value = "" @director.schedule_order(Order::DESELECTED_UNITS, @player.id, diff) if diff.size.positive? if @game.selected_entities.size.positive? @@ -81,9 +82,11 @@ class IMICRTS if @game.selected_entities.size < 2 && ent = @game.selected_entities.first return unless ent.component(:sidebar_actions) + @game.sidebar_title.value = ent.name.to_s.split("_").map { |s| s.capitalize }.join(" ") + @game.sidebar_actions.clear do ent.component(:sidebar_actions).actions.each do |action| - @game.button action.label, tip: action.description, width: 1.0 do + @game.button action.image, tip: action.description, image_width: 0.30 do action.block&.call end end