Class: GTK::Console::Menu

Inherits:
Object show all
Defined in:
dragon/console_menu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(console) ⇒ Menu

Returns a new instance of Menu.


10
11
12
# File 'dragon/console_menu.rb', line 10

def initialize console
  @console = console
end

Instance Attribute Details

#buttonsObject

Returns the value of attribute buttons


8
9
10
# File 'dragon/console_menu.rb', line 8

def buttons
  @buttons
end

Instance Method Details

#button(args) ⇒ Object


126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'dragon/console_menu.rb', line 126

def button args
  id, row, col, text, method = args[:id], args[:row], args[:col], args[:text], args[:method]

  font_height = @console.font_style.line_height_px.half
  {
    id: id,
    rect: (rect_for_layout row, col),
    text: text,
    method: method
  }.let do |entity|
    primitives = []
    primitives << entity[:rect].merge(a: 164).solid
    primitives << entity[:rect].merge(r: 255, g: 255, b: 255).border
    primitives << text.wrapped_lines(5)
                      .map_with_index do |l, i|
                        [
                          entity[:rect][:x] + entity[:rect][:w].half,
                          entity[:rect][:y] + entity[:rect][:h].half + font_height - (i * (font_height + 2)),
                          l, -3, 1, 255, 255, 255
                        ]
                      end.labels

    entity.merge(primitives: primitives)
  end
end

#close_clickedObject


38
39
40
41
# File 'dragon/console_menu.rb', line 38

def close_clicked
  @menu_shown = :hidden
  @console.hide
end

#custom_buttonsObject


66
67
68
# File 'dragon/console_menu.rb', line 66

def custom_buttons
  []
end

#docs_clickedObject


57
58
59
60
# File 'dragon/console_menu.rb', line 57

def docs_clicked
  @console.scroll_to_bottom
  log Kernel.docs_classes
end

#framerate_diagnostics_clickedObject


47
48
49
50
# File 'dragon/console_menu.rb', line 47

def framerate_diagnostics_clicked
  @console.scroll_to_bottom
  $gtk.framerate_diagnostics
end

#hide_menu_clickedObject


43
44
45
# File 'dragon/console_menu.rb', line 43

def hide_menu_clicked
  @menu_shown = :hidden
end

#itch_wizard_clickedObject


52
53
54
55
# File 'dragon/console_menu.rb', line 52

def itch_wizard_clicked
  @console.scroll_to_bottom
  $wizards.itch.start
end

#record_clickedObject


14
15
16
# File 'dragon/console_menu.rb', line 14

def record_clicked
  $recording.start 100
end

#rect_for_layout(row, col) ⇒ Object


116
117
118
119
120
121
122
123
124
# File 'dragon/console_menu.rb', line 116

def rect_for_layout row, col
  col_width  = 100
  row_height = 50
  col_margin = 5
  row_margin = 5
  x = (col_margin + (col * col_width)  + (col * col_margin))
  y = (row_margin + (row * row_height) + (row * row_margin) + row_height).from_top
  { x: x, y: y, w: col_width, h: row_height }
end

#replay_clickedObject


18
19
20
# File 'dragon/console_menu.rb', line 18

def replay_clicked
  $replay.start 'replay.txt'
end

#reset_clickedObject


22
23
24
# File 'dragon/console_menu.rb', line 22

def reset_clicked
  $gtk.reset
end

#scroll_down_clickedObject


30
31
32
# File 'dragon/console_menu.rb', line 30

def scroll_down_clicked
  @console.scroll_down_half
end

#scroll_end_clickedObject


62
63
64
# File 'dragon/console_menu.rb', line 62

def scroll_end_clicked
  @console.scroll_to_bottom
end

#scroll_up_clickedObject


26
27
28
# File 'dragon/console_menu.rb', line 26

def scroll_up_clicked
  @console.scroll_up_half
end

#serializeObject


152
153
154
155
156
# File 'dragon/console_menu.rb', line 152

def serialize
  {
    not_supported: "#{self}"
  }
end

#show_menu_clickedObject


34
35
36
# File 'dragon/console_menu.rb', line 34

def show_menu_clicked
  @menu_shown = :visible
end

#tick(args) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'dragon/console_menu.rb', line 70

def tick args
  return unless @console.visible?

  @menu_shown ||= :hidden

  if $gtk.production
    @buttons = [
      (button id: :record,      row: 0, col:   9, text: "record gameplay",       method: :record_clicked),
      (button id: :replay,      row: 0, col:  10, text: "start replay",          method: :replay_clicked),
    ]
  elsif @menu_shown == :hidden
    @buttons = [
      (button id: :show_menu,       row: 0, col: 10, text: "show menu", method: :show_menu_clicked),
    ]
  else
    @buttons = [
      (button id: :scroll_up,   row: 0, col:  6, text: "scroll up",             method: :scroll_up_clicked),
      (button id: :scroll_down, row: 0, col:  7, text: "scroll down",           method: :scroll_down_clicked),
      (button id: :scroll_down, row: 0, col:  8, text: "scroll end",            method: :scroll_end_clicked),
      (button id: :close,       row: 0, col:  9, text: "close console",         method: :close_clicked),
      (button id: :hide,        row: 0, col: 10, text: "hide menu",             method: :hide_menu_clicked),

      (button id: :record,      row: 1, col:  7, text: "record gameplay",       method: :record_clicked),
      (button id: :replay,      row: 1, col:  8, text: "start replay",          method: :replay_clicked),
      (button id: :record,      row: 1, col:  9, text: "framerate diagnostics", method: :framerate_diagnostics_clicked),
      (button id: :reset,       row: 1, col: 10, text: "reset game",            method: :reset_clicked),

      (button id: :reset,       row: 2, col: 10, text: "docs",                  method: :docs_clicked),
      (button id: :reset,       row: 2, col:  9, text: "itch wizard",           method: :itch_wizard_clicked),
      *custom_buttons
    ]
  end

  # render
  args.outputs.reserved << @buttons.map { |b| b[:primitives] }

  # inputs
  if args.inputs.mouse.click
    clicked = @buttons.find { |b| args.inputs.mouse.inside_rect? b[:rect] }
    if clicked
      args.inputs.mouse.click = nil
      send clicked[:method]
    end
  end
end