/** * This is called from the 5th loop * It should be used for initializing the application. * > adding pages * > adding components to the pages * > linking logic and animations */ private void InitApplication() { // Set up the target screen TerminalUtils.SetupTextSurfaceForMatrixDisplay(GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, PIXEL_SIZE); OnScreenApplication = UiFrameworkUtils.InitSingleScreenApplication( GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, // The target panel RES_X, RES_Y, // The target resolution MIRROR_X_AXIS, // Rendering option N_COMPUTE_FRAMES, // The number of compute iterations N_RENDER_FRAMES // The number of draw iterations ) .WithDefaultPostPage((MyOnScreenApplication app) => { // The POST page should disappear after 100 frames currFrame++; return(currFrame >= POST_SCREEN_DURATION); }); // Add more pages InitPages(OnScreenApplication); }
/** * This is called from the 5th loop * It should be used for initializing the application. * > adding pages * > adding components to the pages * > linking logic and animations */ private void InitApplication() { // Set up the target screen TerminalUtils.SetupTextSurfaceForMatrixDisplay(GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, PIXEL_SIZE); // Initialize the application OnScreenApplication = UiFrameworkUtils.InitSingleScreenApplication(GridTerminalSystem, TARGET_BLOCK_NAME, SURFACE_INDEX, RES_X, RES_Y, false) .WithDefaultPostPage((MyOnScreenApplication app) => { // The POST page should disappear after the configured number of frames currFrame++; return(currFrame >= POST_SCREEN_DURATION); }); // Create the main page and add it to the application MyPage MainPage = InitMainPage(); if (INVERT_COLORS) { MainPage.WithInvertedColors(); } OnScreenApplication.AddPage(MainPage); }
public MyChaseLightController( IMyGridTerminalSystem GridTerminalSystem, string textPanelName, bool mirrored, int operatingMode, int movementSpeed, MySprite[] ChaseLightShapeFrames ) { // Sanity check if (textPanelName == null || textPanelName.Length == 0) { throw new ArgumentException("The name of the text panel must not be at least one character long"); } if (ChaseLightShapeFrames == null || ChaseLightShapeFrames.Length == 0) { throw new ArgumentException("The ChaseLightShapeFrames array must have at least one element"); } if (operatingMode < OP_MODE_LEFT_TO_RIGHT || operatingMode > OP_MODE_BOUNCE_START_FROM_RIGHT) { throw new ArgumentException("The operating mode must have one of the following values: OP_MODE_LEFT_TO_RIGHT, OP_MODE_RIGHT_TO_LEFT, OP_MODE_BOUNCE_START_FROM_LEFT, OP_MODE_BOUNCE_START_FROM_RIGHT"); } if (movementSpeed < 1 || movementSpeed > 10) { throw new ArgumentException("The movement speed must be between 1 and 10"); } // Set up the text panel TerminalUtils.SetupTextSurfaceForMatrixDisplay(GridTerminalSystem, textPanelName, 0, FONT_SIZE); // Initialize the application OnScreenApplication = UiFrameworkUtils.InitSingleScreenApplication( GridTerminalSystem, textPanelName, 0, // Reference to the target text panel RES_X, RES_Y, // The target display resolution mirrored // The screen image might have to be mirrored ); // Create the main page and add it to the application MyPage MainPage = new MyPage(); OnScreenApplication.AddPage(MainPage); // Create the ChaseLightShape with only one state, named "Default", // having the referenced frames array as its animation ChaseLightShape = new MyStatefulAnimatedSprite(0, 0) .WithState("Default", new MyStatefulAnimatedSpriteState(ChaseLightShapeFrames)); // Add the ChaseLightShape to the main page MainPage.AddChild(ChaseLightShape); // Set the movement vector if (operatingMode == OP_MODE_RIGHT_TO_LEFT || operatingMode == OP_MODE_BOUNCE_START_FROM_RIGHT) { movementVector = -movementSpeed; } else { movementVector = movementSpeed; } // Set the client cycle method to the chase light shape according to the referenced operating mode ChaseLightShape.WithClientCycleMethod((MyOnScreenObject Obj, int currFrameIndex) => { // Center vertically (each frame might have a different height, // so this is required to run on every frame) Obj.y = (RES_Y - Obj.GetHeight()) / 2; // Move Obj.x += movementVector; // Apply the proper action for when the object goes off-screen, // according to the set operating mode if (operatingMode == OP_MODE_RIGHT_TO_LEFT) { // If it's right to left, then the objects exits through the // left side and enters through the right side of the screen. if (Obj.x < 0) { Obj.x = RES_X - 1 - Obj.GetWidth(); } } else if ( operatingMode == OP_MODE_BOUNCE_START_FROM_LEFT || operatingMode == OP_MODE_BOUNCE_START_FROM_RIGHT ) { // If it's bouncing, then the object's vector has to be switched // whenever it reches one side or the other. if (Obj.x < 0 || Obj.x + Obj.GetWidth() > RES_X - 1) { movementVector = -movementVector; } } else { // The default is OP_MODE_LEFT_TO_RIGHT. // In this case, the objects exits the screen through the right side // and enters through the left side. if (Obj.x + Obj.GetWidth() > RES_X - 1) { Obj.x = 0; } } }); }