MSXVIEW-DEMO (I)

Post Reply
Javi
Posts: 29
Joined: Sat Jun 11, 2022 5:14 am
Been thanked: 10 times

MSXVIEW-DEMO (I)

Post by Javi »

Tutorial MSXVIEW-DEMO

MSXVIEW-DEMO (I) picture
MSXVIEW-DEMO (I) picture
MSXVIEWDEMOx256x212.png (21.02 KiB) Viewed 53 times


Objetivos / Objectives

Motor de menu VR-VIEW y aplicación VR-SCRIPT.

VR-VIEW menu engine and VR-SCRIPT application.

Descarga los ejemplos y recursos utilizados aquí
MSXVIEW-Demo-I.zip
MSXVIEW-DEMO (I)
(70.74 KiB) Downloaded 4 times


Ficheros / Files


Demo/

test.pi

Demo/scripts/

configuracio.pi
interficie.pi
fons.pi
vista.pi
task.pi


Demo/scripts/utils/

xml_loader.pi


Demo/xml/

stage1.xml
stage2.xml
stage3.xml
stage4.xml
stage5.xml
stage6.xml
stage7.xml
stage8.xml


Demo/data/

Mount_Ossa_Tasmania_1.jpg
Watzmann.jpg
2015-09-05_16.25.01.jpg
6112610781_4602bb2c24_q.jpg
ever.jpg
fall-reflections-sawtooth-mountains-idaho-dave-welling.jpg
PICT0072-175x175.jpg
Smokies-winter-pano-195x195.jpg




Instalación y pruebas / Installation and testing

Ejecución en VR-DOS / Execution on VR-DOS

Code: Select all

C:\>cd Demo
C:\Demo>test
Introducción / Introduction

Se muestra una ventana vista donde el usuario puede personalizar las opciones y carga la información XML que describe la escena.
Cuando se presiona el botón Reproducir, la ventana desaparece.
La escena se mostrará después.


A window vista is displayed where the user can customize options and loads the XML info that describes the scene.
Where the button Play is pressed the window disappears.
The scene will be displayed afterward.



TECLAS / KEYS:

ESPACIO - Muestra la ventana de nuevo. / SPACE - Shows window again.
ESC - Salida del programa. / ESC - Exit program.


test.pi


Es la clase principal del programa. Lo gestiona todo.

function Start : Crea la configuración de clases, interficie, vista. Vista se inicializa cuando se crea.

function Initialize : Inicializar configuración e interficie.

function Main : Es una iteración interminable que espera que se presione una tecla para finalizar o para mostrar la vista de la ventana.


Is the main program class. It manages everything.

function Start : Creates de classes configuracio, interficie, vista. vista is initialized when created.

function Initialize : Initialize configuracio and interficie.

function Main : It is a never ending iteration waiting for a key pressed to end or to show window vista.


Code: Select all

class Test implements GL_Program
{
    
    defines:

		DIR_XML = "xml/";
		DIR_DATA = "data/";
		DIR_SCRIPTS = "scripts/";

	properties:
	
		console = null;
		
		vista = null;
		configuracio = null;
		interficie = null;
		

    function Start()
    {

		AddScriptPackage(DIR_SCRIPTS);
		AddScriptPackage(DIR_SCRIPTS + "utils/");

		console = GetEngine().GetDOS(true).GetConsole();

		
		configuracio = new Configuracio(this);
		interficie = new Interficie(this);
		vista = new Vista(this);

		::Start();

	}
	

    function Initialize()
	{

		_ok = configuracio.Initialize();
		if (!_ok) 
		{
			console.PrintLn("Configuracio : Something wrong..");
			End(0);

		}
	
		_ok =  interficie.Initialize(configuracio);
		if (!_ok) 
		{
			console.PrintLn("Interficie : Something wrong..");
			End(0);

		}
		
		configuracio.FreeData();
		
		return true;
		
	}
	
	
	function Main()
	{
	
		_isGoing = 1;
		while (_isGoing) 
		{
			if (Input_IsKeyPressed(KEY_ESCAPE))
			{
				vista.FreeData();
				console.PrintLn("Ok");
				End(0);               
			
			} 
			else if (Input_IsKeyPressed(KEY_SPACE))
			{
				_isGoing = 0;
				vista.Open();
			
			}
			

		}

	}
	
	
	
}


configuracio.pi


Es la clase de configuración. Contiene todos los parámetros de personalización del programa.

function Fill : Carga la información dada por windows vista. Y carga la información XML que describe la escena.


function FreeData: Para evitar bloqueos, es mejor liberar datos de XML siempre que sea posible.


Is the configuration class. It contains all the customization parameters of the program.

function Fill : It loads the information given by windows vista. And it loads the XML info that describes the scene.

function FreeData: To prevent hangs is better to free data from XML whenever possible.


Code: Select all

class Configuracio implements Task
{

	properties:

		x = null;
		y = null;
		vr = null;
		
		xml = null;
		data = null;
		

		
	function Fill(vista)
	{
		vr = vista.vr;
		x = vista.x;
		y = vista.y;
		xml = vista.xml;

	}
	
	function Initialize()
	{

		data = new XML_Loader();
		_ok = data.Load(app.GetEngine(), xml);
		if (!_ok) return false;

		return true;
	
	}
	
	
	
	function FreeData()
	{
		delete data;
	}
	


}

interficie.pi


clase interficie significa la escena que se va a mostrar. Gestiona todos los elementos mostrados.

function Initialize : Llama a la pantalla de inicialización y todo tipo de elementos que se mostrarán. La información de configuración se proporciona a las llamadas.

function InitializeResolution : Pantalla de inicialización.

function InitializeFons : Inicializa el fondo.


interficie class means the scene to be displayed. It manages all the displayed items.

function Initialize : Calls initialize screen and all sorts of items to be displayed. The configuration info is given to the calls.

function InitializeResolution : Initialize screen.

function InitializeFons : Initialize background.


Code: Select all

class Interficie implements Task
{

	properties:
		
		stage = null;
		fons = [];

	function Initialize(configuracio)
	{
		
		InitializeResolution(configuracio);
		InitializeFons(configuracio);
		
		return true;
	}


	function InitializeResolution(configuracio)
	{
		resX =  configuracio.x; 
		if (configuracio.vr) resX = resX *2;
		
		resY =  configuracio.y;
		
		if (stage!=null) delete stage;
		
		stage = app.NewStage("ts_stage");
       	 stage.SetMain();
        	stage.SetActive();
		
		app.SetBackColor(RGB(0,0,0));
        	app.SetBgColor(RGB(0,0,0));
        	app.SetResolution(resX, resY);
        	app.SetViewScale(-1);
        	app.SetVSync(true);
       	app.Set2DFilter(true);
        
	}

	function InitializeFons(configuracio)
	{
		iter = 1;
		if (configuracio.vr) iter = 2;
		
		for (i =0; i<iter; i++) {

			_fons = new Fons(app);
			_fons.Initialize(configuracio, i);

			fons += [_fons];
		}
	}

}

fons.pi


Es la clase de imagen de fondo. El fondo que se mostrará.

function Initialize: Lee la estructura de datos XML dentro de la configuración, la ajusta en relación con las posiciones globales y crea las imágenes que se mostrarán.

function SetId : Establece id para cada fondo que se mostrará.

function SetFromXmlObject : Lee la estructura de datos XML dentro de la configuración en una búsqueda de información de imagen de fondo.

function AddActor : Extrae la información necesaria de la estructura de datos XML a las variables internas de la clase.

function CorrectRelativePositions : Ajuste en relación con las posiciones globales.


Is the background image class. The background to be displayed.

function Initialize: Reads the XML data structure inside configuration, adjust relative to global positions, and creates the images to be displayed.

function SetId : Sets id for every background to be displayed.

function SetFromXmlObject : Reads the XML data structure inside configuration in a search of background image information.

function AddActor : Extracts the necessary information from the XML data structure to internal variables of the class.

function CorrectRelativePositions : Adjust relative to global positions.


Code: Select all

class Fons implements Task
{
	properties:
	
		id = null;
        	bg = null;
        	icon = null;
		filename = null;
		x = null;
		y = null;

        
	function Initialize(configuracio, i)
	{
		SetId(i);
		SetFromXmlObject(configuracio);
		CorrectRelativePositions(configuracio);
		
		bg = app.NewSprite("bg" + string(i));
		bg.AddFrame( DIR_DATA + filename);
		bg.SetPos(x, y);
		bg.SetPriority(3);
		
		
		return true;
	}

	function SetId(i)
	{
		id = i;
	}

    function SetFromXmlObject(configuracio)
    {
    
		_data = configuracio.data;
        _root = _data.rootList[0];
		_name = _root.name;
        _background = _root.backgroundList[0];
        

		AddActor(app.console, _background);
    
    }

	function AddActor(console, _data)
	{
			icon = _data.iconText;
			filename = _data.imageText;
			x = int( _data.xText );
            y = int( _data.yText );
            
            

	}
	
	function CorrectRelativePositions(configuracio)
    {
        x = (id * configuracio.x) + x;
    }
    
	

}


vista.pi


Es la clase de ventana. Crea una ventana con opciones de personalización.
Contiene la clase ItemComboXml


class ItemComboXml

Creado como un solo elemento XML de cuadro combinado. Contiene la información esencial mínima de un archivo de configuración XML.

function SetFromXmlFile : Lee el archivo xml y carga la información con la función AddActor.

function AddActor : Carga la información sobre los datos de la estructura XML a las variables de la clase.

class vista

function Init : Crea la ventana y carga toda la información de la configuración a mostrar en la ventana.

function FillComboXml : Rellena el cuadro combinado de archivos XML con información de vista previa.

function GetFilesXmlDirectory : Busca en el directorio para encontrar archivos XML y carga los archivos XML para extraer la información esencial mínima para obtener una vista previa.


function OnPlay : La respuesta de la pulsación del botón. Almacena información de la ventana al objeto de configuración. Cerrar ventana. Inicializa el interficie. Finalmente, llame a la función principal.

function FillView: Extrae la información de la ventana antes de que desaparezca.

function Close : Cierra la ventana.

function Open : Vuelve a abrir la ventana.

function OnChangeComboXml : Cuando se cambia la opción del cuadro combinado, muestra una imagen de vista previa en el lienzo.

function FreeData : Definitivamente destruye la ventana y la estructura de datos XML.


Is the window class. It creates a window with customization options.
It contains class ItemComboXml


class ItemComboXml

Created as a single combobox XML item. It contains the minimal essential information from one XML configuration file.

function SetFromXmlFile : Reads the xml file and loads information with AddActor function.

function AddActor : Loads the information on the XML structure data to the variables of the class.





class vista

function Init : Creates the window and loads all the information of the configuration to be displayed on the window.

function FillComboXml : Fills the combobox of XML files with preview information.

function GetFilesXmlDirectory : Look to the directory to find XML files and loads the XML files to extract the minimal essential information to preview.

function OnPlay : The response from the button press. Stores information from the window to the configuration object.Close window. Initialize the interficie. Finally, call the main function.

function FillView: Extracts the information from the window before it disappears.

function Close : closes window.

function Open : reopens window.

function OnChangeComboXml : when the combobox option is changed it displays a preview image on the canvas.

function FreeData : It definitely destroys the window and XML data structure.



Code: Select all

class Vista implements Task
{

	class ItemComboXml
	{
		properties:
		
			filename = "";
			name = "";
			icon = "";
			
		function SetFromXmlFile(engine, _dir, _filename)
		{
    
		    console = engine.getDOS(true).getConsole();

		    filename = _filename;	
			_xml = _dir + _filename;
		    
		    	
		    item = new XML_Loader();
			_ok = item.Load(engine, _xml); //! this
			if (!_ok) return false;
			
			AddActor(console, item);
			
			delete item;
				
			return true;
    
		}	

		function AddActor(console, data)
		{
		
			_root = data.rootList[0];
			name = _root.name;
			_background = _root.backgroundList[0];
			icon = _background.iconText;
			
		}
			
	};


	properties:

		mdi = null;
		tbX = null;
		tbY = null;
		cbVr = null;
		bImageXml = null;
		lbComboXml = null;
		xmlData = [];
		
		vr = null;
		x = null;
		y = null;
		xml = null;
		
		
	function Init()
	{

		
		_wnd = app.GetEngine().GetDesktop().GetActiveWindow();
		_mdi = _wnd.CreateMDI(0, 0, 400, 400);
		_mdi.CenterToDesktop();
		
		mdi = _mdi;
		
		_labelX = _mdi.CreateLabel(10, 10, 100, -1, "Resolució X : ");
		tbX = _mdi.CreateTextBox(10, 40, 50);
		tbX.SetText("256");
		
		_labelY = _mdi.CreateLabel(10, 60, 100, -1, "Resolució Y : ");
		tbY = _mdi.CreateTextBox(10, 90, 50);
		tbY.SetText("212");
		
		cbVr = _mdi.CreateCheckBox(240, 10, 100, -1, "VR");		
		
		_labelSml = _mdi.CreateLabel(10, 160, 100, -1, "Select XML : ");
		lbComboXml = _mdi.CreateComboBox(10, 180, 100);
		lbComboXml.SetOnChange (this, "OnChangeXml");
		
		bImageXml = _mdi.CreateButton(140, 180, 100, 100, "");
		
		
		_ok = FillComboXml();
		
				
		_button = _mdi.CreateButton(240, 240, 100, -1);
		_button.SetText("Play");
		_button.SetOnClick(this, "OnPlay");	
		_button.AlignToParent(UI_BOTTOM | UI_RIGHT, 5);		
		

		if (!_ok) return false;	
		
		
		return true;
		
	}
	
	function FillComboXml()
	{
	
		_ok = GetFilesXmlDirectory();	
		if (!_ok) return false;	

		
		for (i =0; i<sizeof(xmlData); i++) {
		
			lbComboXml.AddItem(xmlData[i].name);
		}
		
		lbComboXml.SelectIndex(0);

		
		return true;

	}
	
	
	function GetFilesXmlDirectory()
	{

		_list = app.GetEngine().FindFiles( DIR_XML + "*.xml" );
	
		for (i =0; i<sizeof(_list); i++) {

	
			item = new ItemComboXml();
			_ok = item.SetFromXmlFile(app.GetEngine(), DIR_XML, _list[i]);
			if (!_ok) return false;
		
			xmlData += [item];
		
		}

		return true;
	
	}
	

	function OnPlay(_sender, _event, _params)
	{
		_ok = FillView();

		if (_ok) 
		{

			app.configuracio.Fill(this);
			Close();

			app.Initialize();
			app.Main();

		}
		
	}
	
	function OnChangeXml(_sender, _event, _params)
	{
		_indexComboXml = lbComboXml.GetSelectedIndex();
		if (_indexComboXml ==-1 ) return false;
	
		icon = DIR_DATA + xmlData[ _indexComboXml ].icon;
		bImageXml.SetIcon(app.GetEngine().GetPath(icon)); 
	
		return true;
	}


	function FillView()
	{
	
		vr = cbVr.GetChecked(); 
		x = int( tbX.GetText() );
		y = int( tbY.GetText() );
		
		_indexComboXml = lbComboXml.GetSelectedIndex();
		if (_indexComboXml ==-1 ) return false;
		
		xml = DIR_XML + xmlData[ _indexComboXml ].filename;
		
		return true;
		
	}	
		
		
	function Close()
	{
		mdi.Hide();
	}
	
	function Open()
	{
		mdi.Show();
	}
	
	
	function FreeData()
	{
	
		for (i =0; i<sizeof(xmlData); i++)
		{
			delete xmlData[i];
		}
	
		//Esto borraría nuestro MDI
		delete mdi;
	}
	

}

task.pi


De (Tutorial Monkey Demo) / From (Tutorial Monkey Demo)
Fuente / Source: http://msxvr.es/doc/wiki/mdwiki.html#!8 ... e27b6a4.md

Permite implementos a una clase para acceder a las funciones y variables principales de la aplicación.
It allows implements to a class to access app main functions and variables.


xml_loader.pi

De (Effective way to load an XML File) / From (Effective way to load an XML File)
Fuente / Source: viewtopic.php?f=4&t=496

Permite cargar un archivo XML.
It allows to load an XML file.
User avatar
efraimsangil
Site Admin
Posts: 209
Joined: Mon Sep 27, 2021 10:42 am
Has thanked: 152 times
Been thanked: 88 times

Re: MSXVIEW-DEMO (I)

Post by efraimsangil »

Muchas gracias por la aportación. Veo que avanzas muy bien. Felicidades.
Javi
Posts: 29
Joined: Sat Jun 11, 2022 5:14 am
Been thanked: 10 times

Re: MSXVIEW-DEMO (I)

Post by Javi »

Thank you, Efraim.
Post Reply