| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include <OgreSingleton.h>
- #include "UiManager.h"
- #include "UiTextArea.h"
- /**
- * Possible states for messages.
- */
- enum MessageState{
- /**
- * The message is now closed.
- */
- MS_CLOSED,
- /**
- * The message window is shown, but there is no text.
- */
- MS_SHOW_WINDOW,
- /**
- * The message window and text are shown.
- */
- MS_SHOW_TEXT,
- /**
- * The message window is open.
- */
- MS_OPENED,
- /**
- * The message window has been hidden.
- */
- MS_HIDE_WINDOW
- };
- /**
- * Styles for message boxes.
- */
- enum MessageStyle{
- /**
- * Regular message box, solid background.
- */
- MSL_SOLID,
- /**
- * Translucent message box.
- */
- MSL_TRANSPARENT,
- /**
- * No message box.
- */
- MSL_NONE
- };
- /**
- * Message data.
- */
- struct MessageData{
- MessageData():
- widget(NULL),
- window(NULL),
- scissor(NULL),
- text_area(NULL),
- cursor(NULL),
- state(MS_CLOSED),
- clickable(true),
- show_window(true),
- show_cursor(false),
- auto_close(false),
- cursor_percent_y(0),
- cursor_y(0),
- cursor_row_selected(0),
- cursor_row_current(0),
- cursor_row_first(0),
- cursor_row_last(0),
- closeable(true),
- visible(true),
- translucent(false),
- timer(false),
- numeric(false)
- {}
- /**
- * The widget where the message is displayed.
- */
- UiWidget* widget;
- /**
- * The window where the message is displayed.
- */
- UiWidget* window;
- /**
- * @todo Understand and document.
- */
- UiWidget* scissor;
- /**
- * The message text area.
- */
- UiTextArea* text_area;
- /**
- * The message cursor.
- */
- UiWidget* cursor;
- /**
- * The state of the message.
- */
- MessageState state;
- /**
- * The message window X coordinate.
- */
- int x = 0;
- /**
- * The message window Y coordinate.
- */
- int y = 0;
- /**
- * The message width, in pixels.
- */
- int w = 0;
- /**
- * The message height, in pixels.
- */
- int h = 0;
- /**
- * @todo Understand and document.
- */
- std::vector<ScriptId> sync;
- /**
- * Indicates if the text is 'clickable', i.e., if it requieres a keypress
- * to advance.
- */
- bool clickable;
- /**
- * Indicates if the dialog window is shown.
- */
- bool show_window;
- /**
- * Indicates if the choice selection cursor must be shown.
- */
- bool show_cursor;
- /**
- * Indicates if the dialog must be closed automatically.
- */
- bool auto_close;
- /**
- * @todo Understand and document.
- */
- float cursor_percent_y;
- /**
- * Y position of the cursor in the message box.
- */
- float cursor_y;
- /**
- * Selected choice line.
- */
- int cursor_row_selected;
- /**
- * Currently selected choice line.
- */
- int cursor_row_current;
- /**
- * First chooseable line.
- */
- int cursor_row_first;
- /**
- * Last chooseable line.
- */
- int cursor_row_last;
- /**
- * Indicates if the window is closeable.
- */
- bool closeable;
- /**
- * Indicates if the window background is visible.
- */
- bool visible;
- /**
- * Indicates if the window background is translucent.
- */
- bool translucent;
- /**
- * Indicates if the window is for a timer.
- */
- bool timer;
- /**
- * Indicates if the window background is for a number.
- */
- bool numeric;
- };
- /**
- * The dialog manager.
- */
- class DialogsManager : public Ogre::Singleton<DialogsManager>{
- public:
- /**
- * Constructor.
- */
- DialogsManager();
- /**
- * Destructor.
- */
- virtual ~DialogsManager();
- /**
- * Initializes the dialog manager.
- */
- void Initialise();
- /**
- * Processes an input event.
- *
- * @param[in] event Event to process.
- */
- void Input(const VGears::Event& event);
- /**
- * Updates all the messages in the manager.
- */
- void Update();
- /**
- * Hides every dialog in the manager.
- */
- void Clear();
- /**
- * Opens a dialog.
- *
- * Equivalent to dialog_open in the field scripts.
- *
- * @param[in] d_name The dialog name. Can be used as ID.
- * @param[in] x X coordinate for the top left corner of the dialog.
- * @param[in] y Y coordinate for the top left corner of the dialog.
- * @param[in] w Width of the dialog, in pixels.
- * @param[in] h Height of the dialog, in pixels.
- */
- void OpenDialog(const char* d_name, int x, int y, int w, int h);
- /**
- * Sets the text of a dialog.
- *
- * Equivalent to dialog_set_text in the field scripts.
- *
- * @param[in] d_name Name of the dialog.
- * @param[in] text Text to set in the dialog.
- */
- void SetText(const char* d_name, const char* text);
- /**
- * Sets or unsets a dialog window as numeric
- *
- * @param[in] d_name Name of the dialog.
- * @param[in] numeric True to make it numeric, false otherwise.
- * @param[in] timer True to use the window for times, false for regular numbers. If used
- * for timer, the window will be used when calling {@see UpdateTimer}
- */
- void SetNumeric(const char* d_name, const bool numeric, const bool timer);
- /**
- * Updates the timer.
- *
- * Displays the formatted time in the timer window. To do so, a timer window must have been
- * set as timer with {@see SetNumeric}
- */
- void UpdateTimer(const unsigned int seconds);
- /**
- * Sets the window mode.
- *
- * @param[in] d_name Name of the dialog.
- * @param[in] bg Background mode. 1: No background/border. 2: Translucent background.
- * Anything else: Normal.
- * @param[in] closeable True if the window can be closed manually, false to lock it.
- */
- void SetMode(const char* d_name, const int bg, const bool closeable);
- /**
- * Syncs the dialog and makes the script wait until it is closed.
- *
- * Equivalent to dialog_wait_for_close in the field scripts.
- *
- * @param[in] d_name Name of the dialog.
- * @return 1 if the dialog doesn't exist, -1 otherwise.
- */
- int Sync(const char* d_name);
- /**
- * Closes and hides a dialog window.
- *
- * Equivalent to dialog_close in the field scripts.
- *
- * @param[in] d_name Name of the dialog to close.
- */
- void Hide(const char* d_name);
- /**
- * Sets a variable in a dialog
- *
- * @param[in] d_name Name of the dialog.
- * @param[in] name Name of the variable.
- * @param[in] value Value for the variable.
- */
- void SetVariable(
- const char* d_name, const char* name, const char* value
- );
- /**
- * Makes the dialog clickable or not.
- *
- * A clickable dialog presents a choice for the user that must be
- * selected with a cursor.
- *
- * @param[in] d_name Name of the dialog.
- * @param[in] clickable True to make the dialog clickable, false to
- * make it unclickable
- */
- void SetClickable(const char* d_name, const bool clickable);
- /**
- * Sets a choice sursor in the dialog.
- *
- * @param[in] d_name Name of the dialog.
- * @param[in] first_row First selectable line.
- * @param[in] last_row Last selectable line.
- */
- void SetCursor(
- const char* d_name, const int first_row, const int last_row
- );
- /**
- * Gets the cursor position in a dialog.
- *
- * @param[in] d_name Dialog name.
- * @return Position of the cursor in the dialog, including unselectable
- * lines (0-index). 0 if the dialog doesn't exist.
- */
- int GetCursor(const char* d_name) const;
- /**
- * Sets the map name from a text ID.
- *
- * @param[in] text_id The ID of the text to set as map name.
- */
- void ScriptSetMapName(const char* text_id);
- /**
- * Sets the map name from a text ID.
- *
- * @param[in] name The new map name.
- */
- void SetMapName(std::string name);
- /**
- * Retrieves the current map name.
- *
- * @return The map name.
- */
- std::string GetMapName();
- private:
- /**
- * Shows a message in a dialog.
- *
- * @param[in] id Message id.
- * @param[in] x X coordinate for the text in the dialog.
- * @param[in] y Y coordinate for the text in the dialog.
- * @param[in] width Width of the text, in pixels.
- * @param[in] height Height of the text, in pixels.
- * @todo Is this a window-limit-aware version of SetText?
- */
- void ShowMessage(
- const int id, const int x, const int y,
- const int width, const int height
- );
- /**
- * Closes and hides a message.
- *
- * @param[in] id ID of the message to close.
- */
- void HideMessage(const int id);
- /**
- * Retrieves a message Id from it's name.
- *
- * @param[in] d_name Dialog name.
- * @return The dialog ID. -1 if there is no dialog by that name.
- */
- int GetMessageId(const char* d_name) const;
- /**
- * Checks if a message is set to close automatically.
- *
- * @param[in] id Message ID.
- * @return True if the message is set to auto close, false otherwise.
- */
- bool AutoCloseCheck(const unsigned int id);
- /**
- * The limit area for message boxes.
- */
- UiWidget* limit_area_;
- /**
- * The list of messages.
- */
- std::vector<MessageData*> messages_;
- /**
- * Indicates if the 'next' button has been pressed.
- */
- bool next_pressed_;
- /**
- * Indicates if the 'next' button is being hold.
- */
- bool next_repeated_;
- /**
- * Indicates if the 'up' button has been pressed.
- */
- bool up_pressed_;
- /**
- * Indicates if the 'down' button has been pressed.
- */
- bool down_pressed_;
- /**
- * Current map name.
- */
- std::string map_name_;
- /**
- * The ID of the window that contains the timer, is any
- */
- int timer_window_id_;
- /**
- * The number of seconds in the timer.
- *
- * Stored solely to not re-set the text if the time is the same.
- */
- unsigned int timer_seconds_;
- };
|