Added the kanamemo & traydict side projects to repository

Originally committed to SVN as r436.
This commit is contained in:
Rodrigo Braz Monteiro 2006-06-29 23:14:54 +00:00
parent 818377243d
commit 4a2c0dbbfa
32 changed files with 3783 additions and 0 deletions

BIN
kanamemo/game_display.cpp Normal file

Binary file not shown.

100
kanamemo/game_display.h Normal file
View file

@ -0,0 +1,100 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <vector>
//////////////
// Prototypes
class KanaTable;
class KanaEntry;
class SwitchUserDialog;
class GamePanel;
//////////////////////
// Game display class
class GameDisplay : public wxWindow {
friend class SwitchUserDialog;
private:
wxStatusBar *statusBar;
const KanaEntry *current;
const KanaEntry *previous;
int curn;
int curTable;
int lastTable;
std::vector<int> scores[2];
bool enabled[2];
wxMenuItem *menuCheck[2];
int status;
int levelUp;
wxString lastEntry;
wxString playerName;
void OnPaint(wxPaintEvent &event);
void OnClick(wxMouseEvent &event);
void Reset();
int GetNAtLevel(int level,int table);
void UpdateStatusBar();
public:
bool autoLevel;
bool isOn;
int level[2];
KanaTable *table;
GamePanel *panel;
GameDisplay(wxWindow *parent);
~GameDisplay();
void ResetTable(int id);
void GetNextKana();
void EnterRomaji(wxString romaji);
void EnableTable(int table,bool enable);
void SetLevel(int table,int level);
void EnableGame(bool enable);
void Save();
void Load();
DECLARE_EVENT_TABLE();
};

109
kanamemo/game_panel.cpp Normal file
View file

@ -0,0 +1,109 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "game_panel.h"
#include "game_display.h"
///////////////
// Constructor
GamePanel::GamePanel(wxWindow *parent,GameDisplay *dsp)
: wxPanel (parent,-1,wxDefaultPosition,wxDefaultSize,wxRAISED_BORDER)
{
// Set display
display = dsp;
// Controls
enterField = new wxTextCtrl(this,Enter_Box,_T(""),wxDefaultPosition,wxSize(50,-1),wxTE_PROCESS_ENTER);
enterField->SetMaxLength(3);
enterField->SetToolTip(_T("Enter the hepburn romaji for the kana you see here and press the Enter key or the enter button to accept. Type '?' for the answer."));
wxButton *enterButton = new wxButton(this,Enter_Button,_T("Enter"),wxDefaultPosition,wxSize(60,-1));
enterButton->SetToolTip(_T("Enter text. (Pressing the enter key on the keyboard will also work)"));
wxButton *questionButton = new wxButton(this,Question_Button,_T("?"),wxDefaultPosition,wxSize(30,-1));
questionButton->SetToolTip(_T("Shows the correct hepburn romaji for the shown kana."));
// Sizers
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *topSizer = new wxBoxSizer(wxHORIZONTAL);
topSizer->AddStretchSpacer(1);
topSizer->Add(new wxStaticText(this,-1,_T("Enter hepburn romaji:")),0,wxALIGN_CENTER | wxRIGHT,8);
topSizer->Add(enterField,0,wxALIGN_CENTER | wxRIGHT,2);
topSizer->Add(enterButton,0,0,0);
topSizer->Add(questionButton,0,0,0);
topSizer->AddStretchSpacer(1);
mainSizer->Add(topSizer,1,wxEXPAND,0);
mainSizer->Add(new wxStaticText(this,-1,_T("Copyright © 2006 - Rodrigo Braz Monteiro. All rights reserved.")),0,wxALIGN_CENTER | wxALL,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
}
//////////////
// Destructor
GamePanel::~GamePanel() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(GamePanel,wxPanel)
EVT_BUTTON(Enter_Button,OnEnterPress)
EVT_BUTTON(Question_Button,OnQuestionPress)
EVT_TEXT_ENTER(Enter_Box,OnEnterPress)
END_EVENT_TABLE()
/////////////////
// Enter pressed
void GamePanel::OnEnterPress(wxCommandEvent &event) {
wxString value = enterField->GetValue();
if (!value.IsEmpty()) {
display->EnterRomaji(value);
enterField->Clear();
}
enterField->SetFocus();
}
////////////////////
// Question pressed
void GamePanel::OnQuestionPress(wxCommandEvent &event) {
display->EnterRomaji(_T("?"));
enterField->Clear();
enterField->SetFocus();
}

72
kanamemo/game_panel.h Normal file
View file

@ -0,0 +1,72 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
///////////////
// Panel class
class GamePanel : public wxPanel {
private:
GameDisplay *display;
void OnEnterPress(wxCommandEvent &event);
void OnQuestionPress(wxCommandEvent &event);
public:
wxTextCtrl *enterField;
GamePanel(wxWindow *parent,GameDisplay *dsp);
~GamePanel();
DECLARE_EVENT_TABLE();
};
///////
// IDs
enum {
Enter_Box = 2500,
Enter_Button,
Question_Button
};

166
kanamemo/game_window.cpp Normal file
View file

@ -0,0 +1,166 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "game_window.h"
#include "game_display.h"
#include "game_panel.h"
#include "version.h"
#include "level.h"
#include "switch_user.h"
///////////////
// Constructor
GameWindow::GameWindow()
: GameWindowBase(NULL,-1,GetVersionString(),wxDefaultPosition,wxDefaultSize,wxMINIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
// Menu bar
menu = new wxMenuBar();
SetMenuBar(menu);
SetIcon(wxICON(wxicon));
// File menu
wxMenu *fileMenu = new wxMenu;
//fileMenu->Append(Menu_File_New,_T("&New Player"),_T(""));
fileMenu->Append(Menu_File_Load,_T("&Switch User..."),_T(""));
fileMenu->Append(Menu_File_Exit,_T("E&xit"),_T(""));
menu->Append(fileMenu,_T("&File"));
// Options menu
wxMenu *optionsMenu = new wxMenu;
optionsMenu->Append(Menu_Options_Hiragana,_T("Hiragana"),_T(""),wxITEM_CHECK);
optionsMenu->Append(Menu_Options_Katakana,_T("Katakana"),_T(""),wxITEM_CHECK);
optionsMenu->Append(Menu_Options_Level,_T("Set Level..."),_T(""));
menu->Append(optionsMenu,_T("&Options"));
// Status bar
wxStatusBar *bar = CreateStatusBar(3,0);
int widths[] = { 85, -1, -1 };
bar->SetStatusWidths(3,widths);
// Subwindows
display = new GameDisplay(this);
panel = new GamePanel(this,display);
display->panel = panel;
// Sizer
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
mainSizer->Add(display,1,wxEXPAND,0);
mainSizer->Add(panel,0,wxEXPAND,0);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
// Prompt user for name
Show();
SwitchUserDialog user(display);
user.ShowModal();
if (!display->isOn) Destroy();
}
//////////////
// Destructor
GameWindow::~GameWindow() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(GameWindow,GameWindowBase)
EVT_CLOSE(GameWindow::OnClose)
EVT_MENU(Menu_File_Exit,GameWindow::OnFileExit)
EVT_MENU(Menu_File_New,GameWindow::OnFileNew)
EVT_MENU(Menu_File_Load,GameWindow::OnFileLoad)
EVT_MENU(Menu_Options_Hiragana,GameWindow::OnOptionsHiragana)
EVT_MENU(Menu_Options_Katakana,GameWindow::OnOptionsKatakana)
EVT_MENU(Menu_Options_Level,GameWindow::OnOptionsLevel)
END_EVENT_TABLE()
///////////////
// Close event
void GameWindow::OnClose(wxCloseEvent &event) {
Destroy();
}
////////
// Exit
void GameWindow::OnFileExit(wxCommandEvent &event) {
Close();
}
//////////////
// New player
void GameWindow::OnFileNew(wxCommandEvent &event) {
}
///////////////
// Load player
void GameWindow::OnFileLoad(wxCommandEvent &event) {
display->Save();
SwitchUserDialog user(display);
user.ShowModal();
}
///////////////////
// Toggle hiragana
void GameWindow::OnOptionsHiragana(wxCommandEvent &event) {
display->EnableTable(0,event.IsChecked());
display->Save();
}
///////////////////
// Toggle katakana
void GameWindow::OnOptionsKatakana(wxCommandEvent &event) {
display->EnableTable(1,event.IsChecked());
display->Save();
}
////////////////////
// Difficulty Level
void GameWindow::OnOptionsLevel(wxCommandEvent &event) {
LevelWindow level(this,display);
level.ShowModal();
display->Save();
}

86
kanamemo/game_window.h Normal file
View file

@ -0,0 +1,86 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
class GamePanel;
///////////
// Typedef
typedef wxFrame GameWindowBase;
/////////////////////
// Game window class
class GameWindow : public GameWindowBase {
private:
GameDisplay *display;
GamePanel *panel;
wxMenuBar *menu;
void OnClose(wxCloseEvent &event);
void OnFileExit(wxCommandEvent &event);
void OnFileNew(wxCommandEvent &event);
void OnFileLoad(wxCommandEvent &event);
void OnOptionsHiragana(wxCommandEvent &event);
void OnOptionsKatakana(wxCommandEvent &event);
void OnOptionsLevel(wxCommandEvent &event);
public:
GameWindow();
~GameWindow();
DECLARE_EVENT_TABLE();
};
////////////////////
// Menu identifiers
enum {
Menu_File_Exit = 2000,
Menu_File_New,
Menu_File_Load,
Menu_Options_Hiragana,
Menu_Options_Katakana,
Menu_Options_Level
};

BIN
kanamemo/icon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

294
kanamemo/kana_table.cpp Normal file
View file

@ -0,0 +1,294 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "kana_table.h"
///////////////
// Constructor
KanaTable::KanaTable() {
level = 0;
groups[0] = 0;
groups[1] = 0;
BeginGroup();
Insert(L"",L"",L"a");
Insert(L"",L"",L"i");
Insert(L"",L"",L"u");
Insert(L"",L"",L"e");
Insert(L"",L"",L"o");
BeginGroup();
Insert(L"",L"",L"ka");
Insert(L"",L"",L"ki");
Insert(L"",L"",L"ku");
Insert(L"",L"",L"ke");
Insert(L"",L"",L"ko");
BeginGroup();
Insert(L"",L"",L"sa");
Insert(L"",L"",L"shi");
Insert(L"",L"",L"su");
Insert(L"",L"",L"se");
Insert(L"",L"",L"so");
BeginGroup();
Insert(L"",L"",L"ta");
Insert(L"",L"",L"chi");
Insert(L"",L"",L"tsu");
Insert(L"",L"",L"te");
Insert(L"",L"",L"to");
BeginGroup();
Insert(L"",L"",L"na");
Insert(L"",L"",L"ni");
Insert(L"",L"",L"nu");
Insert(L"",L"",L"ne");
Insert(L"",L"",L"no");
BeginGroup();
Insert(L"",L"",L"ha");
Insert(L"",L"",L"hi");
Insert(L"",L"",L"fu");
Insert(L"",L"",L"he");
Insert(L"",L"",L"ho");
BeginGroup();
Insert(L"",L"",L"ma");
Insert(L"",L"",L"mi");
Insert(L"",L"",L"mu");
Insert(L"",L"",L"me");
Insert(L"",L"",L"mo");
BeginGroup();
Insert(L"",L"",L"ya");
Insert(L"",L"",L"yu");
Insert(L"",L"",L"yo");
BeginGroup();
Insert(L"",L"",L"ra");
Insert(L"",L"",L"ri");
Insert(L"",L"",L"ru");
Insert(L"",L"",L"re");
Insert(L"",L"",L"ro");
BeginGroup();
Insert(L"",L"",L"wa");
Insert(L"",L"",L"wo");
BeginGroup();
level--;
Insert(L"",L"",L"n");
BeginGroup();
Insert(L"",L"",L"ga");
Insert(L"",L"",L"gi");
Insert(L"",L"",L"gu");
Insert(L"",L"",L"ge");
Insert(L"",L"",L"go");
BeginGroup();
Insert(L"",L"",L"za");
Insert(L"",L"",L"ji");
Insert(L"",L"",L"zu");
Insert(L"",L"",L"ze");
Insert(L"",L"",L"zo");
BeginGroup();
Insert(L"",L"",L"da");
Insert(L"",L"",L"ji");
Insert(L"",L"",L"zu");
Insert(L"",L"",L"de");
Insert(L"",L"",L"do");
BeginGroup();
Insert(L"",L"",L"ba");
Insert(L"",L"",L"bi");
Insert(L"",L"",L"bu");
Insert(L"",L"",L"be");
Insert(L"",L"",L"bo");
BeginGroup();
Insert(L"",L"",L"pa");
Insert(L"",L"",L"pi");
Insert(L"",L"",L"pu");
Insert(L"",L"",L"pe");
Insert(L"",L"",L"po");
BeginGroup();
Insert(L"きゃ",L"キャ",L"kya");
Insert(L"きゅ",L"キュ",L"kyu");
Insert(L"きょ",L"キョ",L"kyo");
BeginGroup();
Insert(L"しゃ",L"シャ",L"sha");
Insert(L"しゅ",L"シュ",L"shu");
Insert(L"しょ",L"ショ",L"sho");
BeginGroup();
Insert(L"ちゃ",L"チャ",L"cha");
Insert(L"ちゅ",L"チュ",L"chu");
Insert(L"ちょ",L"チョ",L"cho");
BeginGroup();
Insert(L"にゃ",L"ニャ",L"nya");
Insert(L"にゅ",L"ニュ",L"nyu");
Insert(L"にょ",L"ニョ",L"nyo");
BeginGroup();
Insert(L"ひゃ",L"ヒャ",L"hya");
Insert(L"ひゅ",L"ヒュ",L"hyu");
Insert(L"ひょ",L"ヒョ",L"hyo");
BeginGroup();
Insert(L"みゃ",L"ミャ",L"mya");
Insert(L"みゅ",L"ミュ",L"myu");
Insert(L"みょ",L"ミョ",L"myo");
BeginGroup();
Insert(L"りゃ",L"リャ",L"rya");
Insert(L"りゅ",L"リュ",L"ryu");
Insert(L"りょ",L"リョ",L"ryo");
BeginGroup();
Insert(L"ぎゃ",L"ギャ",L"gya");
Insert(L"ぎゅ",L"ギュ",L"gyu");
Insert(L"ぎょ",L"ギョ",L"gyo");
BeginGroup();
Insert(L"じゃ",L"ジャ",L"ja");
Insert(L"じゅ",L"ジュ",L"ju");
Insert(L"じょ",L"ジョ",L"jo");
BeginGroup();
Insert(L"ぢゃ",L"ヂャ",L"ja");
Insert(L"ぢゅ",L"ヂュ",L"ju");
Insert(L"ぢょ",L"ヂョ",L"jo");
BeginGroup();
Insert(L"びゃ",L"ビャ",L"bya");
Insert(L"びゅ",L"ビュ",L"byu");
Insert(L"びょ",L"ビョ",L"byo");
BeginGroup();
Insert(L"ぴゃ",L"ピャ",L"pya");
Insert(L"ぴゅ",L"ピュ",L"pyu");
Insert(L"ぴょ",L"ピョ",L"pyo");
BeginGroup();
Insert(L"",L"ファ",L"fa");
Insert(L"",L"フィ",L"fi");
Insert(L"",L"フェ",L"fe");
Insert(L"",L"フォ",L"fo");
BeginGroup();
Insert(L"",L"ヴァ",L"va");
Insert(L"",L"ヴィ",L"vi");
Insert(L"",L"",L"vu");
Insert(L"",L"ヴェ",L"ve");
Insert(L"",L"ヴォ",L"vo");
}
//////////////
// Destructor
KanaTable::~KanaTable() {
}
///////////////
// Begin group
void KanaTable::BeginGroup() {
curGroup = _T("");
level++;
}
//////////
// Insert
void KanaTable::Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep) {
#ifdef _UNICODE
KanaEntry entry(hira,kata,hep);
if (curGroup.IsEmpty()) curGroup = hep;
entry.group = curGroup;
entry.level = level;
if (!entry.hiragana.IsEmpty() && level > groups[0]) groups[0] = level;
if (!entry.katakana.IsEmpty() && level > groups[1]) groups[1] = level;
entries.push_back(entry);
#endif
}
/////////////////////
// Number of entries
int KanaTable::GetNumberEntries(int level) const {
if (level == -1) return entries.size();
else {
int count = 0;
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].level <= level) count++;
}
return count;
}
}
////////////////////////
// Get a specific entry
const KanaEntry &KanaTable::GetEntry(int i) const {
return entries.at(i);
}
//////////////////////////
// Find a specific romaji
const KanaEntry *KanaTable::FindByRomaji(wxString romaji) const {
int n = entries.size();
for (int i=0;i<n;i++) {
if (entries[i].hepburn == romaji) return &entries[i];
}
return NULL;
}
/////////////////////////////////////////////
// Get number of levels for a specific table
int KanaTable::GetLevels(int table) const {
return groups[table];
}

80
kanamemo/kana_table.h Normal file
View file

@ -0,0 +1,80 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <vector>
#include <wx/wxprec.h>
///////////////////////////
// Hiragana/katakana entry
class KanaEntry {
public:
wxString hiragana;
wxString katakana;
wxString hepburn;
wxString group;
int level;
KanaEntry(wxString hira,wxString kata,wxString hep) {
hiragana = hira;
katakana = kata;
hepburn = hep;
}
};
///////////////////////////
// Hiragana/Katakana table
class KanaTable {
private:
std::vector<KanaEntry> entries;
void Insert(wchar_t *hira,wchar_t *kata,wchar_t *hep);
void BeginGroup();
wxString curGroup;
int groups[2];
int level;
public:
KanaTable();
~KanaTable();
int GetNumberEntries(int level=-1) const;
int GetLevels(int table) const;
const KanaEntry &GetEntry(int i) const;
const KanaEntry *FindByRomaji(wxString romaji) const;
};

117
kanamemo/level.cpp Normal file
View file

@ -0,0 +1,117 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include "level.h"
#include "game_display.h"
#include "kana_table.h"
///////////////
// Constructor
LevelWindow::LevelWindow(wxWindow *parent,GameDisplay *dsp)
: wxDialog(parent,-1,_T("Set Level"),wxDefaultPosition,wxDefaultSize)
{
// Set display
display = dsp;
// Sliders
int levelHira = display->level[0];
int levelKata = display->level[1];
int maxLevelHira = display->table->GetLevels(0);
int maxLevelKata = display->table->GetLevels(1);
hiraSlider = new wxSlider(this,-1,levelHira,1,maxLevelHira,wxDefaultPosition,wxSize(200,-1));
kataSlider = new wxSlider(this,-1,levelKata,1,maxLevelKata,wxDefaultPosition,wxSize(200,-1));
// Checkbox
autoLevelCheck = new wxCheckBox(this,-1,_T("Automatically level up"));
autoLevelCheck->SetValue(display->autoLevel);
// Sizers
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *sizer1 = new wxStaticBoxSizer(wxVERTICAL,this,_T("Hiragana and Katakana"));
wxSizer *sizer2 = new wxFlexGridSizer(2,2,5,5);
wxSizer *sizer3 = new wxBoxSizer(wxHORIZONTAL);
// Insert controls
sizer2->Add(new wxStaticText(this,-1,_T("Hiragana")),0,wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT,5);
sizer2->Add(hiraSlider,1,wxEXPAND,0);
sizer2->Add(new wxStaticText(this,-1,_T("Katakana")),0,wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL | wxRIGHT,5);
sizer2->Add(kataSlider,1,wxEXPAND,0);
// Sizer layout
sizer1->Add(sizer2,1,wxEXPAND,0);
sizer1->Add(autoLevelCheck,0,wxALIGN_LEFT | wxTOP,5);
sizer3->AddStretchSpacer(1);
sizer3->Add(new wxButton(this,wxID_OK),0,0,0);
sizer3->Add(new wxButton(this,wxID_CANCEL),0,0,0);
mainSizer->Add(sizer1,1,wxEXPAND | wxALL,5);
mainSizer->Add(sizer3,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
}
//////////////
// Destructor
LevelWindow::~LevelWindow() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(LevelWindow,wxDialog)
EVT_BUTTON(wxID_OK,LevelWindow::OnOK)
EVT_BUTTON(wxID_CANCEL,LevelWindow::OnCancel)
END_EVENT_TABLE()
//////
// OK
void LevelWindow::OnOK(wxCommandEvent &event) {
display->autoLevel = autoLevelCheck->GetValue();
display->SetLevel(0,hiraSlider->GetValue());
display->SetLevel(1,kataSlider->GetValue());
Destroy();
}
//////////
// Cancel
void LevelWindow::OnCancel(wxCommandEvent &event) {
Destroy();
}

65
kanamemo/level.h Normal file
View file

@ -0,0 +1,65 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
/////////////////////
// Game window class
class LevelWindow : public wxDialog {
private:
GameDisplay *display;
wxSlider *hiraSlider;
wxSlider *kataSlider;
wxCheckBox *autoLevelCheck;
void OnOK(wxCommandEvent &event);
void OnCancel(wxCommandEvent &event);
public:
LevelWindow(wxWindow *parent,GameDisplay *dsp);
~LevelWindow();
DECLARE_EVENT_TABLE();
};

115
kanamemo/main.cpp Normal file
View file

@ -0,0 +1,115 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/filename.h>
#include "main.h"
#include "game_window.h"
/////////////////
// Implement app
IMPLEMENT_APP(KanaMemo)
//////////////
// Initialize
bool KanaMemo::OnInit() {
// Configuration
SetAppName(_T("KanaMemo"));
srand((unsigned)time(NULL));
// Get path
GetFullPath(argv[0]);
GetFolderName();
// Create the window
GameWindow *window = new GameWindow();
window->Show();
// Initialization OK
return true;
}
/////////////////////////////
// Gets and stores full path
void KanaMemo::GetFullPath(wxString arg) {
if (wxIsAbsolutePath(arg)) {
fullPath = arg;
return;
}
// Is it a relative path?
wxString currentDir(wxFileName::GetCwd());
if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH;
wxString str = currentDir + arg;
if (wxFileExists(str)) {
fullPath = str;
return;
}
// OK, it's neither an absolute path nor a relative path.
// Search PATH.
wxPathList pathList;
pathList.AddEnvList(_T("PATH"));
str = pathList.FindAbsoluteValidPath(arg);
if (!str.IsEmpty()) {
fullPath = str;
return;
}
fullPath = _T("");
return;
}
///////////////////////////////////
// Gets folder name from full path
void KanaMemo::GetFolderName () {
folderName = _T("");
wxFileName path(fullPath);
folderName += path.GetPath(wxPATH_GET_VOLUME);
folderName += _T("/");
}
///////////
// Statics
wxString KanaMemo::folderName;
wxString KanaMemo::fullPath;

47
kanamemo/main.h Normal file
View file

@ -0,0 +1,47 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
//////////////
// Main class
class KanaMemo : public wxApp {
public:
bool OnInit();
void GetFullPath(wxString arg);
void GetFolderName();
static wxString folderName;
static wxString fullPath;
};

3
kanamemo/res.rc Normal file
View file

@ -0,0 +1,3 @@
wxicon ICON "icon.ico"
#include "wx/msw/wx.rc"

178
kanamemo/switch_user.cpp Normal file
View file

@ -0,0 +1,178 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/filename.h>
#include <wx/dir.h>
#include <stdio.h>
#include "switch_user.h"
#include "game_display.h"
#include "main.h"
///////////////
// Constructor
SwitchUserDialog::SwitchUserDialog(GameDisplay *dspl)
: wxDialog(NULL,-1,_T("Select user..."),wxDefaultPosition,wxDefaultSize)
{
display = dspl;
// Sizers
wxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
wxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
wxSizer *listSizer = new wxStaticBoxSizer(wxVERTICAL,this,_T("Users:"));
// Load list
wxArrayString choices;
wxArrayString files;
wxDir::GetAllFiles(KanaMemo::folderName,&files,_T("*.usr"),wxDIR_FILES);
for (size_t i=0;i<files.Count();i++) {
wxFileName fname(files[i]);
choices.Add(fname.GetName());
}
// List sizer
listBox = new wxListBox(this,1337,wxDefaultPosition,wxSize(200,150),choices,wxLB_SINGLE | wxLB_SORT );
listSizer->Add(listBox,1,wxEXPAND,0);
// Button sizer
buttonSizer->AddStretchSpacer(1);
okButton = new wxButton(this,wxID_OK);
buttonSizer->Add(new wxButton(this,wxID_NEW),0,0,0);
buttonSizer->Add(okButton,0,0,0);
buttonSizer->Add(new wxButton(this,wxID_CANCEL),0,0,0);
// Main sizer
mainSizer->Add(listSizer,1,wxEXPAND | wxALL,5);
mainSizer->Add(buttonSizer,0,wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM,5);
mainSizer->SetSizeHints(this);
SetSizer(mainSizer);
// If list is empty, prompt for new user
if (listBox->GetCount() == 0) NewUser();
UpdateButtons();
}
//////////////
// Destructor
SwitchUserDialog::~SwitchUserDialog() {
}
///////////////
// Event table
BEGIN_EVENT_TABLE(SwitchUserDialog,wxDialog)
EVT_BUTTON(wxID_NEW,SwitchUserDialog::OnButtonCreate)
EVT_BUTTON(wxID_OK,SwitchUserDialog::OnButtonOK)
EVT_BUTTON(wxID_CANCEL,SwitchUserDialog::OnButtonCancel)
EVT_LISTBOX(1337, SwitchUserDialog::OnClickList)
EVT_LISTBOX_DCLICK(1337, SwitchUserDialog::OnDoubleClickList)
END_EVENT_TABLE()
//////////
// Create
void SwitchUserDialog::OnButtonCreate(wxCommandEvent &event) {
NewUser();
}
//////
// OK
void SwitchUserDialog::OnButtonOK(wxCommandEvent &event) {
Select();
}
//////////
// Cancel
void SwitchUserDialog::OnButtonCancel(wxCommandEvent &event) {
Destroy();
}
////////////
// New user
void SwitchUserDialog::NewUser() {
wxString userName = wxGetTextFromUser(_T("Enter the name of the new user:"),_T("New user"),_T(""),this);
if (!userName.IsEmpty()) {
// Create file
wxString path = KanaMemo::folderName + _T("/") + userName + _T(".usr");
FILE *fp = fopen(path.mb_str(wxConvLocal),"wb");
fclose(fp);
// Update stuff
listBox->Append(userName);
listBox->SetStringSelection(userName);
UpdateButtons();
}
}
////////////////
// List clicked
void SwitchUserDialog::OnClickList(wxCommandEvent &event) {
UpdateButtons();
}
///////////////////////
// List double clicked
void SwitchUserDialog::OnDoubleClickList(wxCommandEvent &event) {
Select();
}
//////////////////
// Update buttons
void SwitchUserDialog::UpdateButtons() {
okButton->Enable(!listBox->GetStringSelection().IsEmpty());
}
///////////////
// Select user
void SwitchUserDialog::Select() {
wxString user = listBox->GetStringSelection();
if (!user.IsEmpty()) {
display->playerName = user;
display->Load();
display->EnableGame(true);
Destroy();
}
}

71
kanamemo/switch_user.h Normal file
View file

@ -0,0 +1,71 @@
// Copyright (c) 2006, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <wx/wxprec.h>
//////////////
// Prototypes
class GameDisplay;
///////////////////////
// Switch users dialog
class SwitchUserDialog : public wxDialog {
private:
GameDisplay *display;
wxListBox *listBox;
wxButton *okButton;
void OnButtonCreate(wxCommandEvent &event);
void OnButtonOK(wxCommandEvent &event);