Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file added resources/menus/old_paper_800x500.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 13 additions & 12 deletions src/disconnected/event_loop.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ module Disconnected
@block_render = true
@block_movment = true
sleep 0.15
txt = Text.get_text(10)
inv = "~~Inventory~~\n\n"
@player.inventory.each do |i|
inv += "Name: " + i.name + "\n"
inv += "Id: " + i.id.to_s + "\n"
inv += "\n\n"
end
txt.string = inv
txt.position = @player.position.dup
txt.position.x = @player.position.x + 50.0_f32
@window.draw(txt)
@window.display

# Create a menu instance
inv_menu = InventoryMenu.new(
location: @player.sprite.position.dup,
data: @player.inventory,
name: "Inventory",
texture_path: "./resources/menus/old_paper_800x500.png",
size: {w: 500, h: 400})

# Draw menu
inv_menu.draw_menu(@window)

# @window.display
end

def render
Expand Down
79 changes: 79 additions & 0 deletions src/disconnected/inventory_menu.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module Disconnected
class InventoryMenu
getter :name, :sprite

def initialize(location : SF::Vector2,
@data : Array(Item),
@name : String,
texture_path : String,
@size : NamedTuple(w: Int32, h: Int32))
#
texture = SF::Texture.from_file(texture_path, SF.int_rect(0, 0, size[:w], size[:h]))
texture.smooth = true
@sprite = SF::Sprite.new(texture)
@sprite.origin = SF.vector2(size[:w]/2, size[:h]/2)
@sprite.position = location
end

def draw_menu(window)
# Draw background
window.draw(@sprite)

# Add the menu header
txt = Text.get_text
txt.origin = SF.vector2(60, 0)
txt.string = @name
txt.color = SF::Color::Black
txt.character_size = 24
txt.style = SF::Text::Bold
txt.position = @sprite.position.dup + SF.vector2(0, -(@size[:h] / 2))
# txt.move(SF.vector2(0, -(@size[:h] / 2)))
# txt.position.x = @player.position.x + 50.0_f32
window.draw(txt)

# Move drawing location to the table
x_correction = (@size[:w] / 2) - 20
y_correction = (@size[:h] / 2) - 50
draw_location = @sprite.position.dup - SF.vector2(x_correction, y_correction)

# Add table headers
line_spacing = 30

txt = Text.get_text
txt.string = "Name\t\t\tID"
txt.color = SF::Color::Black
txt.character_size = 20
txt.style = SF::Text::Underlined # Underline doesn't work, must be a bug
txt.position = draw_location
window.draw(txt)

# Move to next line
draw_location += SF.vector2(0, line_spacing*1.2)

# Add table data
@data.each do |i|
data_text = Text.get_text
data_text.string = "#{i.name}\t\t\t\t\t#{i.id.to_s}"
data_text.color = SF::Color::Black
data_text.character_size = 16
data_text.position = draw_location
window.draw(data_text)

# Move to next line
draw_location += SF.vector2(0, line_spacing)
end
@data.each do |i|
data_text = Text.get_text
data_text.string = "#{i.name}\t\t\t\t\t#{i.id.to_s}"
data_text.character_size = 16
data_text.position = draw_location
window.draw(data_text)

# Move sprite vertically
draw_location += SF.vector2(0, line_spacing)
end

window.display
end
end
end
8 changes: 6 additions & 2 deletions src/disconnected/player.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ require "./basic_char.cr"
module Disconnected
class Player < BasicChar
property :interactions
getter :inventory
getter :inventory, :sprite

def initialize(texture_path : Array(String), starting_position_x : Int32, starting_position_y : Int32, @name : String = "", @health : Int32 = 10)
def initialize(texture_path : Array(String),
starting_position_x : Int32,
starting_position_y : Int32,
@name : String = "",
@health : Int32 = 10)
@speed = 1
@images = Array(SF::Image).new
texture_path.each do |p|
Expand Down