Module: GamePlay::DisplayMessage

Included in:
Base
Defined in:
scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb

Overview

Module responsive of adding the display message functionality to a class

Constant Summary collapse

MESSAGE_ERROR =

Message the displays when a GamePlay scene has been initialized without message processing and try to display a message

'This interface has no MessageWindow, you cannot call display_message'
MESSAGE_PROCESS_ERROR =

Error message when display_message is called from “itself”

'display_message was called inside display_message. Please fix your scene update.'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#message_windowUI::Message::Window? (readonly)

The message window

Returns:



10
11
12
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 10

def message_window
  @message_window
end

Instance Method Details

#can_display_message_be_called?Boolean

Tell if the display_message function can be called

Returns:

  • (Boolean)


20
21
22
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 20

def can_display_message_be_called?
  !@still_in_display_message
end

#close_message_window { ... }

Force the message window to “close” (but does not update scene)

Yields:

  • yield to allow some process before updating the message window



26
27
28
29
30
31
32
33
34
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 26

def close_message_window
  return unless @message_window

  while message_processing?
    Graphics.update
    yield if block_given?
    @message_window.update
  end
end

#display_message(message, start = 1, *choices, &block) ⇒ Integer?

Display a message with choice or not

Parameters:

  • message (String)

    the message to display

  • start (Integer) (defaults to: 1)

    the start choice index (1..nb_choice)

  • choices (Array<String>)

    the list of choice options

  • block (Proc)

    block to call while message updates

Returns:

  • (Integer, nil)

    the choice result



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 64

def display_message(message, start = 1, *choices, &block)
  raise ScriptError, MESSAGE_ERROR unless @message_window
  raise ScriptError, MESSAGE_PROCESS_ERROR unless @message_done_processing && can_display_message_be_called?

  block ||= @__display_message_proc
  setup_message_display(message, start, choices)
  # Message update
  until @message_done_processing
    message_update_scene
    block&.call
  end
  Graphics.update
  return @message_choice
ensure
  @still_in_display_message = false
end

#display_message_and_wait(message, start = 1, *choices, &block) ⇒ Integer?

Display a message with choice or not. This method will wait the message window to disappear

Parameters:

  • message (String)

    the message to display

  • start (Integer) (defaults to: 1)

    the start choice index (1..nb_choice)

  • choices (Array<String>)

    the list of choice options

  • block (Proc)

    block to call while message updates

Returns:

  • (Integer, nil)

    the choice result



87
88
89
90
91
92
93
94
95
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 87

def display_message_and_wait(message, start = 1, *choices, &block)
  block ||= @__display_message_proc
  choice = display_message(message, start, *choices, &block)
  @still_in_display_message = true
  close_message_window(&block)
  return choice
ensure
  @still_in_display_message = false
end

#message_classClass<UI::Message::Window>

Return the message class used

Returns:



38
39
40
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 38

def message_class
  UI::Message::Window
end

#message_processing?Boolean

Prevent the update to process if the message are still processing

Returns:

  • (Boolean)


14
15
16
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 14

def message_processing?
  @message_window&.showing_message?
end

#message_visibleBoolean

Get the visibility of message

Returns:

  • (Boolean)


52
53
54
55
56
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 52

def message_visible
  return false unless @message_window

  @message_window.viewport.visible
end

#message_visible=(visible)

Set the visibility of message

Parameters:

  • visible (Boolean)


44
45
46
47
48
# File 'scripts/01450 Systems/00004 Message/00003 GamePlay/00001 DisplayMessage.rb', line 44

def message_visible=(visible)
  return unless @message_window

  @message_window.viewport.visible = visible
end