2021-07-23 15:58:16 +02:00
# pragma once
# include <3ds.h>
# include <citro2d.h>
# include <citro3d.h>
# include <memory>
# include <stack>
# include <string>
# include <functional>
2022-04-10 00:59:30 +02:00
# include <map>
2021-07-23 15:58:16 +02:00
# include <vector>
# include <dirent.h>
# include <unistd.h>
# include <stdio.h>
# include <cstring>
2022-04-08 13:45:10 +02:00
# include <random>
2021-07-23 15:58:16 +02:00
# include <sys/stat.h>
# include <algorithm>
# include <iostream>
2022-04-16 16:02:44 +02:00
# include <filesystem>
# include <locale>
2021-07-23 15:58:16 +02:00
# include "external/lodepng.h"
# include "external/fs.h"
# include <codecvt>
# include "lang.hpp"
# include "parameter.hpp"
# include "thread.hpp"
# include "ini.hpp"
2021-08-12 22:19:15 +02:00
# include "stringtool.hpp"
2021-12-09 20:06:22 +01:00
# include "Clock.hpp"
2021-07-23 15:58:16 +02:00
2022-04-22 20:20:11 +02:00
# define RENDERD7VSTRING "0.7.2"
# define CHANGELOG "0.7.2: Implement MT to csv file saving. Add RGB2HEX. \n0.7.1: Add the New Overlay Handler. Its Just in code and does nothing yet. \n0.7.0: Made Big Progress In the MT Ovl but it still crashes On a Scnd C3D_FrameEnd(). Implement 800px but doesn't work that good. \n0.6.2: Fix Crash when exiting trouth Home Menu. \n0.6.10: rewrite Threadsystem, Improve framerate\n0.6.02: Fix Code in lang.hpp\nadd Draw Text Left Function.\nadd changelog\n0.6.01: add Threading system."
2021-07-23 15:58:16 +02:00
# define DEFAULT_CENTER 0.5f
extern C3D_RenderTarget * Top ;
extern C3D_RenderTarget * TopRight ;
extern C3D_RenderTarget * Bottom ;
extern u32 d7_hDown ;
extern u32 d7_hHeld ;
extern u32 d7_hUp ;
extern touchPosition d7_touch ;
extern std : : string dspststus ;
2021-07-25 00:27:55 +02:00
/// RenderD7
2021-07-23 15:58:16 +02:00
namespace RenderD7
{
2021-08-07 17:07:57 +02:00
enum kbd {
SWKBD ,
BKBD
} ;
enum kbd_type
{
NUMPAD ,
STANDARD
2021-08-08 11:28:11 +02:00
} ;
2022-04-13 01:38:39 +02:00
struct TObject
{
int x ; //Position X
int y ; //Position Y
int w ; //Button Width
int h ; //Button Height
std : : string text = " " ; //Text
float correctx = 0 ; //Correct X Position
float correcty = 0 ; //Correct Y Position
float txtsize = 0.7f ; //Set Text Size
} ;
2021-07-25 00:27:55 +02:00
/// Set current RenderScreen
2021-07-25 16:44:12 +02:00
/// \param target The RenderTarget Top, Bottom
2021-07-23 15:58:16 +02:00
void OnScreen ( C3D_RenderTarget * target ) ;
2021-07-24 23:32:04 +02:00
/** The Spritesheet Class */
2021-07-23 15:58:16 +02:00
class Sheet
{
public :
2021-07-25 00:47:28 +02:00
/// Construct sheet
2021-07-23 15:58:16 +02:00
Sheet ( ) ;
2021-07-25 00:47:28 +02:00
// Deconstruct sheet
2021-07-23 15:58:16 +02:00
~ Sheet ( ) ;
2021-07-25 00:47:28 +02:00
/// Load a Sritesheet
2022-04-12 11:19:37 +02:00
/// \param path Path to the Spritesheet (.t3x)
2021-07-23 15:58:16 +02:00
Result Load ( const char * path ) ;
2021-07-25 00:47:28 +02:00
/// Unload the Spritesheet
2021-07-23 15:58:16 +02:00
void Free ( ) ;
2022-04-12 11:19:37 +02:00
/// The Spritesheet
2021-07-23 15:58:16 +02:00
C2D_SpriteSheet spritesheet ;
} ;
2021-07-25 11:05:06 +02:00
/// Image Class
2021-07-23 15:58:16 +02:00
class Image
{
public :
2021-07-25 11:05:06 +02:00
/// Load Image from Png
2022-04-12 11:19:37 +02:00
/// \param path path to png file
2021-07-23 15:58:16 +02:00
void LoadPng ( const std : : string path ) ;
2021-07-25 11:05:06 +02:00
/// Load the Image from buffer
2022-04-12 11:19:37 +02:00
/// \param buffer the frame buffer
2021-07-23 15:58:16 +02:00
void LoadPFromBuffer ( const std : : vector < u8 > & buffer ) ;
2021-07-25 11:05:06 +02:00
/// Draw the Image directly
2021-07-25 12:37:58 +02:00
/// \param x The x position
/// \param y the y position
2021-07-25 16:44:12 +02:00
/// \param scaleX x scale from 0.0 to 1.0
/// \param scaleY y scale from 0.0 to 1.0
2021-07-23 15:58:16 +02:00
bool Draw ( float x , float y , float scaleX = 1.0f , float scaleY = 1.0f ) ;
2021-07-25 16:44:12 +02:00
/// \brief Get The Image
/// \return C2D_Image
2021-07-23 15:58:16 +02:00
C2D_Image Get ( ) { return this - > img ; }
2022-04-12 11:19:37 +02:00
/// \param img this is the C2D_Image
2021-07-23 15:58:16 +02:00
C2D_Image img ;
2022-04-12 11:19:37 +02:00
/// \param loadet whether the image is loadet or not
2021-07-23 15:58:16 +02:00
bool loadet = false ;
} ;
2021-07-25 10:29:36 +02:00
/// Sprite Class
2021-07-23 15:58:16 +02:00
class Sprite
{
public :
2021-07-25 12:37:58 +02:00
/// \brief Construct Sprite
2021-07-23 15:58:16 +02:00
Sprite ( ) ;
2022-04-12 10:00:49 +02:00
/// \brief Deconstruct Sprite
2021-07-23 15:58:16 +02:00
~ Sprite ( ) ;
2022-04-12 10:00:49 +02:00
/// \brief Load a Sprite From SpriteSheet
/// \param sheet the Sheet to load from.(RenderD7::Sheet)
/// \param index the number of the Sprite in the Sheet
2021-07-23 15:58:16 +02:00
void FromSheet ( RenderD7 : : Sheet * sheet , size_t index ) ;
2022-04-12 10:00:49 +02:00
/// \brief Load a Sprite From SpriteSheet
/// \param img the Image to load from.(RenderD7::Image)
2021-07-23 15:58:16 +02:00
void FromImage ( RenderD7 : : Image * img ) ;
bool Draw ( ) ;
void SetCenter ( float x , float y ) ;
void SetPos ( float x , float y ) ;
void SetScale ( float x , float y ) ;
void SetRotation ( float rotation ) ;
void Rotate ( float speed ) ;
float getWidth ( ) ;
float getHeigh ( ) ;
float getPosX ( ) ;
float getPosY ( ) ;
private :
C2D_ImageTint tint ;
C2D_Sprite sprite ;
} ;
class Scene {
public :
static std : : stack < std : : unique_ptr < Scene > > scenes ;
virtual ~ Scene ( ) { }
virtual void Logic ( u32 hDown , u32 hHeld , u32 hUp , touchPosition touch ) = 0 ;
virtual void Draw ( ) const = 0 ;
2021-08-14 08:15:22 +02:00
//virtual void Ovl() const = 0;
2021-07-23 15:58:16 +02:00
static void Load ( std : : unique_ptr < Scene > scene ) ;
static void Back ( ) ;
static void doDraw ( ) ;
static void doLogic ( u32 hDown , u32 hHeld , u32 hUp , touchPosition touch ) ;
2021-08-14 08:15:22 +02:00
//static void HandleOvl();
2021-07-23 15:58:16 +02:00
} ;
2021-08-08 11:22:42 +02:00
2022-04-10 09:55:05 +02:00
class RSettings : public RenderD7 : : Scene
{
private :
2022-04-13 01:38:39 +02:00
std : : string rd7srstate = " false " ;
2022-04-22 14:27:10 +02:00
std : : string csvstate = " false " ;
std : : string csvlstate = " false " ;
2022-04-13 01:38:39 +02:00
std : : vector < RenderD7 : : TObject > buttons =
{
{ 20 , 35 , 120 , 35 , " RD7SR " , - 11 , 10 } ,
2022-04-22 14:27:10 +02:00
{ 20 , 85 , 120 , 35 , " MT_CSV " , 0 , 9 } ,
{ 20 , 135 , 120 , 35 , " MT_CSV-L " , - 8 , 10 } ,
2022-04-22 20:20:11 +02:00
{ 20 , 185 , 120 , 35 , " FPS " , 8 , 10 } ,
{ 180 , 35 , 120 , 35 , " MTCOL " , - 15 , 10 } ,
{ 180 , 85 , 120 , 35 , " MTTEXT " , - 15 , 10 } ,
{ 180 , 135 , 120 , 35 , " MTA " , - 15 , 10 } ,
{ 180 , 185 , 120 , 35 , " MTTXTA " , - 15 , 10 }
2022-04-13 01:38:39 +02:00
} ;
2022-04-10 09:55:05 +02:00
public :
RSettings ( ) ;
void Draw ( void ) const override ;
~ RSettings ( ) ;
void Logic ( u32 hDown , u32 hHeld , u32 hUp , touchPosition touch ) override ;
} ;
void LoadSettings ( ) ;
2022-04-16 23:11:12 +02:00
class Ovl {
2022-04-10 00:59:30 +02:00
public :
virtual ~ Ovl ( ) { }
virtual void Draw ( ) const = 0 ;
2022-04-16 23:11:12 +02:00
virtual void Logic ( ) = 0 ;
inline bool IsKilled ( ) { return this - > iskilled ; }
inline void Kill ( ) { iskilled = true ; }
private :
bool iskilled = false ;
} ;
class DSP_NF : public RenderD7 : : Ovl
{
public :
DSP_NF ( ) ;
void Draw ( void ) const override ;
void Logic ( ) override ;
private :
int msgposy = 240 ;
2022-04-10 00:59:30 +02:00
} ;
2022-04-16 23:11:12 +02:00
void AddOvl ( std : : unique_ptr < RenderD7 : : Ovl > scene ) ;
2021-07-23 15:58:16 +02:00
namespace Color
{
2021-12-01 21:00:41 +01:00
struct rgba
{
u8 r , g , b , a ;
} ;
2021-12-02 15:33:27 +01:00
class RGBA {
2021-12-01 21:00:41 +01:00
public :
2021-12-02 15:33:27 +01:00
RGBA ( u8 r , u8 g , u8 b , u8 a ) : m_r ( r ) , m_g ( g ) , m_b ( b ) , m_a ( a ) { }
2021-12-04 00:56:49 +01:00
u32 toRGBA ( ) const { return ( m_r < < 24 ) | ( m_g < < 16 ) | ( m_b < < 8 ) | m_a ; }
2021-12-01 21:00:41 +01:00
2021-12-02 15:33:27 +01:00
u8 m_r , m_g , m_b , m_a ;
2021-12-01 21:00:41 +01:00
} ;
2022-04-22 20:24:36 +02:00
std : : string RGB2Hex ( int r , int g , int b ) ;
2021-07-23 15:58:16 +02:00
u32 Hex ( const std : : string color , u8 a = 255 ) ;
}
2022-04-08 13:45:10 +02:00
int GetRandomInt ( int b , int e ) ;
2021-07-23 15:58:16 +02:00
void DrawMetrikOvl ( ) ;
bool DrawImageFromSheet ( RenderD7 : : Sheet * sheet , size_t index , float x , float y , float scaleX = 1.0 , float scaleY = 1.0 ) ;
namespace Error
{
2022-04-13 02:43:17 +02:00
void DisplayError ( std : : string toptext , std : : string errortext , int timesec = 3 ) ;
2021-07-23 15:58:16 +02:00
void DisplayFatalError ( std : : string toptext , std : : string errortext ) ;
}
namespace Init
{
2021-11-27 11:51:56 +01:00
Result Main ( std : : string app_name = " RD7Game " ) ;
2022-04-13 01:38:39 +02:00
Result Reload ( ) ;
2021-07-23 15:58:16 +02:00
void NdspFirm ( bool useit = false ) ;
}
namespace Exit
{
void Main ( ) ;
void NdspFirm ( ) ;
}
namespace Msg
{
void Display ( std : : string titletxt , std : : string subtext , C3D_RenderTarget * target ) ;
void DisplayWithProgress ( std : : string titletext , std : : string subtext , float current , float total , u32 prgbarcolor ) ;
}
namespace Convert
{
inline float StringtoFloat ( std : : string inp ) { return std : : atof ( inp . c_str ( ) ) ; }
2021-11-28 05:44:46 +01:00
inline int StringtoInt ( std : : string inp ) { return std : : atoi ( inp . c_str ( ) ) ; }
2021-07-23 15:58:16 +02:00
inline bool FloatToBool ( float inp ) { if ( inp = = 1 ) return true ; else return false ; }
}
2022-04-16 16:02:44 +02:00
struct DirContent
{
std : : string name ;
std : : string path ;
bool isDir ;
} ;
2021-07-23 15:58:16 +02:00
namespace FS
{
bool FileExist ( const std : : string & path ) ;
}
2022-04-16 17:40:58 +02:00
2021-07-23 15:58:16 +02:00
bool IsNdspInit ( ) ;
void SetupLog ( void ) ;
std : : string GetFramerate ( ) ;
bool MainLoop ( ) ;
void ExitApp ( ) ;
void ClearTextBufs ( void ) ;
bool DrawRect ( float x , float y , float w , float h , u32 color ) ;
2021-12-26 13:16:45 +01:00
bool DrawNFRect ( float p1x , float p1y , float w , float h , u32 color , float scale = 1 ) ;
2021-08-01 12:55:26 +02:00
bool DrawPx ( float x , float y , u32 color ) ;
2021-07-23 15:58:16 +02:00
void DrawTextCentered ( float x , float y , float size , u32 color , std : : string Text , int maxWidth = 0 , int maxHeight = 0 , C2D_Font fnt = nullptr ) ;
void DrawText ( float x , float y , float size , u32 color , std : : string Text , int maxWidth = 0 , int maxHeight = 0 , C2D_Font fnt = nullptr ) ;
void DrawTextLeft ( float x , float y , float size , u32 color , std : : string Text , int maxWidth = 0 , int maxHeight = 0 , C2D_Font fnt = nullptr ) ;
float GetTextWidth ( float size , std : : string Text , C2D_Font fnt = nullptr ) ;
void GetTextSize ( float size , float * width , float * height , std : : string Text , C2D_Font fnt = nullptr ) ;
float GetTextHeight ( float size , std : : string Text , C2D_Font fnt = nullptr ) ;
Result loadFont ( C2D_Font & fnt , const char * Path = " " ) ;
Result unloadFont ( C2D_Font & fnt ) ;
bool DrawCircle ( float x , float y , float radius , u32 color ) ;
bool DrawImage ( C2D_Image img , float x , float y , float scaleX = 1.0f , float scaleY = 1.0f ) ;
2022-04-10 00:41:16 +02:00
void FrameEnd ( ) ;
2022-04-11 17:00:10 +02:00
void ToggleRD7SR ( ) ;
bool IsRD7SR ( ) ;
2021-07-23 15:58:16 +02:00
class SpriteSheetAnimation : public RenderD7 : : Sprite
{
public :
SpriteSheetAnimation ( ) ;
~ SpriteSheetAnimation ( ) ;
void Setup ( RenderD7 : : Sheet * sheet , size_t imagecount , size_t startimage , float frame_begin , float frame_finish ) ;
void Play ( float timespeed ) ;
private :
size_t images ;
size_t imgs = 0 ;
float D_totaltime ;
RenderD7 : : Sheet * sheet ;
float time ;
} ;
2022-04-13 01:38:39 +02:00
2021-07-23 15:58:16 +02:00
2021-08-14 10:01:53 +02:00
struct TLBtn
{
int x ; //Position X
int y ; //Position Y
int w ; //Button Width
int h ; //Button Height
} ;
2021-07-23 15:58:16 +02:00
struct ScrollList1
{
std : : string Text = " " ;
} ;
struct ScrollList2
{
float x ;
float y ;
float w ;
float h ;
std : : string Text = " " ;
} ;
/*enum ListType
{
ONE ,
TWO
} ; */
void DrawList1 ( RenderD7 : : ScrollList1 & l , float txtsize , C3D_RenderTarget * t ) ;
void DrawTObjects ( std : : vector < RenderD7 : : TObject > tobjects , u32 color , u32 txtcolor , int selection = - 1 , u32 selbgcolor = RenderD7 : : Color : : Hex ( " #2D98AF " ) , u32 selcolor = RenderD7 : : Color : : Hex ( " #000000 " ) ) ;
void DrawSTObject ( std : : vector < RenderD7 : : TObject > tobject , int tobjectindex , u32 color , u32 txtcolor ) ;
bool touchTObj ( touchPosition touch , RenderD7 : : TObject button ) ;
2021-08-14 10:01:53 +02:00
void DrawTLBtns ( std : : vector < RenderD7 : : TLBtn > btns , u32 color , int selection = - 1 , u32 selbgcolor = RenderD7 : : Color : : Hex ( " #2D98AF " ) , u32 selcolor = RenderD7 : : Color : : Hex ( " #000000 " ) ) ;
2022-04-16 16:02:44 +02:00
2021-12-24 15:40:47 +01:00
struct Checkbox
{
2021-12-25 13:34:28 +01:00
float x , y , s ;
2021-12-24 15:40:47 +01:00
bool is_chexked = false ;
u32 outcol , incol , chcol ;
} ;
2021-12-25 13:34:28 +01:00
void DrawCheckbox ( Checkbox box ) ;
2022-04-18 14:41:51 +02:00
std : : string FormatString ( std : : string fmt_str , . . . ) ;
std : : string GetTimeStr ( void ) ;
2022-04-10 01:17:34 +02:00
/*class Console
2021-09-21 16:31:45 +02:00
{
public :
2021-11-27 11:22:47 +01:00
Console ( ) ;
2021-09-21 16:31:45 +02:00
Console ( int x , int y , int w , int h , int a = 255 ) ;
2022-04-10 01:13:16 +02:00
Console ( int x , int y , int w , int h , RenderD7 : : Color : : rgba col ) ;
Console ( int x , int y , int w , int h , std : : string name , RenderD7 : : Color : : rgba col = { 255 , 255 , 255 , 255 } , RenderD7 : : Color : : rgba barcol = { 0 , 0 , 0 , 255 } , RenderD7 : : Color : : rgba outlinecol = { 222 , 222 , 222 , 255 } ) ;
2021-11-21 21:37:24 +01:00
void On ( C3D_RenderTarget * t_cscreen ) ;
bool Update ( ) ;
2021-09-21 16:31:45 +02:00
~ Console ( ) ;
private :
2021-11-18 20:51:28 +01:00
std : : vector < std : : string > m_lines ;
int x , y , w , h ;
2021-11-21 21:37:24 +01:00
std : : string m_name = " " ;
C3D_RenderTarget * cscreen ;
bool m_nconsole = false ;
bool m_mconsole = false ;
2022-04-10 01:13:16 +02:00
RenderD7 : : Color : : rgba color = { 255 , 255 , 255 , 255 } ;
RenderD7 : : Color : : rgba outlinecol = { 222 , 222 , 222 , 255 } ;
RenderD7 : : Color : : rgba barcolor = { 0 , 0 , 0 , 255 } ;
2022-04-10 01:17:34 +02:00
} ; */
2021-07-23 15:58:16 +02:00
bool NameIsEndingWith ( const std : : string & name , const std : : vector < std : : string > & extensions ) ;
void GetDirContentsExt ( std : : vector < RenderD7 : : DirContent > & dircontent , const std : : vector < std : : string > & extensions ) ;
void GetDirContents ( std : : vector < RenderD7 : : DirContent > & dircontent ) ;
2021-11-21 21:25:22 +01:00
2021-07-25 00:27:55 +02:00
} /// RenderD7