Skip to content

Commit

Permalink
Implement some RPG Maker 2003 v1.11 features (EasyRPG#587)
Browse files Browse the repository at this point in the history
- Transparent Window also affects Title Screen
- Support for skipping title screen
- The “Y” key has now the function of an additional confirm button
- Event Command: Open Load Menu, Exit Game, Toggle Fullscreen
- ConditionalBranch: Has Savestate, Is Fullscreen
  • Loading branch information
Ghabry committed Dec 15, 2015
1 parent c038a2e commit 555a0b8
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 46 deletions.
15 changes: 15 additions & 0 deletions src/filefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,21 @@ bool FileFinder::IsEasyRpgProject(DirectoryTree const& dir){
return(ldb_it != dir.files.end() && lmt_it != dir.files.end());
}

bool FileFinder::HasSavegame(DirectoryTree const& dir) {
EASYRPG_SHARED_PTR<FileFinder::DirectoryTree> tree = FileFinder::CreateSaveDirectoryTree();

for (int i = 1; i <= 15; i++) {
std::string savename = "Save" + std::string((i <= 9 ? "0" : "")) + std::to_string(i) + ".lsd";

std::string filename = FileFinder::FindDefault(*tree, savename);

if (!filename.empty()) {
return true;
}
}
return false;
}

std::string FileFinder::FindMusic(const std::string& name) {
#ifdef EMSCRIPTEN
return FindDefault("Music", name);
Expand Down
8 changes: 8 additions & 0 deletions src/filefinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ namespace FileFinder {
bool IsValidProject(DirectoryTree const& dir);
bool IsRPG2kProject(DirectoryTree const& dir);
bool IsEasyRpgProject(DirectoryTree const& dir);

/**
* Checks whether the directory contains any savegame with name
* SaveXX.lsd (XX from 00 to 15).
*
* @return If directory Tree contains a savegame
*/
bool HasSavegame(DirectoryTree const& dir);
} // namespace FileFinder

#endif
3 changes: 2 additions & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ void Game_Interpreter::Update() {

if ((Game_Temp::battle_calling && !Game_Temp::battle_running) ||
Game_Temp::shop_calling ||
// Game_Temp::inn_calling ||
Game_Temp::inn_calling ||
Game_Temp::name_calling ||
Game_Temp::menu_calling ||
Game_Temp::save_calling ||
Game_Temp::load_calling ||
Game_Temp::to_title ||
Game_Temp::gameover) {

Expand Down
57 changes: 57 additions & 0 deletions src/game_interpreter_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ bool Game_Interpreter_Map::ExecuteCommand() {
return SkipTo(Cmd::EndBranch);
case Cmd::EndBranch:
return true;
case Cmd::OpenLoadMenu:
return CommandOpenLoadMenu(com);
case Cmd::ExitGame:
return CommandExitGame(com);
case Cmd::ToggleAtbMode:
return CommandToggleAtbMode(com);
case Cmd::ToggleFullscreen:
return CommandToggleFullscreen(com);
case Cmd::OpenVideoOptions:
// don't care
return true;
default:
return Game_Interpreter::ExecuteCommand();
}
Expand Down Expand Up @@ -1786,6 +1797,28 @@ bool Game_Interpreter_Map::CommandHaltAllMovement(RPG::EventCommand const& /* co
return true;
}

bool Game_Interpreter_Map::CommandOpenLoadMenu(RPG::EventCommand const& com) {
Game_Temp::load_calling = true;
return true;
}

bool Game_Interpreter_Map::CommandExitGame(RPG::EventCommand const& com) {
Player::exit_flag = true;
return true;
}

bool Game_Interpreter_Map::CommandToggleAtbMode(RPG::EventCommand const& com) {
Output::Warning("Command Toggle ATB mode not supported");
return true;
}

bool Game_Interpreter_Map::CommandToggleFullscreen(RPG::EventCommand const& com) {
DisplayUi->BeginDisplayModeChange();
DisplayUi->ToggleFullscreen();
DisplayUi->EndDisplayModeChange();
return true;
}

/**
* Conditional Branch
*/
Expand Down Expand Up @@ -1944,6 +1977,30 @@ bool Game_Interpreter_Map::CommandConditionalBranch(RPG::EventCommand const& com
break;
}
break;
case 11:
// RPG Maker 2003 v1.11 features
switch (com.parameters[1]) {
case 0:
// Any savestate available
result = FileFinder::HasSavegame(*FileFinder::CreateSaveDirectoryTree());
break;
case 1:
// Is Test Play mode?
result = Player::debug_flag;
break;
case 2:
// Is ATB wait?
Output::Warning("Branch: Is ATB wait not implemented");
break;
case 3:
// Is Fullscreen active?
result = DisplayUi->IsFullscreen();
break;

}
break;
default:
Output::Warning("Branch %d unsupported", com.parameters[0]);
}

if (result)
Expand Down
4 changes: 4 additions & 0 deletions src/game_interpreter_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class Game_Interpreter_Map : public Game_Interpreter
bool CommandShowBattleAnimation(RPG::EventCommand const& com);
bool CommandChangeClass(RPG::EventCommand const& com);
bool CommandHaltAllMovement(RPG::EventCommand const& com);
bool CommandOpenLoadMenu(RPG::EventCommand const& com);
bool CommandExitGame(RPG::EventCommand const& com);
bool CommandToggleAtbMode(RPG::EventCommand const& com);
bool CommandToggleFullscreen(RPG::EventCommand const& com);

bool ContinuationOpenShop(RPG::EventCommand const& com);
bool ContinuationShowInnStart(RPG::EventCommand const& com);
Expand Down
2 changes: 2 additions & 0 deletions src/game_temp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ bool Game_Temp::shop_calling;
bool Game_Temp::inn_calling;
bool Game_Temp::name_calling;
bool Game_Temp::save_calling;
bool Game_Temp::load_calling;
bool Game_Temp::to_title;
bool Game_Temp::gameover;
bool Game_Temp::transition_processing;
Expand Down Expand Up @@ -59,6 +60,7 @@ void Game_Temp::Init() {
shop_calling = false;
name_calling = false;
save_calling = false;
load_calling = false;
to_title = false;
gameover = false;
transition_processing = false;
Expand Down
1 change: 1 addition & 0 deletions src/game_temp.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Game_Temp {
static bool inn_calling;
static bool name_calling;
static bool save_calling;
static bool load_calling;
static bool to_title;
static bool gameover;

Expand Down
1 change: 1 addition & 0 deletions src/input_buttons_desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void Input::InitButtons() {
buttons[RIGHT].push_back(Keys::L);
buttons[RIGHT].push_back(Keys::KP6);
buttons[DECISION].push_back(Keys::Z);
buttons[DECISION].push_back(Keys::Y);
buttons[DECISION].push_back(Keys::SPACE);
buttons[DECISION].push_back(Keys::RETURN);
buttons[DECISION].push_back(Keys::SELECT);
Expand Down
2 changes: 1 addition & 1 deletion src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ void Player::CreateGameObjects() {
}
else {
Player::engine |= EngineRpg2k3E;
Output::Debug("Using RPG2k3 (English release, v1.10) Interpreter");
Output::Debug("Using RPG2k3 (English release, v1.11) Interpreter");
}
}
else {
Expand Down
8 changes: 7 additions & 1 deletion src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ void Scene::MainFunction() {
switch (push_pop_operation) {
case ScenePushed:
Start();
initialized = true;
break;
case ScenePopped:
Continue();
if (!initialized) {
Start();
initialized = true;
} else {
Continue();
}
break;
default:;
}
Expand Down
7 changes: 7 additions & 0 deletions src/scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class Scene {
static std::vector<EASYRPG_SHARED_PTR<Scene> > instances;

static int push_pop_operation;

/**
* true if Start() was called. For handling the special case that two
* or more scenes are pushed. In that case only the last calls start, the
* other Continue(). This enforces calling Start().
*/
bool initialized = false;
};

#endif
12 changes: 12 additions & 0 deletions src/scene_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "audio.h"
#include "input.h"
#include "screen.h"
#include "scene_load.h"

Scene_Map::Scene_Map(bool from_save) :
from_save(from_save) {
Expand Down Expand Up @@ -170,6 +171,11 @@ void Scene_Map::Update() {
return;
}

if (Game_Temp::load_calling) {
CallLoad();
return;
}

if (Game_Temp::battle_calling) {
CallBattle();
return;
Expand Down Expand Up @@ -253,6 +259,12 @@ void Scene_Map::CallSave() {
Scene::Push(EASYRPG_MAKE_SHARED<Scene_Save>());
}

void Scene_Map::CallLoad() {
Game_Temp::load_calling = false;

Scene::Push(EASYRPG_MAKE_SHARED<Scene_Load>());
}

void Scene_Map::CallDebug() {
if (Player::debug_flag) {
Scene::Push(EASYRPG_MAKE_SHARED<Scene_Debug>());
Expand Down
1 change: 1 addition & 0 deletions src/scene_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Scene_Map: public Scene {
void CallName();
void CallMenu();
void CallSave();
void CallLoad();
void CallDebug();

boost::scoped_ptr<Spriteset_Map> spriteset;
Expand Down
54 changes: 19 additions & 35 deletions src/scene_title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,30 @@

// Headers
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "scene_title.h"
#include "async_handler.h"
#include "audio.h"
#include "bitmap.h"
#include "cache.h"
#include "filefinder.h"
#include "game_map.h"
#include "game_enemyparty.h"
#include "game_player.h"
#include "game_screen.h"
#include "game_switches.h"
#include "game_system.h"
#include "game_variables.h"
#include "graphics.h"
#include "input.h"
#include "ldb_reader.h"
#include "lmt_reader.h"
#include "main_data.h"
#include "options.h"
#include "output.h"
#include "player.h"
#include "reader_lcf.h"
#include "scene_battle.h"
#include "scene_load.h"
#include "scene_map.h"
#include "util_macro.h"
#include "window_command.h"

Scene_Title::Scene_Title() {
type = Scene::Title;
}

void Scene_Title::Start() {
if (!Player::battle_test_flag && !Player::hide_title_flag) {
if (Data::system.show_title && !Player::battle_test_flag && !Player::hide_title_flag) {
CreateTitleGraphic();
PlayTitleMusic();
}
Expand All @@ -73,7 +59,7 @@ void Scene_Title::Continue() {
}

void Scene_Title::TransitionIn() {
if (!Player::battle_test_flag) {
if (!Player::battle_test_flag && Data::system.show_title) {
Graphics::Transition(Graphics::TransitionErase, 1, true);
if (!Player::hide_title_flag) {
Graphics::Transition(Graphics::TransitionFadeIn, 32);
Expand All @@ -84,7 +70,9 @@ void Scene_Title::TransitionIn() {
}

void Scene_Title::Resume() {
command_window->SetVisible(true);
if (Data::system.show_title) {
command_window->SetVisible(true);
}
}

void Scene_Title::Suspend() {
Expand All @@ -97,6 +85,15 @@ void Scene_Title::Update() {
return;
}

if (!Data::system.show_title) {
Player::SetupPlayerSpawn();
Scene::Push(EASYRPG_MAKE_SHARED<Scene_Map>());
if (Player::debug_flag && Player::hide_title_flag) {
Scene::Push(EASYRPG_MAKE_SHARED<Scene_Load>());
}
return;
}

command_window->Update();

if (Input::IsTriggered(Input::DECISION)) {
Expand All @@ -113,23 +110,6 @@ void Scene_Title::Update() {
}
}

bool Scene_Title::CheckContinue() {
EASYRPG_SHARED_PTR<FileFinder::DirectoryTree> tree = FileFinder::CreateSaveDirectoryTree();

for (int i = 1; i <= 15; i++)
{
std::stringstream ss;
ss << "Save" << (i <= 9 ? "0" : "") << i << ".lsd";

std::string filename = FileFinder::FindDefault(*tree, ss.str());

if (!filename.empty()) {
return true;
}
}
return false;
}

void Scene_Title::CreateTitleGraphic() {
// Load Title Graphic
if (!title && !Data::system.title_name.empty()) // No need to recreate Title on Resume
Expand Down Expand Up @@ -157,7 +137,7 @@ void Scene_Title::CreateCommandWindow() {
command_window->SetY(SCREEN_TARGET_HEIGHT / 2 - command_window->GetHeight() / 2);
}
// Enable load game if available
continue_enabled = CheckContinue();
continue_enabled = FileFinder::HasSavegame(*FileFinder::CreateSaveDirectoryTree());
if (continue_enabled) {
command_window->SetIndex(1);
} else {
Expand All @@ -169,6 +149,10 @@ void Scene_Title::CreateCommandWindow() {
command_window->SetOpenAnimation(8);
}

if (Player::IsRPG2k3E() && Data::battlecommands.transparency == RPG::BattleCommands::Transparency_transparent) {
command_window->SetBackOpacity(128);
}

command_window->SetVisible(false);
}

Expand Down
8 changes: 0 additions & 8 deletions src/scene_title.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "sprite.h"
#include "window_command.h"
#include <boost/scoped_ptr.hpp>
#include <vector>

/**
* Scene Title class.
Expand All @@ -47,13 +46,6 @@ class Scene_Title : public Scene {
*/
void LoadDatabase();

/**
* Checks if there are any savegames for the game.
*
* @return true if there are any, false otherwise.
*/
bool CheckContinue();

/**
* Creates the background graphic of the scene.
*/
Expand Down

0 comments on commit 555a0b8

Please sign in to comment.