Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
Starting to update the engine to the new dialog semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
christopho authored and Christophe THIÉRY committed Feb 10, 2012
1 parent 3463fee commit d8d33ad
Show file tree
Hide file tree
Showing 22 changed files with 183 additions and 273 deletions.
8 changes: 4 additions & 4 deletions doc/map_syntax.dox
Expand Up @@ -336,7 +336,7 @@ the interaction will be started only if the hero touches the south face of the e

<tt>behavior</tt> describes what happens when the player presses the action key near this entity.
There are three possible options:
- dialog#XXX: starts a dialog with first message XXX
- dialog#XXX: starts the dialog with id XXX
- map: calls the map script (event_hero_interaction)
- item#XXX calls the script of the item XXX (event_hero_interaction)

Expand Down Expand Up @@ -462,7 +462,7 @@ A shop item is a treasure one can buy in a shop in exchange for money.

Syntax of a shop item:
@verbatim
16 layer x y entity_name treasure_name treasure_variant treasure_savegame_variable price message_id
16 layer x y entity_name treasure_name treasure_variant treasure_savegame_variable price dialog_id
@endverbatim

<tt>treasure_name</tt>, <tt>treasure_variant</tt> and <tt>treasure_savegame_variable</tt>
Expand All @@ -476,8 +476,8 @@ and is not removed from the map.

<tt>price</tt> is the number of rupees to pay to buy the item.

<tt>message_id</tt> is the id of the message to show when the player looks at the item.
The message describes the item. It is automatically followed by a dialog that asks to the player
<tt>dialog_id</tt> is the id of the dialog to show when the player looks at the item.
The dialog describes the item. It is automatically followed by a dialog that asks to the player
if he wants to buy the item.

@section conveyor_belt Conveyor belt (17)
Expand Down
21 changes: 10 additions & 11 deletions include/DialogBox.h
Expand Up @@ -79,18 +79,17 @@ class DialogBox {
// current message
KeysEffect::ActionKeyEffect action_key_effect_saved; /**< effect of the action key before starting the message sequence */
KeysEffect::SwordKeyEffect sword_key_effect_saved; /**< effect of the sword key before starting the message sequence */
MessageId first_message_id; /**< id of the first message of the current sequence */
Message *current_message; /**< the message currently shown (NULL if the dialog box is disabled) */
MessageId current_message_id; /**< id of the message currently shown */
std::map<MessageId, std::string> variables; /**< variables to display if the next messages */
std::string dialog_id; /**< id of the current dialog */
Message* current_message; /**< the message currently shown (NULL if the dialog box is disabled) */
std::map<std::string, std::string> variables; /**< variables to display in dialogs */
Script* issuer_script; /**< the script (if any) that started the current sequence of messages */

Speed speed; /**< speed of the text */
SkipMode skip_mode; /**< indicates what happens when the user tries to skip the current message */
int icon_number; /* index of the 16*16 icon displayed, or -1 if there is no icon */
bool skipped; /* true if the user has skipped the dialog */
int last_answer; /**< the answer selected in the last message sequence: 0 for the first one, 1 for the second one,
* -1 if there was no question */
* -1 if there was no question */

// graphics
Surface *dialog_surface; /**< surface where the dialog is drawn*/
Expand All @@ -106,7 +105,7 @@ class DialogBox {
Rectangle icon_dst_position; /**< destination rectangle of the icon */

void set_vertical_position(VerticalPosition vertical_position);
void show_message(const MessageId &message_id);
void show_message();
void show_next_message();
void close();

Expand All @@ -126,22 +125,22 @@ class DialogBox {
bool is_enabled();

// current message
void start_dialog(const MessageId &first_message_id, Script *issuer_script = NULL,
VerticalPosition vertical_position = POSITION_AUTO);
void start_dialog(const std::string& dialog_id, Script *issuer_script = NULL,
VerticalPosition vertical_position = POSITION_AUTO);
Speed get_speed();
void set_speed(Speed speed);
SkipMode get_skip_mode();
void set_skip_mode(SkipMode skip_mode);
int get_icon_number();
void set_icon_number(int icon_number);
bool is_letter_sound_enabled();
void set_variable(const MessageId &first_message_id, const std::string &value);
void set_variable(const MessageId &first_message_id, int value);
void set_variable(const std::string& dialog_id, const std::string &value);
void set_variable(const std::string& dialog_id, int value);
const std::string& get_variable();
int get_last_answer();
void set_last_answer(int answer);
void key_pressed(GameControls::GameKey key);
MessageId get_first_message_id();
const std::string& get_dialog_id();
bool is_finished();
bool was_skipped();
void show_all_now();
Expand Down
2 changes: 1 addition & 1 deletion include/Game.h
Expand Up @@ -118,7 +118,7 @@ class Game: public Screen {

// current game state
bool is_paused();
bool is_showing_message();
bool is_showing_dialog();
bool is_playing_transition();
bool is_showing_gameover();
bool is_suspended(); // true if at least one of the three functions above returns true
Expand Down
42 changes: 16 additions & 26 deletions include/Message.h
Expand Up @@ -21,54 +21,44 @@
#include "DialogBox.h"

/**
* @brief A message displayed in a dialog box.
* @brief Lines of text displayed in a dialog box.
*
* This class parses the message from a data file and displays it in a dialog box.
* This class displays three lines of text in a dialog box.
* A message is usually part of a sequence of several messages called a dialog.
*/
class Message {

private:

// the dialog box where this message is displayed
DialogBox *dialog_box;

// properties of the message

std::string lines[3]; // the 3 lines of the message
TextSurface *text_surfaces[3];
bool question; // is this message a question?
MessageId next_message_id; // id of the next message (or an empty string if this is the last message)
MessageId next_message_id_2;

int x;
int y;

void parse(MessageId message_id);
void set_variable(const std::string &value);

// current state of the display
DialogBox& dialog_box; /**< the dialog box where this message is displayed */
std::string lines[3]; /**< the 3 lines of text of the message */
TextSurface* text_surfaces[3]; /**< the 3 corresponding text surfaces */
bool question; /**< is this message a question? */
bool last; /**< is this message the last one of the dialog? */

unsigned int line_index; // line currently displayed (0 to 2)
unsigned int char_index; // index of the next character to show
uint32_t delay;
uint32_t next_char_date;
bool show_all;
// current state of displaying

uint32_t next_sound_date;
unsigned int line_index; /**< line currently displayed (0 to 2) */
unsigned int char_index; /**< index of the next character to show */
uint32_t delay; /**< delay between two characters in milliseconds */
uint32_t next_char_date; /**< when the next character is displayed */
uint32_t next_sound_date; /**< date of the next character sound */
bool show_all; /**< makes all text be displayed now */

void update_char_delay();
void add_character();
void set_variable(const std::string& value);

public:

// creation and destruction
Message(DialogBox *dialog_box, MessageId message_id, int x, int y);
Message(DialogBox& dialog_box, const std::string& dialog_id, int x, int y);
~Message();

// message properties
bool is_question();
MessageId get_next_message_id();

// message current state
bool is_finished();
Expand Down
5 changes: 0 additions & 5 deletions include/Types.h
Expand Up @@ -60,11 +60,6 @@ typedef std::string SoundId;
*/
typedef std::string SpriteAnimationSetId;

/**
* @brief Type of the id of messages.
*/
typedef std::string MessageId;

// declaration of all classes to avoid dependencies between the header files

// main classes
Expand Down
4 changes: 2 additions & 2 deletions include/entities/Door.h
Expand Up @@ -47,8 +47,8 @@ class Door: public Detector {

private:

static const std::string animations[]; /**< sprite animation name of each subtype */
static const MessageId key_required_message_ids[]; /**< id of the message shown for each subtype */
static const std::string animations[]; /**< sprite animation name of each subtype */
static const std::string key_required_dialog_ids[]; /**< id of the dialog shown for each subtype */

// properties
Subtype subtype; /**< subtype of door */
Expand Down
7 changes: 4 additions & 3 deletions include/entities/NPC.h
Expand Up @@ -67,16 +67,17 @@ class NPC: public Detector {

Subtype subtype; /**< subtpype of NPC */
Behavior behavior; /**< type of action done when the player interacts with this entity */
MessageId message_to_show; /**< message to show when an interaction occurs, or an empty string */
std::string dialog_to_show; /**< dialog to show when an interaction occurs, or an empty string */
Script* script_to_call; /**< map script or item script to call when an interaction occurs, or NULL */

void initialize_sprite(SpriteAnimationSetId& sprite_name, int initial_direction);
void call_script_hero_interaction();

public:

NPC(Game& game, const std::string& name, Layer layer, int x, int y, Subtype subtype,
SpriteAnimationSetId sprite_name, int initial_direction, const std::string& behavior_string);
NPC(Game& game, const std::string& name, Layer layer, int x, int y,
Subtype subtype, SpriteAnimationSetId sprite_name,
int initial_direction, const std::string& behavior_string);
~NPC();
static CreationFunction parse;

Expand Down
10 changes: 5 additions & 5 deletions include/entities/ShopItem.h
Expand Up @@ -36,7 +36,7 @@ class ShopItem: public Detector {
// data
Treasure treasure; /**< the treasure the player can buy */
int price; /**< the treasure's price in rupees */
MessageId message_id; /**< id of the message describing the shop item */
std::string dialog_id; /**< id of the dialog describing the shop item */

// displaying
TextSurface *price_digits; /**< the digits that show the price */
Expand All @@ -46,14 +46,14 @@ class ShopItem: public Detector {
bool is_looking_item; /**< indicates that the message describing the item is being shown */
bool is_asking_question; /**< indicates that the buy question is being shown */

ShopItem(const std::string &name, Layer layer, int x, int y,
const Treasure &treasure, int price, const MessageId &message_id);
ShopItem(const std::string& name, Layer layer, int x, int y,
const Treasure& treasure, int price, const std::string& dialog_id);

public:

~ShopItem();
static ShopItem* create(Game &game, const std::string &name, Layer layer, int x, int y,
const Treasure &treasure, int price, const MessageId &message_id);
static ShopItem* create(Game& game, const std::string& name, Layer layer, int x, int y,
const Treasure& treasure, int price, const std::string& dialog_id);
static CreationFunction parse;

EntityType get_type();
Expand Down
2 changes: 1 addition & 1 deletion include/hud/HUD.h
Expand Up @@ -31,7 +31,7 @@ class HUD {
int nb_elements;
HudElement *elements[16];

bool showing_message;
bool showing_dialog;

void update_blinking();

Expand Down
7 changes: 4 additions & 3 deletions include/lua/Script.h
Expand Up @@ -383,10 +383,11 @@ class Script {
bool has_played_music();

void event_map_changed(Map &map);
void event_dialog_started(const MessageId &message_id);
void event_dialog_finished(const MessageId &first_message_id, int answer);
void event_dialog_started(const std::string& dialog_id);
void event_dialog_finished(const std::string& dialog_id, int answer);
void event_npc_interaction(const std::string& npc_name);
bool event_npc_interaction_item(const std::string& npc_name, const std::string& item_name, int variant);
bool event_npc_interaction_item(const std::string& npc_name,
const std::string& item_name, int variant);
void event_npc_collision_fire(const std::string &npc_name);

void do_callback(int callback_ref);
Expand Down
2 changes: 1 addition & 1 deletion src/DebugKeys.cpp
Expand Up @@ -192,7 +192,7 @@ void DebugKeys::update() {

#ifdef SOLARUS_DEBUG_KEYS
if (InputEvent::is_shift_down()) {
if (game != NULL && game->is_showing_message()) {
if (game != NULL && game->is_showing_dialog()) {
game->get_dialog_box().show_all_now();
}
}
Expand Down

0 comments on commit d8d33ad

Please sign in to comment.