class Core::Game::Combat::GUI
Attributes
attacking[R]
casting[R]
using[R]
Public Class Methods
new()
click to toggle source
# File lib/game/combat/gui.rb, line 11 def initialize @x = 0 @y = 544 @z = 5000 @bg = Core.sprite("gui/battle_infoback") @w = {} # Currently shown windows @ready = [] @paused = false @chosen = @choose = nil @attacking = [] @casting = [] @using = [] @add = {} end
Public Instance Methods
abort_action(actor)
click to toggle source
# File lib/game/combat/gui.rb, line 93 def abort_action(actor) @paused = false @choose = nil @chosen = nil @w[:select_spell].close! if @w[:select_spell] @w[:select_item].close! if @w[:select_item] setup_ready_actions(actor) end
attacked()
click to toggle source
# File lib/game/combat/gui.rb, line 81 def attacked @attacking = [] end
draw()
click to toggle source
# File lib/game/combat/gui.rb, line 70 def draw @bg.draw(@x, @y, @z, 1024/@bg.width.to_f, 224/@bg.height.to_f) @w.each_value { |w| w.draw } end
item_used()
click to toggle source
# File lib/game/combat/gui.rb, line 89 def item_used @using = [] end
open_info(obj, x, y)
click to toggle source
# File lib/game/combat/gui.rb, line 33 def open_info(obj, x, y) if @choose and !@chosen @chosen = obj else if Core.config[:combat_gui_info_window_x] x = Core.config[:combat_gui_info_window_x] end if Core.config[:combat_gui_info_window_y] y = Core.config[:combat_gui_info_window_y] end @w[:info] = Core::GUI::Window.new(x, y, 320, 256, "Info", true, "gui/container_background", true) @w[:info].add(:text, Core::GUI::Textfield.new(8, 8, 304, 240, "#{obj}")) @w[:info].title = "#{Core::Trans.enemy(obj.data.name)}" @w[:info].save_pos(:combat_gui_info_window_x, :combat_gui_info_window_y) end end
paused?()
click to toggle source
# File lib/game/combat/gui.rb, line 77 def paused? return @paused end
push(type, *parms)
click to toggle source
# File lib/game/combat/gui.rb, line 26 def push(type, *parms) case type when :ready ready(parms) end end
spell_cast()
click to toggle source
# File lib/game/combat/gui.rb, line 85 def spell_cast @casting = [] end
update()
click to toggle source
# File lib/game/combat/gui.rb, line 50 def update @w.each_value { |w| w.update if w.remove? @w.delete(@w.key(w)) end } @add.each do |k, v| @w.store(k, v) end @add = {} w = @w[:select_spell] if w and w.selected @choose = lambda { cast(w.actor, @chosen, w.selected) } end if @choose and @chosen @choose.call end end
Private Instance Methods
attack(attacker, target)
click to toggle source
# File lib/game/combat/gui.rb, line 104 def attack(attacker, target) @attacking = [attacker, target] shift_ready abort_action(@ready.first) end
cast(attacker, target, spell)
click to toggle source
# File lib/game/combat/gui.rb, line 110 def cast(attacker, target, spell) @casting = [attacker, target, spell] shift_ready abort_action(@ready.first) end
open_abort(actor)
click to toggle source
# File lib/game/combat/gui.rb, line 183 def open_abort(actor) @w[:ready].empty @w[:ready].add(:abort, Core::GUI::Button.new(8, 8, 240, 32, Core::Trans.menu(:abort), lambda {abort_action(actor)})) end
open_attack(actor)
click to toggle source
# File lib/game/combat/gui.rb, line 154 def open_attack(actor) @paused = true @choose = lambda { attack(actor, @chosen) } open_abort(actor) end
open_item(actor)
click to toggle source
# File lib/game/combat/gui.rb, line 177 def open_item(actor) puts("STUB: GUI.open_item") @paused = true open_abort(actor) end
open_spell(actor)
click to toggle source
# File lib/game/combat/gui.rb, line 160 def open_spell(actor) @paused = true if Core.config[:combat_gui_spell_select_window_x] x = Core.config[:combat_gui_spell_select_window_x] else x = 192 end if Core.config[:combat_gui_spell_select_window_y] y = Core.config[:combat_gui_spell_select_window_y] else y = 192 end @add.store(:select_spell, SelectSpell.new(x, y, actor)) @add[:select_spell].parent = self open_abort(actor) end
ready(ary)
click to toggle source
# File lib/game/combat/gui.rb, line 122 def ready(ary) actor = ary.first char = actor.character if @ready.empty? @w[:ready] = Core::GUI::Window.new(768, @y, 256, 224, char.name, false, "gui/container_background") setup_ready_actions(actor) end @ready.push(actor) end
setup_ready_actions(actor)
click to toggle source
# File lib/game/combat/gui.rb, line 146 def setup_ready_actions(actor) w = @w[:ready] w.empty w.add(:attack, Core::GUI::Button.new(8, 8, 240, 32, Core::Trans.menu(:attack), lambda {open_attack(actor)})) w.add(:skill, Core::GUI::Button.new(8, 48, 240, 32, Core::Trans.menu(:magic), lambda {open_spell(actor)})) w.add(:item, Core::GUI::Button.new(8, 88, 240, 32, Core::Trans.menu(:item), lambda {open_item(actor)})) end
shift_ready()
click to toggle source
# File lib/game/combat/gui.rb, line 132 def shift_ready if @ready.empty? @w.delete(:ready) else @ready.shift if @ready.empty? @w[:ready].close! else @w[:ready].title = @ready.first.character.name setup_ready_actions(@ready.first.character) end end end
use(attacker, target, item)
click to toggle source
# File lib/game/combat/gui.rb, line 116 def use(attacker, target, item) @using = [attacker, target, item] shift_ready abort_action(@ready.first) end