TwlIPL/build/systemMenu_RED/MachineSettings/ARM9/src/setOwnerInfo.c
yosiokat 7531235341 SDK4505に対応のはず。
LCFGデータおよびAPIの仕様変更に対応。

git-svn-id: file:///Users/lillianskinner/Downloads/platinum/twl/TwlIPL/trunk@813 b08762b0-b915-fc4b-9d8c-17b2551a87ff
2008-03-04 12:51:56 +00:00

1078 lines
30 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*---------------------------------------------------------------------------*
Project: TwlIPL
File: ownerInfo.c
Copyright 2007 Nintendo. All rights reserved.
These coded instructions, statements, and computer programs contain
proprietary information of Nintendo of America Inc. and/or Nintendo
Company Ltd., and are protected by Federal copyright law. They may
not be disclosed to third parties or copied or duplicated in any form,
in whole or in part, without the prior written consent of Nintendo.
$Date:: $
$Rev$
$Author$
*---------------------------------------------------------------------------*/
#include <twl.h>
#include "misc.h"
#include "MachineSetting.h"
// define data----------------------------------
// ソフトウェアキーボードLCD領域
#define CLIST_LT_X 23
#define CLIST_LT_Y 50
#define CLIST_MARGIN 14
#define CLIST_KEY_PER_SEGMENT 5
#define CLIST_SEGMENT_INTERVAL 7
// キャンセルボタン領域
#define CANCEL_BUTTON_TOP_X ( 2 * 8 )
#define CANCEL_BUTTON_TOP_Y ( 21 * 8 )
#define CANCEL_BUTTON_BOTTOM_X ( CANCEL_BUTTON_TOP_X + (8 * 8) )
#define CANCEL_BUTTON_BOTTOM_Y ( CANCEL_BUTTON_TOP_Y + (2 * 8) )
// OKボタン領域
#define OK_BUTTON_TOP_X ( 26 * 8 )
#define OK_BUTTON_TOP_Y ( 21 * 8 )
#define OK_BUTTON_BOTTOM_X ( OK_BUTTON_TOP_X + (4 * 8) )
#define OK_BUTTON_BOTTOM_Y ( OK_BUTTON_TOP_Y + (2 * 8) )
#define USER_INFO_MENU_ELEMENT_NUM 4 // ユーザ情報メニューの項目数
#define CHAR_LIST_CHAR_NUM 120
#define CHAR_LIST_MODE_NUM 3
// 特殊キーコード
#define EOM_ (u16)0xe050
#define CODE_BUTTON_TOP_ (u16)0xe051
#define DEL_BUTTON_ (u16)0xe051
#define SPACE_BUTTON_ (u16)0xe052
#define VAR_BUTTON1_ (u16)0xe053
#define VAR_BUTTON2_ (u16)0xe054
#define OK_BUTTON_ (u16)0xe055
#define CANCEL_BUTTON_ (u16)0xe056
#define CODE_BUTTON_BOTTOM_ (u16)0xe057
#define CHAR_USCORE L'_'
#define KEY_PER_LINE 11
#define KEY_START 109 //ソフトウェアキーのカーソルデフォルト位置はキャンセルキー
#define KEY_OK 0xffff
#define KEY_CANCEL 0xfffe
typedef enum NameOrComment
{
NOC_NAME,
NOC_COMMENT
}NameOrComment;
// extern data----------------------------------
extern u32 bg_char_data[8 * 6];
extern u16 bg_scr_data[32 * 32];
extern u16 bg_birth_scr_data[32 * 32];
// function's prototype-------------------------
static void SetNicknameInit( void );
static int SetNicknameMain( void );
static void SetBirthdayInit( void );
static int SetBirthdayMain( void );
static void SetUserColorInit( void );
static int SetUserColorMain( void );
static void SetCommentInit( void );
static int SetCommentMain( void );
static u8 MY_StrLen( const u16 *pStr );
// static variable------------------------------
// 一時的にしか使わない物をstaticにしているので
// 少しでもダイエットしたい時はWork扱いにしてAlloc→Freeしましょう
static u16 s_csr = 0;
static const u16 *s_pStrSetting[ USER_INFO_MENU_ELEMENT_NUM ]; // メインメニュー用文字テーブルへのポインタリスト
static int s_char_mode = 0;
static u16 s_key_csr = 0;
static u8 s_color_csr = 0;
static BOOL s_birth_csr = FALSE;
static LCFGTWLDate s_temp_birthday;
static u16 s_temp_name[ LCFG_TWL_NICKNAME_LENGTH + 1 ];
static u16 s_temp_comment[ LCFG_TWL_COMMENT_LENGTH + 1 ];
static u8 s_temp_name_length;
static u8 s_temp_comment_length;
// const data-----------------------------------
static const u16 char_tbl[CHAR_LIST_MODE_NUM][CHAR_LIST_CHAR_NUM];
static const u16 *const s_pStrSettingElemTbl[ USER_INFO_MENU_ELEMENT_NUM ][ LCFG_TWL_LANG_CODE_MAX ] = {
{
(const u16 *)L"ユーザーネーム",
(const u16 *)L"NICKNAME",
(const u16 *)L"NICKNAME(F)",
(const u16 *)L"NICKNAME(G)",
(const u16 *)L"NICKNAME(I)",
(const u16 *)L"NICKNAME(S)",
},
{
(const u16 *)L"誕生日",
(const u16 *)L"BIRTHDAY",
(const u16 *)L"BIRTHDAY(F)",
(const u16 *)L"BIRTHDAY(G)",
(const u16 *)L"BIRTHDAY(I)",
(const u16 *)L"BIRTHDAY(S)",
},
{
(const u16 *)L"ユーザーカラー",
(const u16 *)L"USER COLOR",
(const u16 *)L"USER COLOR(F)",
(const u16 *)L"USER COLOR(G)",
(const u16 *)L"USER COLOR(I)",
(const u16 *)L"USER COLOR(S)",
},
{
(const u16 *)L"コメント",
(const u16 *)L"COMMENT",
(const u16 *)L"COMMENT(F)",
(const u16 *)L"COMMENT(G)",
(const u16 *)L"COMMENT(I)",
(const u16 *)L"COMMENT(S)",
},
};
static MenuPos s_settingPos[] = {
{ TRUE, 4 * 8, 8 * 8 },
{ TRUE, 4 * 8, 10 * 8 },
{ TRUE, 4 * 8, 12 * 8 },
{ TRUE, 4 * 8, 14 * 8 },
};
static const MenuParam s_settingParam = {
USER_INFO_MENU_ELEMENT_NUM,
TXT_COLOR_BLACK,
TXT_COLOR_GREEN,
TXT_COLOR_RED,
&s_settingPos[ 0 ],
(const u16 **)&s_pStrSetting,
};
static const u16 *str_button_char[CHAR_LIST_MODE_NUM] = {
L"かな",
L"カナ",
L"英数",
};
static u16 next_char_mode[CHAR_LIST_MODE_NUM-1];
static const u16 str_button_del[] = L"<EFBFBD>DEL";
static const u16 str_button_space[] = L"SPACE";
static const u16 str_button_ok[] = L"OK";
static const u16 str_button_cancel[] = L"CANCEL";
static const u16 *str_button[] = {
(const u16 *)str_button_del,
(const u16 *)str_button_space,
NULL,
NULL,
(const u16 *)str_button_ok,
(const u16 *)str_button_cancel,
};
//======================================================
// オーナー情報編集
//======================================================
static void SetSoftKeyboardButton(int mode)
{
int l;
int count = 0;
for(l=0; l<CHAR_LIST_MODE_NUM ;l++)
{
if(l != mode){
str_button[2+count]=str_button_char[l];
next_char_mode[count] = (u16)l;
count++;
}
}
s_char_mode = mode;
}
// キャンセルボタン専用SelectSomethingFuncの実装
static BOOL SelectCancelFunc( u16 *csr, TPData *tgt )
{
BOOL ret;
ret = WithinRangeTP( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y,
CANCEL_BUTTON_BOTTOM_X, CANCEL_BUTTON_BOTTOM_Y, tgt );
if(ret) *csr = KEY_CANCEL;
return ret;
}
// OKボタン専用SelectSomethingFuncの実装
static BOOL SelectOKFunc( u16 *csr, TPData *tgt )
{
BOOL ret;
ret = WithinRangeTP( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y,
OK_BUTTON_BOTTOM_X, OK_BUTTON_BOTTOM_Y, tgt );
if(ret) *csr = KEY_OK;
return ret;
}
static void DrawOwnerInfoMenuScene( void )
{
u16 tempbuf[LCFG_TWL_COMMENT_LENGTH+2];
u8 color;
NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL );
PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"USER INFORMATION" );
PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"<EFBFBD>RETURN" );
// メニュー項目
DrawMenu( s_csr, &s_settingParam );
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// あらかじめTWL設定データファイルから読み込み済みの設定を取得して表示
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// ニックネーム
PutStringUTF16( 128 , 8*8, TXT_UCOLOR_G0, LCFG_TSD_GetNicknamePtr() );
// 誕生日
PrintfSJIS( 128, 10*8, TXT_UCOLOR_G0, "%d%d", LCFG_TSD_GetBirthdayPtr()->month, LCFG_TSD_GetBirthdayPtr()->day);
// カラー
color = LCFG_TSD_GetUserColor();
PutStringUTF16( 128 , 12*8, TXT_UCOLOR_G0, L"" );
// コメント
SVC_CpuCopy( LCFG_TSD_GetCommentPtr(), tempbuf, 13 * 2, 16 );
*(tempbuf+13)='\n';
SVC_CpuCopy( LCFG_TSD_GetCommentPtr()+13, tempbuf+14, 13 * 2, 16 );
*(tempbuf+LCFG_TWL_COMMENT_LENGTH+1)=0;
PutStringUTF16( 128-78 , 16*8 , TXT_UCOLOR_G0, tempbuf );
}
// オーナー情報編集の初期化
void SetOwnerInfoInit( void )
{
int i;
// NITRO設定データのlanguageに応じたメインメニュー構成言語の切り替え
for( i = 0; i < USER_INFO_MENU_ELEMENT_NUM; i++ ) {
s_pStrSetting[ i ] = s_pStrSettingElemTbl[ i ][ LCFG_TSD_GetLanguage() ];
}
// BGデータのロード処理
GX_LoadBG1Char(bg_char_data, 0, sizeof(bg_char_data));
GX_LoadBG1Scr(bg_scr_data, 0, sizeof(bg_scr_data));
DrawOwnerInfoMenuScene();
SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 );
GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1);
GXS_SetVisiblePlane( GX_PLANEMASK_BG0 );
}
// オーナー情報編集メニュー
int SetOwnerInfoMain( void )
{
static u16 dummy = 0;
SelectSomethingFunc func[1]={SelectCancelFunc};
BOOL tp_select,tp_cancel = FALSE;
ReadTP();
//--------------------------------------
// キー入力処理
//--------------------------------------
if( pad.trg & PAD_KEY_DOWN ){ // カーソルの移動
if( ++s_csr == USER_INFO_MENU_ELEMENT_NUM ) {
s_csr=0;
}
}
if( pad.trg & PAD_KEY_UP ){
if( --s_csr & 0x80 ) {
s_csr=USER_INFO_MENU_ELEMENT_NUM - 1;
}
}
tp_select = SelectMenuByTP( &s_csr, &s_settingParam );
DrawOwnerInfoMenuScene();
// [CANCEL]ボタンチェック
tp_cancel = SelectSomethingByTP(&dummy, func, 1 );
if( ( pad.trg & PAD_BUTTON_A ) || ( tp_select ) ) { // メニュー項目への分岐
if( s_settingPos[ s_csr ].enable ) {
switch( s_csr ) {
case 0:
SetNicknameInit();
g_pNowProcess = SetNicknameMain;
break;
case 1:
SetBirthdayInit();
g_pNowProcess = SetBirthdayMain;
break;
case 2:
SetUserColorInit();
g_pNowProcess = SetUserColorMain;
break;
case 3:
SetCommentInit();
g_pNowProcess = SetCommentMain;
break;
}
}
}else if( ( pad.trg & PAD_BUTTON_B ) || tp_cancel ) {
MachineSettingInit();
return 0;
}
return 0;
}
// ソフトウェアキー関係
// キーの表示
static void DrawCharKeys( void )
{
int l;
u16 code;
for( l=0; l<CHAR_LIST_CHAR_NUM; l++ )
{
int color=TXT_COLOR_BLACK;
code = char_tbl[s_char_mode][l];
if (s_key_csr == l) color = TXT_COLOR_GREEN;
if(code != EOM_)
{
if( (code >= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) )
{
int x = code - CODE_BUTTON_TOP_;
PutStringUTF16( CLIST_LT_X + CLIST_MARGIN*(l%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((l%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT) ,
CLIST_LT_Y + CLIST_MARGIN*(l/KEY_PER_LINE) , color, str_button[x] );
}
else
{
u16 s[2];
s[0] = code;
s[1] = 0;
PutStringUTF16( CLIST_LT_X + CLIST_MARGIN*(l%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((l%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT) ,
CLIST_LT_Y + CLIST_MARGIN*(l/KEY_PER_LINE) , color, s );
}
}
}
}
// 一文字削除
static void DeleteACharacter( NameOrComment noc )
{
u16 *buf;
u8 *length;
if(noc == NOC_NAME)
{
buf = s_temp_name;
length = &s_temp_name_length;
}else if(noc == NOC_COMMENT)
{
buf = s_temp_comment;
length = &s_temp_comment_length;
}else
{
//unknown
return;
}
if(*length > 0) buf[--(*length)] = CHAR_USCORE;
}
// 選択中文字キー・特殊キーで決定した時の挙動
static void PushKeys( u16 code, NameOrComment noc )
{
u16 *buf;
u8 *length;
u16 max_length;
void (*setflag)(BOOL) = NULL;
if(noc == NOC_NAME)
{
buf = s_temp_name;
length = &s_temp_name_length;
max_length = LCFG_TWL_NICKNAME_LENGTH;
setflag = LCFG_TSD_SetFlagNickname;
}else if(noc == NOC_COMMENT)
{
buf = s_temp_comment;
length = &s_temp_comment_length;
max_length = LCFG_TWL_COMMENT_LENGTH;
// setflag = TSD_SetFlagComment;
setflag = NULL;
}else
{
//unknown
return;
}
if( (code >= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) )
{
// 特殊キー
switch(code)
{
case VAR_BUTTON1_:
case VAR_BUTTON2_:
SetSoftKeyboardButton(next_char_mode[code - VAR_BUTTON1_]);
break;
case DEL_BUTTON_:
DeleteACharacter(noc);
break;
case SPACE_BUTTON_:
if(*length < max_length) buf[(*length)++] = L' ';
break;
case OK_BUTTON_:
if(setflag) setflag(TRUE);// 設定完了フラグを立てておく
SVC_CpuClear(0, buf + *length, (max_length - *length) * 2, 16);// ゼロクリア
if(noc == NOC_NAME) {
LCFG_TSD_SetNickname( buf );
}else if(noc == NOC_COMMENT) {
LCFG_TSD_SetComment( buf );
}
// ::::::::::::::::::::::::::::::::::::::::::::::
// TWL設定データファイルへの書き込み
// ::::::::::::::::::::::::::::::::::::::::::::::
if( !MY_WriteTWLSettings() ) {
OS_TPrintf( "TWL settings write failed.\n" );
}
// セーブ後にキャンセル処理と合流
case CANCEL_BUTTON_:
SetOwnerInfoInit();
g_pNowProcess = SetOwnerInfoMain;
break;
default:// unknown code
break;
}
}
else
{
// 普通キー
if(*length < max_length) buf[(*length)++] = code;
}
}
// PadDetectOnKeyのSelectSomethingByTPで使うSelectSomethingFuncの実装
static BOOL SelectSoftwareKeyFunc( u16 *csr, TPData *tgt )
{
// まずは候補となる座標(カーソル単位)を取得
int csrx;
int csry;
int csrxy;
int a;
int b;
NNSG2dTextRect rect;
u16 code;
BOOL ret;
csrx = tgt->x - CLIST_LT_X;
csrx = csrx - (CLIST_SEGMENT_INTERVAL*(csrx/(CLIST_MARGIN*CLIST_KEY_PER_SEGMENT+CLIST_SEGMENT_INTERVAL)));
csrx = csrx / CLIST_MARGIN;
csry = (tgt->y - CLIST_LT_Y) / CLIST_MARGIN;
if(csrx < 0 ) return FALSE;
if ( csrx >= KEY_PER_LINE ) csrx = KEY_PER_LINE - 1;
csrxy = csrx + csry * KEY_PER_LINE;
if ( csrxy < 0 || csrxy >= CHAR_LIST_CHAR_NUM) return FALSE;// 明らかにはみ出した
// 候補座標のキーコード取得
code = char_tbl[s_char_mode][csrxy];
if(code == EOM_) return FALSE;
// 候補座標の領域取得
if( (code >= CODE_BUTTON_TOP_) && (code < CODE_BUTTON_BOTTOM_) )
{
int x = code - CODE_BUTTON_TOP_;
rect = NNS_G2dTextCanvasGetTextRect( &gTextCanvas, str_button[x] );
}
else
{
u16 s[2];
s[0] = code;
s[1] = 0;
// rect = NNS_G2dTextCanvasGetTextRect( &gTextCanvas, s );
// 文字幅じゃかなり判定が厳しい……ギリギリまでとってみる
rect.width = CLIST_MARGIN;
rect.height = CLIST_MARGIN;
}
a = CLIST_LT_X + CLIST_MARGIN*(csrxy%KEY_PER_LINE) + CLIST_SEGMENT_INTERVAL*((csrxy%KEY_PER_LINE)/CLIST_KEY_PER_SEGMENT);
b = CLIST_LT_Y + CLIST_MARGIN*(csrxy/KEY_PER_LINE);
// 候補座標の領域にタッチ座標が含まれているかチェック
ret = WithinRangeTP( a, b, a+rect.width, b+rect.height, tgt );
if(ret)
{
*csr = (u16)csrxy;
}
return ret;
}
// ソフトウェアキー上でのキーパッド及びタッチパッド処理
// 先にReadTPしておくこと。
static void PadDetectOnKey( NameOrComment noc )
{
SelectSomethingFunc func[1];
BOOL tp_select = FALSE;
//--------------------------------------
// キー入力処理
//--------------------------------------
if( pad.trg & PAD_KEY_RIGHT ){ // カーソルの移動
do
{
if(s_key_csr%KEY_PER_LINE != KEY_PER_LINE-1) s_key_csr++;
else s_key_csr -= KEY_PER_LINE-1;
if( s_key_csr == CHAR_LIST_CHAR_NUM ) s_key_csr -= s_key_csr%KEY_PER_LINE;
}
while(char_tbl[s_char_mode][s_key_csr]==EOM_);
}
if( pad.trg & PAD_KEY_LEFT ){
do
{
if(s_key_csr%KEY_PER_LINE != 0) s_key_csr--;
else s_key_csr += KEY_PER_LINE-1;
if( s_key_csr & 0x8000 ) s_key_csr = KEY_PER_LINE-1;
}
while(char_tbl[s_char_mode][s_key_csr]==EOM_);
}
if( pad.trg & PAD_KEY_DOWN ){ // カーソルの移動
do
{
s_key_csr += KEY_PER_LINE;
if( s_key_csr >= CHAR_LIST_CHAR_NUM ) s_key_csr -= KEY_PER_LINE*(s_key_csr/KEY_PER_LINE);
}
while(char_tbl[s_char_mode][s_key_csr]==EOM_);
}
if( pad.trg & PAD_KEY_UP ){
do
{
if( s_key_csr < KEY_PER_LINE ) s_key_csr += (CHAR_LIST_CHAR_NUM/KEY_PER_LINE)*KEY_PER_LINE;
else s_key_csr -= KEY_PER_LINE;
if( s_key_csr >= CHAR_LIST_CHAR_NUM ) s_key_csr -= KEY_PER_LINE;
}
while(char_tbl[s_char_mode][s_key_csr]==EOM_);
}
func[0] = (SelectSomethingFunc)SelectSoftwareKeyFunc;
tp_select = SelectSomethingByTP(&s_key_csr, func, 1 );
if( ( pad.trg & PAD_BUTTON_A ) || ( tp_select ) ) { // キーが押された
PushKeys( char_tbl[s_char_mode][s_key_csr], noc );
}else if( pad.trg & PAD_BUTTON_B ) {
DeleteACharacter(noc);
}
}
// ニックネーム編集画面の描画処理
static void DrawSetNicknameScene( void )
{
NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL );
PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"NICKNAME" );
PutStringUTF16( 128-60 , 21 , TXT_UCOLOR_G0, s_temp_name );
DrawCharKeys();
}
// ニックネーム編集の初期化
static void SetNicknameInit( void )
{
SetSoftKeyboardButton(0);
s_key_csr = KEY_START;
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// あらかじめTWL設定データファイルから読み込み済みの設定を取得
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// ニックネーム用テンポラリバッファの初期化
LCFG_TSD_GetNickname( s_temp_name );
s_temp_name_length = MY_StrLen( s_temp_name );
if( s_temp_name_length < LCFG_TWL_NICKNAME_LENGTH ) {
SVC_CpuClear(CHAR_USCORE, &s_temp_name[ s_temp_name_length ],
( LCFG_TWL_NICKNAME_LENGTH - s_temp_name_length ) * 2, 16);
}
DrawSetNicknameScene();
SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 );
GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1);
GXS_SetVisiblePlane( GX_PLANEMASK_BG0 );
}
// ニックネーム編集メイン
static int SetNicknameMain( void )
{
ReadTP();
PadDetectOnKey(NOC_NAME);
// 描画処理
DrawSetNicknameScene();
return 0;
}
// 誕生日編集画面の表示
static void DrawSetBirthdayScene( void )
{
NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL );
PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"BIRTHDAY" );
PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"<EFBFBD>CANCEL" );
PutStringUTF16( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"<EFBFBD>OK" );
PutStringUTF16( 128-36+16, 11*8, TXT_COLOR_BLACK, (const u16 *)L"月   日" );
PrintfSJIS( 128-36, 11*8, (s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.month / 10);
PrintfSJIS( 128-28, 11*8, (s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.month % 10);
PrintfSJIS( 128+12, 11*8, (!s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.day / 10);
PrintfSJIS( 128+20, 11*8, (!s_birth_csr ? TXT_COLOR_GREEN : TXT_COLOR_BLACK), "%d", s_temp_birthday.day % 10);
}
// SetBirthdayMainのSelectSomethingByTPで使うSelectSomethingFuncの実装
static BOOL SelectBirthdayFunc( u16 *csr, TPData *tgt )
{
int l;
// 単純な実装例
// 有効範囲全部について押されたかどうかの確認
// 有効範囲の区分が多い時は、タッチパッドの座標から確認範囲を絞るのが望ましい
for(l=0; l<4; l++)
{
int x = 12*8 + (l%2)*6*8;
int y = 8*8 + (l/2)*6*8;
if(WithinRangeTP( x, y, x+16, y+16, tgt ))
{
*csr = (u16)l;
return TRUE;
}
}
return FALSE;
}
// 誕生日編集の初期化
static void SetBirthdayInit( void )
{
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// あらかじめTWL設定データファイルから読み込み済みの設定を取得
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// 誕生日
LCFG_TSD_GetBirthday( &s_temp_birthday );
// BGデータのロード処理
GX_LoadBG1Char(bg_char_data, 0, sizeof(bg_char_data));
GX_LoadBG1Scr(bg_birth_scr_data, 0, sizeof(bg_birth_scr_data));
DrawSetBirthdayScene();
SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 );
GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1);
GXS_SetVisiblePlane( GX_PLANEMASK_BG0 );
}
static void CheckDate( void )
{
u8 maxday;
if( s_temp_birthday.month == 0 ) s_temp_birthday.month = 12;
if( s_temp_birthday.month == 13 ) s_temp_birthday.month = 1;
maxday = (u8)SYSM_GetDayNum( 2000, s_temp_birthday.month );
if( s_temp_birthday.day == 0 ) s_temp_birthday.day = maxday;
if( s_temp_birthday.day > maxday ) s_temp_birthday.day = 1;
}
// 押している間数字が一定スピードで変化するような処理
static void Birthday_AutoNumScrollByTP( void )
{
static u16 first_csr = 0xffff;
u16 temp_csr;
static int same_count = 0;
if( tpd.disp.touch )
{
BOOL t = SelectBirthdayFunc( &temp_csr, &tpd.disp );
if( t )
{
if(same_count == 0) // count start
{
first_csr = temp_csr;
same_count = 1;
}else if(first_csr == temp_csr)
{
if( same_count == 1 || (same_count > 29 && same_count%10==0))
{
switch(temp_csr)
{
case 0:
s_birth_csr = TRUE;
s_temp_birthday.month++;
break;
case 1:
s_birth_csr = FALSE;
s_temp_birthday.day++;
break;
case 2:
s_birth_csr = TRUE;
s_temp_birthday.month--;
break;
case 3:
s_birth_csr = FALSE;
s_temp_birthday.day--;
break;
default:
break;
}
}
same_count++;
}
}
}else // touch==0
{
same_count = 0;
first_csr = 0xffff;
}
}
// 誕生日編集メイン
static int SetBirthdayMain( void )
{
SelectSomethingFunc func[2]={SelectCancelFunc, SelectOKFunc};
BOOL tp_touch = FALSE;
u16 temp_ok_cancel;
ReadTP();
//--------------------------------------
// キー入力処理
//--------------------------------------
if( pad.trg & PAD_KEY_DOWN ){
(*(s_birth_csr ? &s_temp_birthday.month : &s_temp_birthday.day))--;
}
if( pad.trg & PAD_KEY_UP ){
(*(s_birth_csr ? &s_temp_birthday.month : &s_temp_birthday.day))++;
}
if( pad.trg & (PAD_KEY_RIGHT | PAD_KEY_LEFT)){ // カーソルの移動
s_birth_csr = !s_birth_csr;
}
// 日付チェック
CheckDate();
// TPチェック
tp_touch = SelectSomethingByTP(&temp_ok_cancel, func, 2 );
// TPでボタンを押している間数字が一定スピードで変化するような処理
Birthday_AutoNumScrollByTP();
// 日付チェック
CheckDate();
DrawSetBirthdayScene();
if( pad.trg & PAD_BUTTON_A || (tp_touch && temp_ok_cancel == KEY_OK) ) {
LCFG_TSD_SetBirthday(&s_temp_birthday);
LCFG_TSD_SetFlagBirthday( TRUE );
// ::::::::::::::::::::::::::::::::::::::::::::::
// TWL設定データファイルへの書き込み
// ::::::::::::::::::::::::::::::::::::::::::::::
if( !MY_WriteTWLSettings() ) {
OS_TPrintf( "TWL settings write failed.\n" );
}
SetOwnerInfoInit();
g_pNowProcess = SetOwnerInfoMain;
return 0;
}else if( ( pad.trg & PAD_BUTTON_B ) || (tp_touch && temp_ok_cancel == KEY_CANCEL) ) {
SetOwnerInfoInit();
g_pNowProcess = SetOwnerInfoMain;
return 0;
}
return 0;
}
static void DrawColorSample( void )
{
int l;
NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL );
PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"USER COLOR" );
PutStringUTF16( CANCEL_BUTTON_TOP_X, CANCEL_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"<EFBFBD>CANCEL" );
PutStringUTF16( OK_BUTTON_TOP_X, OK_BUTTON_TOP_Y, TXT_UCOLOR_G0, (const u16 *)L"<EFBFBD>OK" );
for(l=0;l<16;l++) //16色
{
PutStringUTF16( 88 + 24 * (l%4), 54 + 24 * (l/4), TXT_UCOLOR_GRAY + l, (const u16 *)L"" );
}
for(l=0;l<4;l++)
{
PutStringUTF16( 83 + 24 * (s_color_csr%4) + 10*(l%2), 49 + 24 * (s_color_csr/4) + 10*(l/2), TXT_UCOLOR_G0, (const u16 *)L"" );
}
}
// SetUserColorMainのSelectSomethingByTPで使うSelectSomethingFuncの実装
static BOOL SelectColorFunc( u16 *csr, TPData *tgt )
{
// まずは候補となる座標(カーソル単位)を取得
int csrx;
int csry;
int csrxy;
int a;
int b;
BOOL ret;
csrx = (tgt->x - 88) / 24;
csry = (tgt->y - 54) / 24;
if(csrx < 0 ) return FALSE;
if ( csrx >= 4 ) csrx = 3;
csrxy = csrx + csry * 4;
if ( csrxy < 0 || csrxy >= 16) return FALSE;// はみ出した
a = 88 + csrx * 24;
b = 54 + csry * 24;
// 候補座標の領域にタッチ座標が含まれているかチェック
ret = WithinRangeTP( a, b, a+11, b+11, tgt );
if(ret)
{
*csr = (u16)csrxy;
}
return ret;
}
// ユーザーカラー編集の初期化
static void SetUserColorInit( void )
{
DrawColorSample();
SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 );
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// あらかじめTWL設定データファイルから読み込み済みの設定を取得
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// ユーザーカラー
s_color_csr = LCFG_TSD_GetUserColor();
GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1);
GXS_SetVisiblePlane( GX_PLANEMASK_BG0 );
}
// ユーザーカラー編集メイン
static int SetUserColorMain( void )
{
SelectSomethingFunc func[3]={SelectColorFunc, SelectCancelFunc, SelectOKFunc};
BOOL tp_touch = FALSE;
u16 temp_csr;
ReadTP();
//--------------------------------------
// キー入力処理
//--------------------------------------
if( pad.trg & PAD_KEY_DOWN ){ // カーソルの移動
s_color_csr += 4;
if(s_color_csr >= 16) s_color_csr -= 16;
}
if( pad.trg & PAD_KEY_UP ){
if(s_color_csr < 4) s_color_csr += 16;
s_color_csr -= 4;
}
if( pad.trg & PAD_KEY_RIGHT ){
s_color_csr += 1;
if(s_color_csr%4 == 0) s_color_csr -= 4;
}
if( pad.trg & PAD_KEY_LEFT ){
if(s_color_csr%4 == 0) s_color_csr += 4;
s_color_csr -= 1;
}
temp_csr = s_color_csr;
// TPチェック
tp_touch = SelectSomethingByTP(&temp_csr, func, 3 );
if ((temp_csr != KEY_OK && temp_csr != KEY_CANCEL)){
s_color_csr = (u8)temp_csr;
}
if( ( pad.trg & PAD_BUTTON_A ) || (tp_touch && temp_csr == KEY_OK) ) { // 色決定
LCFG_TSD_SetUserColor( (u8 )s_color_csr );
// ::::::::::::::::::::::::::::::::::::::::::::::
// TWL設定データファイルへの書き込み
// ::::::::::::::::::::::::::::::::::::::::::::::
if( !MY_WriteTWLSettings() ) {
OS_TPrintf( "TWL settings write failed.\n" );
}
SetOwnerInfoInit();
g_pNowProcess = SetOwnerInfoMain;
return 0;
}else if( ( pad.trg & PAD_BUTTON_B ) || (tp_touch && temp_csr == KEY_CANCEL) ) {
ChangeUserColor( LCFG_TSD_GetUserColor() ); // パレット色を元にもどす
SetOwnerInfoInit();
g_pNowProcess = SetOwnerInfoMain;
return 0;
}
ChangeUserColor( s_color_csr );
DrawColorSample();
return 0;
}
// コメント編集画面の描画処理
static void DrawSetCommentScene( void )
{
u16 tempbuf[LCFG_TWL_COMMENT_LENGTH+2];
NNS_G2dCharCanvasClear( &gCanvas, TXT_COLOR_NULL );
PutStringUTF16( 0, 0, TXT_COLOR_BLUE, (const u16 *)L"COMMENT" );
SVC_CpuCopy( s_temp_comment, tempbuf, 13 * 2, 16 );
*(tempbuf+13)='\n';
SVC_CpuCopy( s_temp_comment+13, tempbuf+14, 13 * 2, 16 );
*(tempbuf+LCFG_TWL_COMMENT_LENGTH+1)=0;
PutStringUTF16( 128-78 , 15 , TXT_UCOLOR_G0, tempbuf );
DrawCharKeys();
}
// コメント編集の初期化
static void SetCommentInit( void )
{
SetSoftKeyboardButton(0);
s_key_csr = KEY_START;
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// あらかじめTWL設定データファイルから読み込み済みの設定を取得
// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
// コメント用テンポラリバッファの初期化
LCFG_TSD_GetComment( s_temp_comment );
s_temp_comment_length = MY_StrLen( s_temp_comment );
if( s_temp_comment_length < LCFG_TWL_COMMENT_LENGTH ) {
SVC_CpuClear(CHAR_USCORE, &s_temp_comment[ s_temp_comment_length ],
( LCFG_TWL_COMMENT_LENGTH - s_temp_comment_length ) * 2, 16);
}
DrawSetCommentScene();
SVC_CpuClear( 0x0000, &tpd, sizeof(TpWork), 16 );
GX_SetVisiblePlane ( GX_PLANEMASK_BG0 | GX_PLANEMASK_BG1);
GXS_SetVisiblePlane( GX_PLANEMASK_BG0 );
}
// コメント編集メイン
static int SetCommentMain( void )
{
ReadTP();
PadDetectOnKey(NOC_COMMENT);
// 描画処理
DrawSetCommentScene();
return 0;
}
// UTF16の文字列長算出
static u8 MY_StrLen( const u16 *pStr )
{
u8 len = 0;
while( *pStr++ ) {
++len;
if( len == 255 ) {
break;
}
}
return len;
}
//======================================================
// ソフトウェアキーボード用キャラテーブル
//======================================================
static const u16 char_tbl[CHAR_LIST_MODE_NUM][CHAR_LIST_CHAR_NUM] = {
{ // ひらがな
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', DEL_BUTTON_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', SPACE_BUTTON_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', EOM_,
L'', L'', L'', L'', L'',
L'', EOM_, L'', EOM_, L'', VAR_BUTTON1_,
L'', L'', L'', L'', L'',
L'', EOM_, EOM_, L'', L'', VAR_BUTTON2_,
L'', L'', L'', L'', L'',
L'', EOM_, L'', EOM_, L'', EOM_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', EOM_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', OK_BUTTON_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', EOM_,
L'', L'', L'', EOM_, L'',
EOM_, EOM_, EOM_, EOM_, EOM_, CANCEL_BUTTON_,
EOM_, EOM_, EOM_, EOM_, EOM_,
EOM_, EOM_, EOM_, EOM_, EOM_,
},
{ // カタカナ
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', DEL_BUTTON_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', SPACE_BUTTON_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', EOM_,
L'', L'', L'', L'', L'',
L'', EOM_, L'', EOM_, L'', VAR_BUTTON1_,
L'', L'', L'', L'', L'',
L'', EOM_, L'', EOM_, L'', VAR_BUTTON2_,
L'', L'', L'', L'', L'',
L'', EOM_, L'', EOM_, L'', EOM_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', EOM_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', OK_BUTTON_,
L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'', EOM_,
L'', L'', L'', EOM_, EOM_,
EOM_, EOM_, EOM_, EOM_, EOM_, CANCEL_BUTTON_,
EOM_, EOM_, EOM_, EOM_, EOM_,
EOM_, EOM_, EOM_, EOM_, EOM_,
},
{ // 英数
// 'A'から順にUTF-16文字コード(リトルエンディアン)で代入していく
0x0041, 0x0042, 0x0043, 0x0044, 0x0045,
0x0046, 0x0047, 0x0048, 0x0049, 0x004a, DEL_BUTTON_,
0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, SPACE_BUTTON_,
0x0055, 0x0056, 0x0057, 0x0058, 0x0059,
0x005a, EOM_, EOM_, EOM_, EOM_, EOM_,
// 'a'から順
0x0061, 0x0062, 0x0063, 0x0064, 0x0065,
0x0066, 0x0067, 0x0068, 0x0069, 0x006a, VAR_BUTTON1_,
0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, VAR_BUTTON2_,
0x0075, 0x0076, 0x0077, 0x0078, 0x0079,
0x007a, EOM_, EOM_, EOM_, EOM_, EOM_,
// '0'から順
0x0030, 0x0031, 0x0032, 0x0033, 0x0034,
0x0035, 0x0036, 0x0037, 0x0038, 0x0039, EOM_,
// 特殊文字
// '!' '&' '/'
0x0021, EOM_, 0x0026, EOM_, 0x002f,
// ',' '.' '-'
0x002c, EOM_, 0x002e, EOM_, 0x002d, OK_BUTTON_,
// ''' '"'
0x0027, EOM_, 0x2033, EOM_, EOM_,
// '@' '(' ')'
0x0040, EOM_, 0x0028, EOM_, 0x0029, EOM_,
EOM_, EOM_, EOM_, EOM_, EOM_,
EOM_, EOM_, EOM_, EOM_, EOM_, CANCEL_BUTTON_,
EOM_, EOM_, EOM_, EOM_, EOM_,
EOM_, EOM_, EOM_, EOM_, EOM_,
},
};