Module: UI::Message::Layout

Includes:
PFM::Message::State, TemporaryOverwrites
Included in:
Window
Defined in:
scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb,
scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb

Overview

Module defining the Message layout

Constant Summary collapse

PAUSE_SKIN =

Name of the pause skin in Graphics/Windowskins/

'Pause2'
NAME_SKIN =

Windowskin for the name window

'message'

Instance Attribute Summary collapse

Attributes included from PFM::Message::State

#auto_skip, #current_instruction, #instructions, #last_text, #properties, #stay_visible

Attributes included from TemporaryOverwrites

#line_number_overwrite, #nameskin_overwrite, #position_overwrite, #width_overwrite, #windowskin_overwrite

Instance Method Summary collapse

Methods included from PFM::Message::State

#at_end_of_line?, #done_drawing_message?, #load_next_instruction, #need_to_show_choice?, #need_to_show_message?, #need_to_show_number_input?, #need_to_wait_user_input?, #parse_and_show_new_message, #showing_message?

Methods included from PFM::Message::Parser

#convert_text_to_properties, #make_instructions, register_marker

Methods included from TemporaryOverwrites

#reset_overwrites

Instance Attribute Details

#input_number_windowUI::InputNumber

Attribute that holds the UI::InputNumber object

Returns:



15
16
17
# File 'scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb', line 15

def input_number_window
  @input_number_window
end

#sub_stack (readonly)

Returns the value of attribute sub_stack.



21
22
23
# File 'scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb', line 21

def sub_stack
  @sub_stack
end

#text_stack (readonly)

Returns the value of attribute text_stack.



18
19
20
# File 'scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb', line 18

def text_stack
  @text_stack
end

Instance Method Details

#can_sub_window_be_updated?Boolean

Function that test if sub window can be updated (choice / number)

Returns:

  • (Boolean)


41
42
43
44
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 41

def can_sub_window_be_updated?
  !Graphics::FPSBalancer.global.skipping? || Input.trigger?(:A) || Input.trigger?(:B) ||
    Input.repeat?(:DOWN) || Input.repeat?(:UP) || Input.repeat?(:RIGHT) || Input.repeat?(:LEFT)
end

#current_layoutConfigs::Project::Texts::MessageConfig

Retrieve the current layout configuration based on the scene



37
38
39
40
# File 'scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb', line 37

def current_layout
  config = Configs.texts.messages
  return config[$scene.class.to_s] || config[:any]
end

#dispose(with_viewport: false)

Dispose the layout

Parameters:

  • with_viewport (Boolean) (defaults to: false)

    tell to also dispose the viewport of the layout



44
45
46
47
48
49
# File 'scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb', line 44

def dispose(with_viewport: false)
  vp = viewport
  super()
  @sub_stack.dispose
  vp.dispose if with_viewport
end

#face_speaker_yInteger

Return the face_speaker y position

Returns:



94
95
96
97
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 94

def face_speaker_y
  return viewport.rect.height # if position == :top
  # y
end

#generate_choice_window

Generate the choice window



9
10
11
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 9

def generate_choice_window
  @choice_window = Yuki::ChoiceWindow.generate_for_message(self)
end

#generate_input_number_window

Generate the number input window



14
15
16
17
18
19
20
21
22
23
24
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 14

def generate_input_number_window
  @input_number_window = UI::InputNumber.new(viewport, $game_temp.num_input_digits_max)
  if $game_system.message_position == 0
    @input_number_window.y = y + height + 2
  else
    @input_number_window.y = y - @input_number_window.height - 2
  end
  @input_number_window.z = z + 1
  @input_number_window.max = $game_temp.num_input_start if $game_temp.num_input_start > 0
  @input_number_window.update
end

#initialize

Initialize the states



24
25
26
27
28
29
30
31
32
33
# File 'scripts/01450 Systems/00004 Message/00002 UI/00002 Layout.rb', line 24

def initialize(...)
  super(...) # Forward any arguments to original super ;)
  # Content of the message
  @text_stack = UI::SpriteStack.new(self)
  # Sub stack of sprites/window related to the Message layout
  @sub_stack = UI::SpriteStack.new(viewport)
  # Initialize the window
  init_window
  self.visible = false
end

#load_sub_layout

Load the sub layout based on properties



100
101
102
103
104
105
106
107
108
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 100

def load_sub_layout
  @sub_stack.dispose
  properties.faces.each { |face| show_face(face) }
  show_name_window if properties.name
  show_city_image if properties.city_filename
  show_gold_window if properties.show_gold_window
  properties.process_look_to
  viewport.sort_z
end

#parse_speaker_position(position) ⇒ Integer

Function that translate the position to a coordinate

Parameters:

  • position (Integer)

    position given by the maker

Returns:



87
88
89
90
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 87

def parse_speaker_position(position)
  position = viewport.rect.width + position if position < 0
  return position
end

#show_city_image

Show the city image



59
60
61
62
63
64
65
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 59

def show_city_image
  @city_sprite = Sprite.new(viewport)
  @city_sprite.z = z + 1
  @city_sprite.load(properties.city_filename, :picture)
  @city_sprite.set_position(x + (wb = current_window_builder)[4], y + wb[5])
  @sub_stack.push_sprite(@city_sprite)
end

#show_face(face)

Show a face

Parameters:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 69

def show_face(face)
  sprite = Sprite.new(viewport)
  sprite.load(face.name, :battler)
  sprite.set_position(parse_speaker_position(face.position), face_speaker_y)
  sprite.set_origin(sprite.width / 2, sprite.height)
  def sprite.opacity=(v)
    return @opacity = v unless @opacity

    super(v * @opacity / 255)
  end
  sprite.opacity = face.opacity
  sprite.mirror = face.mirror
  @sub_stack.push_sprite(sprite)
end

#show_gold_window

Show a window that tells the player how much money he got



27
28
29
30
31
32
33
34
35
36
37
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 27

def show_gold_window
  return if @gold_window && !@gold_window.disposed?

  @gold_window = UI::Window.from_metrics(viewport, 318, 2, 48, 32, position: 'top_right')
  @gold_window.z = z + 1
  @gold_window.sprite_stack.with_surface(0, 0, 44) do
    @gold_window.add_line(0, text_get(11, 6))
    @gold_window.add_line(1, PFM::Text.parse(11, 9, ::PFM::Text::NUM7R => PFM.game_state.money.to_s), 2)
  end
  @sub_stack.push_sprite(@gold_window)
end

#show_name_window

Show the name window



47
48
49
50
51
52
53
54
55
56
# File 'scripts/01450 Systems/00004 Message/00002 UI/00003 Layout sub.rb', line 47

def show_name_window
  return if @name_window && !@name_window.disposed?

  wb = current_window_builder
  name_y = y + (current_position == :top ? height + default_vertical_margin : (-wb[5] - wb[-1] - default_line_height - default_vertical_margin))
  text_width = width_computer.normal_width(properties.name)
  @name_window = UI::Window.from_metrics(viewport, x, name_y, text_width, default_line_height, skin: current_name_windowskin)
  @sub_stack.push_sprite(Text.new(0, @name_window, 0, -Text::Util::FOY, 0, default_line_height, properties.name))
  @sub_stack.push_sprite(@name_window)
end