class Gtk::WorldShifter

Public Class Methods

new() click to toggle source
Calls superclass method
# File core/plugin/gtk/world_shifter.rb, line 7
def initialize
  super
  ssc(:button_press_event) do |this,event|
    open_menu event if 3 >= event.button
    false
  end
  ssc_atonce(:realize) do
    refresh
  end
  pluggaloid_event_listener
end

Public Instance Methods

add_face_widget_ifn() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 106
def add_face_widget_ifn
  if not @face
    @face = Gtk::Image.new(Skin['loading.png'].pixbuf(width: UserConfig[:gtk_accountbox_geometry], height: UserConfig[:gtk_accountbox_geometry]))
    self.add(@face).show_all
  end
  world, = Plugin.filtering(:world_current, nil)
  if world
    @face.tooltip(world.title)
  end
end
destroy_menu() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 50
def destroy_menu
  @menu&.destroy
  @menu = nil
end
modify_face() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 92
def modify_face
  if @face
    world, = Plugin.filtering(:world_current, nil)
    transaction = @world_transaction = SecureRandom.uuid
    rect = { width:  UserConfig[:gtk_accountbox_geometry],
             height: UserConfig[:gtk_accountbox_geometry] }
    @face.pixbuf = world&.icon&.load_pixbuf(**rect) do |pixbuf|
      if transaction == @world_transaction
        @face.pixbuf = pixbuf
      end
    end || Skin['add.png'].pixbuf(**rect)
  end
end
open_menu(event) click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 25
def open_menu(event)
  @menu ||= Gtk::Menu.new.tap do |menu|
    Enumerator.new{|y|
      Plugin.filtering(:worlds, y)
    }.each do |world|
      item = Gtk::ImageMenuItem.new(world.title, false)
      item.set_image Gtk::WebIcon.new(world.icon, UserConfig[:gtk_accountbox_geometry], UserConfig[:gtk_accountbox_geometry])
      item.ssc(:activate) { |w|
        Plugin.call(:world_change_current, world)
        @face.tooltip(world.title)
        false }
      menu.append item
    end
    menu.append Gtk::SeparatorMenuItem.new
    item = Gtk::ImageMenuItem.new(Plugin[:gtk]._('Worldを追加'), false)
    item.set_image Gtk::WebIcon.new(Skin['add.png'], UserConfig[:gtk_accountbox_geometry], UserConfig[:gtk_accountbox_geometry])
    item.ssc(:activate) { |w|
      Plugin.call(:request_world_add)
      false }
    menu.append item
    menu
  end
  @menu.show_all.popup(nil, nil, event.button, event.time)
end
pluggaloid_event_listener() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 55
def pluggaloid_event_listener
  tag = Plugin[:gtk].handler_tag(:world_shifter) do
    Plugin[:gtk].on_world_change_current{ refresh }
    Plugin[:gtk].on_userconfig_modify do |key, newval|
      refresh if key == :world_shifter_visibility
    end
    Plugin[:gtk].on_world_after_created do |world|
      refresh
    end
    Plugin[:gtk].on_world_destroy do |world|
      refresh
    end
  end
  ssc(:destroy) do
    Plugin[:gtk].detach(tag)
  end
end
put_face() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 73
def put_face
  if visible?
    add_face_widget_ifn
  else
    remove_face_widget_ifn
  end
end
refresh() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 19
def refresh
  destroy_menu
  put_face
  modify_face
end
remove_face_widget_ifn() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 117
def remove_face_widget_ifn
  if @face
    self.remove(@face)
    @face.destroy
    @face = nil
  end
end
visible?() click to toggle source
# File core/plugin/gtk/world_shifter.rb, line 81
def visible?
  case UserConfig[:world_shifter_visibility]
  when :always
    true
  when :auto
    1 < Enumerator.new{|y| Plugin.filtering(:worlds, y) }.take(2).to_a.size
  else
    false
  end
end