Class: UI::Window

Inherits:
Window show all
Defined in:
scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb

Overview

Window utility allowing to make Window easilly

Direct Known Subclasses

LevelUpWindow

Constant Summary collapse

DEFAULT_SKIN =
'message'

Instance Attribute Summary

Attributes inherited from LiteRGSS::Window

#__index__, #active, #back_opacity, #contents_opacity, #cursor_rect, #cursorskin, #height, #opacity, #ox, #oy, #pause, #pause_x, #pause_y, #pauseskin, #stretch, #viewport, #visible, #width, #window_builder, #windowskin, #x, #y, #z

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Window

#simple_mouse_in?, #translate_mouse_coords

Methods inherited from LiteRGSS::Window

#lock, #locked?, new, #set_origin, #set_position, #set_size, #unlock, #update

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Constructor Details

#initialize(viewport, x = 2, y = 2, width = 316, height = 48, skin: DEFAULT_SKIN) ⇒ Window

Create a new Window

Parameters:

  • viewport (Viewport)

    viewport where the window is shown

  • x (Integer) (defaults to: 2)

    X position of the window

  • y (Integer) (defaults to: 2)

    Y position of the window

  • width (Integer) (defaults to: 316)

    Width of the window

  • height (Integer) (defaults to: 48)

    Height of the window

  • skin (String) (defaults to: DEFAULT_SKIN)

    Windowskin used to display the window



12
13
14
15
16
17
18
19
20
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 12

def initialize(viewport, x = 2, y = 2, width = 316, height = 48, skin: DEFAULT_SKIN)
  super(viewport)
  lock
  set_position(x, y)
  set_size(width, height)
  self.windowskin = RPG::Cache.windowskin(skin)
  self.window_builder = current_window_builder(skin)
  unlock
end

Class Method Details

.from_metrics(viewport, x, y, width, height, skin: DEFAULT_SKIN, position: 'top_left')

Create a new window from given metrics

Parameters:

  • viewport (Viewport)

    viewport where the window is shown

  • x (Integer)

    x position of the window frame

  • y (Integer)

    y position of the window frame

  • width (Integer)

    width of the window contents

  • height (Integer)

    height of the window contents

  • skin (String) (defaults to: DEFAULT_SKIN)

    windowskin used to draw the window frame:

  • position (String) (defaults to: 'top_left')

    precision of the x/y positioning of the frame

    • 'top_left' : y is top side of the frame, x is left side of the frame

    • 'top_right' : y is top side of the frame, x is right side of the frame

    • 'bottom_left' : y is bottom side of the frame, x is left side of the frame

    • 'bottom_right' : y is bottom side of the frame, x is right side of the frame

    • 'middle_center' : y is middle height of the frame, x is center of the frame



36
37
38
39
40
41
42
43
44
45
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 36

def from_metrics(viewport, x, y, width, height, skin: DEFAULT_SKIN, position: 'top_left')
  wb = window_builder(skin)
  width = (wb[4] + wb[-2] + width)
  height = (wb[5] + wb[-1] + height)
  x -= width if position.include?('right')
  x -= width / 2 if position.include?('center')
  y -= height if position.include?('bottom')
  y -= height / 2 if position.include?('middle')
  return new(viewport, x, y, width, height, skin: skin)
end

.window_builder(skin) ⇒ Array<Integer>

Get the Window Builder according to the skin

Parameters:

  • skin (String)

    windowskin used to show the window

Returns:

  • (Array<Integer>)

    the window builder



50
51
52
53
54
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 50

def window_builder(skin)
  return Configs.window.builders[:message_box] if skin[0, 2].casecmp?('m_') # SkinHGSS

  return Configs.window.builders[:generic]
end

Instance Method Details

#add_line(line_index, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, dx: 0)

Add a text line to the window



65
66
67
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 65

def add_line(line_index, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: nil, dx: 0)
  sprite_stack.add_line(line_index, str, align, outlinesize, type: type, color: color, dx: dx)
end

#add_text(x, y, width, height, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: 0)

Add a text to the window



59
60
61
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 59

def add_text(x, y, width, height, str, align = 0, outlinesize = Text::Util::DEFAULT_OUTLINE_SIZE, type: Text, color: 0)
  sprite_stack.add_text(x, y, width, height, str, align, outlinesize, type: type, color: color)
end

#load_cursor

Load the cursor



88
89
90
91
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 88

def load_cursor
  cursor_rect.set(0, 0, 16, 16)
  self.cursorskin = RPG::Cache.windowskin('cursor')
end

#push(x, y, bmp, *args, rect: nil, type: Sprite, ox: 0, oy: 0)

Push a sprite to the window



71
72
73
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 71

def push(x, y, bmp, *args, rect: nil, type: Sprite, ox: 0, oy: 0)
  sprite_stack.push(x, y, bmp, *args, rect: rect, type: type, ox: ox, oy: oy)
end

#sprite_stackSpriteStack

Return the sprite stack used by the window

Returns:



83
84
85
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 83

def sprite_stack
  @stack ||= SpriteStack.new(self)
end

#stackArray

Return the stack of the window if any

Returns:

  • (Array)


77
78
79
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00200 Window.rb', line 77

def stack
  return (@stack&.stack || [])
end