[1.4.5 Teascript-vb] Windows manager

General discussion about Super Mario Bros. X.

Moderator: Userbase Moderators

erwill
Koopa
Koopa
Posts: 18
Joined: Tue Feb 08, 2022 4:39 pm

[1.4.5 Teascript-vb] Windows manager

Postby erwill » Sun Oct 08, 2023 2:05 pm

Windows manager

What is a window?
A window is a graphic element having a background and borders, the first one is fully scaled to the size of the window, and the borders don't.
Image

How it works?
The window will use 10 bitmaps, (A window id is the ten of the bitmap id) then you have to use a NPC graphic as a source.
The window graphic is organized like this: Image
Here's the template, the purple part is the window background, the yellow part is the border and the red part is the corner. Image
You can put as many window graphics as you want in one file, just put together vertically, the value to use one of those window graphics are called "winid"
Image

The script (To past above all the ones)

Code: Select all

'	o Create window
export script Window_create(id as double, picid as double, winid as double, useScreenCoords as double, isVisible as double, destx as double, desty as double, width as double, height as double, color as double, gap as double)
	'	o Fix incorrect values
	winid = int(winid)
	'	o Erase all slots already taken to overwrite
	call Window_erase(id)
	'	o Create window background
	call bmpcreate(id*10, picid, useScreenCoords, isVisible, 0, 0+64*winid, 64, 64, destx+gap, desty+gap, 1/64*(width-gap*2), 1/64*(height-gap*2), 0, 0, 0, color)
	'	o Create up left border
	call bmpcreate(id*10+1, picid, useScreenCoords, isVisible, 64, 0+64*winid, 16, 16, destx, desty, 1, 1, 0, 0, 0, -1)
	'	o Create up border
	call bmpcreate(id*10+2, picid, useScreenCoords, isVisible, 80, 0+64*winid, 32, 16, destx+16, desty, 1/32*(width-32), 1, 0, 0, 0, -1)
	'	o Create up right border
	call bmpcreate(id*10+3, picid, useScreenCoords, isVisible, 112, 0+64*winid, 16, 16, destx+width-16, desty, 1, 1, 0, 0, 0, -1)
	'	o Create right border
	call bmpcreate(id*10+4, picid, useScreenCoords, isVisible, 112, 16+64*winid, 16, 32, destx+width-16, desty+16, 1, 1/32*(height-32), 0, 0, 0, -1)
	'	o Create down right border
	call bmpcreate(id*10+5, picid, useScreenCoords, isVisible, 112, 48+64*winid, 16, 16, destx+width-16, desty+height-16, 1, 1, 0, 0, 0, -1)
	'	o Create down border
	call bmpcreate(id*10+6, picid, useScreenCoords, isVisible, 80, 48+64*winid, 32, 16, destx+16, desty+height-16, 1/32*(width-32), 1, 0, 0, 0, -1)
	'	o Create down left border
	call bmpcreate(id*10+7, picid, useScreenCoords, isVisible, 64, 48+64*winid, 16, 16, destx, desty+height-16, 1, 1, 0, 0, 0, -1)
	'	o Create left border
	call bmpcreate(id*10+8, picid, useScreenCoords, isVisible, 64, 16+64*winid, 16, 32, destx, desty+16, 1, 1/32*(height-32), 0, 0, 0, -1)
	'	o Create an invisible bitmap to stock some informations
	call bmpcreate(id*10+9, picid, useScreenCoords, isVisible, gap, 1, width, height, 1, 1, 1, 1.0, 0, 0, 0, 0)
	' * sx/scrx = gap
	' * scrwidth = width
	' * scrheight = height
	' * sy/scry = used for loop function
end script 
'	o Erase window
export script Window_erase(id as double)
	for bitmap(id*10+9).scry = id*10 to id*10+9
		call BErase(2, bitmap(id*10+9).scry)
	next
end script 
'	o Set window infos
export script Set_Window_X(id as double, xpos as double) 
	'	o Move window background
	bitmap(id*10).destx = xpos+bitmap(id*10+9).scrx
	'	o Move up left border
	bitmap(id*10+1).destx = xpos
	'	o Move up  border
	bitmap(id*10+2).destx = xpos+16
	'	o Move up right border
	bitmap(id*10+3).destx = xpos+bitmap(id*10+9).scrwidth-16
	'	o Move right and right down border
	bitmap(id*10+4).destx = bitmap(id*10+3).destx
	bitmap(id*10+5).destx = bitmap(id*10+3).destx
	'	o Move down border
	bitmap(id*10+6).destx = bitmap(id*10+2).destx
	'	o Move down left border
	bitmap(id*10+7).destx = bitmap(id*10+1).destx
	'	o Move  left border
	bitmap(id*10+8).destx = bitmap(id*10+1).destx
end script 
export script Set_Window_Y(id as double, ypos as double) 
	'	o Move window background
	bitmap(id*10).desty = ypos+bitmap(id*10+9).scrx
	'	o Move up left border
	bitmap(id*10+1).desty = ypos
	'	o Move up  border
	bitmap(id*10+2).desty = bitmap(id*10+1).desty
	'	o Move up right border
	bitmap(id*10+3).desty = bitmap(id*10+1).desty
	'	o Move right border
	bitmap(id*10+4).desty = ypos+16
	'	o Move right down border
	bitmap(id*10+5).desty = Ypos+bitmap(id*10+9).scrheight-16
	'	o Move down border
	bitmap(id*10+6).desty = bitmap(id*10+5).desty
	'	o Move down left border
	bitmap(id*10+7).desty = bitmap(id*10+5).desty
	'	o Move  left border
	bitmap(id*10+8).desty = bitmap(id*10+4).desty
end script 
export script Set_Window_pos(id as double, xpos as double, ypos as double)
	call Set_Window_X(id, xpos)
	call Set_Window_Y(id, ypos)
end script
export script Set_Window_width(id as double, width as double)
	'	o Change window background width
	bitmap(id*10).scalex = 1/64*(width-bitmap(id*10+9).scrx*2)
	'	o Change up border
	bitmap(id*10+2).scalex = 1/32*(width-32)
	'	o Change up right border
	bitmap(id*10+3).destx = bitmap(id*10+1).destx+width-16
	'	o Change right border
	bitmap(id*10+4).destx = bitmap(id*10+3).destx
	'	o Change down right border
	bitmap(id*10+5).destx = bitmap(id*10+3).destx
	'	o Change down border
	bitmap(id*10+6).scalex = bitmap(id*10+2).scalex
	'	o Set width info
	bitmap(id*10+9).scrwidth = width
end script
export script Set_Window_height(id as double, height as double)
	'	o Change window background width
	bitmap(id*10).scaley = 1/64*(height-bitmap(id*10+9).scrx*2)
	'	o Change right border
	bitmap(id*10+4).scaley = 1/32*(height-32)
	'	o Change right down border
	bitmap(id*10+5).desty = bitmap(id*10+3).desty+height-16
	'	o Change down border
	bitmap(id*10+6).desty = bitmap(id*10+5).desty
	'	o Change down left border
	bitmap(id*10+7).desty = bitmap(id*10+5).desty
	'	o Change left border
	bitmap(id*10+8).scaley = bitmap(id*10+4).scaley
	'	o Set width info
	bitmap(id*10+9).scrheight = height
end script
export script Set_Window_size(id as double, width as double, height as double)
	call Set_Window_width(id, width)
	call Set_Window_height(id, height)
end script
export script Set_Window_hide(id as double, hid as double)
	for bitmap(id*10+9).scry = id*10 to id*10+8
		bitmap(bitmap(id*10+9).scry)).hide = hid
	next
end script
export script Set_Window_Zpos(id as double, z as double)
	for bitmap(id*10+9).scry = id*10 to id*10+8
		bitmap(bitmap(id*10+9).scry)).zpos = z
	next
end script
export script Set_Window_color(id as double, color as string, value as double)
	select case color
		case "c"
			bitmap(id*10).color = value
		case "r"
			bitmap(id*10).forecolor_r = value
		case "g"
			bitmap(id*10).forecolor_g = value
		case "b"
			bitmap(id*10).forecolor_b = value
		case "a"
			bitmap(id*10).forecolor_a = value
	end select
end script
export script Set_Window_border_color(id as double, color as string, value as double)
	select case color
		case "c"
			for bitmap(id*10+9).scry = id*10+1 to id*10+8
				bitmap(bitmap(id*10+9).scry)).color = value
			next
		case "r"
			for bitmap(id*10+9).scry = id*10+1 to id*10+8
				bitmap(bitmap(id*10+9).scry)).forecolor_r = value
			next
		case "g"
			for bitmap(id*10+9).scry = id*10+1 to id*10+8
				bitmap(bitmap(id*10+9).scry)).forecolor_g = value
			next
		case "b"
			for bitmap(id*10+9).scry = id*10+1 to id*10+8
				bitmap(bitmap(id*10+9).scry)).forecolor_b = value
			next
		case "a"
			for bitmap(id*10+9).scry = id*10+1 to id*10+8
				bitmap(bitmap(id*10+9).scry)).forecolor_a = value
			next
	end select
end script
export script Set_Window_blend(id as double, value as double)
	bitmap(id*10).Blendmode = value
end script
export script Set_Window_border_blend(id as double, value as double)
	for bitmap(id*10+9).scry = id*10+1 to id*10+8
		bitmap(bitmap(id*10+9).scry)).Blendmode = value
	next
end script
export script Set_Window_attscreen(id as double, value as double)
	for bitmap(id*10+9).scry = id*10 to id*10+8
		bitmap(bitmap(id*10+9).scry)).attscreen = value
	next
end script
export script Set_Window_npcid(id as double, value as double)
	for bitmap(id*10+9).scry = id*10 to id*10+8
		bitmap(bitmap(id*10+9).scry)).scrid = value
	next
end script
export script Set_Window_winid(id as double, winid as double)
	'	o Change background
	bitmap(id*10).scry = winid*64
	'	o Change up left border
	bitmap(id*10+1).scry = 0+64*winid
	'	o Change up border
	bitmap(id*10+2).scry = 0+64*winid
	'	o Change up right border
	bitmap(id*10+3).scry = 0+64*winid
	'	o Change right border
	bitmap(id*10+4).scry = 16+64*winid
	'	o Change down right border
	bitmap(id*10+5).scry = 48+64*winid
	'	o Change down border
	bitmap(id*10+6).scry = 48+64*winid
	'	o Change down left border
	bitmap(id*10+7).scry = 48+64*winid
	'	o Change left border
	bitmap(id*10+8).scry = 16+64*winid
end script
export script Set_Window_gap(id as double, value as double)
	bitmap(id*10).destx = bitmap(id*10+1).destx + value
	bitmap(id*10).desty = bitmap(id*10+1).desty + value
	bitmap(id*10).scalex = 1/64*(bitmap(id*10+9).scrwidth - value*2)
	bitmap(id*10).scaley = 1/64*(bitmap(id*10+9).scrheight - value*2)
	bitmap(id*10+9).scrx = value
end script
'	o Get window infos
export script Window_X(id as double, return double) return bitmap(id*10+1).destx end
export script Window_Y(id as double, return double) return bitmap(id*10+1).desty end
export script Window_width(id as double, return double) return (bitmap(id*10+3).destx-bitmap(id*10+1).destx+bitmap(id*10+1).scrwidth) end
export script Window_height(id as double, return double) return (bitmap(id*10+7).desty-bitmap(id*10+1).desty+bitmap(id*10+1).scrheight) end 
export script Window_hide(id as double, return double) return bitmap(id*10).hide end 
export script Window_Zpos(id as double, return double) return bitmap(id*10).Zpos end 
export script Window_color(id as double, return double) return bitmap(id*10).color end 
export script Window_border_color(id as double, return double) return bitmap(id*10+1).color end 
export script Window_Blendmode(id as double, return double) return bitmap(id*10).Blendmode end 
export script Window_border_Blendmode(id as double, return double) return bitmap(id*10+1).Blendmode end 
export script Window_attscreen(id as double, return double) return bitmap(id*10).attscreen end 
export script Window_winid(id as double, return double) return int(bitmap(id*10).scry/64) end
export script Window_npcid(id as double, return double) return bitmap(id*10).scrid end
export script Window_forecolor_r(id as double, return double) return bitmap(id*10).forecolor_r end
export script Window_forecolor_g(id as double, return double) return bitmap(id*10).forecolor_g end
export script Window_forecolor_b(id as double, return double) return bitmap(id*10).forecolor_b end
export script Window_forecolor_a(id as double, return double) return bitmap(id*10).forecolor_a end
export script Window_border_forecolor_r(id as double, return double) return bitmap(id*10+1).forecolor_r end
export script Window_border_forecolor_g(id as double, return double) return bitmap(id*10+1).forecolor_g end
export script Window_border_forecolor_b(id as double, return double) return bitmap(id*10+1).forecolor_b end
export script Window_border_forecolor_a(id as double, return double) return bitmap(id*10+1).forecolor_a end
export script Window_gap(id as double, return double) return bitmap(id*10+9).scrx end
export script Window_debug(id as double)
	call Debug("____WINDOW "&id&" INFO____")
	call Debug("* POSITION X: "&Window_X(id)&" Y: "&Window_Y(id))
	call Debug("* POSITION Z: "&Window_Zpos(id))
	call Debug("* SIZE W: "&Window_width(id)&" H: "&Window_height(id))
	call Debug("* COLOR R: "&window_forecolor_r(id)&" G: "&window_forecolor_g(id)&" B: "&window_forecolor_b(id)&" A: "&window_forecolor_a(id))
	call Debug("* COLOR C: "&Window_color(id)&" BLENDMODE: "&Window_Blendmode(id))
	call Debug("* COLOR B R: "&window_border_forecolor_r(id)&" G: "&window_border_forecolor_g(id)&" B: "&window_border_forecolor_b(id)&" A: "&window_border_forecolor_a(id))
	call Debug("* COLOR B C: "&Window_border_color(id)&" BLENDMODE B: "&Window_border_Blendmode(id))
	call Debug("* NPCID: "&window_npcid(id)&" WINID: "&window_winid(id))
	call Debug("* ATTSCREEN: "&Window_attscreen(id)&" HIDE: "&Window_hide(id)&" GAP: "&window_gap(id))
	call Debug("______________________")
end script
Documentation
Functions: show
Window_create will create a window by using 10 bitmaps, it needs an NPC for the graphic.
id - The window ID slot for the window
npcid - The ID of the npc graphic used for the window
winid - The ID of the window graphic
useScreenCoords Determines if the window positions is oriented to the level's coordinate (0) of the top left corner of the screen (1)
isVisible - Determines if the window is visible (1) or hidden (0)
destx - The X coordinate of the window
desty - The X coordinate of the window
width - The width size of the window
height - The height size of the window
color - the forecolor of the window background (-1 is normal)
gap - The gap between the real border of the window and the border of the window background

Code: Select all

call Window_create(id, npcid, winid, useScreenCoords, isVisible, destx, desty, width, height, color, gap)
Window_erase will erase the window from its ID.

Code: Select all

call Window_erase(id)
Set_Window_X will change the X position of the window.

Code: Select all

call Set_Window_X(id , x) 
Set_Window_Y will change the Y position of the window.

Code: Select all

call Set_Window_Y(id , y) 
Set_Window_pos will change the positions of the window.

Code: Select all

call Set_Window_pos(id, x, y) 
Set_Window_width will change the width of the window.

Code: Select all

call Set_Window_width(id, width) 
Set_Window_height will change the height of the window.

Code: Select all

call Set_Window_height(id, height) 
Set_Window_size will change the size of the window.

Code: Select all

call Set_Window_size(id, width, height) 
Set_Window_hide will make the window hiden (1) or not (0).

Code: Select all

call Set_Window_hide(id, hide) 
Set_Window_Zpos will change the Z position of the window.

Code: Select all

call Set_Window_Zpos(id, z) 
Set_Window_color will change the color of the window background.
color - Can be the color ("c") or one of the four color channel ("r" for red, "g" for green, "b" for blue, "a" for alpha)

Code: Select all

call Set_Window_color(id, color, value)
Set_Window_border_color will change the color of the window borders.
color - Can be the color ("c") or one of the four color channel ("r" for red, "g" for green, "b" for blue, "a" for alpha)

Code: Select all

call Set_Window_border_color(id, color, value)
Set_Window_blend will change the blendmode of the window background.

Code: Select all

call Set_Window_blend(id, value)
Set_Window_border_blend will change the blendmode of the window borders.

Code: Select all

call Set_Window_border_blend(id, value)
Set_Window_attscreen will make the window positions oriented to the level's coordinate (0) of the top left corner of the screen (1).

Code: Select all

call Set_Window_attscreen(id, value)
Set_Window_npcid will change the npc graphic for the window.

Code: Select all

call Set_Window_npcid(id, value)
Set_Window_winid will change the id of the window graphic.

Code: Select all

call Set_Window_winid(id, value)
Set_Window_gap will change the gap between the real border of the window and the border of the window background.

Code: Select all

call Set_Window_gap(id, value)
Window_debug will write all the informations of the window in the debug console.
Image

Code: Select all

call Window_debug(id)
Values: show
Window_X(id) - Stands for the X position of the window.
Window_Y(id) - Stands for the Y position of the window.
Window_width(id) - Stands for the width of the window.
Window_height(id) - Stands for the height of the window.
Window_hide(id) - Stands for if the window is hidden (1) or not (0).
Window_Zpos(id) - Stands for the Z position of the window.
Window_color(id) - Stands for the color of the window background.
Window_border_color(id) - Stands for the color of the window borders.
Window_Blendmode(id) - Stands for the blendmode of the window background.
Window_border_Blendmode(id) - Stands for the blendmode of the window borders.
Window_attscreen(id) - Stands for whether the window's coordinates are oriented to the level's coordinate system or if it's oriented to the player's screen
Window_winid(id) - Stands for the window ID.
Window_npcid(id) - Stands for the NPC ID used as the window source.
Window_forecolor_r(id) - Stands for the red channel of the window background.
Window_forecolor_g(id) - Stands for the green channel of the window background.
Window_forecolor_b(id) - Stands for the blue channel of the window background.
Window_forecolor_a(id) - Stands for the alpha channel of the window background.
Window_border_forecolor_r(id) - Stands for the red channel of the window borders.
Window_border_forecolor_g(id) - Stands for the green channel of the window borders.
Window_border_forecolor_b(id) - Stands for the blue channel of the window borders.
Window_border_forecolor_a(id) - Stands for the alpha channel of the window borders.
Window_gap(id) - Stands for the gap between the real border of the window and the border of the window background.

Return to “General”

Who is online

Users browsing this forum: No registered users and 2 guests

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari