Skip to content

Commit

Permalink
new languages
Browse files Browse the repository at this point in the history
  • Loading branch information
karwler committed Jun 10, 2016
1 parent 1415cdb commit 7b97323
Show file tree
Hide file tree
Showing 28 changed files with 414 additions and 189 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#directories
bin
build
out
CMakeFiles
*.dir
.vs
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf
The default font is set to "Arial" so you need the mscorefonts as well:
sudo apt-get install ttf-mscorefonts-installer

It's possible that neither the mouse wheel nor the audio system work properly under Linux and I've got no idea why.

##Windows
All needed libraries are already included in the project, however they're built only for the MSVC 14 (2015).
All necessary libraries are already included in the project, however they're built only for the MSVC 14 (2015).

##OS X
The project is configured to use the SDL2 frameworks and boost library.
Expand Down
21 changes: 21 additions & 0 deletions data/languages/german.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library=Bibliothek
playlists=Wiedergabelisten
settings=Einstellungen
exit=beenden
back=zurück
books=Bücher
songs=Lieder
add=hinzufügen
new=neu
edit=bearbeiten
del=löschen
save=speichern
close=schließen
ok=ok
cancel=Abbrechen
new playlist=neue Wiedergabeliste
general=Allgemeine
video=Video
audio=Tom
controls=Bedienung
language=Sprache
21 changes: 21 additions & 0 deletions data/languages/polish.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library=biblioteka
playlists=listy odtwarzania
settings=ustawienia
exit=zamknij
back=wróć
books=książki
songs=piosenki
add=dodaj
new=nowa
edit=edytuj
del=usuń
save=zapisz
close=zamknij
ok=ok
cancel=anuluj
new playlist=nowa lista odtwarzania
general=ogólne
video=wideo
audio=dźwięk
controls=sterowanie
language=język
21 changes: 21 additions & 0 deletions data/languages/russian.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library=библиотека
playlists=списки воспроизведения
settings=параметры
exit=выход
back=назад
books=книги
songs=песни
add=добавий
new=новый
edit=редактировай
del=удалий
save=сохраний
close=закрый
ok=ok
cancel=отмена
new playlist=новый список воспроизведения
general=общие
video=видео
audio=аудио
controls=управление
language=язык
Binary file modified rsc/resource.rc
Binary file not shown.
20 changes: 2 additions & 18 deletions src/engine/audioSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
AudioSys::AudioSys(const AudioSettings& SETS) :
sets(SETS),
curMusic(nullptr),
curSound(nullptr),
deltaDelay(0.f)
{
Initialize();
Expand All @@ -19,15 +18,13 @@ void AudioSys::Initialize() {
Mix_AllocateChannels(1);

Mix_HookMusicFinished(MusicFinishCallback);
Mix_ChannelFinished(ChannelFinishCallback);

MusicVolume(sets.musicVolume);
SoundVolume(sets.soundVolume);
}

void AudioSys::Cleanup() {
FreeMusic();
FreeSound();
Mix_CloseAudio();
Mix_Quit();
}
Expand All @@ -39,13 +36,6 @@ void AudioSys::FreeMusic() {
}
}

void AudioSys::FreeSound() {
if (curSound) {
Mix_FreeChunk(curSound);
curSound = nullptr;
}
}

void AudioSys::Tick(float dSec) {
if (deltaDelay != 0.f) {
deltaDelay -= dSec;
Expand All @@ -60,10 +50,6 @@ void AudioSys::MusicFinishCallback() {
World::audioSys()->deltaDelay = World::audioSys()->sets.songDelay;
}

void AudioSys::ChannelFinishCallback(int channel) {
World::audioSys()->FreeSound();
}

void AudioSys::PlayPauseMusic() {
if (!curMusic) {
curSong = 0;
Expand Down Expand Up @@ -92,10 +78,8 @@ void AudioSys::SwitchSong(int step) {
Mix_PlayMusic(curMusic, 0);
}

void AudioSys::PlaySound(const string& file) {
FreeSound();
if (curSound = Mix_LoadWAV(file.c_str()))
Mix_PlayChannel(0, curSound, 0);
void AudioSys::PlaySound(const string& name) {
Mix_PlayChannel(0, World::library()->getSound(name), 0);
}

AudioSettings AudioSys::Settings() const {
Expand Down
5 changes: 1 addition & 4 deletions src/engine/audioSys.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ class AudioSys {
void Initialize();
void Cleanup();
void FreeMusic();
void FreeSound();

void Tick(float dSec);
static void MusicFinishCallback();
static void ChannelFinishCallback(int channel);

void PlayPauseMusic();
void SwitchSong(int step=1);
void PlaySound(const string& file);
void PlaySound(const string& name);

AudioSettings Settings() const;
void LoadPlaylist(const Playlist& newList);
Expand All @@ -34,7 +32,6 @@ class AudioSys {
vector<string> playlist;
uint curSong;
Mix_Music* curMusic;
Mix_Chunk* curSound;
float deltaDelay;

int CheckVolume(int value);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void Engine::Run() {

winSys->SetWindow();
scene = new Scene(Filer::LoadGeneralSettings()); // initializes program and library
winSys->SetIcon(scene->getLibrary()->getTexPath("icon"));
winSys->SetIcon(scene->getLibrary()->getTex("icon")->surface);

// initialize scene and timer
scene->getProgram()->Event_OpenBookList();
Expand Down
65 changes: 44 additions & 21 deletions src/engine/filer.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#include "world.h"

EDirFilter operator|(EDirFilter a, EDirFilter b) {
return static_cast<EDirFilter>(static_cast<byte>(a) | static_cast<byte>(b));
}

byte Filer::CheckDirectories(const GeneralSettings& sets) {
byte retval = 0;
if (!fs::exists(dirSets()))
Expand All @@ -12,6 +8,10 @@ byte Filer::CheckDirectories(const GeneralSettings& sets) {
fs::create_directories(sets.libraryParh());
if (!fs::exists(sets.playlistParh()))
fs::create_directories(sets.playlistParh());
if (!fs::exists(dirLangs())) {
cerr << "couldn't find translation directory" << endl;
retval = 1;
}
if (!fs::exists(dirSnds())) {
cerr << "couldn't find sound directory" << endl;
retval = 1;
Expand Down Expand Up @@ -53,7 +53,7 @@ vector<fs::path> Filer::ListDir(const fs::path& dir, EDirFilter filter, const ve
return names;

for (fs::directory_iterator it(dir); it != fs::directory_iterator(); it++) {
if (filter == 0)
if (filter == FILTER_ALL)
names.push_back(it->path());
else if ((filter & FILTER_FILE) && fs::is_regular_file(it->path())) {
if (extFilter.empty())
Expand All @@ -73,7 +73,37 @@ vector<fs::path> Filer::ListDir(const fs::path& dir, EDirFilter filter, const ve
return names;
}

vector<string> Filer::GetPicsFromDir(const fs::path& dir) {
map<string, string> Filer::GetLines(const string& language) {
vector<string> lines;
if (!ReadTextFile(dirLangs() + language + ".ini", lines, false))
return map<string, string>();

map<string, string> translation;
for (string& line : lines) {
string arg, val;
splitIniLine(line, &arg, &val);
translation.insert(make_pair(arg, val));
}
return translation;
}

map<string, Mix_Chunk*> Filer::GetSounds() {
map<string, Mix_Chunk*> sounds;
for (fs::directory_iterator it(dirSnds()); it != fs::directory_iterator(); it++)
if (Mix_Chunk* cue = Mix_LoadWAV(it->path().string().c_str())) // add only valid sound files
sounds.insert(make_pair(removeExtension(it->path().filename()).string(), cue));
return sounds;
}

map<string, Texture> Filer::GetTextures() {
map<string, Texture> texes;
for (fs::directory_iterator it(dirTexs()); it != fs::directory_iterator(); it++)
if (SDL_Surface* surf = IMG_Load(it->path().string().c_str())) // add only valid textures
texes.insert(make_pair(removeExtension(it->path().filename()).string(), Texture(it->path().string(), surf)));
return texes;
}

vector<string> Filer::GetPics(const fs::path& dir) {
vector<string> pics;
if (!fs::is_directory(dir))
return pics;
Expand All @@ -85,20 +115,6 @@ vector<string> Filer::GetPicsFromDir(const fs::path& dir) {
return pics;
}

map<string, string> Filer::GetTextures() {
map<string, string> paths;
for (fs::directory_iterator it(dirTexs()); it != fs::directory_iterator(); it++)
paths.insert(make_pair(removeExtension(it->path().filename()).string(), it->path().string()));
return paths;
}

map<string, string> Filer::GetSounds() {
map<string, string> paths;
for (fs::directory_iterator it(dirSnds()); it != fs::directory_iterator(); it++)
paths.insert(make_pair(removeExtension(it->path().filename()).string(), it->path().string()));
return paths;
}

Playlist Filer::LoadPlaylist(const string& name) {
vector<string> lines;
if (!ReadTextFile(World::scene()->Settings().playlistParh() + name, lines))
Expand Down Expand Up @@ -135,7 +151,9 @@ GeneralSettings Filer::LoadGeneralSettings() {
for (string& line : lines) {
string arg, val;
splitIniLine(line, &arg, &val);
if (arg == "library")
if (arg == "language")
sets.language = val;
else if (arg == "library")
sets.dirLib = val;
else if (arg == "playlists")
sets.dirPlist = val;
Expand All @@ -145,6 +163,7 @@ GeneralSettings Filer::LoadGeneralSettings() {

void Filer::SaveSettings(const GeneralSettings& sets) {
vector<string> lines = {
"language=" + sets.language,
"library=" + sets.dirLib,
"playlists=" + sets.dirPlist
};
Expand Down Expand Up @@ -321,6 +340,10 @@ string Filer::dirData() {
#endif
}

string Filer::dirLangs() {
return dirData() + "languages"+dsep;
}

string Filer::dirSnds() {
return dirData() + "sounds"+dsep;
}
Expand Down
17 changes: 6 additions & 11 deletions src/engine/filer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@

#include "utils/types.h"

enum EDirFilter : byte {
FILTER_FILE = 1,
FILTER_DIR = 2,
FILTER_LINK = 4
};
EDirFilter operator|(EDirFilter a, EDirFilter b);

class Filer {
public:
static byte CheckDirectories(const GeneralSettings& sets);
static bool ReadTextFile(const string& file, vector<string>& lines, bool printMessage=true);
static bool WriteTextFile(const string& file, const vector<string>& lines);
static vector<fs::path> ListDir(const fs::path& dir, EDirFilter filter, const vector<string>& extFilter={});
static vector<string> GetPicsFromDir(const fs::path& dir);
static vector<fs::path> ListDir(const fs::path& dir, EDirFilter filter=FILTER_ALL, const vector<string>& extFilter={});

static map<string, string> GetTextures();
static map<string, string> GetSounds();
static map<string, string> GetLines(const string& language);
static map<string, Mix_Chunk*> GetSounds();
static map<string, Texture> GetTextures();
static vector<string> GetPics(const fs::path& dir);

static Playlist LoadPlaylist(const string& name);
static void SavePlaylist(const Playlist& plist);
Expand All @@ -39,6 +33,7 @@ class Filer {
#endif
static string dirSets();
static string dirData();
static string dirLangs();
static string dirSnds();
static string dirTexs();

Expand Down
14 changes: 8 additions & 6 deletions src/engine/inputSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ void InputSys::MouseButtonEvent(const SDL_MouseButtonEvent& button) {
if (dynamic_cast<KeyGetter*>(captured)) // mouse button cancels key capture
World::program()->Event_Back();
else if (button.clicks == 1) {
if (button.button == SDL_BUTTON_LEFT) { // so far only left mouse button is neeeded
if (button.type == SDL_MOUSEBUTTONDOWN)
World::scene()->OnMouseDown(false);
if (button.button == SDL_BUTTON_LEFT) {
if (button.type == SDL_MOUSEBUTTONDOWN) // single left click
World::scene()->OnMouseDown(EClick::left);
else
World::scene()->OnMouseUp();
World::scene()->OnMouseUp(); // left up
}
else if (button.button == SDL_BUTTON_RIGHT && button.type == SDL_MOUSEBUTTONDOWN) // songle right click
World::scene()->OnMouseDown(EClick::right);
}
else if (button.type == SDL_MOUSEBUTTONDOWN && button.button == SDL_BUTTON_LEFT) // double left click
World::scene()->OnMouseDown(true);
else if (button.button == SDL_BUTTON_LEFT && button.type == SDL_MOUSEBUTTONDOWN) // double left click
World::scene()->OnMouseDown(EClick::left_double);
}

void InputSys::MouseWheelEvent(const SDL_MouseWheelEvent& wheel) {
Expand Down
Loading

0 comments on commit 7b97323

Please sign in to comment.