diff --git a/.gitignore b/.gitignore index 9a949cb..9d5dcdb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,22 @@ base_override.h base-full/ bass.lib + +bins/ +release/ +debug/ + +.qmake.stash + +Makefile* +object_script* +/Attorney_Online_remake_resource.rc +/attorney_online_remake_plugin_import.cpp + +server/__pycache__ +discord/ + +*.o +moc* +/Attorney_Online_CC_resource.rc +/attorney_online_cc_plugin_import.cpp diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 86a8607..2e8a5f8 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -5,15 +5,14 @@ #------------------------------------------------- QT += core gui multimedia network - greaterThan(QT_MAJOR_VERSION, 4): QT += widgets RC_ICONS = logo.ico -TARGET = Attorney_Online_remake +TARGET = Attorney_Online TEMPLATE = app -VERSION = 2.4.10.0 +VERSION = 2.6.0.0 SOURCES += main.cpp\ lobby.cpp \ @@ -48,7 +47,10 @@ SOURCES += main.cpp\ aolineedit.cpp \ aotextedit.cpp \ aoevidencedisplay.cpp \ - discord_rich_presence.cpp + discord_rich_presence.cpp \ + aooptionsdialog.cpp \ + chatlogpiece.cpp \ + aocaseannouncerdialog.cpp HEADERS += lobby.h \ aoimage.h \ @@ -78,18 +80,36 @@ HEADERS += lobby.h \ aotextedit.h \ aoevidencedisplay.h \ discord_rich_presence.h \ - discord-rpc.h + discord-rpc.h \ + aooptionsdialog.h \ + text_file_functions.h \ + chatlogpiece.h \ + aocaseannouncerdialog.h -# You need to compile the Discord Rich Presence SDK separately and add the lib/headers. -# Discord RPC uses CMake, which does not play nicely with QMake, so this step must be manual. - -unix:LIBS += -L$$PWD -ldiscord-rpc -win32:LIBS += -L$$PWD -ldiscord-rpc #"$$PWD/discord-rpc.dll" +# 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder +# AND the compilation output folder. If you are compiling statically, you'll probably +# need the .lib file too. MinGW-GCC is really finicky finding BASS, it seems. However, +# even with the .lib file, you still need the DLL in the final output. +# 2. You need to compile the Discord Rich Presence SDK separately and add the lib/headers +# in the same way as BASS. Discord RPC uses CMake, which does not play nicely with +# QMake, so this step must be manual. If you are compiling dynamically, it's fine to +# use the prebuilt libraries. +# 3. You also need to build QtApng (https://github.com/Skycoder42/QtApng). +# Optionally, you may install it in /usr/share/qt5/plugins/imageformats, but if you do +# so, then you must patch qapng.pri, qapngd.pri, png.pri, pngd.pri, z.pri, and zd.pri +# such that they no longer point to the builds in the original project directory +# (by removing those respective entries in QMAKE_PRL_LIBS and replacing them with +# something like `-L$$[QT_INSTALL_LIBS] -lpng -lz`). +# +# Naturally, the build process becomes significantly less convoluted if you simply +# compile dynamically. If your primary distribution method is via the launcher, then +# a simple dynamic compilation is recommended. +unix:LIBS += -L$$PWD -lbass -ldiscord-rpc +win32:LIBS += -L$$PWD "$$PWD/bass.dll" -ldiscord-rpc +INCLUDEPATH += $$PWD/include CONFIG += c++11 -ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android - RESOURCES += \ resources.qrc diff --git a/LICENSE.MIT b/LICENSE.MIT index 5197aaa..65d3853 100644 --- a/LICENSE.MIT +++ b/LICENSE.MIT @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 David Skoland, oldmud0 +Copyright (c) 2018 David Skoland, oldmud0, Cerapter Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 569b6b2..5e6adb2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,232 @@ -# Attorney-Online-Client-Remake +# Attorney Online 2 + +[Attorney Online](https://aceattorneyonline.com) is an online version of the world-renowned courtroom drama simulator that allows you to create and play out cases in an off-the-cuff format. + +## Introduction for beginners + +You may already be familiar with roleplaying in forums, Roll20, and/or [AAO](http://aaonline.fr/) (the online casemaker). In this sense, Attorney Online is nothing more than a medium - an animated chatroom client - that allows cases to be played out as if it were an Ace Attorney game. + +Not unlike other roleplaying games, cases can last an absurd amount of time (between 4 to 6 hours) and generally follow a roleplaying format directed by a case sheet. + +An implied expectation for fast typing and real-time communication may seem daunting at first, but due to the number of people in the courtroom, things get hectic very quickly even with only a few people talking. Therefore, you should not feel pressured to talk constantly: only when you have the attention of the court (or when you have an objection to make) should you feel the need to speak. + +It is recommended, but not strictly necessary, to have played an Ace Attorney game before creating your own case. You should also try to spectate or take part in a community case in order to get a grasp of how cases are done in practice. + +--- + +## Basic features + +### In-character chat + +Type in a message in the gray box under the viewport, select an emote, and press Enter. + +### Emotes + +An emote represents a set of animations played while the character is speaking and idle. Some emotes also contain a preanimation, which is played before the text is said by the character. + +### Interjections (shouts) + +Select an interjection to toggle it. When you send a message, it will interrupt all other dialogue and interject with your message. + +### Out-of-character chat + +This is a general-purpose chat isolated within areas to discuss matters without interrupting cases. You must enter a name before chatting. + +### Music list + +Double-click a track to play it. Some servers automatically loop the track. Green tracks are available locally; red tracks are not. + +### Areas + +Servers have multiple areas to hold multiple cases simultaneously. Double-click an area in the music list to switch to it. (The reason that +areas are in the music list is a historical one.) + +### Judge controls + +The judge can set health bars and play the Witness Testimony, Cross Examination, Guilty, and Not Guilty animations. + +### Mod calls + +Calling a mod notifies moderators currently in the server of an incident. (Mod call reasons require 2.6+ server-side support.) Logged-in moderators can toggle the Guard option to be notified of mod calls. + +### Muting + +Click on a character in the mute list to ignore any in-character chat from the specified character. + +### Positions + +All characters have a default position within the courtroom, but they can nonetheless be changed within the interface. + +Available positions: + +- `def` - Defense +- `pro` - Prosecution +- `hld` - Helper defense +- `hlp` - Helper prosecution +- `jud` - Judge +- `wit` - Witness +- `jur` - Juror (2.6+) +- `sea` - Seance (2.6+) + +## Advanced features + +### Markup language + +2.6.0 introduces a markup language for in-character chat. It does not require server-side support. + +#### Color + +Wrapping text with these characters will set the text inside of them to the associated color. + +- `(` and `)` (parentheses) - blue +- \` (backtick) - green +- `|` (vertical bar) - orange +- `[` and `]` (square brackets) - grey + +#### Speed + +Type `{` to slow down the text a bit, and `}` to speed it up. This takes effect after the character has been typed, so the text may take up different speeds at different points. Both of these can be stacked up to three times, and even against each other. + +Example: +``` +Hello there! This text goes at normal speed.} Now, it's a bit faster!{ Now, it's back to normal.}}} Now it goes at maximum speed! {{Now it's only a little bit faster than normal. +``` + +#### Position + +If you begin a message with `~~` (two tildes), the two tildes are removed and the message is centered. + +### Pairing (2.6+) + +If two players are in the same position and select each other's characters using the in-game pair list (or with `/pair [id]`), they will appear alongside each other. You can set the offset of your character using the provided spinbox (or with `/offset [percentage]`). + +### Non-interrupting preanimations (2.6+) + +When checked, this will force text to immediately begin displaying without waiting for the preanimation to finish. + +### Custom IC names (shownames) (2.6+) + +You can set a custom in-character name using the provided text box. An option in the interface (or `/force_nonint_pres`) is also present to disable custom IC names for other players to prevent impersonation. + +### Extended area support (2.6+) + +Areas can be listed by clicking the A/M button (or `/switch_am`). The statuses of such areas are displayed (and updated automatically) if the server has 2.6+ support. + +--- + +## Upgrade guide for 2.6 + +2.6 inherits features from the Case Café custom client and server. Old themes and servers will still work, but they will not expose the new additions to players. + +### Server + +2.6 support has only been developed for tsuserver3. serverD is currently not equipped at all for such support. + +- Apply the new code changes. +- In `areas.yaml`: + - You may add `shouts_allowed` to any of the areas to enable / disable shouts (and judge buttons, and realisation). By default, it's `shouts_allowed: true`. + - You may add `jukebox` to any of the areas to enable the jukebox in there, but you can also use `/jukebox_toggle` in game as a mod to do the same thing. By default, it's `jukebox: false`. + - You may add `showname_changes_allowed` to any of the areas to allow custom shownames used in there. If it's forbidden, players can't send messages or change music as long as they have a custom name set. By default, it's `showname_changes_allowed: false`. + - You may add `abbreviation` to override the server-generated abbreviation of the area. Instead of area numbers, this server-pack uses area abbreviations in server messages for easier understanding (but still uses area IDs in commands, of course). No default here, but here is an example: `abbreviation: SIN` gives the area the abbreviation of 'SIN'. + - You may add `noninterrupting_pres` to force users to use non-interrupting pres only. 2.6 users will see the pres play as the text goes; pre-2.6 users will not see pres at all. The default is `noninterrupting_pres: false`. + +### Client themes + +- You'll need the following, additional images: + - `notguilty.gif` - Not Guilty verdict animation + - `guilty.gif` - Guilty verdict animation + - `notguilty.png` - Not Guilty button + - `guilty.png` - Guilty button + - `pair_button.png` - Pair button + - `pair_button_pressed.png` - Pair button (selected) +- In your `courtroom_sounds.ini`: + - Add a sound effect for `not_guilty`, for example: `not_guilty = sfx-notguilty.wav`. + - Add a sound effect for `guilty`, for example: `guilty = sfx-guilty.wav`. + - Add a sound effect for the case alerts. They work similarly to modcall alerts, or callword alerts. For example: `case_call = sfx-triplegavel-soj.wav`. +- In your `courtroom_design.ini`, place the following new UI elements as desired: + - `log_limit_label`, which is a simple text that explains what the spinbox with the numbers is. Needs an X, Y, width, height number. + - `log_limit_spinbox`, which is the spinbox for the log limit, allowing you to set the size of the log limit in-game. Needs the same stuff as above. + - `ic_chat_name`, which is an input field for your custom showname. Needs the same stuff. + - `ao2_ic_chat_name`, which is the same as above, but comes into play when the background has a desk. + - Further comments on this: all `ao2_` UI elements come into play when the background has a desk. However, in AO2 nowadays, it's customary for every background to have a desk, even if it's just an empty gif. So you most likely have never seen the `ao2_`-less UI elements ever come into play, unless someone mis-named a desk or something. + - `showname_enable` is a tickbox that toggles whether you should see shownames or not. This does not influence whether you can USE custom shownames or not, so you can have it off, while still showing a custom showname to everyone else. Needs X, Y, width, height as usual. + - `settings` is a plain button that takes up the OS's looks, like the 'Call mod' button. Takes the same arguments as above. + - You can also just type `/settings` in OOC. + - `char_search` is a text input box on the character selection screen, which allows you to filter characters down to name. Needs the same arguments. + - `char_passworded` is a tickbox, that when ticked, shows all passworded characters on the character selection screen. Needs the same as above. + - `char_taken` is another tickbox, that does the same, but for characters that are taken. + - `not_guilty` is a button similar to the CE / WT buttons, that if pressed, plays the Not Guilty verdict animation. Needs the same arguments. + - `guilty` is similar to `not_guilty`, but for the Guilty verdict. + - `pair_button` is a toggleable button, that shows and hides the pairing list and the offset spinbox. Works similarly to the mute button. + - `pair_list` is a list of all characters in alphabetical order, shown when the user presses the Pair button. If a character is clicked on it, it is selected as the character the user wants to pair up with. + - `pair_offset_spinbox` is a spinbox that allows the user to choose between offsets of -100% to 100%. + - `switch_area_music` is a button with the text 'A/M', that toggles between the music list and the areas list. Though the two are different, they are programmed to take the same space. + - `pre_no_interrupt` is a tickbox with the text 'No Intrpt', that toggles whether preanimations should delay the text or not. + - `area_free_color` is a combination of red, green, and blue values ranging from 0 to 255. This determines the colour of the area in the Area list if it's free, and has a status of `IDLE`. + - `area_lfp_color` determines the colour of the area if its status is `LOOKING-FOR-PLAYERS`. + - `area_casing_color` determines the colour of the area if its status is `CASING`. + - `area_recess_color` determines the colour of the area if its status is `RECESS`. + - `area_rp_color` determines the colour of the area if its status is `RP`. + - `area_gaming_color` determines the colour of the area if its status is `GAMING`. + - `area_locked_color` determines the colour of the area if it is locked, regardless of status. + - `ooc_default_color` determines the colour of the username in the OOC chat if the message doesn't come from the server. + - `ooc_server_color` determines the colour of the username if the message arrived from the server. + - `casing_button` is a button with the text 'Casing' that when clicked, brings up the Case Announcements dialog. You can give the case a name, and tick whom do you want to alert. You need to be a CM for it to go through. Only people who have at least one of the roles ticked will get the alert. + - `casing` is a tickbox with the text 'Casing'. If ticked, you will get the case announcements alerts you should get, in accordance to the above. In the settings, you can change your defaults on the 'Casing' tab. (That's a buncha things titled 'Casing'!) + +--- + +## Compiling + +The traditional route is by undergoing the [AO2 Rite of Passage](https://gist.github.com/oldmud0/6c645bd1667370c3e92686f7d0642c38). Recently, however, it has become more feasible to get away with a dynamic compilation, which is much easier for beginners and requires less setup. + +### Dependencies + +- [QtApng](https://github.com/Skycoder42/QtApng) +- [BASS](http://un4seen.com) (proprietary, but will become optional in the future; see #35) +- [Discord Rich Presence](https://github.com/discordapp/discord-rpc) + +## Release instructions + +Follow these steps to make a new full release: + +- Set a new AO version in the `.pro` file and in `aoapplication.h`. +- Compile the project. +- Commit the version bump and and create a tag for the commit. +- Rename the executable to `Attorney_Online`. +- Create a temp directory. +- Copy a fresh `base` folder to the temp dir. Ensure that the timestamps are consistent. + - Ignore this step if creating a client-only release. +- Copy the repository's `base` folder to the temp dir. +- Append `.sample` to the names of all `.ini` files, including `serverlist.txt`. +- Copy the game executable to the temp dir. +- Copy `bass.dll`, `discord-rpc.dll`, and `qapng.dll` if applicable. +- Copy `README.md` as `README.md.txt` with CRLF line endings. +- Copy `LICENSE` as `LICENSE.txt` with CRLF line endings. +- Compress the contents of the temp dir to an archive with maximum compression, but + be sure that the contents are placed inside the root directory of the archive and not + within a subdirectory. +- Compute the SHA-1 hash of the archive. +- Upload the archive to the Wasabi bucket and an additional mirror (e.g. MEGA or OneDrive) + (if this is a full release). +- Publish a GitHub release and upload the archive there (if this is a client-only release). +- Add the new version to the `program.json` manifest for the respective platform + (if this is a client-only release). +- Update the following on the website for the respective platform: + - Full download links (Wasabi and mirror) + - Client download link + - Full download hash + - Client download hash + +Repeat for each platform (currently 32-bit Windows and 64-bit Linux). Once you're done, don't forget to announce your release! + +## Credits + This is a open-source remake of Attorney Online written by OmniTroid. The original Attorney Online client was written by FanatSors in Delphi. The logo (`logo.png` and `logo.ico`) was designed by Lucas Carbi. The characters depicted in the logo are owned by Capcom. -## License +### Project The project is dual-licensed; you are free to copy, modify and distribute AO2 under the GPLv3 or the MIT license. @@ -11,7 +234,16 @@ Copyright (c) 2016-2018 David "OmniTroid" Skoland Modifications copyright (c) 2017-2018 oldmud0 -## Qt +Case Café additions copyright (c) 2018 Cerapter + +### Qt + This project uses Qt 5, which is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.txt) with [certain licensing restrictions and exceptions](https://www.qt.io/qt-licensing-terms/). To comply with licensing requirements for static linking, object code is available if you would like to relink with an alternative version of Qt, and the source code for Qt may be found at https://github.com/qt/qtbase, http://code.qt.io/cgit/, or at https://qt.io. Copyright (c) 2016 The Qt Company Ltd. + +### BASS + +This project depends on the BASS shared library. Get it here: http://www.un4seen.com/ + +Copyright (c) 1999-2016 Un4seen Developments Ltd. All rights reserved. diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml deleted file mode 100644 index f458c6a..0000000 --- a/android/AndroidManifest.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/android/project.properties b/android/project.properties deleted file mode 100644 index a08f37e..0000000 --- a/android/project.properties +++ /dev/null @@ -1 +0,0 @@ -target=android-21 \ No newline at end of file diff --git a/aoapplication.cpp b/aoapplication.cpp index 62a4a39..cb98aef 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -5,8 +5,14 @@ #include "networkmanager.h" #include "debug_functions.h" +#include "aooptionsdialog.h" +#include "aocaseannouncerdialog.h" + AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { + // Create the QSettings class that points to the config.ini. + configini = new QSettings(get_base_path() + "config.ini", QSettings::IniFormat); + net_manager = new NetworkManager(this); discord = new AttorneyOnline::Discord(); QObject::connect(net_manager, SIGNAL(ms_connect_finished(bool, bool)), @@ -36,7 +42,7 @@ void AOApplication::construct_lobby() int y = (screenGeometry.height()-w_lobby->height()) / 2; w_lobby->move(x, y); - if(is_discord_enabled()) + if (is_discord_enabled()) discord->state_lobby(); w_lobby->show(); @@ -151,8 +157,9 @@ void AOApplication::ms_connect_finished(bool connected, bool will_retry) { if (will_retry) { - w_lobby->append_error("Error connecting to master server. Will try again in " - + QString::number(net_manager->ms_reconnect_delay_ms / 1000.f) + " seconds."); + if (w_lobby != nullptr) + w_lobby->append_error("Error connecting to master server. Will try again in " + + QString::number(net_manager->ms_reconnect_delay_ms / 1000.f) + " seconds."); } else { @@ -164,3 +171,15 @@ void AOApplication::ms_connect_finished(bool connected, bool will_retry) } } } + +void AOApplication::call_settings_menu() +{ + AOOptionsDialog settings(nullptr, this); + settings.exec(); +} + +void AOApplication::call_announce_menu(Courtroom *court) +{ + AOCaseAnnouncerDialog announcer(nullptr, this, court); + announcer.exec(); +} diff --git a/aoapplication.h b/aoapplication.h index f69a0ea..f420733 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -8,10 +8,21 @@ #include #include #include +#include + #include #include #include +#include + +#include +#include + +#include +#include +#include + class NetworkManager; class Lobby; class Courtroom; @@ -44,6 +55,9 @@ public: void send_ms_packet(AOPacket *p_packet); void send_server_packet(AOPacket *p_packet, bool encoded = true); + void call_settings_menu(); + void call_announce_menu(Courtroom *court); + /////////////////server metadata////////////////// unsigned int s_decryptor = 5; @@ -56,6 +70,10 @@ public: bool improved_loading_enabled = false; bool desk_mod_enabled = false; bool evidence_enabled = false; + bool cccc_ic_support_enabled = false; + bool arup_enabled = false; + bool casing_alerts_enabled = false; + bool modcall_reason_enabled = false; ///////////////loading info/////////////////// @@ -66,6 +84,7 @@ public: int char_list_size = 0; int loaded_chars = 0; + int generated_chars = 0; int evidence_list_size = 0; int loaded_evidence = 0; int music_list_size = 0; @@ -75,9 +94,9 @@ public: //////////////////versioning/////////////// - int get_release() {return RELEASE;} - int get_major_version() {return MAJOR_VERSION;} - int get_minor_version() {return MINOR_VERSION;} + constexpr int get_release() const { return RELEASE; } + constexpr int get_major_version() const { return MAJOR_VERSION; } + constexpr int get_minor_version() const { return MINOR_VERSION; } QString get_version_string(); /////////////////////////////////////////// @@ -98,21 +117,22 @@ public: //implementation in path_functions.cpp QString get_base_path(); QString get_data_path(); - QString get_theme_path(); - QString get_default_theme_path(); - QString get_character_path(QString p_character); - QString get_demothings_path(); - QString get_sounds_path(); + QString get_theme_path(QString p_file); + QString get_default_theme_path(QString p_file); + QString get_custom_theme_path(QString p_theme, QString p_file); + QString get_character_path(QString p_char, QString p_file); + QString get_sounds_path(QString p_file); QString get_music_path(QString p_song); - QString get_background_path(); - QString get_default_background_path(); - QString get_evidence_path(); + QString get_background_path(QString p_file); + QString get_default_background_path(QString p_file); + QString get_evidence_path(QString p_file); + QString get_case_sensitive_path(QString p_file); ////// Functions for reading and writing files ////// // Implementations file_functions.cpp - //Returns the config value for the passed searchline from a properly formatted config ini file - QString read_config(QString searchline); + // Instead of reinventing the wheel, we'll use a QSettings class. + QSettings *configini; //Reads the theme from config.ini and loads it into the current_theme variable QString read_theme(); @@ -135,11 +155,26 @@ public: //Returns the value of default_blip in config.ini int get_default_blip(); - //Returns true if discord is enabled in config.ini and false otherwise + // Returns the value of whether Discord should be enabled on startup + // from the config.ini. bool is_discord_enabled(); - //Returns true if reverse IC is enabled in config.ini and false otherwise - bool ic_scroll_down_enabled(); + // Returns the value of the maximum amount of lines the IC chatlog + // may contain, from config.ini. + int get_max_log_size(); + + // Returns whether the log should go upwards (new behaviour) + // or downwards (vanilla behaviour). + bool get_log_goes_downwards(); + + // Returns the username the user may have set in config.ini. + QString get_default_username(); + + // Returns the audio device used for the client. + QString get_audio_output_device(); + + // Returns whether the user would like to have custom shownames on by default. + bool get_showname_enabled_by_default(); //Returns the list of words in callwords.ini QStringList get_call_words(); @@ -165,11 +200,20 @@ public: //Returns the color with p_identifier from p_file QColor get_color(QString p_identifier, QString p_file); + // Returns the colour from the misc folder. + QColor get_chat_color(QString p_identifier, QString p_chat); + //Returns the sfx with p_identifier from sounds.ini in the current theme path QString get_sfx(QString p_identifier); + //Figure out if we can opus this or if we should fall back to wav + QString get_sfx_suffix(QString sound_to_check); + + // Can we use APNG for this? If not, fall back to a gif. + QString get_image_suffix(QString path_to_check); + //Returns the value of p_search_line within target_tag and terminator_tag - QString read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag); + QString read_char_ini(QString p_char, QString p_search_line, QString target_tag); //Returns the side of the p_char character from that characters ini file QString get_char_side(QString p_char); @@ -192,6 +236,9 @@ public: //Not in use int get_text_delay(QString p_char, QString p_emote); + // Returns the custom realisation used by the character. + QString get_custom_realization(QString p_char); + //Returns the name of p_char QString get_char_name(QString p_char); @@ -222,10 +269,38 @@ public: //Returns p_char's gender QString get_gender(QString p_char); + // ====== + // These are all casing-related settings. + // ====== + + // Returns if the user has casing alerts enabled. + bool get_casing_enabled(); + + // Returns if the user wants to get alerts for the defence role. + bool get_casing_defence_enabled(); + + // Same for prosecution. + bool get_casing_prosecution_enabled(); + + // Same for judge. + bool get_casing_judge_enabled(); + + // Same for juror. + bool get_casing_juror_enabled(); + + // Same for steno. + bool get_casing_steno_enabled(); + + // Same for CM. + bool get_casing_cm_enabled(); + + // Get the message for the CM for casing alerts. + QString get_casing_can_host_cases(); + private: const int RELEASE = 2; - const int MAJOR_VERSION = 4; - const int MINOR_VERSION = 10; + const int MAJOR_VERSION = 6; + const int MINOR_VERSION = 0; QString current_theme = "default"; diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index 5e3929e..74757c5 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -2,32 +2,46 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { - m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; } -AOBlipPlayer::~AOBlipPlayer() -{ - m_sfxplayer->stop(); - m_sfxplayer->deleteLater(); -} - void AOBlipPlayer::set_blips(QString p_sfx) { - m_sfxplayer->stop(); - QString f_path = ao_app->get_sounds_path() + p_sfx.toLower(); - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + QString f_path = ao_app->get_sounds_path(p_sfx); + + for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + { + BASS_StreamFree(m_stream_list[n_stream]); + + m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); + } + set_volume(m_volume); } void AOBlipPlayer::blip_tick() { - m_sfxplayer->play(); + int f_cycle = m_cycle++; + + if (m_cycle == 5) + m_cycle = 0; + + HSTREAM f_stream = m_stream_list[f_cycle]; + + if (ao_app->get_audio_output_device() != "default") + BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); + BASS_ChannelPlay(f_stream, false); } void AOBlipPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + + float volume = p_value / 100.0f; + + for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + { + BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); + } } diff --git a/aoblipplayer.h b/aoblipplayer.h index c8a8cb6..aebba77 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -1,18 +1,17 @@ #ifndef AOBLIPPLAYER_H #define AOBLIPPLAYER_H +#include "bass.h" #include "aoapplication.h" #include #include #include -#include class AOBlipPlayer { public: AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app); - ~AOBlipPlayer(); void set_blips(QString p_sfx); void blip_tick(); @@ -23,9 +22,9 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; int m_volume; + HSTREAM m_stream_list[5]; }; #endif // AOBLIPPLAYER_H diff --git a/aobutton.cpp b/aobutton.cpp index ded35af..5be2e67 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -15,8 +15,8 @@ AOButton::~AOButton() void AOButton::set_image(QString p_image) { - QString image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); if (file_exists(image_path)) this->setStyleSheet("border-image:url(\"" + image_path + "\")"); diff --git a/aocaseannouncerdialog.cpp b/aocaseannouncerdialog.cpp new file mode 100644 index 0000000..5b82b64 --- /dev/null +++ b/aocaseannouncerdialog.cpp @@ -0,0 +1,82 @@ +#include "aocaseannouncerdialog.h" + +AOCaseAnnouncerDialog::AOCaseAnnouncerDialog(QWidget *parent, AOApplication *p_ao_app, Courtroom *p_court) + : QDialog(parent) +{ + ao_app = p_ao_app; + court = p_court; + + setWindowTitle(tr("Case Announcer")); + resize(405, 235); + + ui_announcer_buttons = new QDialogButtonBox(this); + + QSizePolicy sizepolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + sizepolicy.setHorizontalStretch(0); + sizepolicy.setVerticalStretch(0); + sizepolicy.setHeightForWidth(ui_announcer_buttons->sizePolicy().hasHeightForWidth()); + ui_announcer_buttons->setSizePolicy(sizepolicy); + ui_announcer_buttons->setOrientation(Qt::Horizontal); + ui_announcer_buttons->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); + + QObject::connect(ui_announcer_buttons, SIGNAL(accepted()), this, SLOT(ok_pressed())); + QObject::connect(ui_announcer_buttons, SIGNAL(rejected()), this, SLOT(cancel_pressed())); + + setUpdatesEnabled(false); + + ui_vbox_layout = new QVBoxLayout(this); + + ui_form_layout = new QFormLayout(this); + ui_form_layout->setLabelAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignVCenter); + ui_form_layout->setFormAlignment(Qt::AlignLeading | Qt::AlignLeft | Qt::AlignTop); + ui_form_layout->setContentsMargins(6, 6, 6, 6); + + ui_vbox_layout->addItem(ui_form_layout); + ui_vbox_layout->addWidget(ui_announcer_buttons); + + ui_case_title_label = new QLabel(this); + ui_case_title_label->setText(tr("Case title:")); + + ui_form_layout->setWidget(0, QFormLayout::LabelRole, ui_case_title_label); + + ui_case_title_textbox = new QLineEdit(this); + ui_case_title_textbox->setMaxLength(50); + + ui_form_layout->setWidget(0, QFormLayout::FieldRole, ui_case_title_textbox); + + ui_defense_needed = new QCheckBox(this); + ui_defense_needed->setText(tr("Defense needed")); + ui_prosecutor_needed = new QCheckBox(this); + ui_prosecutor_needed->setText(tr("Prosecution needed")); + ui_judge_needed = new QCheckBox(this); + ui_judge_needed->setText(tr("Judge needed")); + ui_juror_needed = new QCheckBox(this); + ui_juror_needed->setText(tr("Jurors needed")); + ui_steno_needed = new QCheckBox(this); + ui_steno_needed->setText(tr("Stenographer needed")); + + ui_form_layout->setWidget(1, QFormLayout::FieldRole, ui_defense_needed); + ui_form_layout->setWidget(2, QFormLayout::FieldRole, ui_prosecutor_needed); + ui_form_layout->setWidget(3, QFormLayout::FieldRole, ui_judge_needed); + ui_form_layout->setWidget(4, QFormLayout::FieldRole, ui_juror_needed); + ui_form_layout->setWidget(5, QFormLayout::FieldRole, ui_steno_needed); + + setUpdatesEnabled(true); +} + +void AOCaseAnnouncerDialog::ok_pressed() +{ + court->announce_case(ui_case_title_textbox->text(), + ui_defense_needed->isChecked(), + ui_prosecutor_needed->isChecked(), + ui_judge_needed->isChecked(), + ui_juror_needed->isChecked(), + ui_steno_needed->isChecked()); + + done(0); +} + +void AOCaseAnnouncerDialog::cancel_pressed() +{ + done(0); +} diff --git a/aocaseannouncerdialog.h b/aocaseannouncerdialog.h new file mode 100644 index 0000000..a238c3f --- /dev/null +++ b/aocaseannouncerdialog.h @@ -0,0 +1,45 @@ +#ifndef AOCASEANNOUNCERDIALOG_H +#define AOCASEANNOUNCERDIALOG_H + +#include "aoapplication.h" +#include "courtroom.h" + +#include +#include +#include +#include +#include +#include +#include + +class AOCaseAnnouncerDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AOCaseAnnouncerDialog(QWidget *parent = nullptr, AOApplication *p_ao_app = nullptr, Courtroom *p_court = nullptr); + +private: + AOApplication *ao_app; + Courtroom *court; + + QDialogButtonBox *ui_announcer_buttons; + + QVBoxLayout *ui_vbox_layout; + QFormLayout *ui_form_layout; + + QLabel *ui_case_title_label; + QLineEdit *ui_case_title_textbox; + + QCheckBox *ui_defense_needed; + QCheckBox *ui_prosecutor_needed; + QCheckBox *ui_judge_needed; + QCheckBox *ui_juror_needed; + QCheckBox *ui_steno_needed; + +public slots: + void ok_pressed(); + void cancel_pressed(); +}; + +#endif // AOCASEANNOUNCERDIALOG_H diff --git a/aocharbutton.cpp b/aocharbutton.cpp index 550e819..7661027 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -2,12 +2,14 @@ #include "file_functions.h" -AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos) : QPushButton(parent) +AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos, bool is_taken) : QPushButton(parent) { m_parent = parent; ao_app = p_ao_app; + taken = is_taken; + this->resize(60, 60); this->move(x_pos, y_pos); @@ -38,9 +40,22 @@ void AOCharButton::reset() ui_selector->hide(); } -void AOCharButton::set_taken() +void AOCharButton::set_taken(bool is_taken) { - ui_taken->show(); + taken = is_taken; +} + +void AOCharButton::apply_taken_image() +{ + if (taken) + { + ui_taken->move(0,0); + ui_taken->show(); + } + else + { + ui_taken->hide(); + } } void AOCharButton::set_passworded() @@ -50,20 +65,12 @@ void AOCharButton::set_passworded() void AOCharButton::set_image(QString p_character) { - QString image_path = ao_app->get_character_path(p_character) + "char_icon.png"; - QString legacy_path = ao_app->get_demothings_path() + p_character.toLower() + "_char_icon.png"; - QString alt_path = ao_app->get_demothings_path() + p_character.toLower() + "_off.png"; + QString image_path = ao_app->get_character_path(p_character, "char_icon.png"); this->setText(""); if (file_exists(image_path)) this->setStyleSheet("border-image:url(\"" + image_path + "\")"); - else if (file_exists(legacy_path)) - { - this->setStyleSheet("border-image:url(\"" + legacy_path + "\")"); - //ninja optimization - QFile::copy(legacy_path, image_path); - } else { this->setStyleSheet("border-image:url()"); @@ -73,6 +80,7 @@ void AOCharButton::set_image(QString p_character) void AOCharButton::enterEvent(QEvent * e) { + ui_selector->move(this->x() - 1, this->y() - 1); ui_selector->raise(); ui_selector->show(); diff --git a/aocharbutton.h b/aocharbutton.h index 6b80460..f372cdf 100644 --- a/aocharbutton.h +++ b/aocharbutton.h @@ -14,17 +14,22 @@ class AOCharButton : public QPushButton Q_OBJECT public: - AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos); + AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos, bool is_taken); AOApplication *ao_app; + void refresh(); void reset(); - void set_taken(); + void set_taken(bool is_taken); void set_passworded(); + void apply_taken_image(); + void set_image(QString p_character); private: + bool taken; + QWidget *m_parent; AOImage *ui_taken; diff --git a/aocharmovie.cpp b/aocharmovie.cpp index b591c22..5748723 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -19,13 +19,16 @@ AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) { - QString original_path = ao_app->get_character_path(p_char) + emote_prefix + p_emote.toLower() + ".gif"; - QString alt_path = ao_app->get_character_path(p_char) + p_emote.toLower() + ".png"; - QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; - QString placeholder_default_path = ao_app->get_default_theme_path() + "placeholder.gif"; + QString original_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".gif"); + QString alt_path = ao_app->get_character_path(p_char, p_emote + ".png"); + QString apng_path = ao_app->get_character_path(p_char, emote_prefix + p_emote + ".apng"); + QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); + QString placeholder_default_path = ao_app->get_default_theme_path("placeholder.gif"); QString gif_path; - if (file_exists(original_path)) + if (file_exists(apng_path)) + gif_path = apng_path; + else if (file_exists(original_path)) gif_path = original_path; else if (file_exists(alt_path)) gif_path = alt_path; @@ -58,7 +61,7 @@ void AOCharMovie::play(QString p_char, QString p_emote, QString emote_prefix) void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) { - QString gif_path = ao_app->get_character_path(p_char) + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, p_emote); m_movie->stop(); this->clear(); @@ -75,8 +78,11 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) real_duration += m_movie->nextFrameDelay(); m_movie->jumpToFrame(n_frame + 1); } + +#ifdef DEBUG_GIF qDebug() << "full_duration: " << full_duration; qDebug() << "real_duration: " << real_duration; +#endif double percentage_modifier = 100.0; @@ -88,7 +94,10 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) if (percentage_modifier > 100.0) percentage_modifier = 100.0; } + +#ifdef DEBUG_GIF qDebug() << "% mod: " << percentage_modifier; +#endif if (full_duration == 0 || full_duration >= real_duration) { @@ -107,7 +116,7 @@ void AOCharMovie::play_pre(QString p_char, QString p_emote, int duration) void AOCharMovie::play_talking(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char) + "(b)" + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, "(b)" + p_emote); m_movie->stop(); this->clear(); @@ -120,7 +129,7 @@ void AOCharMovie::play_talking(QString p_char, QString p_emote) void AOCharMovie::play_idle(QString p_char, QString p_emote) { - QString gif_path = ao_app->get_character_path(p_char) + "(a)" + p_emote.toLower(); + QString gif_path = ao_app->get_character_path(p_char, "(a)" + p_emote); m_movie->stop(); this->clear(); @@ -146,14 +155,31 @@ void AOCharMovie::combo_resize(int w, int h) m_movie->setScaledSize(f_size); } +void AOCharMovie::move(int ax, int ay) +{ + x = ax; + y = ay; + QLabel::move(x, y); +} + void AOCharMovie::frame_change(int n_frame) { + if (movie_frames.size() > n_frame) { QPixmap f_pixmap = QPixmap::fromImage(movie_frames.at(n_frame)); + auto aspect_ratio = Qt::KeepAspectRatio; - this->setPixmap(f_pixmap.scaled(this->width(), this->height())); - } + if (f_pixmap.size().width() > f_pixmap.size().height()) + aspect_ratio = Qt::KeepAspectRatioByExpanding; + + if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation)); + else + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation)); + + QLabel::move(x + (this->width() - this->pixmap()->width())/2, y); + } if (m_movie->frameCount() - 1 == n_frame && play_once) { diff --git a/aocharmovie.h b/aocharmovie.h index b26bada..7ef7da3 100644 --- a/aocharmovie.h +++ b/aocharmovie.h @@ -25,6 +25,8 @@ public: void stop(); + void move(int ax, int ay); + void combo_resize(int w, int h); private: @@ -36,6 +38,10 @@ private: const int time_mod = 62; + // These are the X and Y values before they are fixed based on the sprite's width. + int x = 0; + int y = 0; + bool m_flipped = false; bool play_once = true; diff --git a/aoemotebutton.cpp b/aoemotebutton.cpp index 9e3c446..9c1d388 100644 --- a/aoemotebutton.cpp +++ b/aoemotebutton.cpp @@ -16,19 +16,13 @@ AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x void AOEmoteButton::set_image(QString p_char, int p_emote, QString suffix) { QString emotion_number = QString::number(p_emote + 1); - QString image_path = ao_app->get_character_path(p_char) + "emotions/ao2/button" + emotion_number + suffix; - QString alt_path = ao_app->get_character_path(p_char) + "emotions/button" + emotion_number + suffix; + QString image_path = ao_app->get_character_path(p_char, "emotions/button" + emotion_number + suffix); if (file_exists(image_path)) { this->setText(""); this->setStyleSheet("border-image:url(\"" + image_path + "\")"); } - else if (file_exists(alt_path)) - { - this->setText(""); - this->setStyleSheet("border-image:url(\"" + alt_path + "\")"); - } else { this->setText(ao_app->get_emote_comment(p_char, p_emote)); diff --git a/aoevidencebutton.cpp b/aoevidencebutton.cpp index 573b8ef..924aeb8 100644 --- a/aoevidencebutton.cpp +++ b/aoevidencebutton.cpp @@ -37,7 +37,7 @@ void AOEvidenceButton::reset() void AOEvidenceButton::set_image(QString p_image) { - QString image_path = ao_app->get_evidence_path() + p_image; + QString image_path = ao_app->get_evidence_path(p_image); if (file_exists(image_path)) { @@ -53,8 +53,8 @@ void AOEvidenceButton::set_image(QString p_image) void AOEvidenceButton::set_theme_image(QString p_image) { - QString theme_image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString theme_image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); QString final_image_path; diff --git a/aoevidencedisplay.cpp b/aoevidencedisplay.cpp index 5364ffb..9ec105d 100644 --- a/aoevidencedisplay.cpp +++ b/aoevidencedisplay.cpp @@ -21,7 +21,7 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image, bool is_left_sid sfx_player->set_volume(p_volume); - QString f_evidence_path = ao_app->get_evidence_path() + p_evidence_image; + QString f_evidence_path = ao_app->get_evidence_path(p_evidence_image); QPixmap f_pixmap(f_evidence_path); @@ -47,8 +47,8 @@ void AOEvidenceDisplay::show_evidence(QString p_evidence_image, bool is_left_sid evidence_icon->setPixmap(f_pixmap.scaled(evidence_icon->width(), evidence_icon->height(), Qt::IgnoreAspectRatio)); - QString f_default_gif_path = ao_app->get_default_theme_path() + gif_name; - QString f_gif_path = ao_app->get_theme_path() + gif_name; + QString f_default_gif_path = ao_app->get_default_theme_path(gif_name); + QString f_gif_path = ao_app->get_theme_path(gif_name); if (file_exists(f_gif_path)) final_gif_path = f_gif_path; diff --git a/aoimage.cpp b/aoimage.cpp index 935ba74..7bb56bb 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -15,8 +15,8 @@ AOImage::~AOImage() void AOImage::set_image(QString p_image) { - QString theme_image_path = ao_app->get_theme_path() + p_image; - QString default_image_path = ao_app->get_default_theme_path() + p_image; + QString theme_image_path = ao_app->get_theme_path(p_image); + QString default_image_path = ao_app->get_default_theme_path(p_image); QString final_image_path; @@ -32,7 +32,7 @@ void AOImage::set_image(QString p_image) void AOImage::set_image_from_path(QString p_path) { - QString default_path = ao_app->get_default_theme_path() + "chatmed.png"; + QString default_path = ao_app->get_default_theme_path("chatmed.png"); QString final_path; diff --git a/aomovie.cpp b/aomovie.cpp index 90c3701..edf5bdb 100644 --- a/aomovie.cpp +++ b/aomovie.cpp @@ -28,18 +28,21 @@ void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme) QString custom_path; if (p_gif == "custom") - custom_path = ao_app->get_character_path(p_char) + p_gif + ".gif"; + custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif)); else - custom_path = ao_app->get_character_path(p_char) + p_gif + "_bubble.gif"; + custom_path = ao_app->get_image_suffix(ao_app->get_character_path(p_char, p_gif + "_bubble")); - QString custom_theme_path = ao_app->get_base_path() + "themes/" + p_custom_theme + "/" + p_gif + ".gif"; - QString theme_path = ao_app->get_theme_path() + p_gif + ".gif"; - QString default_theme_path = ao_app->get_default_theme_path() + p_gif + ".gif"; - QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; - QString default_placeholder_path = ao_app->get_default_theme_path() + "placeholder.gif"; + QString misc_path = ao_app->get_base_path() + "misc/" + p_custom_theme + "/" + p_gif + "_bubble.gif"; + QString custom_theme_path = ao_app->get_custom_theme_path(p_custom_theme, p_gif + ".gif"); + QString theme_path = ao_app->get_theme_path(p_gif + ".gif"); + QString default_theme_path = ao_app->get_default_theme_path(p_gif + ".gif"); + QString placeholder_path = ao_app->get_theme_path("placeholder.gif"); + QString default_placeholder_path = ao_app->get_default_theme_path("placeholder.gif"); if (file_exists(custom_path)) gif_path = custom_path; + else if (file_exists(misc_path)) + gif_path = misc_path; else if (file_exists(custom_theme_path)) gif_path = custom_theme_path; else if (file_exists(theme_path)) diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp index ca37ac7..997d82d 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -4,24 +4,31 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - m_player = new QMediaPlayer; } AOMusicPlayer::~AOMusicPlayer() { - m_player->stop(); - m_player->deleteLater(); + BASS_ChannelStop(m_stream); } void AOMusicPlayer::play(QString p_song) { - m_player->setMedia(QUrl::fromLocalFile(ao_app->get_music_path(p_song))); + BASS_ChannelStop(m_stream); + + QString f_path = ao_app->get_music_path(p_song); + + m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); + this->set_volume(m_volume); - m_player->play(); + + if (ao_app->get_audio_output_device() != "default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + BASS_ChannelPlay(m_stream, false); } void AOMusicPlayer::set_volume(int p_value) { m_volume = p_value; - m_player->setVolume(p_value); + float volume = m_volume / 100.0f; + BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); } diff --git a/aomusicplayer.h b/aomusicplayer.h index f7b2d0d..560a7f9 100644 --- a/aomusicplayer.h +++ b/aomusicplayer.h @@ -1,12 +1,12 @@ #ifndef AOMUSICPLAYER_H #define AOMUSICPLAYER_H +#include "bass.h" #include "aoapplication.h" #include #include #include -#include class AOMusicPlayer { @@ -21,8 +21,8 @@ private: QWidget *m_parent; AOApplication *ao_app; - QMediaPlayer *m_player; int m_volume = 0; + HSTREAM m_stream; }; #endif // AOMUSICPLAYER_H diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp new file mode 100644 index 0000000..2b8259f --- /dev/null +++ b/aooptionsdialog.cpp @@ -0,0 +1,517 @@ +#include "aooptionsdialog.h" +#include "aoapplication.h" +#include "bass.h" + +AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDialog(parent) +{ + ao_app = p_ao_app; + + // Setting up the basics. + // setAttribute(Qt::WA_DeleteOnClose); + setWindowTitle(tr("Settings")); + resize(398, 320); + + ui_settings_buttons = new QDialogButtonBox(this); + + QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Fixed); + sizePolicy1.setHorizontalStretch(0); + sizePolicy1.setVerticalStretch(0); + sizePolicy1.setHeightForWidth(ui_settings_buttons->sizePolicy().hasHeightForWidth()); + ui_settings_buttons->setSizePolicy(sizePolicy1); + ui_settings_buttons->setOrientation(Qt::Horizontal); + ui_settings_buttons->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Save); + + QObject::connect(ui_settings_buttons, SIGNAL(accepted()), this, SLOT(save_pressed())); + QObject::connect(ui_settings_buttons, SIGNAL(rejected()), this, SLOT(discard_pressed())); + + // We'll stop updates so that the window won't flicker while it's being made. + setUpdatesEnabled(false); + + // First of all, we want a tabbed dialog, so let's add some layout. + ui_vertical_layout = new QVBoxLayout(this); + ui_settings_tabs = new QTabWidget(this); + + ui_vertical_layout->addWidget(ui_settings_tabs); + ui_vertical_layout->addWidget(ui_settings_buttons); + + // Let's add the tabs one by one. + // First, we'll start with 'Gameplay'. + ui_gameplay_tab = new QWidget(); + ui_settings_tabs->addTab(ui_gameplay_tab, tr("Gameplay")); + + ui_form_layout_widget = new QWidget(ui_gameplay_tab); + ui_form_layout_widget->setGeometry(QRect(10, 10, 361, 211)); + + ui_gameplay_form = new QFormLayout(ui_form_layout_widget); + ui_gameplay_form->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + ui_gameplay_form->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + ui_gameplay_form->setContentsMargins(0, 0, 0, 0); + + ui_theme_label = new QLabel(ui_form_layout_widget); + ui_theme_label->setText(tr("Theme:")); + ui_theme_label->setToolTip(tr("Sets the theme used in-game. If the new theme changes " + "the lobby's look as well, you'll need to reload the " + "lobby for the changes to take effect, such as by joining " + "a server and leaving it.")); + ui_gameplay_form->setWidget(0, QFormLayout::LabelRole, ui_theme_label); + + ui_theme_combobox = new QComboBox(ui_form_layout_widget); + + // Fill the combobox with the names of the themes. + QDirIterator it(p_ao_app->get_base_path() + "themes", QDir::Dirs, QDirIterator::NoIteratorFlags); + while (it.hasNext()) + { + QString actualname = QDir(it.next()).dirName(); + if (actualname != "." && actualname != "..") + ui_theme_combobox->addItem(actualname); + if (actualname == p_ao_app->read_theme()) + ui_theme_combobox->setCurrentIndex(ui_theme_combobox->count()-1); + } + + ui_gameplay_form->setWidget(0, QFormLayout::FieldRole, ui_theme_combobox); + + ui_theme_log_divider = new QFrame(ui_form_layout_widget); + ui_theme_log_divider->setMidLineWidth(0); + ui_theme_log_divider->setFrameShape(QFrame::HLine); + ui_theme_log_divider->setFrameShadow(QFrame::Sunken); + + ui_gameplay_form->setWidget(1, QFormLayout::FieldRole, ui_theme_log_divider); + + ui_downwards_lbl = new QLabel(ui_form_layout_widget); + ui_downwards_lbl->setText(tr("Log goes downwards:")); + ui_downwards_lbl->setToolTip(tr("If ticked, new messages will appear at " + "the bottom (like the OOC chatlog). The traditional " + "(AO1) behaviour is equivalent to this being unticked.")); + + ui_gameplay_form->setWidget(2, QFormLayout::LabelRole, ui_downwards_lbl); + + ui_downwards_cb = new QCheckBox(ui_form_layout_widget); + ui_downwards_cb->setChecked(p_ao_app->get_log_goes_downwards()); + + ui_gameplay_form->setWidget(2, QFormLayout::FieldRole, ui_downwards_cb); + + ui_length_lbl = new QLabel(ui_form_layout_widget); + ui_length_lbl->setText(tr("Log length:")); + ui_length_lbl->setToolTip(tr("The amount of messages the IC chatlog will keep before " + "deleting older messages. A value of 0 or below counts as 'infinite'.")); + + ui_gameplay_form->setWidget(3, QFormLayout::LabelRole, ui_length_lbl); + + ui_length_spinbox = new QSpinBox(ui_form_layout_widget); + ui_length_spinbox->setMaximum(10000); + ui_length_spinbox->setValue(p_ao_app->get_max_log_size()); + + ui_gameplay_form->setWidget(3, QFormLayout::FieldRole, ui_length_spinbox); + + ui_log_names_divider = new QFrame(ui_form_layout_widget); + ui_log_names_divider->setFrameShape(QFrame::HLine); + ui_log_names_divider->setFrameShadow(QFrame::Sunken); + + ui_gameplay_form->setWidget(4, QFormLayout::FieldRole, ui_log_names_divider); + + ui_username_lbl = new QLabel(ui_form_layout_widget); + ui_username_lbl->setText(tr("Default username:")); + ui_username_lbl->setToolTip(tr("Your OOC name will be automatically set to this value " + "when you join a server.")); + + ui_gameplay_form->setWidget(5, QFormLayout::LabelRole, ui_username_lbl); + + ui_username_textbox = new QLineEdit(ui_form_layout_widget); + ui_username_textbox->setMaxLength(30); + ui_username_textbox->setText(p_ao_app->get_default_username()); + + ui_gameplay_form->setWidget(5, QFormLayout::FieldRole, ui_username_textbox); + + ui_showname_lbl = new QLabel(ui_form_layout_widget); + ui_showname_lbl->setText(tr("Custom shownames:")); + ui_showname_lbl->setToolTip(tr("Gives the default value for the in-game 'Custom shownames' " + "tickbox, which in turn determines whether the client should " + "display custom in-character names.")); + + ui_gameplay_form->setWidget(6, QFormLayout::LabelRole, ui_showname_lbl); + + ui_showname_cb = new QCheckBox(ui_form_layout_widget); + ui_showname_cb->setChecked(p_ao_app->get_showname_enabled_by_default()); + + ui_gameplay_form->setWidget(6, QFormLayout::FieldRole, ui_showname_cb); + + ui_net_divider = new QFrame(ui_form_layout_widget); + ui_net_divider->setFrameShape(QFrame::HLine); + ui_net_divider->setFrameShadow(QFrame::Sunken); + + ui_gameplay_form->setWidget(7, QFormLayout::FieldRole, ui_net_divider); + + ui_ms_lbl = new QLabel(ui_form_layout_widget); + ui_ms_lbl->setText(tr("Backup MS:")); + ui_ms_lbl->setToolTip(tr("If the built-in server lookups fail, the game will try the " + "address given here and use it as a backup master server address.")); + + ui_gameplay_form->setWidget(8, QFormLayout::LabelRole, ui_ms_lbl); + + QSettings* configini = ao_app->configini; + ui_ms_textbox = new QLineEdit(ui_form_layout_widget); + ui_ms_textbox->setText(configini->value("master", "").value()); + + ui_gameplay_form->setWidget(8, QFormLayout::FieldRole, ui_ms_textbox); + + ui_discord_lbl = new QLabel(ui_form_layout_widget); + ui_discord_lbl->setText(tr("Discord:")); + ui_discord_lbl->setToolTip(tr("Allows others on Discord to see what server you are in, " + "what character are you playing, and how long you have " + "been playing for.")); + + ui_gameplay_form->setWidget(9, QFormLayout::LabelRole, ui_discord_lbl); + + ui_discord_cb = new QCheckBox(ui_form_layout_widget); + ui_discord_cb->setChecked(ao_app->is_discord_enabled()); + + ui_gameplay_form->setWidget(9, QFormLayout::FieldRole, ui_discord_cb); + + // Here we start the callwords tab. + ui_callwords_tab = new QWidget(); + ui_settings_tabs->addTab(ui_callwords_tab, tr("Callwords")); + + ui_callwords_widget = new QWidget(ui_callwords_tab); + ui_callwords_widget->setGeometry(QRect(10, 10, 361, 211)); + + ui_callwords_layout = new QVBoxLayout(ui_callwords_widget); + ui_callwords_layout->setContentsMargins(0,0,0,0); + + ui_callwords_textbox = new QPlainTextEdit(ui_callwords_widget); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(ui_callwords_textbox->sizePolicy().hasHeightForWidth()); + ui_callwords_textbox->setSizePolicy(sizePolicy); + + // Let's fill the callwords text edit with the already present callwords. + ui_callwords_textbox->document()->clear(); + foreach (QString callword, p_ao_app->get_call_words()) { + ui_callwords_textbox->appendPlainText(callword); + } + + ui_callwords_layout->addWidget(ui_callwords_textbox); + + ui_callwords_explain_lbl = new QLabel(ui_callwords_widget); + ui_callwords_explain_lbl->setWordWrap(true); + ui_callwords_explain_lbl->setText(tr("Enter as many callwords as you would like. These are case insensitive. Make sure to leave every callword in its own line!
Do not leave a line with a space at the end -- you will be alerted everytime someone uses a space in their messages.")); + + ui_callwords_layout->addWidget(ui_callwords_explain_lbl); + + // The audio tab. + ui_audio_tab = new QWidget(); + ui_settings_tabs->addTab(ui_audio_tab, tr("Audio")); + + ui_audio_widget = new QWidget(ui_audio_tab); + ui_audio_widget->setGeometry(QRect(10, 10, 361, 211)); + + ui_audio_layout = new QFormLayout(ui_audio_widget); + ui_audio_layout->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + ui_audio_layout->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + ui_audio_layout->setContentsMargins(0, 0, 0, 0); + + ui_audio_device_lbl = new QLabel(ui_audio_widget); + ui_audio_device_lbl->setText(tr("Audio device:")); + ui_audio_device_lbl->setToolTip(tr("Sets the audio device for all sounds.")); + + ui_audio_layout->setWidget(0, QFormLayout::LabelRole, ui_audio_device_lbl); + + ui_audio_device_combobox = new QComboBox(ui_audio_widget); + + // Let's fill out the combobox with the available audio devices. + int a = 0; + BASS_DEVICEINFO info; + + if (needs_default_audiodev()) + { + ui_audio_device_combobox->addItem("default"); + } + + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + { + ui_audio_device_combobox->addItem(info.name); + if (p_ao_app->get_audio_output_device() == info.name) + ui_audio_device_combobox->setCurrentIndex(ui_audio_device_combobox->count()-1); + } + + ui_audio_layout->setWidget(0, QFormLayout::FieldRole, ui_audio_device_combobox); + + ui_audio_volume_divider = new QFrame(ui_audio_widget); + ui_audio_volume_divider->setFrameShape(QFrame::HLine); + ui_audio_volume_divider->setFrameShadow(QFrame::Sunken); + + ui_audio_layout->setWidget(1, QFormLayout::FieldRole, ui_audio_volume_divider); + + ui_music_volume_lbl = new QLabel(ui_audio_widget); + ui_music_volume_lbl->setText(tr("Music:")); + ui_music_volume_lbl->setToolTip(tr("Sets the music's default volume.")); + + ui_audio_layout->setWidget(2, QFormLayout::LabelRole, ui_music_volume_lbl); + + ui_music_volume_spinbox = new QSpinBox(ui_audio_widget); + ui_music_volume_spinbox->setValue(p_ao_app->get_default_music()); + ui_music_volume_spinbox->setMaximum(100); + ui_music_volume_spinbox->setSuffix("%"); + + ui_audio_layout->setWidget(2, QFormLayout::FieldRole, ui_music_volume_spinbox); + + ui_sfx_volume_lbl = new QLabel(ui_audio_widget); + ui_sfx_volume_lbl->setText(tr("SFX:")); + ui_sfx_volume_lbl->setToolTip(tr("Sets the SFX's default volume. " + "Interjections and actual sound effects count as 'SFX'.")); + + ui_audio_layout->setWidget(3, QFormLayout::LabelRole, ui_sfx_volume_lbl); + + ui_sfx_volume_spinbox = new QSpinBox(ui_audio_widget); + ui_sfx_volume_spinbox->setValue(p_ao_app->get_default_sfx()); + ui_sfx_volume_spinbox->setMaximum(100); + ui_sfx_volume_spinbox->setSuffix("%"); + + ui_audio_layout->setWidget(3, QFormLayout::FieldRole, ui_sfx_volume_spinbox); + + ui_blips_volume_lbl = new QLabel(ui_audio_widget); + ui_blips_volume_lbl->setText(tr("Blips:")); + ui_blips_volume_lbl->setToolTip(tr("Sets the volume of the blips, the talking sound effects.")); + + ui_audio_layout->setWidget(4, QFormLayout::LabelRole, ui_blips_volume_lbl); + + ui_blips_volume_spinbox = new QSpinBox(ui_audio_widget); + ui_blips_volume_spinbox->setValue(p_ao_app->get_default_blip()); + ui_blips_volume_spinbox->setMaximum(100); + ui_blips_volume_spinbox->setSuffix("%"); + + ui_audio_layout->setWidget(4, QFormLayout::FieldRole, ui_blips_volume_spinbox); + + ui_volume_blip_divider = new QFrame(ui_audio_widget); + ui_volume_blip_divider->setFrameShape(QFrame::HLine); + ui_volume_blip_divider->setFrameShadow(QFrame::Sunken); + + ui_audio_layout->setWidget(5, QFormLayout::FieldRole, ui_volume_blip_divider); + + ui_bliprate_lbl = new QLabel(ui_audio_widget); + ui_bliprate_lbl->setText(tr("Blip rate:")); + ui_bliprate_lbl->setToolTip(tr("Sets the delay between playing the blip sounds.")); + + ui_audio_layout->setWidget(6, QFormLayout::LabelRole, ui_bliprate_lbl); + + ui_bliprate_spinbox = new QSpinBox(ui_audio_widget); + ui_bliprate_spinbox->setValue(p_ao_app->read_blip_rate()); + ui_bliprate_spinbox->setMinimum(1); + + ui_audio_layout->setWidget(6, QFormLayout::FieldRole, ui_bliprate_spinbox); + + ui_blank_blips_lbl = new QLabel(ui_audio_widget); + ui_blank_blips_lbl->setText(tr("Blank blips:")); + ui_blank_blips_lbl->setToolTip(tr("If true, the game will play a blip sound even " + "when a space is 'being said'.")); + + ui_audio_layout->setWidget(7, QFormLayout::LabelRole, ui_blank_blips_lbl); + + ui_blank_blips_cb = new QCheckBox(ui_audio_widget); + ui_blank_blips_cb->setChecked(p_ao_app->get_blank_blip()); + + ui_audio_layout->setWidget(7, QFormLayout::FieldRole, ui_blank_blips_cb); + + // The casing tab! + ui_casing_tab = new QWidget(); + ui_settings_tabs->addTab(ui_casing_tab, tr("Casing")); + + ui_casing_widget = new QWidget(ui_casing_tab); + ui_casing_widget->setGeometry(QRect(10,10, 361, 211)); + + ui_casing_layout = new QFormLayout(ui_casing_widget); + ui_casing_layout->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + ui_casing_layout->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + ui_casing_layout->setContentsMargins(0, 0, 0, 0); + + // -- SERVER SUPPORTS CASING + + ui_casing_supported_lbl = new QLabel(ui_casing_widget); + if (ao_app->casing_alerts_enabled) + ui_casing_supported_lbl->setText(tr("This server supports case alerts.")); + else + ui_casing_supported_lbl->setText(tr("This server does not support case alerts.")); + ui_casing_supported_lbl->setToolTip(tr("Pretty self-explanatory.")); + + ui_casing_layout->setWidget(0, QFormLayout::FieldRole, ui_casing_supported_lbl); + + // -- CASE ANNOUNCEMENTS + + ui_casing_enabled_lbl = new QLabel(ui_casing_widget); + ui_casing_enabled_lbl->setText(tr("Casing:")); + ui_casing_enabled_lbl->setToolTip(tr("If checked, you will get alerts about case " + "announcements.")); + + ui_casing_layout->setWidget(1, QFormLayout::LabelRole, ui_casing_enabled_lbl); + + ui_casing_enabled_cb = new QCheckBox(ui_casing_widget); + ui_casing_enabled_cb->setChecked(ao_app->get_casing_enabled()); + + ui_casing_layout->setWidget(1, QFormLayout::FieldRole, ui_casing_enabled_cb); + + // -- DEFENSE ANNOUNCEMENTS + + ui_casing_def_lbl = new QLabel(ui_casing_widget); + ui_casing_def_lbl->setText(tr("Defense:")); + ui_casing_def_lbl->setToolTip(tr("If checked, you will get alerts about case " + "announcements if a defense spot is open.")); + + ui_casing_layout->setWidget(2, QFormLayout::LabelRole, ui_casing_def_lbl); + + ui_casing_def_cb = new QCheckBox(ui_casing_widget); + ui_casing_def_cb->setChecked(ao_app->get_casing_defence_enabled()); + + ui_casing_layout->setWidget(2, QFormLayout::FieldRole, ui_casing_def_cb); + + // -- PROSECUTOR ANNOUNCEMENTS + + ui_casing_pro_lbl = new QLabel(ui_casing_widget); + ui_casing_pro_lbl->setText(tr("Prosecution:")); + ui_casing_pro_lbl->setToolTip(tr("If checked, you will get alerts about case " + "announcements if a prosecutor spot is open.")); + + ui_casing_layout->setWidget(3, QFormLayout::LabelRole, ui_casing_pro_lbl); + + ui_casing_pro_cb = new QCheckBox(ui_casing_widget); + ui_casing_pro_cb->setChecked(ao_app->get_casing_prosecution_enabled()); + + ui_casing_layout->setWidget(3, QFormLayout::FieldRole, ui_casing_pro_cb); + + // -- JUDGE ANNOUNCEMENTS + + ui_casing_jud_lbl = new QLabel(ui_casing_widget); + ui_casing_jud_lbl->setText(tr("Judge:")); + ui_casing_jud_lbl->setToolTip(tr("If checked, you will get alerts about case " + "announcements if the judge spot is open.")); + + ui_casing_layout->setWidget(4, QFormLayout::LabelRole, ui_casing_jud_lbl); + + ui_casing_jud_cb = new QCheckBox(ui_casing_widget); + ui_casing_jud_cb->setChecked(ao_app->get_casing_judge_enabled()); + + ui_casing_layout->setWidget(4, QFormLayout::FieldRole, ui_casing_jud_cb); + + // -- JUROR ANNOUNCEMENTS + + ui_casing_jur_lbl = new QLabel(ui_casing_widget); + ui_casing_jur_lbl->setText(tr("Juror:")); + ui_casing_jur_lbl->setToolTip(tr("If checked, you will get alerts about case " + "announcements if a juror spot is open.")); + + ui_casing_layout->setWidget(5, QFormLayout::LabelRole, ui_casing_jur_lbl); + + ui_casing_jur_cb = new QCheckBox(ui_casing_widget); + ui_casing_jur_cb->setChecked(ao_app->get_casing_juror_enabled()); + + ui_casing_layout->setWidget(5, QFormLayout::FieldRole, ui_casing_jur_cb); + + // -- STENO ANNOUNCEMENTS + + ui_casing_steno_lbl = new QLabel(ui_casing_widget); + ui_casing_steno_lbl->setText(tr("Stenographer:")); + ui_casing_steno_lbl->setToolTip(tr("If checked, you will get alerts about case " + "announcements if a stenographer spot is open.")); + + ui_casing_layout->setWidget(6, QFormLayout::LabelRole, ui_casing_steno_lbl); + + ui_casing_steno_cb = new QCheckBox(ui_casing_widget); + ui_casing_steno_cb->setChecked(ao_app->get_casing_steno_enabled()); + + ui_casing_layout->setWidget(6, QFormLayout::FieldRole, ui_casing_steno_cb); + + // -- CM ANNOUNCEMENTS + + ui_casing_cm_lbl = new QLabel(ui_casing_widget); + ui_casing_cm_lbl->setText(tr("CM:")); + ui_casing_cm_lbl->setToolTip(tr("If checked, you will appear amongst the potential " + "CMs on the server.")); + + ui_casing_layout->setWidget(7, QFormLayout::LabelRole, ui_casing_cm_lbl); + + ui_casing_cm_cb = new QCheckBox(ui_casing_widget); + ui_casing_cm_cb->setChecked(ao_app->get_casing_cm_enabled()); + + ui_casing_layout->setWidget(7, QFormLayout::FieldRole, ui_casing_cm_cb); + + // -- CM CASES ANNOUNCEMENTS + + ui_casing_cm_cases_lbl = new QLabel(ui_casing_widget); + ui_casing_cm_cases_lbl->setText(tr("Hosting cases:")); + ui_casing_cm_cases_lbl->setToolTip(tr("If you're a CM, enter what cases you are " + "willing to host.")); + + ui_casing_layout->setWidget(8, QFormLayout::LabelRole, ui_casing_cm_cases_lbl); + + ui_casing_cm_cases_textbox = new QLineEdit(ui_casing_widget); + ui_casing_cm_cases_textbox->setText(ao_app->get_casing_can_host_cases()); + + ui_casing_layout->setWidget(8, QFormLayout::FieldRole, ui_casing_cm_cases_textbox); + + // When we're done, we should continue the updates! + setUpdatesEnabled(true); +} + +void AOOptionsDialog::save_pressed() +{ + // Save everything into the config.ini. + QSettings* configini = ao_app->configini; + + configini->setValue("theme", ui_theme_combobox->currentText()); + configini->setValue("log_goes_downwards", ui_downwards_cb->isChecked()); + configini->setValue("log_maximum", ui_length_spinbox->value()); + configini->setValue("default_username", ui_username_textbox->text()); + configini->setValue("show_custom_shownames", ui_showname_cb->isChecked()); + configini->setValue("master", ui_ms_textbox->text()); + configini->setValue("discord", ui_discord_cb->isChecked()); + + QFile* callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini"); + + if (!callwordsini->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) + { + // Nevermind! + } + else + { + QTextStream out(callwordsini); + out << ui_callwords_textbox->toPlainText(); + callwordsini->close(); + } + + configini->setValue("default_audio_device", ui_audio_device_combobox->currentText()); + configini->setValue("default_music", ui_music_volume_spinbox->value()); + configini->setValue("default_sfx", ui_sfx_volume_spinbox->value()); + configini->setValue("default_blip", ui_blips_volume_spinbox->value()); + configini->setValue("blip_rate", ui_bliprate_spinbox->value()); + configini->setValue("blank_blip", ui_blank_blips_cb->isChecked()); + + configini->setValue("casing_enabled", ui_casing_enabled_cb->isChecked()); + configini->setValue("casing_defence_enabled", ui_casing_def_cb->isChecked()); + configini->setValue("casing_prosecution_enabled", ui_casing_pro_cb->isChecked()); + configini->setValue("casing_judge_enabled", ui_casing_jud_cb->isChecked()); + configini->setValue("casing_juror_enabled", ui_casing_jur_cb->isChecked()); + configini->setValue("casing_steno_enabled", ui_casing_steno_cb->isChecked()); + configini->setValue("casing_cm_enabled", ui_casing_cm_cb->isChecked()); + configini->setValue("casing_can_host_cases", ui_casing_cm_cases_textbox->text()); + + callwordsini->close(); + done(0); +} + +void AOOptionsDialog::discard_pressed() +{ + done(0); +} + +#if (defined (_WIN32) || defined (_WIN64)) +bool AOOptionsDialog::needs_default_audiodev() +{ + return true; +} +#elif (defined (LINUX) || defined (__linux__)) +bool AOOptionsDialog::needs_default_audiodev() +{ + return false; +} +#else +#error This operating system is not supported. +#endif diff --git a/aooptionsdialog.h b/aooptionsdialog.h new file mode 100644 index 0000000..a65e3f5 --- /dev/null +++ b/aooptionsdialog.h @@ -0,0 +1,115 @@ +#ifndef AOOPTIONSDIALOG_H +#define AOOPTIONSDIALOG_H + +#include "aoapplication.h" +#include "bass.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +class AOOptionsDialog: public QDialog +{ + Q_OBJECT +public: + explicit AOOptionsDialog(QWidget *parent = nullptr, AOApplication *p_ao_app = nullptr); + +private: + AOApplication *ao_app; + + QVBoxLayout *ui_vertical_layout; + QTabWidget *ui_settings_tabs; + + QWidget *ui_gameplay_tab; + QWidget *ui_form_layout_widget; + QFormLayout *ui_gameplay_form; + QLabel *ui_theme_label; + QComboBox *ui_theme_combobox; + QFrame *ui_theme_log_divider; + QLabel *ui_downwards_lbl; + QCheckBox *ui_downwards_cb; + QLabel *ui_length_lbl; + QSpinBox *ui_length_spinbox; + QFrame *ui_log_names_divider; + QLineEdit *ui_username_textbox; + QLabel *ui_username_lbl; + QLabel *ui_showname_lbl; + QCheckBox *ui_showname_cb; + QFrame *ui_net_divider; + QLabel *ui_ms_lbl; + QLineEdit *ui_ms_textbox; + QLabel *ui_discord_lbl; + QCheckBox *ui_discord_cb; + + QWidget *ui_callwords_tab; + QWidget *ui_callwords_widget; + QVBoxLayout *ui_callwords_layout; + QPlainTextEdit *ui_callwords_textbox; + QLabel *ui_callwords_explain_lbl; + QCheckBox *ui_callwords_char_textbox; + + QWidget *ui_audio_tab; + QWidget *ui_audio_widget; + QFormLayout *ui_audio_layout; + QLabel *ui_audio_device_lbl; + QComboBox *ui_audio_device_combobox; + QFrame *ui_audio_volume_divider; + QSpinBox *ui_music_volume_spinbox; + QLabel *ui_music_volume_lbl; + QSpinBox *ui_sfx_volume_spinbox; + QSpinBox *ui_blips_volume_spinbox; + QLabel *ui_sfx_volume_lbl; + QLabel *ui_blips_volume_lbl; + QFrame *ui_volume_blip_divider; + QSpinBox *ui_bliprate_spinbox; + QLabel *ui_bliprate_lbl; + QCheckBox *ui_blank_blips_cb; + QLabel *ui_blank_blips_lbl; + QDialogButtonBox *ui_settings_buttons; + + QWidget *ui_casing_tab; + QWidget *ui_casing_widget; + QFormLayout *ui_casing_layout; + QLabel *ui_casing_supported_lbl; + QLabel *ui_casing_enabled_lbl; + QCheckBox *ui_casing_enabled_cb; + QLabel *ui_casing_def_lbl; + QCheckBox *ui_casing_def_cb; + QLabel *ui_casing_pro_lbl; + QCheckBox *ui_casing_pro_cb; + QLabel *ui_casing_jud_lbl; + QCheckBox *ui_casing_jud_cb; + QLabel *ui_casing_jur_lbl; + QCheckBox *ui_casing_jur_cb; + QLabel *ui_casing_steno_lbl; + QCheckBox *ui_casing_steno_cb; + QLabel *ui_casing_cm_lbl; + QCheckBox *ui_casing_cm_cb; + QLabel *ui_casing_cm_cases_lbl; + QLineEdit *ui_casing_cm_cases_textbox; + + bool needs_default_audiodev(); + +signals: + +public slots: + void save_pressed(); + void discard_pressed(); +}; + +#endif // AOOPTIONSDIALOG_H diff --git a/aoscene.cpp b/aoscene.cpp index 5fe8304..344522b 100644 --- a/aoscene.cpp +++ b/aoscene.cpp @@ -6,27 +6,41 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) { m_parent = parent; ao_app = p_ao_app; + m_movie = new QMovie(this); } void AOScene::set_image(QString p_image) { - QString background_path = ao_app->get_background_path() + p_image + ".png"; - QString animated_background_path = ao_app->get_background_path() + p_image + ".gif"; - QString default_path = ao_app->get_default_background_path() + p_image; + QString background_path = ao_app->get_background_path(p_image + ".png"); + QString animated_background_path = ao_app->get_background_path(p_image + ".gif"); + QString default_path = ao_app->get_default_background_path(p_image + ".png"); QPixmap background(background_path); - QPixmap animated_background(animated_background_path); QPixmap default_bg(default_path); int w = this->width(); int h = this->height(); - if (file_exists(animated_background_path)) - this->setPixmap(animated_background.scaled(w, h)); + this->clear(); + this->setMovie(nullptr); + + m_movie->stop(); + m_movie->setFileName(animated_background_path); + m_movie->setScaledSize(QSize(w, h)); + + if (m_movie->isValid()) + { + this->setMovie(m_movie); + m_movie->start(); + } else if (file_exists(background_path)) + { this->setPixmap(background.scaled(w, h)); + } else + { this->setPixmap(default_bg.scaled(w, h)); + } } void AOScene::set_legacy_desk(QString p_image) @@ -34,8 +48,8 @@ void AOScene::set_legacy_desk(QString p_image) //vanilla desks vary in both width and height. in order to make that work with viewport rescaling, //some INTENSE math is needed. - QString desk_path = ao_app->get_background_path() + p_image; - QString default_path = ao_app->get_default_background_path() + p_image; + QString desk_path = ao_app->get_background_path(p_image); + QString default_path = ao_app->get_default_background_path(p_image); QPixmap f_desk; @@ -53,7 +67,7 @@ void AOScene::set_legacy_desk(QString p_image) //int final_y = y_modifier * vp_height; //int final_w = w_modifier * f_desk.width(); - int final_h = h_modifier * f_desk.height(); + int final_h = static_cast(h_modifier * f_desk.height()); //this->resize(final_w, final_h); //this->setPixmap(f_desk.scaled(final_w, final_h)); diff --git a/aoscene.h b/aoscene.h index 08c286e..b58c0fd 100644 --- a/aoscene.h +++ b/aoscene.h @@ -3,6 +3,7 @@ #include #include +#include class Courtroom; class AOApplication; @@ -18,6 +19,7 @@ public: private: QWidget *m_parent; + QMovie *m_movie; AOApplication *ao_app; }; diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index cc2f383..90e458e 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -1,41 +1,49 @@ #include "aosfxplayer.h" +#include "file_functions.h" AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { - m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; } -AOSfxPlayer::~AOSfxPlayer() +void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) { - m_sfxplayer->stop(); - m_sfxplayer->deleteLater(); -} + QString misc_path = ""; + QString char_path = ""; + QString sound_path = ao_app->get_sounds_path(p_sfx); -void AOSfxPlayer::play(QString p_sfx, QString p_char) -{ - m_sfxplayer->stop(); - p_sfx = p_sfx.toLower(); - QString f_path; + if (shout != "") + misc_path = ao_app->get_base_path() + "misc/" + shout + "/" + p_sfx; if (p_char != "") - f_path = ao_app->get_character_path(p_char) + p_sfx; - else - f_path = ao_app->get_sounds_path() + p_sfx; + char_path = ao_app->get_character_path(p_char, p_sfx); + + QString f_path; + + if (file_exists(char_path)) + f_path = char_path; + else if (file_exists(misc_path)) + f_path = misc_path; + else + f_path = sound_path; + + m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); set_volume(m_volume); - m_sfxplayer->play(); + if (ao_app->get_audio_output_device() != "default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + BASS_ChannelPlay(m_stream, false); } void AOSfxPlayer::stop() { - m_sfxplayer->stop(); + BASS_ChannelStop(m_stream); } void AOSfxPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + float volume = p_value / 100.0f; + BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 1b73e49..30cbe9d 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -1,29 +1,28 @@ #ifndef AOSFXPLAYER_H #define AOSFXPLAYER_H +#include "bass.h" #include "aoapplication.h" #include #include #include -#include class AOSfxPlayer { public: AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app); - ~AOSfxPlayer(); - void play(QString p_sfx, QString p_char = ""); + void play(QString p_sfx, QString p_char = "", QString shout = ""); void stop(); void set_volume(int p_volume); private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; int m_volume = 0; + HSTREAM m_stream; }; #endif // AOSFXPLAYER_H diff --git a/aotextarea.cpp b/aotextarea.cpp index 16add10..5e14632 100644 --- a/aotextarea.cpp +++ b/aotextarea.cpp @@ -5,7 +5,7 @@ AOTextArea::AOTextArea(QWidget *p_parent) : QTextBrowser(p_parent) } -void AOTextArea::append_chatmessage(QString p_name, QString p_message) +void AOTextArea::append_chatmessage(QString p_name, QString p_message, QString p_colour) { const QTextCursor old_cursor = this->textCursor(); const int old_scrollbar_value = this->verticalScrollBar()->value(); @@ -14,7 +14,7 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message) this->moveCursor(QTextCursor::End); this->append(""); - this->insertHtml("" + p_name.toHtmlEscaped() + ": "); + this->insertHtml("" + p_name.toHtmlEscaped() + ": "); //cheap workarounds ahoy p_message += " "; diff --git a/aotextarea.h b/aotextarea.h index 9f01f15..d44596b 100644 --- a/aotextarea.h +++ b/aotextarea.h @@ -12,7 +12,7 @@ class AOTextArea : public QTextBrowser public: AOTextArea(QWidget *p_parent = nullptr); - void append_chatmessage(QString p_name, QString p_message); + void append_chatmessage(QString p_name, QString p_message, QString p_colour); void append_error(QString p_message); private: diff --git a/base/serverlist.txt b/base/serverlist.txt index fef701d..f700836 100644 --- a/base/serverlist.txt +++ b/base/serverlist.txt @@ -1,4 +1 @@ -10.0.0.1:27071:the shit server -88.203.168.170:27777:Demon Server For Demons! Vanilla! 1.8+ -24.193.75.13:27053:The Flaming Phoenix -51.255.160.217:50000:Attorney Online Vidya(Dedicated) +127.0.0.1:27016:Default local server diff --git a/base/themes/default/addevidence.png b/base/themes/default/addevidence.png new file mode 100644 index 0000000..7a432af Binary files /dev/null and b/base/themes/default/addevidence.png differ diff --git a/base/themes/default/arrow_left.png b/base/themes/default/arrow_left.png index b44504e..f1098c4 100644 Binary files a/base/themes/default/arrow_left.png and b/base/themes/default/arrow_left.png differ diff --git a/base/themes/default/arrow_right.png b/base/themes/default/arrow_right.png index 8dd6d3a..2b5ad70 100644 Binary files a/base/themes/default/arrow_right.png and b/base/themes/default/arrow_right.png differ diff --git a/base/themes/default/char_selector.png b/base/themes/default/char_selector.png index 566d96f..e868cdb 100644 Binary files a/base/themes/default/char_selector.png and b/base/themes/default/char_selector.png differ diff --git a/base/themes/default/char_taken.png b/base/themes/default/char_taken.png index 6230c83..efad48d 100644 Binary files a/base/themes/default/char_taken.png and b/base/themes/default/char_taken.png differ diff --git a/base/themes/default/charselect_background.png b/base/themes/default/charselect_background.png index 53a64ca..4480e6f 100644 Binary files a/base/themes/default/charselect_background.png and b/base/themes/default/charselect_background.png differ diff --git a/base/themes/default/courtroom_design.ini b/base/themes/default/courtroom_design.ini index 16e5f47..b9c6835 100644 --- a/base/themes/default/courtroom_design.ini +++ b/base/themes/default/courtroom_design.ini @@ -1,52 +1,236 @@ +; Client size. Changing it to something other than 714, 668 will stretch or +; compress courtroombackground.png accordingly. courtroom = 0, 0, 714, 668 + +; IC Area. Changing 256, 192 will stretch or compress character gifs and the +; /bgs being used accordingly viewport = 0, 0, 256, 192 -chatbox = 0, 96, 256, 78 -ao2_chatbox = 0, 114, 256, 78 -showname = 6, 113, 80, 15 -message = 3, 132, 250, 60 + +; IC chatbox +chatbox = 0, 174, 256, 108 + +; IC chatbox if the current background's folder contains stand.png, +; defensedesk.png and prosecutiondesk.png +ao2_chatbox = 0, 174, 256, 108 + +; Textbox for custom IC name (the "showname") +showname = 6, 1, 256, 15 + +; IC message, positioned within the chatbox. Changing 250 affects how +; long text goes on before going onto the next line. Changing 89 affects +; how many lines you can see before the message starts scrolling, based on +; the formula of n = 25+(n-1)*16, where n is the number of lines to be +; displayed. (ie, set it to 25 for 1 line, 41 for 2, 57 for 3, 73 for 4, +; 89 for 5, 105 for 6... Less than 25 displays nothing) +message = 3, 18, 250, 89 + +; Where you type to make an IC chat message +ic_chat_message = 2, 283, 250, 23 + +; IC chat message if the current background's folder contains stand.png, +; defensedesk.png and prosecutiondesk.png +ao2_ic_chat_message = 2, 283, 250, 23 + +; IC chatlog ic_chatlog = 260, 0, 231, 319 + +; Master server chatlog ms_chatlog = 490, 1, 224, 277 + +; OOC Chatlog server_chatlog = 490, 1, 224, 277 -mute_list = 260, 160, 231, 159 -area_list = 266, 494, 224, 174 -music_list = 490, 342, 224, 326 -ic_chat_message = 0, 174, 256, 23 -ao2_ic_chat_message = 0, 192, 256, 23 + +; Where you type to make an OOC chat message +; NOTE: THIS DOES NOT HAVE ANY VISUAL APPEARANCE ooc_chat_message = 492, 281, 222, 19 + +; Where you enter your OOC name, and also where it shows up ooc_chat_name = 492, 300, 85, 19 -area_password = 266, 471, 224, 23 -music_search = 490, 319, 226, 23 -emote_left = 0, 253, 20, 20 -emote_right = 236, 253, 20, 20 -defense_bar = 393, 323, 84, 14 -prosecution_bar = 393, 340, 84, 14 -music_label = 260, 390, 41, 16 -sfx_label = 260, 410, 21, 16 -blip_label = 260, 430, 31, 16 -hold_it = 10, 312, 76, 28 -objection = 90, 312, 76, 28 -take_that = 170, 312, 76, 28 + +; Toggle between Server and Master OOC chats ooc_toggle = 580, 300, 133, 19 -witness_testimony = 5, 345, 85, 42 -cross_examination = 95, 345, 85, 42 -change_character = 5, 390, 121, 23 -reload_theme = 5, 415, 101, 23 -call_mod = 5, 440, 71, 23 -pre = 187, 345, 51, 21 -flip = 187, 362, 51, 21 -guard = 187, 379, 61, 21 -custom_objection = 250, 325, 40, 40 -realization = 295, 325, 40, 40 -mute_button = 340, 325, 40, 40 -defense_plus = 477, 325, 9, 9 -defense_minus = 385, 325, 9, 9 -prosecution_plus = 477, 342, 9, 9 -prosecution_minus = 385, 342, 9, 9 -text_color = 390, 360, 79, 23 -music_slider = 310, 392, 160, 16 -sfx_slider = 310, 412, 160, 16 -blip_slider = 310, 432, 160, 16 + +; Where the jukebox is +music_list = 490, 342, 224, 326 + +; Jukebox search bar +music_search = 490, 319, 100, 23 + +found_song_color = 100, 255, 100 +missing_song_color = 255, 100, 100 + +; Labels and sliders for music/sfx/blips +music_label = 282, 607, 41, 16 +sfx_label = 282, 627, 41, 16 +blip_label = 282, 647, 41, 16 +music_slider = 326, 608, 140, 16 +sfx_slider = 326, 628, 140, 16 +blip_slider = 326, 648, 140, 16 + +; Emote buttons - [490, 98] determines how many columns and rows of buttons are +; displayed per page. 49, 49 is the ABSOLUTE MINIMUM, and displays 1 button per +; page. Having either number lower than 49 crashes the client when you try to +; pick a character. If you want X columns and Y rows, you would change it to +; 49X, 49Y (ie. 490, 147 if you want 10 columns and 3 rows) +emotes = 10, 342, 490, 147 +emote_button_spacing = 9, 9 + +; Page togglers for emotes +emote_left = 373, 475, 17, 17 +emote_right = 392, 475, 17, 17 + +; Emote dropdown/emote names - Change '125' to make it longer/shorter and +; display the full emote name or truncate it based on length +emote_dropdown = 5, 470, 105, 20 + +; Hold it/Take That/Objection and the "BLING!" buttons +hold_it = 10, 310, 76, 28 +objection = 90, 310, 76, 28 +take_that = 170, 310, 76, 28 +realization = 5, 515, 42, 42 + +; If the server supports it (AOV does not currently) - if a character has a +; custom.gif and custom.wav in their folder, this button acts as another +; Objection/Take That/Hold It for that character that uses the custom animation +; and sfx. (Think Satorah! Such Insolence!, Gotcha!) +custom_objection = 340, 565, 76, 28 + +; Text color dropdown menu +text_color = 115, 470, 80, 20 + +pos_dropdown = 200, 470, 80, 20 + +; Preanimation toggle +pre = 5, 490, 80, 21 + +; Flip button +flip = 104, 490, 51, 21 + +; Guard button +guard = 200, 560, 61, 21 + +pre_no_interrupt = 200, 490, 80, 21 + +; Penalty bars and judge's buttons for penalizing. Other than the bars, these +; ONLY show up on a character with /pos jud +defense_bar = 15, 566, 170, 9 +prosecution_bar = 15, 582, 170, 9 +defense_plus = 183, 566, 9, 9 +defense_minus = 6, 566, 9, 9 +prosecution_plus = 183, 582, 9, 9 +prosecution_minus = 6, 582, 9, 9 + +; Judge's buttons for WT and CE. /pos jud +witness_testimony = 290, 470, 85, 42 +cross_examination = 290, 515, 85, 42 + +; Buttons to change character/Reload theme/Call Mod +change_character = 5, 610, 120, 23 +reload_theme = 5, 637, 94, 23 +call_mod = 104, 637, 64, 23 + +; Mute button +mute_button = 150, 515, 42, 42 + +; Where the Mute list pops up when you click Mute +mute_list = 280, 469, 210, 198 + +; ???? - if there was an Area button, where the area list would show up? +; area_list = 270, 494, 224, 174 + +; ???? - where a password box appears if an area is password locked? +; area_password = 266, 471, 224, 23 + +; >Evidence meme +evidence_button = 627, 322, 85, 18 +evidence_background = 0, 385, 490, 284 +evidence_name = 112, 4, 264, 19 +evidence_buttons = 28, 27, 430, 216 +evidence_button_spacing = 2, 3 +evidence_overlay = 24, 24, 439, 222 +evidence_delete = 78, 8, 70, 20 +evidence_image_name = 150, 8, 130, 20 +evidence_image_button = 280, 8, 60, 20 +evidence_x = 341, 8, 20, 20 +evidence_description = 78, 28, 281, 166 +evidence_left = 2, 124, 20, 20 +evidence_right = 465, 124, 20, 20 +evidence_present = 165, 247, 158, 41 + +; Character select widgets char_select = 0, 0, 714, 668 back_to_lobby = 5, 5, 91, 23 char_password = 297, 7, 120, 22 +char_buttons = 25, 36, 663, 596 +char_button_spacing = 7, 7 +char_select_left = 2, 325, 20, 20 +char_select_right = 691, 325, 20, 20 spectator = 317, 640, 80, 23 + +; ------------------------- +; New in 2.6.0 +; ------------------------- + +; The log limiter explaining label. This is simply a piece of text that +; explains what the spin box is for. +; log_limit_label = 190, 612, 50, 30 + +; The spinbox allows you to set the log limit ingame inbetween 1 and 10000, +; with the option to set it to 0 as well (which is considered 'infinite' by +; the log limiter). +; log_limit_spinbox = 168, 636, 70, 25 + +; This is an input field that allows you to change your in-character showname. +ic_chat_name = 200, 534, 78, 23 + +; I am sure there are some differences between the 'ao2_' versions and the +; 'ao2_'-less versions of the IC text display and input, but I do not know +; what. Still, here you go! +ao2_ic_chat_name = 200, 534, 78, 23 + +; An in-game tickbox that allows you to set whether your client should show +; custom shownames where possible, or always keep to character names. +; This is useful if you suspect someone is impersonating others, for example, +; and they are using this in combination with ini-swapping to 'duplicate' a +; character. +showname_enable = 200, 510, 80, 21 + +; A simple button that opens up the settings menu. +; Equivalent to typing /settings in the OOC chat. +settings = 130, 610, 60, 23 + +; The character search text input in the character selecton screen. +; The moment you enter some text, it immediately starts filtering. +char_search = 420, 7, 120, 22 + +; A tickbox that filters based on if a character requires password to access or not. +; Note that this is actually only partially implemented in AO. +; The interface exists for it, but no way to actually password the characters. +char_passworded = 545, 7, 100, 22 + +; A tickbox that filters characters based on if they are taken. +char_taken = 635, 7, 80, 22 + +; These buttons are similar to the CE / WT buttons, except they show a +; Not Guilty or Guilty animation instead. +not_guilty = 380, 470, 85, 42 +guilty = 380, 515, 85, 42 + +; These are responsible for the pairing stuff. +; These work much like muting, actually. +pair_button = 104, 515, 42, 42 +pair_list = 280, 490, 210, 177 +pair_offset_spinbox = 280, 470, 210, 20 + +; This button allows switching between music and areas. +switch_area_music = 590, 319, 35, 23 + +; These are colours for the various statuses an area can be in. +area_free_color = 54, 198, 68 +area_lfp_color = 255, 255 0 +area_casing_color = 255, 166, 0 +area_recess_color = 255, 190, 30 +area_rp_color = 200, 52, 252 +area_gaming_color = 55, 255, 255 +area_locked_color = 165, 43, 43 + diff --git a/base/themes/default/courtroom_fonts.ini b/base/themes/default/courtroom_fonts.ini new file mode 100644 index 0000000..16e2f41 --- /dev/null +++ b/base/themes/default/courtroom_fonts.ini @@ -0,0 +1,11 @@ +showname = 8 +message = 10 +ic_chatlog = 10 +ms_chatlog = 10 +server_chatlog = 9 +music_list = 8 + +ic_chatlog_color = 255, 255, 255 + +; Color for all labels and checkboxes +label_color = 255, 255, 255 diff --git a/base/themes/default/courtroom_sounds.ini b/base/themes/default/courtroom_sounds.ini new file mode 100644 index 0000000..b24e2ce --- /dev/null +++ b/base/themes/default/courtroom_sounds.ini @@ -0,0 +1,8 @@ +realization = sfx-realization.wav +witness_testimony = sfx-testimony2.wav +cross_examination = sfx-testimony.wav +evidence_present = sfx-evidenceshoop.wav +word_call = sfx-gaspen-yeah!.wav +mod_call = sfx-gallery.wav +not_guilty = sfx-notguilty.wav +guilty = sfx-guilty.wav \ No newline at end of file diff --git a/base/themes/default/courtroombackground.png b/base/themes/default/courtroombackground.png index e940404..5ad8d51 100644 Binary files a/base/themes/default/courtroombackground.png and b/base/themes/default/courtroombackground.png differ diff --git a/base/themes/default/custom.png b/base/themes/default/custom.png index b34ccfb..b58d162 100644 Binary files a/base/themes/default/custom.png and b/base/themes/default/custom.png differ diff --git a/base/themes/default/custom_selected.png b/base/themes/default/custom_selected.png index 68b4160..d8dc525 100644 Binary files a/base/themes/default/custom_selected.png and b/base/themes/default/custom_selected.png differ diff --git a/base/themes/default/defensebar0.png b/base/themes/default/defensebar0.png index 44ffa2c..e15b727 100644 Binary files a/base/themes/default/defensebar0.png and b/base/themes/default/defensebar0.png differ diff --git a/base/themes/default/defensebar1.png b/base/themes/default/defensebar1.png index 7b929a1..ddc7c05 100644 Binary files a/base/themes/default/defensebar1.png and b/base/themes/default/defensebar1.png differ diff --git a/base/themes/default/defensebar10.png b/base/themes/default/defensebar10.png index 9dfbc6f..5c955b4 100644 Binary files a/base/themes/default/defensebar10.png and b/base/themes/default/defensebar10.png differ diff --git a/base/themes/default/defensebar2.png b/base/themes/default/defensebar2.png index 440783c..78835aa 100644 Binary files a/base/themes/default/defensebar2.png and b/base/themes/default/defensebar2.png differ diff --git a/base/themes/default/defensebar3.png b/base/themes/default/defensebar3.png index 93ef86f..8d8427a 100644 Binary files a/base/themes/default/defensebar3.png and b/base/themes/default/defensebar3.png differ diff --git a/base/themes/default/defensebar4.png b/base/themes/default/defensebar4.png index a36fec7..0441683 100644 Binary files a/base/themes/default/defensebar4.png and b/base/themes/default/defensebar4.png differ diff --git a/base/themes/default/defensebar5.png b/base/themes/default/defensebar5.png index 321c4f3..d9236c2 100644 Binary files a/base/themes/default/defensebar5.png and b/base/themes/default/defensebar5.png differ diff --git a/base/themes/default/defensebar6.png b/base/themes/default/defensebar6.png index c8e7029..373bc1b 100644 Binary files a/base/themes/default/defensebar6.png and b/base/themes/default/defensebar6.png differ diff --git a/base/themes/default/defensebar7.png b/base/themes/default/defensebar7.png index c3af2a2..09c8d1a 100644 Binary files a/base/themes/default/defensebar7.png and b/base/themes/default/defensebar7.png differ diff --git a/base/themes/default/defensebar8.png b/base/themes/default/defensebar8.png index e1176f6..13a4548 100644 Binary files a/base/themes/default/defensebar8.png and b/base/themes/default/defensebar8.png differ diff --git a/base/themes/default/defensebar9.png b/base/themes/default/defensebar9.png index 171e648..d98ab4d 100644 Binary files a/base/themes/default/defensebar9.png and b/base/themes/default/defensebar9.png differ diff --git a/base/themes/default/deleteevidence.png b/base/themes/default/deleteevidence.png new file mode 100644 index 0000000..396d990 Binary files /dev/null and b/base/themes/default/deleteevidence.png differ diff --git a/base/themes/default/evidence_appear_left.gif b/base/themes/default/evidence_appear_left.gif new file mode 100644 index 0000000..352a7f1 Binary files /dev/null and b/base/themes/default/evidence_appear_left.gif differ diff --git a/base/themes/default/evidence_appear_right.gif b/base/themes/default/evidence_appear_right.gif new file mode 100644 index 0000000..bc45e52 Binary files /dev/null and b/base/themes/default/evidence_appear_right.gif differ diff --git a/base/themes/default/evidence_selected.png b/base/themes/default/evidence_selected.png new file mode 100644 index 0000000..6230c83 Binary files /dev/null and b/base/themes/default/evidence_selected.png differ diff --git a/base/themes/default/evidence_selector.png b/base/themes/default/evidence_selector.png new file mode 100644 index 0000000..266493d Binary files /dev/null and b/base/themes/default/evidence_selector.png differ diff --git a/base/themes/default/evidencebackground.png b/base/themes/default/evidencebackground.png new file mode 100644 index 0000000..ca28532 Binary files /dev/null and b/base/themes/default/evidencebackground.png differ diff --git a/base/themes/default/evidencebutton.png b/base/themes/default/evidencebutton.png new file mode 100644 index 0000000..2c395ec Binary files /dev/null and b/base/themes/default/evidencebutton.png differ diff --git a/base/themes/default/evidenceoverlay.png b/base/themes/default/evidenceoverlay.png new file mode 100644 index 0000000..d409cc5 Binary files /dev/null and b/base/themes/default/evidenceoverlay.png differ diff --git a/base/themes/default/evidencex.png b/base/themes/default/evidencex.png new file mode 100644 index 0000000..6a6be36 Binary files /dev/null and b/base/themes/default/evidencex.png differ diff --git a/base/themes/default/guilty.gif b/base/themes/default/guilty.gif new file mode 100644 index 0000000..3dd95d5 Binary files /dev/null and b/base/themes/default/guilty.gif differ diff --git a/base/themes/default/guilty.png b/base/themes/default/guilty.png new file mode 100644 index 0000000..efe68f7 Binary files /dev/null and b/base/themes/default/guilty.png differ diff --git a/base/themes/default/holdit.png b/base/themes/default/holdit.png index d7112e2..09d1d37 100644 Binary files a/base/themes/default/holdit.png and b/base/themes/default/holdit.png differ diff --git a/base/themes/default/holdit_selected.png b/base/themes/default/holdit_selected.png index 6887676..51586e7 100644 Binary files a/base/themes/default/holdit_selected.png and b/base/themes/default/holdit_selected.png differ diff --git a/base/themes/default/lobby_design.ini b/base/themes/default/lobby_design.ini index 4806b86..ef64114 100644 --- a/base/themes/default/lobby_design.ini +++ b/base/themes/default/lobby_design.ini @@ -1,9 +1,10 @@ lobby = 0, 0, 517, 666 -publi_servers = 46, 88, 114, 30 +public_servers = 46, 88, 114, 30 favorites = 164, 88, 114, 30 refresh = 56, 381, 132, 28 add_to_fav = 194, 381, 132, 28 connect = 332, 381, 132, 28 +version = 170, 1, 300, 21 about = 428, 1, 88, 21 server_list = 20, 125, 286, 240 player_count = 336, 91, 173, 16 diff --git a/base/themes/default/mute.png b/base/themes/default/mute.png index 6de496c..a184cbf 100644 Binary files a/base/themes/default/mute.png and b/base/themes/default/mute.png differ diff --git a/base/themes/default/mute_pressed.png b/base/themes/default/mute_pressed.png index 548f804..e9793ce 100644 Binary files a/base/themes/default/mute_pressed.png and b/base/themes/default/mute_pressed.png differ diff --git a/base/themes/default/notguilty.gif b/base/themes/default/notguilty.gif new file mode 100644 index 0000000..d057715 Binary files /dev/null and b/base/themes/default/notguilty.gif differ diff --git a/base/themes/default/notguilty.png b/base/themes/default/notguilty.png new file mode 100644 index 0000000..b9cfe31 Binary files /dev/null and b/base/themes/default/notguilty.png differ diff --git a/base/themes/default/objection.png b/base/themes/default/objection.png index 655a724..6fbcbc2 100644 Binary files a/base/themes/default/objection.png and b/base/themes/default/objection.png differ diff --git a/base/themes/default/objection_selected.png b/base/themes/default/objection_selected.png index 3254263..384e4e9 100644 Binary files a/base/themes/default/objection_selected.png and b/base/themes/default/objection_selected.png differ diff --git a/base/themes/default/pair_button.png b/base/themes/default/pair_button.png new file mode 100644 index 0000000..19f6f22 Binary files /dev/null and b/base/themes/default/pair_button.png differ diff --git a/base/themes/default/pair_button_pressed.png b/base/themes/default/pair_button_pressed.png new file mode 100644 index 0000000..aaf53fb Binary files /dev/null and b/base/themes/default/pair_button_pressed.png differ diff --git a/base/themes/default/prosecutionbar0.png b/base/themes/default/prosecutionbar0.png index 44ffa2c..040d671 100644 Binary files a/base/themes/default/prosecutionbar0.png and b/base/themes/default/prosecutionbar0.png differ diff --git a/base/themes/default/prosecutionbar1.png b/base/themes/default/prosecutionbar1.png index bba1ec8..cb9af2d 100644 Binary files a/base/themes/default/prosecutionbar1.png and b/base/themes/default/prosecutionbar1.png differ diff --git a/base/themes/default/prosecutionbar10.png b/base/themes/default/prosecutionbar10.png index 318f0d7..f0a79c3 100644 Binary files a/base/themes/default/prosecutionbar10.png and b/base/themes/default/prosecutionbar10.png differ diff --git a/base/themes/default/prosecutionbar2.png b/base/themes/default/prosecutionbar2.png index ceb6e06..08ef12b 100644 Binary files a/base/themes/default/prosecutionbar2.png and b/base/themes/default/prosecutionbar2.png differ diff --git a/base/themes/default/prosecutionbar3.png b/base/themes/default/prosecutionbar3.png index 44e87f1..278d3e4 100644 Binary files a/base/themes/default/prosecutionbar3.png and b/base/themes/default/prosecutionbar3.png differ diff --git a/base/themes/default/prosecutionbar4.png b/base/themes/default/prosecutionbar4.png index a48e67e..64f2e9d 100644 Binary files a/base/themes/default/prosecutionbar4.png and b/base/themes/default/prosecutionbar4.png differ diff --git a/base/themes/default/prosecutionbar5.png b/base/themes/default/prosecutionbar5.png index e67ca1b..5cf62a4 100644 Binary files a/base/themes/default/prosecutionbar5.png and b/base/themes/default/prosecutionbar5.png differ diff --git a/base/themes/default/prosecutionbar6.png b/base/themes/default/prosecutionbar6.png index 14a3b77..c87b86f 100644 Binary files a/base/themes/default/prosecutionbar6.png and b/base/themes/default/prosecutionbar6.png differ diff --git a/base/themes/default/prosecutionbar7.png b/base/themes/default/prosecutionbar7.png index 1d0ac1f..f31fcc1 100644 Binary files a/base/themes/default/prosecutionbar7.png and b/base/themes/default/prosecutionbar7.png differ diff --git a/base/themes/default/prosecutionbar8.png b/base/themes/default/prosecutionbar8.png index 1edc893..a2a8935 100644 Binary files a/base/themes/default/prosecutionbar8.png and b/base/themes/default/prosecutionbar8.png differ diff --git a/base/themes/default/prosecutionbar9.png b/base/themes/default/prosecutionbar9.png index ad3a245..d272ca3 100644 Binary files a/base/themes/default/prosecutionbar9.png and b/base/themes/default/prosecutionbar9.png differ diff --git a/base/themes/default/realization.png b/base/themes/default/realization.png index e171813..f791d29 100644 Binary files a/base/themes/default/realization.png and b/base/themes/default/realization.png differ diff --git a/base/themes/default/realization_pressed.png b/base/themes/default/realization_pressed.png index be029d7..9a72ed3 100644 Binary files a/base/themes/default/realization_pressed.png and b/base/themes/default/realization_pressed.png differ diff --git a/base/themes/default/takethat.png b/base/themes/default/takethat.png index 3c87805..8ff2bef 100644 Binary files a/base/themes/default/takethat.png and b/base/themes/default/takethat.png differ diff --git a/base/themes/default/takethat_selected.png b/base/themes/default/takethat_selected.png index 06581a0..3fe0a8c 100644 Binary files a/base/themes/default/takethat_selected.png and b/base/themes/default/takethat_selected.png differ diff --git a/base/themes/default/testimony.png b/base/themes/default/testimony.png new file mode 100644 index 0000000..7b81fc8 Binary files /dev/null and b/base/themes/default/testimony.png differ diff --git a/charselect.cpp b/charselect.cpp index 4e4bccb..8e1b912 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -1,11 +1,10 @@ #include "courtroom.h" +#include "lobby.h" #include "file_functions.h" #include "debug_functions.h" #include "hardware_functions.h" -#include - void Courtroom::construct_char_select() { ui_char_select_background = new AOImage(this, ao_app); @@ -19,49 +18,32 @@ void Courtroom::construct_char_select() ui_back_to_lobby = new AOButton(ui_char_select_background, ao_app); ui_char_password = new QLineEdit(ui_char_select_background); + ui_char_password->setPlaceholderText(tr("Password")); ui_char_select_left = new AOButton(ui_char_select_background, ao_app); ui_char_select_right = new AOButton(ui_char_select_background, ao_app); ui_spectator = new AOButton(ui_char_select_background, ao_app); - ui_spectator->setText("Spectator"); + ui_spectator->setText(tr("Spectator")); - QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini"); + ui_char_search = new QLineEdit(ui_char_select_background); + ui_char_search->setPlaceholderText(tr("Search")); + ui_char_search->setFocus(); + set_size_and_pos(ui_char_search, "char_search"); - const int button_width = 60; - int x_spacing = f_spacing.x(); - int x_mod_count = 0; + ui_char_passworded = new QCheckBox(ui_char_select_background); + ui_char_passworded->setText(tr("Passworded")); + set_size_and_pos(ui_char_passworded, "char_passworded"); - const int button_height = 60; - int y_spacing = f_spacing.y(); - int y_mod_count = 0; + ui_char_taken = new QCheckBox(ui_char_select_background); + ui_char_taken->setText(tr("Taken")); + set_size_and_pos(ui_char_taken, "char_taken"); + + ui_char_taken->setChecked(true); + ui_char_passworded->setChecked(true); set_size_and_pos(ui_char_buttons, "char_buttons"); - char_columns = ((ui_char_buttons->width() - button_width) / (x_spacing + button_width)) + 1; - char_rows = ((ui_char_buttons->height() - button_height) / (y_spacing + button_height)) + 1; - - max_chars_on_page = char_columns * char_rows; - - for (int n = 0 ; n < max_chars_on_page ; ++n) - { - int x_pos = (button_width + x_spacing) * x_mod_count; - int y_pos = (button_height + y_spacing) * y_mod_count; - - ui_char_button_list.append(new AOCharButton(ui_char_buttons, ao_app, x_pos, y_pos)); - - connect(ui_char_button_list.at(n), SIGNAL(clicked()), char_button_mapper, SLOT(map())) ; - char_button_mapper->setMapping (ui_char_button_list.at(n), n) ; - - ++x_mod_count; - - if (x_mod_count == char_columns) - { - ++y_mod_count; - x_mod_count = 0; - } - } - connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(int))); connect(ui_back_to_lobby, SIGNAL(clicked()), this, SLOT(on_back_to_lobby_clicked())); @@ -69,6 +51,10 @@ void Courtroom::construct_char_select() connect(ui_char_select_right, SIGNAL(clicked()), this, SLOT(on_char_select_right_clicked())); connect(ui_spectator, SIGNAL(clicked()), this, SLOT(on_spectator_clicked())); + + connect(ui_char_search, SIGNAL(textEdited(const QString&)), this, SLOT(on_char_search_changed(const QString&))); + connect(ui_char_passworded, SIGNAL(stateChanged(int)), this, SLOT(on_char_passworded_clicked(int))); + connect(ui_char_taken, SIGNAL(stateChanged(int)), this, SLOT(on_char_taken_clicked(int))); } void Courtroom::set_char_select() @@ -87,6 +73,10 @@ void Courtroom::set_char_select() ui_char_select_background->resize(f_charselect.width, f_charselect.height); ui_char_select_background->set_image("charselect_background.png"); + + filter_character_list(); + + ui_char_search->setFocus(); } void Courtroom::set_char_select_page() @@ -97,19 +87,23 @@ void Courtroom::set_char_select_page() ui_char_select_right->hide(); for (AOCharButton *i_button : ui_char_button_list) + { + i_button->reset(); i_button->hide(); + i_button->move(0,0); + } - int total_pages = char_list.size() / max_chars_on_page; + int total_pages = ui_char_button_list_filtered.size() / max_chars_on_page; int chars_on_page = 0; - if (char_list.size() % max_chars_on_page != 0) + if (ui_char_button_list_filtered.size() % max_chars_on_page != 0) { ++total_pages; //i. e. not on the last page if (total_pages > current_char_page + 1) chars_on_page = max_chars_on_page; else - chars_on_page = char_list.size() % max_chars_on_page; + chars_on_page = ui_char_button_list_filtered.size() % max_chars_on_page; } else @@ -121,42 +115,154 @@ void Courtroom::set_char_select_page() if (current_char_page > 0) ui_char_select_left->show(); - for (int n_button = 0 ; n_button < chars_on_page ; ++n_button) - { - int n_real_char = n_button + current_char_page * max_chars_on_page; - AOCharButton *f_button = ui_char_button_list.at(n_button); - - f_button->reset(); - f_button->set_image(char_list.at(n_real_char).name); - f_button->show(); - - if (char_list.at(n_real_char).taken) - f_button->set_taken(); - } - + put_button_in_place(current_char_page * max_chars_on_page, chars_on_page); } void Courtroom::char_clicked(int n_char) { - int n_real_char = n_char + current_char_page * max_chars_on_page; + QString char_ini_path = ao_app->get_character_path(char_list.at(n_char).name, "char.ini"); - QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name) + "char.ini"; qDebug() << "char_ini_path" << char_ini_path; if (!file_exists(char_ini_path)) { - qDebug() << "did not find " << char_ini_path; call_notice("Could not find " + char_ini_path); return; } - if (n_real_char == m_cid) + if (n_char == m_cid) { enter_courtroom(m_cid); } else { - ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%")); + ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_char) + "#" + get_hdid() + "#%")); } + + ui_ic_chat_name->setPlaceholderText(char_list.at(n_char).name); } +void Courtroom::put_button_in_place(int starting, int chars_on_this_page) +{ + if (ui_char_button_list_filtered.size() == 0) + return; + + QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini"); + + int x_spacing = f_spacing.x(); + int x_mod_count = 0; + + int y_spacing = f_spacing.y(); + int y_mod_count = 0; + + char_columns = ((ui_char_buttons->width() - button_width) / (x_spacing + button_width)) + 1; + char_rows = ((ui_char_buttons->height() - button_height) / (y_spacing + button_height)) + 1; + + max_chars_on_page = char_columns * char_rows; + + int startout = starting; + for (int n = starting ; n < startout+chars_on_this_page ; ++n) + { + int x_pos = (button_width + x_spacing) * x_mod_count; + int y_pos = (button_height + y_spacing) * y_mod_count; + + ui_char_button_list_filtered.at(n)->move(x_pos, y_pos); + ui_char_button_list_filtered.at(n)->show(); + ui_char_button_list_filtered.at(n)->apply_taken_image(); + + ++x_mod_count; + + if (x_mod_count == char_columns) + { + ++y_mod_count; + x_mod_count = 0; + } + } +} + +void Courtroom::character_loading_finished() +{ + // Zeroeth, we'll clear any leftover characters from previous server visits. + ao_app->generated_chars = 0; + if (ui_char_button_list.size() > 0) + { + foreach (AOCharButton* item, ui_char_button_list) { + delete item; + } + ui_char_button_list.clear(); + } + + // First, we'll make all the character buttons in the very beginning. + // We also hide them all, so they can't be accidentally clicked. + // Later on, we'll be revealing buttons as we need them. + for (int n = 0; n < char_list.size(); n++) + { + AOCharButton* character = new AOCharButton(ui_char_buttons, ao_app, 0, 0, char_list.at(n).taken); + character->reset(); + character->hide(); + character->set_image(char_list.at(n).name); + ui_char_button_list.append(character); + + connect(character, SIGNAL(clicked()), char_button_mapper, SLOT(map())); + char_button_mapper->setMapping(character, ui_char_button_list.size() - 1); + + // This part here serves as a way of showing to the player that the game is still running, it is + // just loading the pictures of the characters. + if (ao_app->lobby_constructed) + { + ao_app->generated_chars++; + int total_loading_size = ao_app->char_list_size * 2 + ao_app->evidence_list_size + ao_app->music_list_size; + int loading_value = int(((ao_app->loaded_chars + ao_app->generated_chars + ao_app->loaded_music + ao_app->loaded_evidence) / static_cast(total_loading_size)) * 100); + ao_app->w_lobby->set_loading_value(loading_value); + ao_app->w_lobby->set_loading_text("Generating chars:\n" + QString::number(ao_app->generated_chars) + "/" + QString::number(ao_app->char_list_size)); + } + } + + filter_character_list(); +} + +void Courtroom::filter_character_list() +{ + ui_char_button_list_filtered.clear(); + for (int i = 0; i < char_list.size(); i++) + { + AOCharButton* current_char = ui_char_button_list.at(i); + + // It seems passwording characters is unimplemented yet? + // Until then, this will stay here, I suppose. + //if (ui_char_passworded->isChecked() && character_is_passworded??) + // continue; + + if (!ui_char_taken->isChecked() && char_list.at(i).taken) + continue; + + if (!char_list.at(i).name.contains(ui_char_search->text(), Qt::CaseInsensitive)) + continue; + + // We only really need to update the fact that a character is taken + // for the buttons that actually appear. + // You'd also update the passwordedness and etc. here later. + current_char->reset(); + current_char->set_taken(char_list.at(i).taken); + + ui_char_button_list_filtered.append(current_char); + } + + current_char_page = 0; + set_char_select_page(); +} + +void Courtroom::on_char_search_changed(const QString& newtext) +{ + filter_character_list(); +} + +void Courtroom::on_char_passworded_clicked(int newstate) +{ + filter_character_list(); +} + +void Courtroom::on_char_taken_clicked(int newstate) +{ + filter_character_list(); +} diff --git a/chatlogpiece.cpp b/chatlogpiece.cpp new file mode 100644 index 0000000..6c861f0 --- /dev/null +++ b/chatlogpiece.cpp @@ -0,0 +1,76 @@ +#include "chatlogpiece.h" + +chatlogpiece::chatlogpiece() +{ + name = "UNKNOWN"; + showname = "UNKNOWN"; + message = "UNKNOWN"; + is_song = false; + datetime = QDateTime::currentDateTime().toUTC(); +} + +chatlogpiece::chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song) +{ + name = p_name; + showname = p_showname; + message = p_message; + is_song = p_song; + datetime = QDateTime::currentDateTime().toUTC(); +} + +chatlogpiece::chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song, QDateTime p_datetime) +{ + name = p_name; + showname = p_showname; + message = p_message; + is_song = p_song; + datetime = p_datetime.toUTC(); +} + +QString chatlogpiece::get_name() +{ + return name; +} + +QString chatlogpiece::get_showname() +{ + return showname; +} + +QString chatlogpiece::get_message() +{ + return message; +} + +QDateTime chatlogpiece::get_datetime() +{ + return datetime; +} + +bool chatlogpiece::get_is_song() +{ + return is_song; +} + +QString chatlogpiece::get_datetime_as_string() +{ + return datetime.toString(); +} + + +QString chatlogpiece::get_full() +{ + QString full = "["; + + full.append(get_datetime_as_string()); + full.append(" UTC] "); + full.append(get_showname()); + full.append(" ("); + full.append(get_name()); + full.append(")"); + if (is_song) + full.append(" has played a song: "); + full.append(get_message()); + + return full; +} diff --git a/chatlogpiece.h b/chatlogpiece.h new file mode 100644 index 0000000..34c5926 --- /dev/null +++ b/chatlogpiece.h @@ -0,0 +1,31 @@ +#ifndef CHATLOGPIECE_H +#define CHATLOGPIECE_H + +#include +#include + +class chatlogpiece +{ +public: + chatlogpiece(); + chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song); + chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song, QDateTime p_datetime); + + QString get_name(); + QString get_showname(); + QString get_message(); + bool get_is_song(); + QDateTime get_datetime(); + QString get_datetime_as_string(); + + QString get_full(); + +private: + QString name; + QString showname; + QString message; + QDateTime datetime; + bool is_song; +}; + +#endif // CHATLOGPIECE_H diff --git a/courtroom.cpp b/courtroom.cpp index 5c552a1..249cc16 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -4,6 +4,31 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; + // Change the default audio output device to be the one the user has given + // in his config.ini file for now. + int a = 0; + BASS_DEVICEINFO info; + + if (ao_app->get_audio_output_device() == "default") + { + BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); + load_bass_opus_plugin(); + } + else + { + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + { + if (ao_app->get_audio_output_device() == info.name) + { + BASS_SetDevice(a); + BASS_Init(a, 48000, BASS_DEVICE_LATENCY, nullptr, nullptr); + load_bass_opus_plugin(); + qDebug() << info.name << "was set as the default audio output device."; + break; + } + } + } + keepalive_timer = new QTimer(this); keepalive_timer->start(60000); @@ -45,6 +70,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_vp_speedlines = new AOMovie(ui_viewport, ao_app); ui_vp_speedlines->set_play_once(false); ui_vp_player_char = new AOCharMovie(ui_viewport, ao_app); + ui_vp_sideplayer_char = new AOCharMovie(ui_viewport, ao_app); + ui_vp_sideplayer_char->hide(); ui_vp_desk = new AOScene(ui_viewport, ao_app); ui_vp_legacy_desk = new AOScene(ui_viewport, ao_app); @@ -66,6 +93,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ic_chatlog = new QTextEdit(this); ui_ic_chatlog->setReadOnly(true); + log_maximum_blocks = ao_app->get_max_log_size(); + log_goes_downwards = ao_app->get_log_goes_downwards(); + ui_ms_chatlog = new AOTextArea(this); ui_ms_chatlog->setReadOnly(true); ui_ms_chatlog->setOpenExternalLinks(true); @@ -75,12 +105,17 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_server_chatlog->setReadOnly(true); ui_server_chatlog->setOpenExternalLinks(true); - ui_mute_list = new QListWidget(this); - //ui_area_list = new QListWidget(this); + ui_area_list = new QListWidget(this); + ui_area_list->hide(); ui_music_list = new QListWidget(this); + ui_ic_chat_name = new QLineEdit(this); + ui_ic_chat_name->setFrame(false); + ui_ic_chat_name->setPlaceholderText(tr("Showname")); + ui_ic_chat_message = new QLineEdit(this); ui_ic_chat_message->setFrame(false); + ui_ic_chat_message->setPlaceholderText(tr("Message")); ui_muted = new AOImage(ui_ic_chat_message, ao_app); ui_muted->hide(); @@ -91,12 +126,14 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_chat_name = new QLineEdit(this); ui_ooc_chat_name->setFrame(false); ui_ooc_chat_name->setPlaceholderText("Name"); - ui_ooc_chat_name->setText(ao_app->get_ooc_name()); + ui_ooc_chat_name->setMaxLength(30); + ui_ooc_chat_name->setText(p_ao_app->get_default_username()); //ui_area_password = new QLineEdit(this); //ui_area_password->setFrame(false); ui_music_search = new QLineEdit(this); ui_music_search->setFrame(false); + ui_music_search->setPlaceholderText(tr("Search")); construct_emotes(); @@ -111,6 +148,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_pos_dropdown->addItem("jud"); ui_pos_dropdown->addItem("hld"); ui_pos_dropdown->addItem("hlp"); + ui_pos_dropdown->addItem("jur"); + ui_pos_dropdown->addItem("sea"); ui_defense_bar = new AOImage(this, ao_app); ui_prosecution_bar = new AOImage(this, ao_app); @@ -119,6 +158,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_sfx_label = new QLabel(this); ui_blip_label = new QLabel(this); + ui_log_limit_label = new QLabel(this); + ui_hold_it = new AOButton(this, ao_app); ui_objection = new AOButton(this, ao_app); ui_take_that = new AOButton(this, ao_app); @@ -126,10 +167,15 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_toggle = new AOButton(this, ao_app); ui_witness_testimony = new AOButton(this, ao_app); ui_cross_examination = new AOButton(this, ao_app); + ui_guilty = new AOButton(this, ao_app); + ui_not_guilty = new AOButton(this, ao_app); ui_change_character = new AOButton(this, ao_app); ui_reload_theme = new AOButton(this, ao_app); ui_call_mod = new AOButton(this, ao_app); + ui_settings = new AOButton(this, ao_app); + ui_announce_casing = new AOButton(this, ao_app); + ui_switch_area_music = new AOButton(this, ao_app); ui_pre = new QCheckBox(this); ui_pre->setText("Pre"); @@ -139,6 +185,18 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_guard = new QCheckBox(this); ui_guard->setText("Guard"); ui_guard->hide(); + ui_casing = new QCheckBox(this); + ui_casing->setChecked(ao_app->get_casing_enabled()); + ui_casing->setText(tr("Casing")); + ui_casing->hide(); + + ui_showname_enable = new QCheckBox(this); + ui_showname_enable->setChecked(ao_app->get_showname_enabled_by_default()); + ui_showname_enable->setText(tr("Shownames")); + + ui_pre_non_interrupt = new QCheckBox(this); + ui_pre_non_interrupt->setText(tr("No Interrupt")); + ui_pre_non_interrupt->hide(); ui_custom_objection = new AOButton(this, ao_app); ui_realization = new AOButton(this, ao_app); @@ -156,8 +214,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_text_color->addItem("Red"); ui_text_color->addItem("Orange"); ui_text_color->addItem("Blue"); - if (ao_app->yellow_text_enabled) - ui_text_color->addItem("Yellow"); + ui_text_color->addItem("Yellow"); + ui_text_color->addItem("Rainbow"); + ui_text_color->addItem("Pink"); + ui_text_color->addItem("Cyan"); ui_music_slider = new QSlider(Qt::Horizontal, this); ui_music_slider->setRange(0, 100); @@ -171,6 +231,17 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_blip_slider->setRange(0, 100); ui_blip_slider->setValue(ao_app->get_default_blip()); + ui_log_limit_spinbox = new QSpinBox(this); + ui_log_limit_spinbox->setRange(0, 10000); + ui_log_limit_spinbox->setValue(ao_app->get_max_log_size()); + + ui_mute_list = new QListWidget(this); + ui_pair_list = new QListWidget(this); + ui_pair_offset_spinbox = new QSpinBox(this); + ui_pair_offset_spinbox->setRange(-100,100); + ui_pair_offset_spinbox->setSuffix("% offset"); + ui_pair_button = new AOButton(this, ao_app); + ui_evidence_button = new AOButton(this, ao_app); construct_evidence(); @@ -196,7 +267,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_emote_right, SIGNAL(clicked()), this, SLOT(on_emote_right_clicked())); connect(ui_emote_dropdown, SIGNAL(activated(int)), this, SLOT(on_emote_dropdown_changed(int))); - connect(ui_pos_dropdown, SIGNAL(activated(int)), this, SLOT(on_pos_dropdown_changed(int))); + connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(on_pos_dropdown_changed(int))); connect(ui_mute_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_mute_list_clicked(QModelIndex))); @@ -205,6 +276,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_ooc_chat_message, SIGNAL(returnPressed()), this, SLOT(on_ooc_return_pressed())); connect(ui_music_list, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_music_list_double_clicked(QModelIndex))); + connect(ui_area_list, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_area_list_double_clicked(QModelIndex))); connect(ui_hold_it, SIGNAL(clicked()), this, SLOT(on_hold_it_clicked())); connect(ui_objection, SIGNAL(clicked()), this, SLOT(on_objection_clicked())); @@ -226,20 +298,34 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_sfx_slider, SIGNAL(valueChanged(int)), this, SLOT(on_sfx_slider_moved(int))); connect(ui_blip_slider, SIGNAL(valueChanged(int)), this, SLOT(on_blip_slider_moved(int))); + connect(ui_log_limit_spinbox, SIGNAL(valueChanged(int)), this, SLOT(on_log_limit_changed(int))); + connect(ui_ooc_toggle, SIGNAL(clicked()), this, SLOT(on_ooc_toggle_clicked())); connect(ui_music_search, SIGNAL(textChanged(QString)), this, SLOT(on_music_search_edited(QString))); connect(ui_witness_testimony, SIGNAL(clicked()), this, SLOT(on_witness_testimony_clicked())); connect(ui_cross_examination, SIGNAL(clicked()), this, SLOT(on_cross_examination_clicked())); + connect(ui_guilty, SIGNAL(clicked()), this, SLOT(on_guilty_clicked())); + connect(ui_not_guilty, SIGNAL(clicked()), this, SLOT(on_not_guilty_clicked())); connect(ui_change_character, SIGNAL(clicked()), this, SLOT(on_change_character_clicked())); connect(ui_reload_theme, SIGNAL(clicked()), this, SLOT(on_reload_theme_clicked())); connect(ui_call_mod, SIGNAL(clicked()), this, SLOT(on_call_mod_clicked())); + connect(ui_settings, SIGNAL(clicked()), this, SLOT(on_settings_clicked())); + connect(ui_announce_casing, SIGNAL(clicked()), this, SLOT(on_announce_casing_clicked())); + connect(ui_switch_area_music, SIGNAL(clicked()), this, SLOT(on_switch_area_music_clicked())); connect(ui_pre, SIGNAL(clicked()), this, SLOT(on_pre_clicked())); connect(ui_flip, SIGNAL(clicked()), this, SLOT(on_flip_clicked())); connect(ui_guard, SIGNAL(clicked()), this, SLOT(on_guard_clicked())); + connect(ui_casing, SIGNAL(clicked()), this, SLOT(on_casing_clicked())); + + connect(ui_showname_enable, SIGNAL(clicked()), this, SLOT(on_showname_enable_clicked())); + + connect(ui_pair_button, SIGNAL(clicked()), this, SLOT(on_pair_clicked())); + connect(ui_pair_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_pair_list_clicked(QModelIndex))); + connect(ui_pair_offset_spinbox, SIGNAL(valueChanged(int)), this, SLOT(on_pair_offset_changed(int))); connect(ui_evidence_button, SIGNAL(clicked()), this, SLOT(on_evidence_button_clicked())); @@ -272,6 +358,21 @@ void Courtroom::set_mute_list() } } +void Courtroom::set_pair_list() +{ + QStringList sorted_pair_list; + + for (char_type i_char : char_list) + sorted_pair_list.append(i_char.name); + + sorted_pair_list.sort(); + + for (QString i_name : sorted_pair_list) + { + ui_pair_list->addItem(i_name); + } +} + void Courtroom::set_widgets() { blip_rate = ao_app->read_blip_rate(); @@ -303,6 +404,40 @@ void Courtroom::set_widgets() set_size_and_pos(ui_viewport, "viewport"); + // If there is a point to it, show all CCCC features. + // We also do this this soon so that set_size_and_pos can hide them all later, if needed. + if (ao_app->cccc_ic_support_enabled) + { + ui_pair_button->show(); + ui_pre_non_interrupt->show(); + ui_showname_enable->show(); + ui_ic_chat_name->show(); + ui_ic_chat_name->setEnabled(true); + } + else + { + ui_pair_button->hide(); + ui_pre_non_interrupt->hide(); + ui_showname_enable->hide(); + ui_ic_chat_name->hide(); + ui_ic_chat_name->setEnabled(false); + } + + if (ao_app->casing_alerts_enabled) + { + ui_announce_casing->show(); + } + else + { + ui_announce_casing->hide(); + } + + // We also show the non-server-dependent client additions. + // Once again, if the theme can't display it, set_move_and_pos will catch them. + ui_settings->show(); + ui_log_limit_label->show(); + ui_log_limit_spinbox->show(); + ui_vp_background->move(0, 0); ui_vp_background->resize(ui_viewport->width(), ui_viewport->height()); @@ -312,6 +447,9 @@ void Courtroom::set_widgets() ui_vp_player_char->move(0, 0); ui_vp_player_char->combo_resize(ui_viewport->width(), ui_viewport->height()); + ui_vp_sideplayer_char->move(0, 0); + ui_vp_sideplayer_char->combo_resize(ui_viewport->width(), ui_viewport->height()); + //the AO2 desk element ui_vp_desk->move(0, 0); ui_vp_desk->resize(ui_viewport->width(), ui_viewport->height()); @@ -319,7 +457,7 @@ void Courtroom::set_widgets() //the size of the ui_vp_legacy_desk element relies on various factors and is set in set_scene() double y_modifier = 147.0 / 192.0; - int final_y = y_modifier * ui_viewport->height(); + int final_y = static_cast(y_modifier * ui_viewport->height()); ui_vp_legacy_desk->move(0, final_y); ui_vp_legacy_desk->hide(); @@ -358,8 +496,15 @@ void Courtroom::set_widgets() set_size_and_pos(ui_mute_list, "mute_list"); ui_mute_list->hide(); - //set_size_and_pos(ui_area_list, "area_list"); - //ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); + set_size_and_pos(ui_pair_list, "pair_list"); + ui_pair_list->hide(); + set_size_and_pos(ui_pair_offset_spinbox, "pair_offset_spinbox"); + ui_pair_offset_spinbox->hide(); + set_size_and_pos(ui_pair_button, "pair_button"); + ui_pair_button->set_image("pair_button.png"); + + set_size_and_pos(ui_area_list, "music_list"); + ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); set_size_and_pos(ui_music_list, "music_list"); @@ -367,14 +512,17 @@ void Courtroom::set_widgets() { set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); set_size_and_pos(ui_vp_chatbox, "ao2_chatbox"); + set_size_and_pos(ui_ic_chat_name, "ao2_ic_chat_name"); } else { set_size_and_pos(ui_ic_chat_message, "ic_chat_message"); set_size_and_pos(ui_vp_chatbox, "chatbox"); + set_size_and_pos(ui_ic_chat_name, "ic_chat_name"); } ui_ic_chat_message->setStyleSheet("QLineEdit{background-color: rgba(100, 100, 100, 255);}"); + ui_ic_chat_name->setStyleSheet("QLineEdit{background-color: rgba(180, 180, 180, 255);}"); ui_vp_chatbox->set_image("chatmed.png"); ui_vp_chatbox->hide(); @@ -415,6 +563,9 @@ void Courtroom::set_widgets() set_size_and_pos(ui_blip_label, "blip_label"); ui_blip_label->setText("Blips"); + set_size_and_pos(ui_log_limit_label, "log_limit_label"); + ui_log_limit_label->setText("Log limit"); + set_size_and_pos(ui_hold_it, "hold_it"); ui_hold_it->set_image("holdit.png"); set_size_and_pos(ui_objection, "objection"); @@ -430,6 +581,11 @@ void Courtroom::set_widgets() set_size_and_pos(ui_cross_examination, "cross_examination"); ui_cross_examination->set_image("crossexamination.png"); + set_size_and_pos(ui_guilty, "guilty"); + ui_guilty->set_image("guilty.png"); + set_size_and_pos(ui_not_guilty, "not_guilty"); + ui_not_guilty->set_image("notguilty.png"); + set_size_and_pos(ui_change_character, "change_character"); ui_change_character->setText("Change character"); @@ -439,13 +595,27 @@ void Courtroom::set_widgets() set_size_and_pos(ui_call_mod, "call_mod"); ui_call_mod->setText("Call mod"); - set_size_and_pos(ui_pre, "pre"); - ui_pre->setText("Pre"); + set_size_and_pos(ui_settings, "settings"); + ui_settings->setText("Settings"); + set_size_and_pos(ui_announce_casing, "casing_button"); + ui_announce_casing->setText("Casing"); + + set_size_and_pos(ui_switch_area_music, "switch_area_music"); + ui_switch_area_music->setText("A/M"); + + set_size_and_pos(ui_pre, "pre"); + ui_pre->setText("Preanim"); + + set_size_and_pos(ui_pre_non_interrupt, "pre_no_interrupt"); set_size_and_pos(ui_flip, "flip"); set_size_and_pos(ui_guard, "guard"); + set_size_and_pos(ui_casing, "casing"); + + set_size_and_pos(ui_showname_enable, "showname_enable"); + set_size_and_pos(ui_custom_objection, "custom_objection"); ui_custom_objection->set_image("custom.png"); @@ -473,6 +643,8 @@ void Courtroom::set_widgets() set_size_and_pos(ui_sfx_slider, "sfx_slider"); set_size_and_pos(ui_blip_slider, "blip_slider"); + set_size_and_pos(ui_log_limit_spinbox, "log_limit_spinbox"); + set_size_and_pos(ui_evidence_button, "evidence_button"); ui_evidence_button->set_image("evidencebutton.png"); @@ -534,6 +706,18 @@ void Courtroom::set_fonts() set_font(ui_ms_chatlog, "ms_chatlog"); set_font(ui_server_chatlog, "server_chatlog"); set_font(ui_music_list, "music_list"); + set_font(ui_area_list, "music_list"); + + // Set color of labels and checkboxes + const QString design_file = "courtroom_fonts.ini"; + QColor f_color = ao_app->get_color("label_color", design_file); + QString color_string = "color: rgba(" + + QString::number(f_color.red()) + ", " + + QString::number(f_color.green()) + ", " + + QString::number(f_color.blue()) + ", 255); }"; + QString style_sheet_string = "QLabel {" + color_string + "}" + "QCheckBox {" + color_string + "}"; + setStyleSheet(style_sheet_string); } void Courtroom::set_font(QWidget *widget, QString p_identifier) @@ -607,6 +791,7 @@ void Courtroom::done_received() set_char_select_page(); set_mute_list(); + set_pair_list(); set_char_select(); @@ -620,11 +805,10 @@ void Courtroom::set_background(QString p_background) testimony_in_progress = false; current_background = p_background; - QString bg_path = get_background_path(); - is_ao2_bg = file_exists(bg_path + "defensedesk.png") && - file_exists(bg_path + "prosecutiondesk.png") && - file_exists(bg_path + "stand.png"); + is_ao2_bg = file_exists(ao_app->get_background_path("defensedesk.png")) && + file_exists(ao_app->get_background_path("prosecutiondesk.png")) && + file_exists(ao_app->get_background_path("stand.png")); if (is_ao2_bg) { @@ -646,14 +830,15 @@ void Courtroom::enter_courtroom(int p_cid) if (m_cid == -1) { - if(ao_app->is_discord_enabled()) + if (ao_app->is_discord_enabled()) ao_app->discord->state_spectate(); f_char = ""; } else { f_char = ao_app->get_char_name(char_list.at(m_cid).name); - if(ao_app->is_discord_enabled()) + + if (ao_app->is_discord_enabled()) ao_app->discord->state_character(f_char.toStdString()); } @@ -681,6 +866,8 @@ void Courtroom::enter_courtroom(int p_cid) { ui_witness_testimony->show(); ui_cross_examination->show(); + ui_not_guilty->show(); + ui_guilty->show(); ui_defense_minus->show(); ui_defense_plus->show(); ui_prosecution_minus->show(); @@ -690,17 +877,18 @@ void Courtroom::enter_courtroom(int p_cid) { ui_witness_testimony->hide(); ui_cross_examination->hide(); + ui_guilty->hide(); + ui_not_guilty->hide(); ui_defense_minus->hide(); ui_defense_plus->hide(); ui_prosecution_minus->hide(); ui_prosecution_plus->hide(); } - QString char_path = ao_app->get_character_path(current_char); - if (ao_app->custom_objection_enabled && - file_exists(char_path + "custom.gif") && - file_exists(char_path + "custom.wav")) + (file_exists(ao_app->get_character_path(current_char, "custom.gif")) || + file_exists(ao_app->get_character_path(current_char, "custom.apng"))) && + file_exists(ao_app->get_character_path(current_char, "custom.wav"))) ui_custom_objection->show(); else ui_custom_objection->hide(); @@ -710,7 +898,13 @@ void Courtroom::enter_courtroom(int p_cid) else ui_flip->hide(); + if (ao_app->casing_alerts_enabled) + ui_casing->show(); + else + ui_casing->hide(); + list_music(); + list_areas(); music_player->set_volume(ui_music_slider->value()); sfx_player->set_volume(ui_sfx_slider->value()); @@ -732,6 +926,7 @@ void Courtroom::enter_courtroom(int p_cid) void Courtroom::list_music() { ui_music_list->clear(); + music_row_to_number.clear(); QString f_file = "courtroom_design.ini"; @@ -743,12 +938,15 @@ void Courtroom::list_music() for (int n_song = 0 ; n_song < music_list.size() ; ++n_song) { QString i_song = music_list.at(n_song); + QString i_song_listname = i_song; + i_song_listname = i_song_listname.left(i_song_listname.lastIndexOf(".")); if (i_song.toLower().contains(ui_music_search->text().toLower())) { - ui_music_list->addItem(i_song); + ui_music_list->addItem(i_song_listname); + music_row_to_number.append(n_song); - QString song_path = ao_app->get_base_path() + "sounds/music/" + i_song.toLower(); + QString song_path = ao_app->get_music_path(i_song); if (file_exists(song_path)) ui_music_list->item(n_listed_songs)->setBackground(found_brush); @@ -760,14 +958,100 @@ void Courtroom::list_music() } } -void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) +void Courtroom::list_areas() { - ui_ms_chatlog->append_chatmessage(f_name, f_message); + ui_area_list->clear(); + area_row_to_number.clear(); + + QString f_file = "courtroom_design.ini"; + + QBrush free_brush(ao_app->get_color("area_free_color", f_file)); + QBrush lfp_brush(ao_app->get_color("area_lfp_color", f_file)); + QBrush casing_brush(ao_app->get_color("area_casing_color", f_file)); + QBrush recess_brush(ao_app->get_color("area_recess_color", f_file)); + QBrush rp_brush(ao_app->get_color("area_rp_color", f_file)); + QBrush gaming_brush(ao_app->get_color("area_gaming_color", f_file)); + QBrush locked_brush(ao_app->get_color("area_locked_color", f_file)); + + int n_listed_areas = 0; + + for (int n_area = 0 ; n_area < area_list.size() ; ++n_area) + { + QString i_area = ""; + i_area.append("["); + i_area.append(QString::number(n_area)); + i_area.append("] "); + + i_area.append(area_list.at(n_area)); + + if (ao_app->arup_enabled) + { + i_area.append("\n "); + + i_area.append(arup_statuses.at(n_area)); + i_area.append(" | CM: "); + i_area.append(arup_cms.at(n_area)); + + i_area.append("\n "); + + i_area.append(QString::number(arup_players.at(n_area))); + i_area.append(" users | "); + + i_area.append(arup_locks.at(n_area)); + } + + if (i_area.toLower().contains(ui_music_search->text().toLower())) + { + ui_area_list->addItem(i_area); + area_row_to_number.append(n_area); + + if (ao_app->arup_enabled) + { + // Colouring logic here. + ui_area_list->item(n_listed_areas)->setBackground(free_brush); + if (arup_locks.at(n_area) == "LOCKED") + { + ui_area_list->item(n_listed_areas)->setBackground(locked_brush); + } + else + { + if (arup_statuses.at(n_area) == "LOOKING-FOR-PLAYERS") + ui_area_list->item(n_listed_areas)->setBackground(lfp_brush); + else if (arup_statuses.at(n_area) == "CASING") + ui_area_list->item(n_listed_areas)->setBackground(casing_brush); + else if (arup_statuses.at(n_area) == "RECESS") + ui_area_list->item(n_listed_areas)->setBackground(recess_brush); + else if (arup_statuses.at(n_area) == "RP") + ui_area_list->item(n_listed_areas)->setBackground(rp_brush); + else if (arup_statuses.at(n_area) == "GAMING") + ui_area_list->item(n_listed_areas)->setBackground(gaming_brush); + } + } + else + { + ui_area_list->item(n_listed_areas)->setBackground(free_brush); + } + + ++n_listed_areas; + } + } } -void Courtroom::append_server_chatmessage(QString p_name, QString p_message) +void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) { - ui_server_chatlog->append_chatmessage(p_name, p_message); + ui_ms_chatlog->append_chatmessage(f_name, f_message, ao_app->get_color("ooc_default_color", "courtroom_design.ini").name()); +} + +void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QString p_colour) +{ + QString colour = "#000000"; + + if (p_colour == "0") + colour = ao_app->get_color("ooc_default_color", "courtroom_design.ini").name(); + if (p_colour == "1") + colour = ao_app->get_color("ooc_server_color", "courtroom_design.ini").name(); + + ui_server_chatlog->append_chatmessage(p_name, p_message, colour); } void Courtroom::on_chat_return_pressed() @@ -796,6 +1080,13 @@ void Courtroom::on_chat_return_pressed() //realization# //text_color#% + // Additionally, in our case: + + //showname# + //other_charid# + //self_offset# + //noninterrupting_preanim#% + QStringList packet_contents; QString f_side = ao_app->get_char_side(current_char); @@ -828,12 +1119,15 @@ void Courtroom::on_chat_return_pressed() //needed or else legacy won't understand what we're saying if (objection_state > 0) { - if (f_emote_mod == 5) - f_emote_mod = 6; - else - f_emote_mod = 2; + if (ui_pre->isChecked()) + { + if (f_emote_mod == 5) + f_emote_mod = 6; + else + f_emote_mod = 2; + } } - else if (ui_pre->isChecked()) + else if (ui_pre->isChecked() and !ui_pre_non_interrupt->isChecked()) { if (f_emote_mod == 0) f_emote_mod = 1; @@ -890,24 +1184,78 @@ void Courtroom::on_chat_return_pressed() if (text_color < 0) f_text_color = "0"; - else if (text_color > 4 && !ao_app->yellow_text_enabled) + else if (text_color > 8) f_text_color = "0"; else f_text_color = QString::number(text_color); packet_contents.append(f_text_color); + // If the server we're on supports CCCC stuff, we should use it! + if (ao_app->cccc_ic_support_enabled) + { + // If there is a showname entered, use that -- else, just send an empty packet-part. + if (!ui_ic_chat_name->text().isEmpty()) + { + packet_contents.append(ui_ic_chat_name->text()); + } + else + { + packet_contents.append(""); + } + + // Similarly, we send over whom we're paired with, unless we have chosen ourselves. + // Or a charid of -1 or lower, through some means. + if (other_charid > -1 && other_charid != m_cid) + { + packet_contents.append(QString::number(other_charid)); + packet_contents.append(QString::number(offset_with_pair)); + } + else + { + packet_contents.append("-1"); + packet_contents.append("0"); + } + + // Finally, we send over if we want our pres to not interrupt. + if (ui_pre_non_interrupt->isChecked() && ui_pre->isChecked()) + { + packet_contents.append("1"); + } + else + { + packet_contents.append("0"); + } + } + ao_app->send_server_packet(new AOPacket("MS", packet_contents)); } void Courtroom::handle_chatmessage(QStringList *p_contents) { - if (p_contents->size() < chatmessage_size) + // Instead of checking for whether a message has at least chatmessage_size + // amount of packages, we'll check if it has at least 15. + // That was the original chatmessage_size. + if (p_contents->size() < 15) return; for (int n_string = 0 ; n_string < chatmessage_size ; ++n_string) { - m_chatmessage[n_string] = p_contents->at(n_string); + //m_chatmessage[n_string] = p_contents->at(n_string); + + // Note that we have added stuff that vanilla clients and servers simply won't send. + // So now, we have to check if the thing we want even exists amongst the packet's content. + // We also have to check if the server even supports CCCC's IC features, or if it's just japing us. + // Also, don't forget! A size 15 message will have indices from 0 to 14. + if (n_string < p_contents->size() && + (n_string < 15 || ao_app->cccc_ic_support_enabled)) + { + m_chatmessage[n_string] = p_contents->at(n_string); + } + else + { + m_chatmessage[n_string] = ""; + } } int f_char_id = m_chatmessage[CHAR_ID].toInt(); @@ -918,7 +1266,16 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) if (mute_map.value(m_chatmessage[CHAR_ID].toInt())) return; - QString f_showname = ao_app->get_showname(char_list.at(f_char_id).name); + QString f_showname; + if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked()) + { + f_showname = ao_app->get_showname(char_list.at(f_char_id).name); + } + else + { + f_showname = m_chatmessage[SHOWNAME]; + } + QString f_message = f_showname + ": " + m_chatmessage[MESSAGE] + '\n'; @@ -949,6 +1306,14 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) ui_evidence_present->set_image("present_disabled.png"); } + chatlogpiece* temp = new chatlogpiece(ao_app->get_showname(char_list.at(f_char_id).name), f_showname, ": " + m_chatmessage[MESSAGE], false); + ic_chatlog_history.append(*temp); + + while(ic_chatlog_history.size() > log_maximum_blocks && log_maximum_blocks > 0) + { + ic_chatlog_history.removeFirst(); + } + append_ic_text(": " + m_chatmessage[MESSAGE], f_showname); previous_ic_message = f_message; @@ -964,20 +1329,20 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) { case 1: ui_vp_objection->play("holdit", f_char, f_custom_theme); - objection_player->play("holdit.wav", f_char); + objection_player->play("holdit.wav", f_char, f_custom_theme); break; case 2: ui_vp_objection->play("objection", f_char, f_custom_theme); - objection_player->play("objection.wav", f_char); + objection_player->play("objection.wav", f_char, f_custom_theme); break; case 3: ui_vp_objection->play("takethat", f_char, f_custom_theme); - objection_player->play("takethat.wav", f_char); + objection_player->play("takethat.wav", f_char, f_custom_theme); break; //case 4 is AO2 only case 4: ui_vp_objection->play("custom", f_char, f_custom_theme); - objection_player->play("custom.wav", f_char); + objection_player->play("custom.wav", f_char, f_custom_theme); break; default: qDebug() << "W: Logic error in objection switch statement!"; @@ -1002,11 +1367,18 @@ void Courtroom::handle_chatmessage_2() ui_vp_speedlines->stop(); ui_vp_player_char->stop(); - QString real_name = char_list.at(m_chatmessage[CHAR_ID].toInt()).name; + if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked()) + { + QString real_name = char_list.at(m_chatmessage[CHAR_ID].toInt()).name; - QString f_showname = ao_app->get_showname(real_name); + QString f_showname = ao_app->get_showname(real_name); - ui_vp_showname->setText(f_showname); + ui_vp_showname->setText(f_showname); + } + else + { + ui_vp_showname->setText(m_chatmessage[SHOWNAME]); + } ui_vp_message->clear(); ui_vp_chatbox->hide(); @@ -1017,13 +1389,34 @@ void Courtroom::handle_chatmessage_2() ui_vp_chatbox->set_image("chatmed.png"); else { - QString chatbox_path = ao_app->get_base_path() + "misc/" + chatbox + ".png"; + QString chatbox_path = ao_app->get_base_path() + "misc/" + chatbox + "/chatbox.png"; ui_vp_chatbox->set_image_from_path(chatbox_path); } + ui_vp_showname->setStyleSheet("QLabel { color : " + get_text_color("_showname").name() + "; }"); + set_scene(); set_text_color(); + // Check if the message needs to be centered. + QString f_message = m_chatmessage[MESSAGE]; + if (f_message.size() >= 2) + { + if (f_message.startsWith("~~")) + { + message_is_centered = true; + } + else + { + message_is_centered = false; + } + } + else + { + ui_vp_message->setAlignment(Qt::AlignLeft); + } + + int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); if (ao_app->flipping_enabled && m_chatmessage[FLIP].toInt() == 1) @@ -1031,17 +1424,157 @@ void Courtroom::handle_chatmessage_2() else ui_vp_player_char->set_flipped(false); + QString side = m_chatmessage[SIDE]; + + // Making the second character appear. + if (m_chatmessage[OTHER_CHARID].isEmpty()) + { + // If there is no second character, hide 'em, and center the first. + ui_vp_sideplayer_char->hide(); + ui_vp_sideplayer_char->move(0,0); + + ui_vp_player_char->move(0,0); + } + else + { + bool ok; + int got_other_charid = m_chatmessage[OTHER_CHARID].toInt(&ok); + if (ok) + { + if (got_other_charid > -1) + { + // If there is, show them! + ui_vp_sideplayer_char->show(); + + // Depending on where we are, we offset the characters, and reorder their stacking. + if (side == "def") + { + // We also move the character down depending on how far the are to the right. + int hor_offset = m_chatmessage[SELF_OFFSET].toInt(); + int vert_offset = 0; + if (hor_offset > 0) + { + vert_offset = hor_offset / 10; + } + ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, ui_viewport->height() * vert_offset / 100); + + // We do the same with the second character. + int hor2_offset = m_chatmessage[OTHER_OFFSET].toInt(); + int vert2_offset = 0; + if (hor2_offset > 0) + { + vert2_offset = hor2_offset / 10; + } + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, ui_viewport->height() * vert2_offset / 100); + + // Finally, we reorder them based on who is more to the left. + // The person more to the left is more in the front. + if (hor2_offset >= hor_offset) + { + ui_vp_sideplayer_char->raise(); + ui_vp_player_char->raise(); + } + else + { + ui_vp_player_char->raise(); + ui_vp_sideplayer_char->raise(); + } + ui_vp_desk->raise(); + ui_vp_legacy_desk->raise(); + } + else if (side == "pro") + { + // Almost the same thing happens here, but in reverse. + int hor_offset = m_chatmessage[SELF_OFFSET].toInt(); + int vert_offset = 0; + if (hor_offset < 0) + { + // We don't want to RAISE the char off the floor. + vert_offset = -1 * hor_offset / 10; + } + ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, ui_viewport->height() * vert_offset / 100); + + // We do the same with the second character. + int hor2_offset = m_chatmessage[OTHER_OFFSET].toInt(); + int vert2_offset = 0; + if (hor2_offset < 0) + { + vert2_offset = -1 * hor2_offset / 10; + } + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, ui_viewport->height() * vert2_offset / 100); + + // Finally, we reorder them based on who is more to the right. + if (hor2_offset <= hor_offset) + { + ui_vp_sideplayer_char->raise(); + ui_vp_player_char->raise(); + } + else + { + ui_vp_player_char->raise(); + ui_vp_sideplayer_char->raise(); + } + ui_vp_desk->raise(); + ui_vp_legacy_desk->raise(); + } + else + { + // In every other case, the person more to the left is on top. + // These cases also don't move the characters down. + int hor_offset = m_chatmessage[SELF_OFFSET].toInt(); + ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, 0); + + // We do the same with the second character. + int hor2_offset = m_chatmessage[OTHER_OFFSET].toInt(); + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, 0); + + // Finally, we reorder them based on who is more to the left. + // The person more to the left is more in the front. + if (hor2_offset >= hor_offset) + { + ui_vp_sideplayer_char->raise(); + ui_vp_player_char->raise(); + } + else + { + ui_vp_player_char->raise(); + ui_vp_sideplayer_char->raise(); + } + ui_vp_desk->raise(); + ui_vp_legacy_desk->raise(); + } + // We should probably also play the other character's idle emote. + if (ao_app->flipping_enabled && m_chatmessage[OTHER_FLIP].toInt() == 1) + ui_vp_sideplayer_char->set_flipped(true); + else + ui_vp_sideplayer_char->set_flipped(false); + ui_vp_sideplayer_char->play_idle(m_chatmessage[OTHER_NAME], m_chatmessage[OTHER_EMOTE]); + } + else + { + // If the server understands other characters, but there + // really is no second character, hide 'em, and center the first. + ui_vp_sideplayer_char->hide(); + ui_vp_sideplayer_char->move(0,0); + + ui_vp_player_char->move(0,0); + } + } + } switch (emote_mod) { case 1: case 2: case 6: - play_preanim(); + play_preanim(false); + break; + case 0: case 5: + if (m_chatmessage[NONINTERRUPTING_PRE].toInt() == 0) + handle_chatmessage_3(); + else + play_preanim(true); break; default: qDebug() << "W: invalid emote mod: " << QString::number(emote_mod); - //intentional fallthru - case 0: case 5: - handle_chatmessage_3(); } } @@ -1049,6 +1582,13 @@ void Courtroom::handle_chatmessage_3() { start_chat_ticking(); + if (m_chatmessage[REALIZATION] == "1") + { + realization_timer->start(60); + ui_vp_realization->show(); + sfx_player->play(ao_app->get_custom_realization(m_chatmessage[CHAR_NAME])); + } + int f_evi_id = m_chatmessage[EVIDENCE_ID].toInt(); QString f_side = m_chatmessage[SIDE]; @@ -1057,19 +1597,24 @@ void Courtroom::handle_chatmessage_3() //shifted by 1 because 0 is no evidence per legacy standards QString f_image = local_evidence_list.at(f_evi_id - 1).image; //def jud and hlp should display the evidence icon on the RIGHT side - bool is_left_side = !(f_side == "def" || f_side == "hlp" || f_side == "jud"); + bool is_left_side = !(f_side == "def" || f_side == "hlp" || f_side == "jud" || f_side == "jur"); ui_vp_evidence_display->show_evidence(f_image, is_left_side, ui_sfx_slider->value()); } int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); + QString side = m_chatmessage[SIDE]; + if (emote_mod == 5 || emote_mod == 6) { - QString side = m_chatmessage[SIDE]; ui_vp_desk->hide(); ui_vp_legacy_desk->hide(); + // Since we're zooming, hide the second character, and centre the first. + ui_vp_sideplayer_char->hide(); + ui_vp_player_char->move(0,0); + if (side == "pro" || side == "hlp" || side == "wit") @@ -1084,11 +1629,17 @@ void Courtroom::handle_chatmessage_3() bool text_is_blue = m_chatmessage[TEXT_COLOR].toInt() == BLUE; if (!text_is_blue && text_state == 1) + { //talking f_anim_state = 2; + entire_message_is_blue = false; + } else + { //idle f_anim_state = 3; + entire_message_is_blue = true; + } if (f_anim_state <= anim_state) return; @@ -1097,26 +1648,16 @@ void Courtroom::handle_chatmessage_3() QString f_char = m_chatmessage[CHAR_NAME]; QString f_emote = m_chatmessage[EMOTE]; - switch (f_anim_state) - { - case 2: + if (f_anim_state == 2) { ui_vp_player_char->play_talking(f_char, f_emote); anim_state = 2; - break; - default: - qDebug() << "W: invalid anim_state: " << f_anim_state; - case 3: + } + else + { ui_vp_player_char->play_idle(f_char, f_emote); anim_state = 3; } - if (m_chatmessage[REALIZATION] == "1") - { - realization_timer->start(60); - ui_vp_realization->show(); - sfx_player->play(ao_app->get_sfx("realization")); - } - QString f_message = m_chatmessage[MESSAGE]; QStringList call_words = ao_app->get_call_words(); @@ -1133,52 +1674,250 @@ void Courtroom::handle_chatmessage_3() } -void Courtroom::append_ic_text(QString p_text, QString p_name) +QString Courtroom::filter_ic_text(QString p_text) +{ + // Get rid of centering. + if(p_text.startsWith(": ~~")) + { + // Don't forget, the p_text part actually everything after the name! + // Hence why we check for ': ~~'. + + // Let's remove those two tildes, then. + // : _ ~ ~ + // 0 1 2 3 + p_text.remove(2,2); + } + + // Get rid of the inline-colouring. + // I know, I know, excessive code duplication. + // Nobody looks in here, I'm fine. + int trick_check_pos = 0; + bool ic_next_is_not_special = false; + QString f_character = p_text.at(trick_check_pos); + std::stack ic_colour_stack; + while (trick_check_pos < p_text.size()) + { + f_character = p_text.at(trick_check_pos); + + // Escape character. + if (f_character == "\\" and !ic_next_is_not_special) + { + ic_next_is_not_special = true; + p_text.remove(trick_check_pos,1); + } + + // Text speed modifier. + else if (f_character == "{" and !ic_next_is_not_special) + { + p_text.remove(trick_check_pos,1); + } + else if (f_character == "}" and !ic_next_is_not_special) + { + p_text.remove(trick_check_pos,1); + } + + // Orange inline colourisation. + else if (f_character == "|" and !ic_next_is_not_special) + { + if (!ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_ORANGE) + { + ic_colour_stack.pop(); + p_text.remove(trick_check_pos,1); + } + else + { + ic_colour_stack.push(INLINE_ORANGE); + p_text.remove(trick_check_pos,1); + } + } + else + { + ic_colour_stack.push(INLINE_ORANGE); + p_text.remove(trick_check_pos,1); + } + } + + // Blue inline colourisation. + else if (f_character == "(" and !ic_next_is_not_special) + { + ic_colour_stack.push(INLINE_BLUE); + trick_check_pos++; + } + else if (f_character == ")" and !ic_next_is_not_special + and !ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_BLUE) + { + ic_colour_stack.pop(); + trick_check_pos++; + } + else + { + ic_next_is_not_special = true; + } + } + + // Grey inline colourisation. + else if (f_character == "[" and !ic_next_is_not_special) + { + ic_colour_stack.push(INLINE_GREY); + trick_check_pos++; + } + else if (f_character == "]" and !ic_next_is_not_special + and !ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_GREY) + { + ic_colour_stack.pop(); + trick_check_pos++; + } + else + { + ic_next_is_not_special = true; + } + } + + // Green inline colourisation. + else if (f_character == "`" and !ic_next_is_not_special) + { + if (!ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_GREEN) + { + ic_colour_stack.pop(); + p_text.remove(trick_check_pos,1); + } + else + { + ic_colour_stack.push(INLINE_GREEN); + p_text.remove(trick_check_pos,1); + } + } + else + { + ic_colour_stack.push(INLINE_GREEN); + p_text.remove(trick_check_pos,1); + } + } + else + { + trick_check_pos++; + ic_next_is_not_special = false; + } + } + + return p_text; +} + +void Courtroom::append_ic_text(QString p_text, QString p_name, bool is_songchange) { QTextCharFormat bold; QTextCharFormat normal; + QTextCharFormat italics; bold.setFontWeight(QFont::Bold); normal.setFontWeight(QFont::Normal); + italics.setFontItalic(true); const QTextCursor old_cursor = ui_ic_chatlog->textCursor(); const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value(); - - int scrollbar_limit; - - if(ao_app->ic_scroll_down_enabled()) { - scrollbar_limit = ui_ic_chatlog->verticalScrollBar()->maximum(); - ui_ic_chatlog->moveCursor(QTextCursor::End); - } - else { - scrollbar_limit = ui_ic_chatlog->verticalScrollBar()->minimum(); - ui_ic_chatlog->moveCursor(QTextCursor::Start); - } - - const bool is_fully_scrolled = old_scrollbar_value == scrollbar_limit; - ui_ic_chatlog->textCursor().insertText(p_name, bold); - ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal); - - if (old_cursor.hasSelection() || !is_fully_scrolled) + if (!is_songchange) + p_text = filter_ic_text(p_text); + + if (log_goes_downwards) { - // The user has selected text or scrolled away from the top: maintain position. - ui_ic_chatlog->setTextCursor(old_cursor); - ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); + + ui_ic_chatlog->moveCursor(QTextCursor::End); + + if (!first_message_sent) + { + ui_ic_chatlog->textCursor().insertText(p_name, bold); + first_message_sent = true; + } + else + { + ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold); + } + + if (is_songchange) + { + ui_ic_chatlog->textCursor().insertText(" has played a song: ", normal); + ui_ic_chatlog->textCursor().insertText(p_text + ".", italics); + } + else + { + ui_ic_chatlog->textCursor().insertText(p_text, normal); + } + + // If we got too many blocks in the current log, delete some from the top. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks && log_maximum_blocks > 0) + { + ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor); + ui_ic_chatlog->textCursor().removeSelectedText(); + ui_ic_chatlog->textCursor().deleteChar(); + //qDebug() << ui_ic_chatlog->document()->blockCount() << " < " << log_maximum_blocks; + } + + if (old_cursor.hasSelection() || !is_scrolled_down) + { + // The user has selected text or scrolled away from the bottom: maintain position. + ui_ic_chatlog->setTextCursor(old_cursor); + ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + } + else + { + // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the bottom. + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); + } } else { - // The user hasn't selected any text and the scrollbar is at the top: scroll to the top. - if(ao_app->ic_scroll_down_enabled()) { - ui_ic_chatlog->moveCursor(QTextCursor::End); - ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); + const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum(); + + ui_ic_chatlog->moveCursor(QTextCursor::Start); + + ui_ic_chatlog->textCursor().insertText(p_name, bold); + + if (is_songchange) + { + ui_ic_chatlog->textCursor().insertText(" has played a song: ", normal); + ui_ic_chatlog->textCursor().insertText(p_text + "." + '\n', italics); } - else { - ui_ic_chatlog->moveCursor(QTextCursor::Start); - ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); + else + { + ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal); + } + + // If we got too many blocks in the current log, delete some from the bottom. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks && log_maximum_blocks > 0) + { + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor); + ui_ic_chatlog->textCursor().removeSelectedText(); + ui_ic_chatlog->textCursor().deletePreviousChar(); + //qDebug() << ui_ic_chatlog->document()->blockCount() << " < " << log_maximum_blocks; + } + + if (old_cursor.hasSelection() || !is_scrolled_up) + { + // The user has selected text or scrolled away from the top: maintain position. + ui_ic_chatlog->setTextCursor(old_cursor); + ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + } + else + { + // The user hasn't selected any text and the scrollbar is at the top: scroll to the top. + ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); } } } -void Courtroom::play_preanim() +void Courtroom::play_preanim(bool noninterrupting) { QString f_char = m_chatmessage[CHAR_NAME]; QString f_preanim = m_chatmessage[PRE_EMOTE]; @@ -1196,25 +1935,36 @@ void Courtroom::play_preanim() preanim_duration = ao2_duration; sfx_delay_timer->start(sfx_delay); - - if (!file_exists(ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif") || + QString anim_to_find = ao_app->get_image_suffix(ao_app->get_character_path(f_char, f_preanim)); + if (!file_exists(anim_to_find) || preanim_duration < 0) { - anim_state = 1; + if (noninterrupting) + anim_state = 4; + else + anim_state = 1; preanim_done(); - qDebug() << "could not find " + ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif"; + qDebug() << "could not find " + anim_to_find; return; } ui_vp_player_char->play_pre(f_char, f_preanim, preanim_duration); - anim_state = 1; + + if (noninterrupting) + anim_state = 4; + else + anim_state = 1; + if (text_delay >= 0) text_delay_timer->start(text_delay); + if (noninterrupting) + handle_chatmessage_3(); } void Courtroom::preanim_done() { + anim_state = 1; handle_chatmessage_3(); } @@ -1225,13 +1975,14 @@ void Courtroom::realization_done() void Courtroom::start_chat_ticking() { - ui_vp_message->clear(); - set_text_color(); - rainbow_counter = 0; //we need to ensure that the text isn't already ticking because this function can be called by two logic paths if (text_state != 0) return; + ui_vp_message->clear(); + set_text_color(); + rainbow_counter = 0; + if (chatmessage_is_empty) { //since the message is empty, it's technically done ticking @@ -1239,11 +1990,25 @@ void Courtroom::start_chat_ticking() return; } + // At this point, we'd do well to clear the inline colour stack. + // This stops it from flowing into next messages. + while (!inline_colour_stack.empty()) + { + inline_colour_stack.pop(); + } + ui_vp_chatbox->show(); tick_pos = 0; blip_pos = 0; - chat_tick_timer->start(chat_tick_interval); + + // Just in case we somehow got inline blue text left over from a previous message, + // let's set it to false. + inline_blue_depth = 0; + + // At the start of every new message, we set the text speed to the default. + current_display_speed = 3; + chat_tick_timer->start(message_display_speed[current_display_speed]); QString f_gender = ao_app->get_gender(m_chatmessage[CHAR_NAME]); @@ -1260,12 +2025,27 @@ void Courtroom::chat_tick() QString f_message = m_chatmessage[MESSAGE]; + // Due to our new text speed system, we always need to stop the timer now. + chat_tick_timer->stop(); + + // Stops blips from playing when we have a formatting option. + bool formatting_char = false; + + // If previously, we have detected that the message is centered, now + // is the time to remove those two tildes at the start. + if (message_is_centered) + { + f_message.remove(0,2); + } + if (tick_pos >= f_message.size()) { text_state = 2; - chat_tick_timer->stop(); - anim_state = 3; - ui_vp_player_char->play_idle(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE]); + if (anim_state != 4) + { + anim_state = 3; + ui_vp_player_char->play_idle(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE]); + } } else @@ -1282,19 +2062,19 @@ void Courtroom::chat_tick() switch (rainbow_counter) { case 0: - html_color = "#FF0000"; + html_color = get_text_color(QString::number(RED)).name(); break; case 1: - html_color = "#FF7F00"; + html_color = get_text_color(QString::number(ORANGE)).name(); break; case 2: - html_color = "#FFFF00"; + html_color = get_text_color(QString::number(YELLOW)).name(); break; case 3: - html_color = "#00FF00"; + html_color = get_text_color(QString::number(GREEN)).name(); break; default: - html_color = "#2d96ff"; + html_color = get_text_color(QString::number(BLUE)).name(); rainbow_counter = -1; } @@ -1302,8 +2082,181 @@ void Courtroom::chat_tick() ui_vp_message->insertHtml("" + f_character + ""); } + + // Escape character. + else if (f_character == "\\" and !next_character_is_not_special) + { + next_character_is_not_special = true; + formatting_char = true; + } + + // Text speed modifier. + else if (f_character == "{" and !next_character_is_not_special) + { + // ++, because it INCREASES delay! + current_display_speed++; + formatting_char = true; + } + else if (f_character == "}" and !next_character_is_not_special) + { + current_display_speed--; + formatting_char = true; + } + + // Orange inline colourisation. + else if (f_character == "|" and !next_character_is_not_special) + { + if (!inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_ORANGE) + { + inline_colour_stack.pop(); + } + else + { + inline_colour_stack.push(INLINE_ORANGE); + } + } + else + { + inline_colour_stack.push(INLINE_ORANGE); + } + formatting_char = true; + } + + // Blue inline colourisation. + else if (f_character == "(" and !next_character_is_not_special) + { + inline_colour_stack.push(INLINE_BLUE); + ui_vp_message->insertHtml("" + f_character + ""); + + // Increase how deep we are in inline blues. + inline_blue_depth++; + + // Here, we check if the entire message is blue. + // If it isn't, we stop talking. + if (!entire_message_is_blue and anim_state != 4) + { + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_emote = m_chatmessage[EMOTE]; + ui_vp_player_char->play_idle(f_char, f_emote); + } + } + else if (f_character == ")" and !next_character_is_not_special + and !inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_BLUE) + { + inline_colour_stack.pop(); + ui_vp_message->insertHtml("" + f_character + ""); + + // Decrease how deep we are in inline blues. + // Just in case, we do a check if we're above zero, but we should be. + if (inline_blue_depth > 0) + { + inline_blue_depth--; + // Here, we check if the entire message is blue. + // If it isn't, we start talking if we have completely climbed out of inline blues. + if (!entire_message_is_blue) + { + // We should only go back to talking if we're out of inline blues, not during a non. int. pre, and not on the last character. + if (inline_blue_depth == 0 and anim_state != 4 and !(tick_pos+1 >= f_message.size())) + { + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_emote = m_chatmessage[EMOTE]; + ui_vp_player_char->play_talking(f_char, f_emote); + } + } + } + } + else + { + next_character_is_not_special = true; + tick_pos--; + } + } + + // Grey inline colourisation. + else if (f_character == "[" and !next_character_is_not_special) + { + inline_colour_stack.push(INLINE_GREY); + ui_vp_message->insertHtml("" + f_character + ""); + } + else if (f_character == "]" and !next_character_is_not_special + and !inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_GREY) + { + inline_colour_stack.pop(); + ui_vp_message->insertHtml("" + f_character + ""); + } + else + { + next_character_is_not_special = true; + tick_pos--; + } + } + + // Green inline colourisation. + else if (f_character == "`" and !next_character_is_not_special) + { + if (!inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_GREEN) + { + inline_colour_stack.pop(); + formatting_char = true; + } + else + { + inline_colour_stack.push(INLINE_GREEN); + formatting_char = true; + } + } + else + { + inline_colour_stack.push(INLINE_GREEN); + formatting_char = true; + } + } else - ui_vp_message->insertHtml(f_character); + { + next_character_is_not_special = false; + if (!inline_colour_stack.empty()) + { + switch (inline_colour_stack.top()) { + case INLINE_ORANGE: + ui_vp_message->insertHtml("" + f_character + ""); + break; + case INLINE_BLUE: + ui_vp_message->insertHtml("" + f_character + ""); + break; + case INLINE_GREEN: + ui_vp_message->insertHtml("" + f_character + ""); + break; + case INLINE_GREY: + ui_vp_message->insertHtml("" + f_character + ""); + break; + default: + ui_vp_message->insertHtml(f_character); + break; + } + + } + else + { + ui_vp_message->insertHtml(f_character); + } + + if (message_is_centered) + { + ui_vp_message->setAlignment(Qt::AlignCenter); + } + else + { + ui_vp_message->setAlignment(Qt::AlignLeft); + } + } QScrollBar *scroll = ui_vp_message->verticalScrollBar(); scroll->setValue(scroll->maximum()); @@ -1314,7 +2267,7 @@ void Courtroom::chat_tick() if (f_message.at(tick_pos) != ' ' || blank_blip) { - if (blip_pos % blip_rate == 0) + if (blip_pos % blip_rate == 0 && !formatting_char) { blip_pos = 0; blip_player->blip_tick(); @@ -1324,6 +2277,29 @@ void Courtroom::chat_tick() } ++tick_pos; + + // Restart the timer, but according to the newly set speeds, if there were any. + // Keep the speed at bay. + if (current_display_speed < 0) + { + current_display_speed = 0; + } + + if (current_display_speed > 6) + { + current_display_speed = 6; + } + + // If we had a formatting char, we shouldn't wait so long again, as it won't appear! + if (formatting_char) + { + chat_tick_timer->start(1); + } + else + { + chat_tick_timer->start(message_display_speed[current_display_speed]); + } + } } @@ -1354,7 +2330,7 @@ void Courtroom::play_sfx() if (sfx_name == "1") return; - sfx_player->play(sfx_name + ".wav"); + sfx_player->play(ao_app->get_sfx_suffix(sfx_name)); } void Courtroom::set_scene() @@ -1399,6 +2375,18 @@ void Courtroom::set_scene() f_background = "prohelperstand"; f_desk_image = "prohelperdesk"; } + else if (f_side == "jur" && (file_exists(ao_app->get_background_path("jurystand.png")) || + file_exists(ao_app->get_background_path("jurystand.gif")))) + { + f_background = "jurystand"; + f_desk_image = "jurydesk"; + } + else if (f_side == "sea" && (file_exists(ao_app->get_background_path("seancestand.png")) || + file_exists(ao_app->get_background_path("seancestand.gif")))) + { + f_background = "seancestand"; + f_desk_image = "seancedesk"; + } else { if (is_ao2_bg) @@ -1443,35 +2431,26 @@ void Courtroom::set_scene() void Courtroom::set_text_color() { - switch (m_chatmessage[TEXT_COLOR].toInt()) - { - case GREEN: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: rgb(0, 255, 0)"); - break; - case RED: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: red"); - break; - case ORANGE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: orange"); - break; - case BLUE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: rgb(45, 150, 255)"); - break; - case YELLOW: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: yellow"); - break; - default: - qDebug() << "W: undefined text color: " << m_chatmessage[TEXT_COLOR]; - case WHITE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: white"); + QColor textcolor = ao_app->get_chat_color(m_chatmessage[TEXT_COLOR], ao_app->get_chat(m_chatmessage[CHAR_NAME])); - } + ui_vp_message->setTextBackgroundColor(QColor(0,0,0,0)); + ui_vp_message->setTextColor(textcolor); + + QString style = "background-color: rgba(0, 0, 0, 0);"; + style.append("color: rgb("); + style.append(QString::number(textcolor.red())); + style.append(", "); + style.append(QString::number(textcolor.green())); + style.append(", "); + style.append(QString::number(textcolor.blue())); + style.append(")"); + + ui_vp_message->setStyleSheet(style); +} + +QColor Courtroom::get_text_color(QString color) +{ + return ao_app->get_chat_color(color, ao_app->get_chat(m_chatmessage[CHAR_NAME])); } void Courtroom::set_ip_list(QString p_list) @@ -1520,6 +2499,8 @@ void Courtroom::handle_song(QStringList *p_contents) return; QString f_song = f_contents.at(0); + QString f_song_clear = f_song; + f_song_clear = f_song_clear.left(f_song_clear.lastIndexOf(".")); int n_char = f_contents.at(1).toInt(); if (n_char < 0 || n_char >= char_list.size()) @@ -1529,16 +2510,30 @@ void Courtroom::handle_song(QStringList *p_contents) else { QString str_char = char_list.at(n_char).name; + QString str_show = char_list.at(n_char).name; + + if (p_contents->length() > 2) + { + str_show = p_contents->at(2); + } if (!mute_map.value(n_char)) { - append_ic_text(" has played a song: " + f_song, str_char); + chatlogpiece* temp = new chatlogpiece(str_char, str_show, f_song, true); + ic_chatlog_history.append(*temp); + + while(ic_chatlog_history.size() > log_maximum_blocks && log_maximum_blocks > 0) + { + ic_chatlog_history.removeFirst(); + } + + append_ic_text(f_song_clear, str_show, true); music_player->play(f_song); } } } -void Courtroom::handle_wtce(QString p_wtce) +void Courtroom::handle_wtce(QString p_wtce, int variant) { QString sfx_file = "courtroom_sounds.ini"; @@ -1557,6 +2552,20 @@ void Courtroom::handle_wtce(QString p_wtce) ui_vp_wtce->play("crossexamination"); testimony_in_progress = false; } + else if (p_wtce == "judgeruling") + { + if (variant == 0) + { + sfx_player->play(ao_app->get_sfx("not_guilty")); + ui_vp_wtce->play("notguilty"); + testimony_in_progress = false; + } + else if (variant == 1) { + sfx_player->play(ao_app->get_sfx("guilty")); + ui_vp_wtce->play("guilty"); + testimony_in_progress = false; + } + } } void Courtroom::set_hp_bar(int p_bar, int p_state) @@ -1586,6 +2595,23 @@ void Courtroom::mod_called(QString p_ip) } } +void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno) +{ + if (ui_casing->isChecked()) + { + ui_server_chatlog->append(msg); + if ((ao_app->get_casing_defence_enabled() && def) || + (ao_app->get_casing_prosecution_enabled() && pro) || + (ao_app->get_casing_judge_enabled() && jud) || + (ao_app->get_casing_juror_enabled() && jur) || + (ao_app->get_casing_steno_enabled() && steno)) + { + modcall_player->play(ao_app->get_sfx("case_call")); + ao_app->alert(this); + } + } +} + void Courtroom::on_ooc_return_pressed() { QString ooc_message = ui_ooc_chat_message->text(); @@ -1599,6 +2625,8 @@ void Courtroom::on_ooc_return_pressed() { ui_witness_testimony->show(); ui_cross_examination->show(); + ui_guilty->show(); + ui_not_guilty->show(); ui_defense_minus->show(); ui_defense_plus->show(); ui_prosecution_minus->show(); @@ -1608,6 +2636,8 @@ void Courtroom::on_ooc_return_pressed() { ui_witness_testimony->hide(); ui_cross_examination->hide(); + ui_guilty->hide(); + ui_not_guilty->hide(); ui_defense_minus->hide(); ui_defense_plus->hide(); ui_prosecution_minus->hide(); @@ -1615,12 +2645,198 @@ void Courtroom::on_ooc_return_pressed() } } else if (ooc_message.startsWith("/login")) + { ui_guard->show(); + append_server_chatmessage("CLIENT", "You were granted the Guard button.", "1"); + } else if (ooc_message.startsWith("/rainbow") && ao_app->yellow_text_enabled && !rainbow_appended) { - ui_text_color->addItem("Rainbow"); + //ui_text_color->addItem("Rainbow"); + ui_ooc_chat_message->clear(); + //rainbow_appended = true; + append_server_chatmessage("CLIENT", "This does nohing, but there you go.", "1"); + return; + } + else if (ooc_message.startsWith("/settings")) + { + ui_ooc_chat_message->clear(); + ao_app->call_settings_menu(); + append_server_chatmessage("CLIENT", "You opened the settings menu.", "1"); + return; + } + else if (ooc_message.startsWith("/pair")) + { + ui_ooc_chat_message->clear(); + ooc_message.remove(0,6); + + bool ok; + int whom = ooc_message.toInt(&ok); + if (ok) + { + if (whom > -1) + { + other_charid = whom; + QString msg = "You will now pair up with "; + msg.append(char_list.at(whom).name); + msg.append(" if they also choose your character in return."); + append_server_chatmessage("CLIENT", msg, "1"); + } + else + { + append_server_chatmessage("CLIENT", "You are no longer paired with anyone.", "1"); + } + } + else + { + append_server_chatmessage("CLIENT", "Are you sure you typed that well? The char ID could not be recognised.", "1"); + } + return; + } + else if (ooc_message.startsWith("/offset")) + { + ui_ooc_chat_message->clear(); + ooc_message.remove(0,8); + + bool ok; + int off = ooc_message.toInt(&ok); + if (ok) + { + if (off >= -100 && off <= 100) + { + offset_with_pair = off; + QString msg = "You have set your offset to "; + msg.append(QString::number(off)); + msg.append("%."); + append_server_chatmessage("CLIENT", msg, "1"); + } + else + { + append_server_chatmessage("CLIENT", "Your offset must be between -100% and 100%!", "1"); + } + } + else + { + append_server_chatmessage("CLIENT", "That offset does not look like one.", "1"); + } + return; + } + else if (ooc_message.startsWith("/switch_am")) + { + append_server_chatmessage("CLIENT", "You switched your music and area list.", "1"); + on_switch_area_music_clicked(); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/enable_blocks")) + { + append_server_chatmessage("CLIENT", "You have forcefully enabled features that the server may not support. You may not be able to talk IC, or worse, because of this.", "1"); + ao_app->cccc_ic_support_enabled = true; + ao_app->arup_enabled = true; + ao_app->modcall_reason_enabled = true; + on_reload_theme_clicked(); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/non_int_pre")) + { + if (ui_pre_non_interrupt->isChecked()) + append_server_chatmessage("CLIENT", "Your pre-animations interrupt again.", "1"); + else + append_server_chatmessage("CLIENT", "Your pre-animations will not interrupt text.", "1"); + ui_pre_non_interrupt->setChecked(!ui_pre_non_interrupt->isChecked()); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/save_chatlog")) + { + QFile file("chatlog.txt"); + + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) + { + append_server_chatmessage("CLIENT", "Couldn't open chatlog.txt to write into.", "1"); + ui_ooc_chat_message->clear(); + return; + } + + QTextStream out(&file); + + foreach (chatlogpiece item, ic_chatlog_history) { + out << item.get_full() << '\n'; + } + + file.close(); + + append_server_chatmessage("CLIENT", "The IC chatlog has been saved.", "1"); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/load_case")) + { + QStringList command = ooc_message.split(" ", QString::SkipEmptyParts); + + QDir casefolder("base/cases"); + if (!casefolder.exists()) + { + QDir::current().mkdir("base/" + casefolder.dirName()); + append_server_chatmessage("CLIENT", "You don't have a `base/cases/` folder! It was just made for you, but seeing as it WAS just made for you, it's likely the case file you're looking for can't be found in there.", "1"); + ui_ooc_chat_message->clear(); + return; + } + QStringList caseslist = casefolder.entryList(); + caseslist.removeOne("."); + caseslist.removeOne(".."); + caseslist.replaceInStrings(".ini",""); + + if (command.size() < 2) + { + append_server_chatmessage("CLIENT", "You need to give a filename to load (extension not needed)! Make sure that it is in the `base/cases/` folder, and that it is a correctly formatted ini.\nCases you can load: " + caseslist.join(", "), "1"); + ui_ooc_chat_message->clear(); + return; + } + + + if (command.size() > 2) + { + append_server_chatmessage("CLIENT", "Too many arguments to load a case! You only need one filename, without extension.", "1"); + ui_ooc_chat_message->clear(); + return; + } + + QSettings casefile("base/cases/" + command[1] + ".ini", QSettings::IniFormat); + + QString caseauth = casefile.value("author", "").value(); + QString casedoc = casefile.value("doc", "").value(); + QString cmdoc = casefile.value("cmdoc", "").value(); + QString casestatus = casefile.value("status", "").value(); + + if (!caseauth.isEmpty()) + append_server_chatmessage("CLIENT", "Case made by " + caseauth + ".", "1"); + if (!casedoc.isEmpty()) + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/doc " + casedoc + "#%")); + if (!casestatus.isEmpty()) + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/status " + casestatus + "#%")); + if (!cmdoc.isEmpty()) + append_server_chatmessage("CLIENT", "Navigate to " + cmdoc + " for the CM doc.", "1"); + + for (int i = local_evidence_list.size() - 1; i >= 0; i--) { + ao_app->send_server_packet(new AOPacket("DE#" + QString::number(i) + "#%")); + } + + foreach (QString evi, casefile.childGroups()) { + if (evi == "General") + continue; + + QStringList f_contents; + + f_contents.append(casefile.value(evi + "/name", "UNKNOWN").value()); + f_contents.append(casefile.value(evi + "/description", "UNKNOWN").value()); + f_contents.append(casefile.value(evi + "/image", "UNKNOWN.png").value()); + + ao_app->send_server_packet(new AOPacket("PE", f_contents)); + } + + append_server_chatmessage("CLIENT", "Your case \"" + command[1] + "\" was loaded!", "1"); ui_ooc_chat_message->clear(); - rainbow_appended = true; return; } @@ -1665,6 +2881,7 @@ void Courtroom::on_music_search_edited(QString p_text) //preventing compiler warnings p_text += "a"; list_music(); + list_areas(); } void Courtroom::on_pos_dropdown_changed(int p_index) @@ -1741,25 +2958,51 @@ void Courtroom::on_mute_list_clicked(QModelIndex p_index) mute_map.insert(f_cid, true); f_item->setText(real_char + " [x]"); } +} +void Courtroom::on_pair_list_clicked(QModelIndex p_index) +{ + QListWidgetItem *f_item = ui_pair_list->item(p_index.row()); + QString f_char = f_item->text(); + QString real_char; - - /* if (f_char.endsWith(" [x]")) { real_char = f_char.left(f_char.size() - 4); - mute_map.remove(real_char); - mute_map.insert(real_char, false); f_item->setText(real_char); } else - { real_char = f_char; - mute_map.remove(real_char); - mute_map.insert(real_char, true); - f_item->setText(real_char + " [x]"); + + int f_cid = -1; + + for (int n_char = 0 ; n_char < char_list.size() ; n_char++) + { + if (char_list.at(n_char).name == real_char) + f_cid = n_char; } - */ + + if (f_cid < 0 || f_cid >= char_list.size()) + { + qDebug() << "W: " << real_char << " not present in char_list"; + return; + } + + other_charid = f_cid; + + // Redo the character list. + QStringList sorted_pair_list; + + for (char_type i_char : char_list) + sorted_pair_list.append(i_char.name); + + sorted_pair_list.sort(); + + for (int i = 0; i < ui_pair_list->count(); i++) { + ui_pair_list->item(i)->setText(sorted_pair_list.at(i)); + } + + f_item->setText(real_char + " [x]"); } void Courtroom::on_music_list_double_clicked(QModelIndex p_model) @@ -1767,9 +3010,22 @@ void Courtroom::on_music_list_double_clicked(QModelIndex p_model) if (is_muted) return; - QString p_song = ui_music_list->item(p_model.row())->text(); + QString p_song = music_list.at(music_row_to_number.at(p_model.row())); - ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#%"), false); + if (!ui_ic_chat_name->text().isEmpty() && ao_app->cccc_ic_support_enabled) + { + ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#" + ui_ic_chat_name->text() + "#%"), false); + } + else + { + ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#%"), false); + } +} + +void Courtroom::on_area_list_double_clicked(QModelIndex p_model) +{ + QString p_area = area_list.at(area_row_to_number.at(p_model.row())); + ao_app->send_server_packet(new AOPacket("MC#" + p_area + "#" + QString::number(m_cid) + "#%"), false); } void Courtroom::on_hold_it_clicked() @@ -1873,6 +3129,9 @@ void Courtroom::on_mute_clicked() if (ui_mute_list->isHidden()) { ui_mute_list->show(); + ui_pair_list->hide(); + ui_pair_offset_spinbox->hide(); + ui_pair_button->set_image("pair_button.png"); ui_mute->set_image("mute_pressed.png"); } else @@ -1882,6 +3141,24 @@ void Courtroom::on_mute_clicked() } } +void Courtroom::on_pair_clicked() +{ + if (ui_pair_list->isHidden()) + { + ui_pair_list->show(); + ui_pair_offset_spinbox->show(); + ui_mute_list->hide(); + ui_mute->set_image("mute.png"); + ui_pair_button->set_image("pair_button_pressed.png"); + } + else + { + ui_pair_list->hide(); + ui_pair_offset_spinbox->hide(); + ui_pair_button->set_image("pair_button.png"); + } +} + void Courtroom::on_defense_minus_clicked() { int f_state = defense_bar_state - 1; @@ -1939,6 +3216,16 @@ void Courtroom::on_blip_slider_moved(int p_value) ui_ic_chat_message->setFocus(); } +void Courtroom::on_log_limit_changed(int value) +{ + log_maximum_blocks = value; +} + +void Courtroom::on_pair_offset_changed(int value) +{ + offset_with_pair = value; +} + void Courtroom::on_witness_testimony_clicked() { if (is_muted) @@ -1959,6 +3246,26 @@ void Courtroom::on_cross_examination_clicked() ui_ic_chat_message->setFocus(); } +void Courtroom::on_not_guilty_clicked() +{ + if (is_muted) + return; + + ao_app->send_server_packet(new AOPacket("RT#judgeruling#0#%")); + + ui_ic_chat_message->setFocus(); +} + +void Courtroom::on_guilty_clicked() +{ + if (is_muted) + return; + + ao_app->send_server_packet(new AOPacket("RT#judgeruling#1#%")); + + ui_ic_chat_message->setFocus(); +} + void Courtroom::on_change_character_clicked() { music_player->set_volume(0); @@ -2014,11 +3321,48 @@ void Courtroom::on_spectator_clicked() void Courtroom::on_call_mod_clicked() { - ao_app->send_server_packet(new AOPacket("ZZ#%")); + if (ao_app->modcall_reason_enabled) { + QMessageBox errorBox; + QInputDialog input; + + input.setWindowFlags(Qt::WindowSystemMenuHint); + input.setLabelText("Reason:"); + input.setWindowTitle("Call Moderator"); + auto code = input.exec(); + + if (code != QDialog::Accepted) + return; + + QString text = input.textValue(); + if (text.isEmpty()) { + errorBox.critical(nullptr, "Error", "You must provide a reason."); + return; + } else if (text.length() > 256) { + errorBox.critical(nullptr, "Error", "The message is too long."); + return; + } + + QStringList mod_reason; + mod_reason.append(text); + + ao_app->send_server_packet(new AOPacket("ZZ", mod_reason)); + } else { + ao_app->send_server_packet(new AOPacket("ZZ#%")); + } ui_ic_chat_message->setFocus(); } +void Courtroom::on_settings_clicked() +{ + ao_app->call_settings_menu(); +} + +void Courtroom::on_announce_casing_clicked() +{ + ao_app->call_announce_menu(this); +} + void Courtroom::on_pre_clicked() { ui_ic_chat_message->setFocus(); @@ -2034,6 +3378,31 @@ void Courtroom::on_guard_clicked() ui_ic_chat_message->setFocus(); } +void Courtroom::on_showname_enable_clicked() +{ + ui_ic_chatlog->clear(); + first_message_sent = false; + + foreach (chatlogpiece item, ic_chatlog_history) { + if (ui_showname_enable->isChecked()) + { + if (item.get_is_song()) + append_ic_text(item.get_message(), item.get_showname(), true); + else + append_ic_text(item.get_message(), item.get_showname()); + } + else + { + if (item.get_is_song()) + append_ic_text(item.get_message(), item.get_name(), true); + else + append_ic_text(item.get_message(), item.get_name()); + } + } + + ui_ic_chat_message->setFocus(); +} + void Courtroom::on_evidence_button_clicked() { if (ui_evidence->isHidden()) @@ -2047,11 +3416,65 @@ void Courtroom::on_evidence_button_clicked() } } +void Courtroom::on_switch_area_music_clicked() +{ + if (ui_area_list->isHidden()) + { + ui_area_list->show(); + ui_music_list->hide(); + } + else + { + ui_area_list->hide(); + ui_music_list->show(); + } +} + void Courtroom::ping_server() { ao_app->send_server_packet(new AOPacket("CH#" + QString::number(m_cid) + "#%")); } +void Courtroom::on_casing_clicked() +{ + if (ao_app->casing_alerts_enabled) + { + if (ui_casing->isChecked()) + { + QStringList f_packet; + + f_packet.append(ao_app->get_casing_can_host_cases()); + f_packet.append(QString::number(ao_app->get_casing_cm_enabled())); + f_packet.append(QString::number(ao_app->get_casing_defence_enabled())); + f_packet.append(QString::number(ao_app->get_casing_prosecution_enabled())); + f_packet.append(QString::number(ao_app->get_casing_judge_enabled())); + f_packet.append(QString::number(ao_app->get_casing_juror_enabled())); + f_packet.append(QString::number(ao_app->get_casing_steno_enabled())); + + ao_app->send_server_packet(new AOPacket("SETCASE", f_packet)); + } + else + ao_app->send_server_packet(new AOPacket("SETCASE#\"\"#0#0#0#0#0#0#%")); + } +} + +void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, bool jur, bool steno) +{ + if (ao_app->casing_alerts_enabled) + { + QStringList f_packet; + + f_packet.append(title); + f_packet.append(QString::number(def)); + f_packet.append(QString::number(pro)); + f_packet.append(QString::number(jud)); + f_packet.append(QString::number(jur)); + f_packet.append(QString::number(steno)); + + ao_app->send_server_packet(new AOPacket("CASEA", f_packet)); + } +} + Courtroom::~Courtroom() { delete music_player; @@ -2059,3 +3482,17 @@ Courtroom::~Courtroom() delete objection_player; delete blip_player; } + +#if (defined (_WIN32) || defined (_WIN64)) +void Courtroom::load_bass_opus_plugin() +{ + BASS_PluginLoad("bassopus.dll", 0); +} +#elif (defined (LINUX) || defined (__linux__)) +void Courtroom::load_bass_opus_plugin() +{ + BASS_PluginLoad("libbassopus.so", 0); +} +#else +#error This operating system is unsupported for bass plugins. +#endif diff --git a/courtroom.h b/courtroom.h index 2cc099c..0b5c0ea 100644 --- a/courtroom.h +++ b/courtroom.h @@ -24,13 +24,8 @@ #include "file_functions.h" #include "datatypes.h" #include "debug_functions.h" +#include "chatlogpiece.h" -#include -#include -#include -#include -#include -#include #include #include #include @@ -43,6 +38,18 @@ #include #include #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include class AOApplication; @@ -55,6 +62,49 @@ public: void append_char(char_type p_char){char_list.append(p_char);} void append_evidence(evi_type p_evi){evidence_list.append(p_evi);} void append_music(QString f_music){music_list.append(f_music);} + void append_area(QString f_area){area_list.append(f_area);} + + void fix_last_area() + { + QString malplaced = area_list.last(); + area_list.removeLast(); + append_music(malplaced); + } + + void arup_append(int players, QString status, QString cm, QString locked) + { + arup_players.append(players); + arup_statuses.append(status); + arup_cms.append(cm); + arup_locks.append(locked); + } + + void arup_modify(int type, int place, QString value) + { + if (type == 0) + { + if (arup_players.size() > place) + arup_players[place] = value.toInt(); + } + else if (type == 1) + { + if (arup_statuses.size() > place) + arup_statuses[place] = value; + } + else if (type == 2) + { + if (arup_cms.size() > place) + arup_cms[place] = value; + } + else if (type == 3) + { + if (arup_locks.size() > place) + arup_locks[place] = value; + } + list_areas(); + } + + void character_loading_finished(); //sets position of widgets based on theme ini files void set_widgets(); @@ -83,12 +133,18 @@ public: //sets the local mute list based on characters available on the server void set_mute_list(); + // Sets the local pair list based on the characters available on the server. + void set_pair_list(); + //sets desk and bg based on pos in chatmessage void set_scene(); //sets text color based on text color in chatmessage void set_text_color(); + // And gets the colour, too! + QColor get_text_color(QString color); + //takes in serverD-formatted IP list as prints a converted version to server OOC //admittedly poorly named void set_ip_list(QString p_list); @@ -100,23 +156,21 @@ public: //send a message that the player is banned and quits the server void set_ban(int p_cid); - //implementations in path_functions.cpp - QString get_background_path(); - QString get_default_background_path(); - //cid = character id, returns the cid of the currently selected character int get_cid() {return m_cid;} QString get_current_char() {return current_char;} + QString get_current_background() {return current_background;} //properly sets up some varibles: resets user state void enter_courtroom(int p_cid); //helper function that populates ui_music_list with the contents of music_list void list_music(); + void list_areas(); //these are for OOC chat void append_ms_chatmessage(QString f_name, QString f_message); - void append_server_chatmessage(QString p_name, QString p_message); + void append_server_chatmessage(QString p_name, QString p_message, QString p_colour); //these functions handle chatmessages sequentially. //The process itself is very convoluted and merits separate documentation @@ -125,24 +179,30 @@ public: void handle_chatmessage_2(); void handle_chatmessage_3(); + //This function filters out the common CC inline text trickery, for appending to + //the IC chatlog. + QString filter_ic_text(QString p_text); + //adds text to the IC chatlog. p_name first as bold then p_text then a newlin //this function keeps the chatlog scrolled to the top unless there's text selected // or the user isn't already scrolled to the top - void append_ic_text(QString p_text, QString p_name = ""); + void append_ic_text(QString p_text, QString p_name = "", bool is_songchange = false); //prints who played the song to IC chat and plays said song(if found on local filesystem) //takes in a list where the first element is the song name and the second is the char id of who played it void handle_song(QStringList *p_contents); - void play_preanim(); + void play_preanim(bool noninterrupting); //plays the witness testimony or cross examination animation based on argument - void handle_wtce(QString p_wtce); + void handle_wtce(QString p_wtce, int variant); //sets the hp bar of defense(p_bar 1) or pro(p_bar 2) //state is an number between 0 and 10 inclusive void set_hp_bar(int p_bar, int p_state); + void announce_case(QString title, bool def, bool pro, bool jud, bool jur, bool steno); + void check_connection_received(); ~Courtroom(); @@ -159,18 +219,67 @@ private: int m_viewport_width = 256; int m_viewport_height = 192; + bool first_message_sent = false; + int maximumMessages = 0; + + // This is for inline message-colouring. + + enum INLINE_COLOURS { + INLINE_BLUE, + INLINE_GREEN, + INLINE_ORANGE, + INLINE_GREY + }; + + // A stack of inline colours. + std::stack inline_colour_stack; + + bool next_character_is_not_special = false; // If true, write the + // next character as it is. + + bool message_is_centered = false; + + int current_display_speed = 3; + int message_display_speed[7] = {30, 40, 50, 60, 75, 100, 120}; + + // This is for checking if the character should start talking again + // when an inline blue text ends. + bool entire_message_is_blue = false; + + // And this is the inline 'talking checker'. Counts how 'deep' we are + // in inline blues. + int inline_blue_depth = 0; + + // The character ID of the character this user wants to appear alongside with. + int other_charid = -1; + + // The offset this user has given if they want to appear alongside someone. + int offset_with_pair = 0; + QVector char_list; QVector evidence_list; QVector music_list; + QVector area_list; + + QVector arup_players; + QVector arup_statuses; + QVector arup_cms; + QVector arup_locks; QSignalMapper *char_button_mapper; + QVector ic_chatlog_history; + + // These map music row items and area row items to their actual IDs. + QVector music_row_to_number; + QVector area_row_to_number; + //triggers ping_server() every 60 seconds QTimer *keepalive_timer; //determines how fast messages tick onto screen QTimer *chat_tick_timer; - int chat_tick_interval = 60; + //int chat_tick_interval = 60; //which tick position(character in chat message) we are at int tick_pos = 0; //used to determine how often blips sound @@ -180,6 +289,12 @@ private: bool rainbow_appended = false; bool blank_blip = false; + // Used for getting the current maximum blocks allowed in the IC chatlog. + int log_maximum_blocks = 0; + + // True, if the log should go downwards. + bool log_goes_downwards = false; + //delay before chat messages starts ticking QTimer *text_delay_timer; @@ -197,7 +312,7 @@ private: //every time point in char.inis times this equals the final time const int time_mod = 40; - static const int chatmessage_size = 15; + static const int chatmessage_size = 23; QString m_chatmessage[chatmessage_size]; bool chatmessage_is_empty = false; @@ -218,7 +333,7 @@ private: bool is_muted = false; - //state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle + //state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle, 4 = noniterrupting preanim int anim_state = 3; //state of text ticking, 0 = not yet ticking, 1 = ticking in progress, 2 = ticking done @@ -242,6 +357,9 @@ private: int char_rows = 9; int max_chars_on_page = 90; + const int button_width = 60; + const int button_height = 60; + int current_emote_page = 0; int current_emote = 0; int emote_columns = 5; @@ -277,6 +395,7 @@ private: AOScene *ui_vp_background; AOMovie *ui_vp_speedlines; AOCharMovie *ui_vp_player_char; + AOCharMovie *ui_vp_sideplayer_char; AOScene *ui_vp_desk; AOScene *ui_vp_legacy_desk; AOEvidenceDisplay *ui_vp_evidence_display; @@ -297,7 +416,12 @@ private: QListWidget *ui_area_list; QListWidget *ui_music_list; + AOButton *ui_pair_button; + QListWidget *ui_pair_list; + QSpinBox *ui_pair_offset_spinbox; + QLineEdit *ui_ic_chat_message; + QLineEdit *ui_ic_chat_name; QLineEdit *ui_ooc_chat_message; QLineEdit *ui_ooc_chat_name; @@ -328,14 +452,23 @@ private: AOButton *ui_witness_testimony; AOButton *ui_cross_examination; + AOButton *ui_guilty; + AOButton *ui_not_guilty; AOButton *ui_change_character; AOButton *ui_reload_theme; AOButton *ui_call_mod; + AOButton *ui_settings; + AOButton *ui_announce_casing; + AOButton *ui_switch_area_music; QCheckBox *ui_pre; QCheckBox *ui_flip; QCheckBox *ui_guard; + QCheckBox *ui_casing; + + QCheckBox *ui_pre_non_interrupt; + QCheckBox *ui_showname_enable; AOButton *ui_custom_objection; AOButton *ui_realization; @@ -355,6 +488,9 @@ private: AOImage *ui_muted; + QSpinBox *ui_log_limit_spinbox; + QLabel *ui_log_limit_label; + AOButton *ui_evidence_button; AOImage *ui_evidence; AOLineEdit *ui_evidence_name; @@ -376,6 +512,7 @@ private: QWidget *ui_char_buttons; QVector ui_char_button_list; + QVector ui_char_button_list_filtered; AOImage *ui_selector; AOButton *ui_back_to_lobby; @@ -387,9 +524,15 @@ private: AOButton *ui_spectator; + QLineEdit *ui_char_search; + QCheckBox *ui_char_passworded; + QCheckBox *ui_char_taken; + void construct_char_select(); void set_char_select(); void set_char_select_page(); + void put_button_in_place(int starting, int chars_on_this_page); + void filter_character_list(); void construct_emotes(); void set_emote_page(); @@ -398,8 +541,6 @@ private: void construct_evidence(); void set_evidence_page(); - - public slots: void objection_done(); void preanim_done(); @@ -411,6 +552,8 @@ public slots: void mod_called(QString p_ip); + void case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno); + private slots: void start_chat_ticking(); void play_sfx(); @@ -418,6 +561,7 @@ private slots: void chat_tick(); void on_mute_list_clicked(QModelIndex p_index); + void on_pair_list_clicked(QModelIndex p_index); void on_chat_return_pressed(); @@ -425,6 +569,7 @@ private slots: void on_music_search_edited(QString p_text); void on_music_list_double_clicked(QModelIndex p_model); + void on_area_list_double_clicked(QModelIndex p_model); void select_emote(int p_id); @@ -456,6 +601,7 @@ private slots: void on_realization_clicked(); void on_mute_clicked(); + void on_pair_clicked(); void on_defense_minus_clicked(); void on_defense_plus_clicked(); @@ -468,19 +614,28 @@ private slots: void on_sfx_slider_moved(int p_value); void on_blip_slider_moved(int p_value); + void on_log_limit_changed(int value); + void on_pair_offset_changed(int value); + void on_ooc_toggle_clicked(); void on_witness_testimony_clicked(); void on_cross_examination_clicked(); + void on_not_guilty_clicked(); + void on_guilty_clicked(); void on_change_character_clicked(); void on_reload_theme_clicked(); void on_call_mod_clicked(); + void on_settings_clicked(); + void on_announce_casing_clicked(); void on_pre_clicked(); void on_flip_clicked(); void on_guard_clicked(); + void on_showname_enable_clicked(); + void on_evidence_button_clicked(); void on_evidence_delete_clicked(); @@ -490,12 +645,21 @@ private slots: void on_char_select_left_clicked(); void on_char_select_right_clicked(); + void on_char_search_changed(const QString& newtext); + void on_char_taken_clicked(int newstate); + void on_char_passworded_clicked(int newstate); void on_spectator_clicked(); void char_clicked(int n_char); + void on_switch_area_music_clicked(); + + void on_casing_clicked(); + void ping_server(); + + void load_bass_opus_plugin(); }; #endif // COURTROOM_H diff --git a/datatypes.h b/datatypes.h index 37d3e99..aaa5de5 100644 --- a/datatypes.h +++ b/datatypes.h @@ -92,7 +92,15 @@ enum CHAT_MESSAGE EVIDENCE_ID, FLIP, REALIZATION, - TEXT_COLOR + TEXT_COLOR, + SHOWNAME, + OTHER_CHARID, + OTHER_NAME, + OTHER_EMOTE, + SELF_OFFSET, + OTHER_OFFSET, + OTHER_FLIP, + NONINTERRUPTING_PRE }; enum COLOR @@ -103,7 +111,9 @@ enum COLOR ORANGE, BLUE, YELLOW, - RAINBOW + RAINBOW, + PINK, + CYAN }; #endif // DATATYPES_H diff --git a/discord_rich_presence.h b/discord_rich_presence.h index 348d36f..e7ecc6e 100644 --- a/discord_rich_presence.h +++ b/discord_rich_presence.h @@ -7,6 +7,11 @@ #include #include +#include +#include + +#include + namespace AttorneyOnline { class Discord diff --git a/emotes.cpp b/emotes.cpp index 27a1a4f..b6a217e 100644 --- a/emotes.cpp +++ b/emotes.cpp @@ -2,8 +2,6 @@ #include "aoemotebutton.h" -#include - void Courtroom::construct_emotes() { ui_emotes = new QWidget(this); diff --git a/encryption_functions.cpp b/encryption_functions.cpp index 56b6e34..ffbe0cd 100644 --- a/encryption_functions.cpp +++ b/encryption_functions.cpp @@ -2,12 +2,6 @@ #include "hex_functions.h" -#include -#include -#include -#include -#include - QString fanta_encrypt(QString temp_input, unsigned int p_key) { //using standard stdlib types is actually easier here because of implicit char<->int conversion diff --git a/encryption_functions.h b/encryption_functions.h index b6ea1d7..dc67d12 100644 --- a/encryption_functions.h +++ b/encryption_functions.h @@ -3,6 +3,12 @@ #include +#include +#include +#include +#include +#include + QString fanta_encrypt(QString p_input, unsigned int key); QString fanta_decrypt(QString p_input, unsigned int key); diff --git a/evidence.cpp b/evidence.cpp index 19ffecf..4e79664 100644 --- a/evidence.cpp +++ b/evidence.cpp @@ -1,8 +1,5 @@ #include "courtroom.h" -#include -#include - void Courtroom::construct_evidence() { ui_evidence = new AOImage(this, ao_app); @@ -195,7 +192,7 @@ void Courtroom::on_evidence_image_button_clicked() dialog.setFileMode(QFileDialog::ExistingFile); dialog.setNameFilter(tr("Images (*.png)")); dialog.setViewMode(QFileDialog::List); - dialog.setDirectory(ao_app->get_evidence_path()); + dialog.setDirectory(ao_app->get_base_path() + "evidence"); QStringList filenames; diff --git a/file_functions.cpp b/file_functions.cpp index bc9185f..f93ee15 100644 --- a/file_functions.cpp +++ b/file_functions.cpp @@ -1,6 +1,3 @@ -#include -#include - #include "file_functions.h" bool file_exists(QString file_path) @@ -16,3 +13,9 @@ bool dir_exists(QString dir_path) return check_dir.exists(); } + +bool exists(QString p_path) { + QFile file(p_path); + + return file.exists(); +} diff --git a/file_functions.h b/file_functions.h index 81a90ed..6937ed8 100644 --- a/file_functions.h +++ b/file_functions.h @@ -1,9 +1,12 @@ #ifndef FILE_FUNCTIONS_H #define FILE_FUNCTIONS_H +#include +#include #include bool file_exists(QString file_path); bool dir_exists(QString file_path); +bool exists(QString p_path); #endif // FILE_FUNCTIONS_H diff --git a/hex_functions.cpp b/hex_functions.cpp index 3bb535b..4a58d2b 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -9,7 +9,7 @@ namespace omni std::stringstream stream; stream << std::setfill('0') << std::setw(sizeof(char)*2) - << std::hex << input; + << std::hex << input; std::string result(stream.str()); std::transform(result.begin(), result.end(), result.begin(), ::toupper); diff --git a/include/discord_register.h b/include/discord_register.h new file mode 100644 index 0000000..4c16b68 --- /dev/null +++ b/include/discord_register.h @@ -0,0 +1,26 @@ +#pragma once + +#if defined(DISCORD_DYNAMIC_LIB) +# if defined(_WIN32) +# if defined(DISCORD_BUILDING_SDK) +# define DISCORD_EXPORT __declspec(dllexport) +# else +# define DISCORD_EXPORT __declspec(dllimport) +# endif +# else +# define DISCORD_EXPORT __attribute__((visibility("default"))) +# endif +#else +# define DISCORD_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command); +DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId); + +#ifdef __cplusplus +} +#endif diff --git a/include/discord_rpc.h b/include/discord_rpc.h new file mode 100644 index 0000000..3e1441e --- /dev/null +++ b/include/discord_rpc.h @@ -0,0 +1,87 @@ +#pragma once +#include + +// clang-format off + +#if defined(DISCORD_DYNAMIC_LIB) +# if defined(_WIN32) +# if defined(DISCORD_BUILDING_SDK) +# define DISCORD_EXPORT __declspec(dllexport) +# else +# define DISCORD_EXPORT __declspec(dllimport) +# endif +# else +# define DISCORD_EXPORT __attribute__((visibility("default"))) +# endif +#else +# define DISCORD_EXPORT +#endif + +// clang-format on + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct DiscordRichPresence { + const char* state; /* max 128 bytes */ + const char* details; /* max 128 bytes */ + int64_t startTimestamp; + int64_t endTimestamp; + const char* largeImageKey; /* max 32 bytes */ + const char* largeImageText; /* max 128 bytes */ + const char* smallImageKey; /* max 32 bytes */ + const char* smallImageText; /* max 128 bytes */ + const char* partyId; /* max 128 bytes */ + int partySize; + int partyMax; + const char* matchSecret; /* max 128 bytes */ + const char* joinSecret; /* max 128 bytes */ + const char* spectateSecret; /* max 128 bytes */ + int8_t instance; +} DiscordRichPresence; + +typedef struct DiscordUser { + const char* userId; + const char* username; + const char* discriminator; + const char* avatar; +} DiscordUser; + +typedef struct DiscordEventHandlers { + void (*ready)(const DiscordUser* request); + void (*disconnected)(int errorCode, const char* message); + void (*errored)(int errorCode, const char* message); + void (*joinGame)(const char* joinSecret); + void (*spectateGame)(const char* spectateSecret); + void (*joinRequest)(const DiscordUser* request); +} DiscordEventHandlers; + +#define DISCORD_REPLY_NO 0 +#define DISCORD_REPLY_YES 1 +#define DISCORD_REPLY_IGNORE 2 + +DISCORD_EXPORT void Discord_Initialize(const char* applicationId, + DiscordEventHandlers* handlers, + int autoRegister, + const char* optionalSteamId); +DISCORD_EXPORT void Discord_Shutdown(void); + +/* checks for incoming messages, dispatches callbacks */ +DISCORD_EXPORT void Discord_RunCallbacks(void); + +/* If you disable the lib starting its own io thread, you'll need to call this from your own */ +#ifdef DISCORD_DISABLE_IO_THREAD +DISCORD_EXPORT void Discord_UpdateConnection(void); +#endif + +DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence); +DISCORD_EXPORT void Discord_ClearPresence(void); + +DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply); + +DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers); + +#ifdef __cplusplus +} /* extern "C" */ +#endif diff --git a/lobby.cpp b/lobby.cpp index c0dbf0c..5158a1f 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -5,14 +5,12 @@ #include "networkmanager.h" #include "aosfxplayer.h" -#include -#include - Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; this->setWindowTitle("Attorney Online 2"); + this->setWindowIcon(QIcon(":/logo.png")); ui_background = new AOImage(this, ao_app); ui_public_servers = new AOButton(this, ao_app); @@ -52,6 +50,8 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() connect(ui_chatmessage, SIGNAL(returnPressed()), this, SLOT(on_chatfield_return_pressed())); connect(ui_cancel, SIGNAL(clicked()), ao_app, SLOT(loading_cancelled())); + ui_connect->setEnabled(false); + set_widgets(); } @@ -265,21 +265,19 @@ void Lobby::on_connect_released() void Lobby::on_about_clicked() { - call_notice("Attorney Online 2 is built using Qt 5.7\n\n" - "Lead development:\n" - "OmniTroid\n\n" - "stonedDiscord\n" - "longbyte1\n" - "Supporting development:\n" - "Fiercy\n\n" - "UI design:\n" - "Ruekasu\n" - "Draxirch\n\n" - "Special thanks:\n" - "Unishred\n" - "Argoneus\n" - "Noevain\n" - "Cronnicossy"); + QString msg = tr("

Attorney Online %1

" + "The courtroom drama simulator" + "

Source code: " + "" + "https://github.com/AttorneyOnline/AO2-Client" + "

Major development:
" + "OmniTroid, stonedDiscord, longbyte1, gameboyprinter, Cerapter" + "

Special thanks:
" + "Remy, Iamgoofball, Hibiki, Qubrick (webAO), Ruekasu (UI design), " + "Draxirch (UI design), Unishred, Argoneus (tsuserver), Fiercy, " + "Noevain, Cronnicossy") + .arg(ao_app->get_version_string()); + QMessageBox::about(this, "About", msg); } void Lobby::on_server_list_clicked(QModelIndex p_model) @@ -315,6 +313,8 @@ void Lobby::on_server_list_clicked(QModelIndex p_model) ui_player_count->setText("Offline"); + ui_connect->setEnabled(false); + ao_app->net_manager->connect_to_server(f_server); } @@ -361,7 +361,7 @@ void Lobby::list_favorites() void Lobby::append_chatmessage(QString f_name, QString f_message) { - ui_chatbox->append_chatmessage(f_name, f_message); + ui_chatbox->append_chatmessage(f_name, f_message, ao_app->get_color("ooc_default_color", "courtroom_design.ini").name()); } void Lobby::append_error(QString f_message) @@ -375,6 +375,11 @@ void Lobby::set_player_count(int players_online, int max_players) ui_player_count->setText(f_string); } +void Lobby::enable_connect_button() +{ + ui_connect->setEnabled(true); +} + Lobby::~Lobby() { diff --git a/lobby.h b/lobby.h index 2d3aee5..19276a7 100644 --- a/lobby.h +++ b/lobby.h @@ -14,6 +14,9 @@ #include #include +#include +#include + class AOApplication; class Lobby : public QMainWindow @@ -34,6 +37,7 @@ public: void hide_loading_overlay(){ui_loading_background->hide();} QString get_chatlog(); int get_selected_server(); + void enable_connect_button(); void set_loading_value(int p_value); diff --git a/main.cpp b/main.cpp index 5696e2e..cf51b0a 100644 --- a/main.cpp +++ b/main.cpp @@ -5,9 +5,9 @@ #include "networkmanager.h" #include "lobby.h" #include "courtroom.h" - +#include #include - +Q_IMPORT_PLUGIN(ApngImagePlugin); int main(int argc, char *argv[]) { #if QT_VERSION > QT_VERSION_CHECK(5, 6, 0) @@ -16,10 +16,10 @@ int main(int argc, char *argv[]) // packages up to Qt 5.6, so this is conditional. AOApplication::setAttribute(Qt::AA_EnableHighDpiScaling); #endif + AOApplication main_app(argc, argv); main_app.construct_lobby(); main_app.net_manager->connect_to_master(); main_app.w_lobby->show(); - return main_app.exec(); } diff --git a/misc_functions.cpp b/misc_functions.cpp index e767b2e..2352055 100644 --- a/misc_functions.cpp +++ b/misc_functions.cpp @@ -1,8 +1,5 @@ #include "misc_functions.h" -#include -#include - void delay(int p_milliseconds) { QTime dieTime = QTime::currentTime().addMSecs(p_milliseconds); diff --git a/misc_functions.h b/misc_functions.h index 0de2d8a..026c635 100644 --- a/misc_functions.h +++ b/misc_functions.h @@ -1,6 +1,9 @@ #ifndef MISC_FUNCTIONS_H #define MISC_FUNCTIONS_H +#include +#include + void delay(int p_milliseconds); #endif // MISC_FUNCTIONS_H diff --git a/networkmanager.cpp b/networkmanager.cpp index e7246fe..288a900 100644 --- a/networkmanager.cpp +++ b/networkmanager.cpp @@ -4,8 +4,6 @@ #include "debug_functions.h" #include "lobby.h" -#include - NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) { ao_app = parent; @@ -21,10 +19,9 @@ NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) QObject::connect(server_socket, SIGNAL(readyRead()), this, SLOT(handle_server_packet())); QObject::connect(server_socket, SIGNAL(disconnected()), ao_app, SLOT(server_disconnected())); - QString master_config = ao_app->read_config("master"); - if (master_config != "") { + QString master_config = ao_app->configini->value("master", "").value(); + if (master_config != "") ms_nosrv_hostname = master_config; - } } NetworkManager::~NetworkManager() diff --git a/networkmanager.h b/networkmanager.h index 99987f3..e28abfd 100644 --- a/networkmanager.h +++ b/networkmanager.h @@ -21,6 +21,7 @@ #include #include #include +#include class NetworkManager : public QObject { diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 83faccf..954062e 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -7,9 +7,6 @@ #include "hardware_functions.h" #include "debug_functions.h" -#include -#include - void AOApplication::ms_packet_received(AOPacket *p_packet) { p_packet->net_decode(); @@ -150,6 +147,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet) improved_loading_enabled = false; desk_mod_enabled = false; evidence_enabled = false; + cccc_ic_support_enabled = false; + arup_enabled = false; + casing_alerts_enabled = false; + modcall_reason_enabled = false; //workaround for tsuserver4 if (f_contents.at(0) == "NOENCRYPT") @@ -177,7 +178,12 @@ void AOApplication::server_packet_received(AOPacket *p_packet) goto end; if (courtroom_constructed) - w_courtroom->append_server_chatmessage(f_contents.at(0), f_contents.at(1)); + { + if (f_contents.size() == 3) + w_courtroom->append_server_chatmessage(f_contents.at(0), f_contents.at(1), f_contents.at(2)); + else + w_courtroom->append_server_chatmessage(f_contents.at(0), f_contents.at(1), "0"); + } } else if (header == "FL") { @@ -195,6 +201,16 @@ void AOApplication::server_packet_received(AOPacket *p_packet) desk_mod_enabled = true; if (f_packet.contains("evidence",Qt::CaseInsensitive)) evidence_enabled = true; + if (f_packet.contains("cccc_ic_support",Qt::CaseInsensitive)) + cccc_ic_support_enabled = true; + if (f_packet.contains("arup",Qt::CaseInsensitive)) + arup_enabled = true; + if (f_packet.contains("casing_alerts",Qt::CaseInsensitive)) + casing_alerts_enabled = true; + if (f_packet.contains("modcall_reason",Qt::CaseInsensitive)) + modcall_reason_enabled = true; + + w_lobby->enable_connect_button(); } else if (header == "PN") { @@ -218,6 +234,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) loaded_chars = 0; loaded_evidence = 0; loaded_music = 0; + generated_chars = 0; destruct_courtroom(); construct_courtroom(); @@ -233,7 +250,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (selected_server >= 0 && selected_server < server_list.size()) { auto info = server_list.at(selected_server); server_name = info.name; - server_address = info.ip + info.port; + server_address = QString("%1:%2").arg(info.ip, info.port); window_title += ": " + server_name; } } @@ -264,7 +281,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256); hash.addData(server_address.toUtf8()); - if(is_discord_enabled()) + if (is_discord_enabled()) discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString()); } else if (header == "CI") @@ -272,8 +289,6 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - for (int n_element = 0 ; n_element < f_contents.size() ; n_element += 2) { if (f_contents.at(n_element).toInt() != loaded_chars) @@ -300,7 +315,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_char(f_char); - int loading_value = (loaded_chars / static_cast(total_loading_size)) * 100; + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); } @@ -343,8 +359,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_evidence(f_evi); - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = ((loaded_chars + loaded_evidence) / static_cast(total_loading_size)) * 100; + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); QString next_packet_number = QString::number(loaded_evidence); @@ -356,7 +372,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; - int total_loading_size = char_list_size + evidence_list_size + music_list_size; + bool musics_time = false; + int areas = 0; for (int n_element = 0 ; n_element < f_contents.size() ; n_element += 2) { @@ -372,12 +389,40 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_lobby->set_loading_text("Loading music:\n" + QString::number(loaded_music) + "/" + QString::number(music_list_size)); - w_courtroom->append_music(f_music); + if (musics_time) + { + w_courtroom->append_music(f_music); + } + else + { + if (f_music.endsWith(".wav") || + f_music.endsWith(".mp3") || + f_music.endsWith(".mp4") || + f_music.endsWith(".ogg") || + f_music.endsWith(".opus")) + { + musics_time = true; + areas--; + w_courtroom->fix_last_area(); + w_courtroom->append_music(f_music); + } + else + { + w_courtroom->append_area(f_music); + areas++; + } + } - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; + for (int area_n = 0; area_n < areas; area_n++) + { + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); + } + + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); - } + QString next_packet_number = QString::number(((loaded_music - 1) / 10) + 1); send_server_packet(new AOPacket("AM#" + next_packet_number + "#%")); } @@ -400,8 +445,6 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - for (int n_element = 0 ; n_element < f_contents.size() ; ++n_element) { QStringList sub_elements = f_contents.at(n_element).split("&"); @@ -420,7 +463,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_char(f_char); - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); } @@ -431,7 +475,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; - int total_loading_size = char_list_size + evidence_list_size + music_list_size; + bool musics_time = false; + int areas = 0; for (int n_element = 0 ; n_element < f_contents.size() ; ++n_element) { @@ -439,9 +484,37 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_lobby->set_loading_text("Loading music:\n" + QString::number(loaded_music) + "/" + QString::number(music_list_size)); - w_courtroom->append_music(f_contents.at(n_element)); + if (musics_time) + { + w_courtroom->append_music(f_contents.at(n_element)); + } + else + { + if (f_contents.at(n_element).endsWith(".wav") || + f_contents.at(n_element).endsWith(".mp3") || + f_contents.at(n_element).endsWith(".mp4") || + f_contents.at(n_element).endsWith(".ogg") || + f_contents.at(n_element).endsWith(".opus")) + { + musics_time = true; + w_courtroom->fix_last_area(); + w_courtroom->append_music(f_contents.at(n_element)); + areas--; + } + else + { + w_courtroom->append_area(f_contents.at(n_element)); + areas++; + } + } - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; + for (int area_n = 0; area_n < areas; area_n++) + { + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); + } + + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); } @@ -455,6 +528,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (lobby_constructed) w_courtroom->append_ms_chatmessage("", w_lobby->get_chatlog()); + w_courtroom->character_loading_finished(); w_courtroom->done_received(); courtroom_loaded = true; @@ -493,7 +567,13 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (f_contents.size() < 1) goto end; if (courtroom_constructed) - w_courtroom->handle_wtce(f_contents.at(0)); + { + if (f_contents.size() == 1) + w_courtroom->handle_wtce(f_contents.at(0), 0); + else if (f_contents.size() == 2) { + w_courtroom->handle_wtce(f_contents.at(0), f_contents.at(1).toInt()); + } + } } else if (header == "HP") { @@ -524,6 +604,17 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->set_evidence_list(f_evi_list); } } + else if (header == "ARUP") + { + if (courtroom_constructed) + { + int arup_type = f_contents.at(0).toInt(); + for (int n_element = 1 ; n_element < f_contents.size() ; n_element++) + { + w_courtroom->arup_modify(arup_type, n_element - 1, f_contents.at(n_element)); + } + } + } else if (header == "IL") { if (courtroom_constructed && f_contents.size() > 0) @@ -541,25 +632,23 @@ void AOApplication::server_packet_received(AOPacket *p_packet) } else if (header == "KK") { - if (courtroom_constructed && f_contents.size() > 0) + if (courtroom_constructed && f_contents.size() >= 1) { - int f_cid = w_courtroom->get_cid(); - int remote_cid = f_contents.at(0).toInt(); - - if (f_cid != remote_cid && remote_cid != -1) - goto end; - - call_notice("You have been kicked."); + call_notice("You have been kicked from the server.\nReason: " + f_contents.at(0)); + construct_lobby(); + destruct_courtroom(); + } + } + else if (header == "KB") + { + if (courtroom_constructed && f_contents.size() >= 1) + { + call_notice("You have been banned from the server.\nReason: " + f_contents.at(0)); construct_lobby(); destruct_courtroom(); } } - else if (header == "KB") - { - if (courtroom_constructed && f_contents.size() > 0) - w_courtroom->set_ban(f_contents.at(0).toInt()); - } else if (header == "BD") { call_notice("You are banned on this server."); @@ -569,6 +658,11 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (courtroom_constructed && f_contents.size() > 0) w_courtroom->mod_called(f_contents.at(0)); } + else if (header == "CASEA") + { + if (courtroom_constructed && f_contents.size() > 6) + w_courtroom->case_called(f_contents.at(0), f_contents.at(1) == "1", f_contents.at(2) == "1", f_contents.at(3) == "1", f_contents.at(4) == "1", f_contents.at(5) == "1"); + } end: diff --git a/path_functions.cpp b/path_functions.cpp index 820c05a..7d40054 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -1,34 +1,40 @@ #include "aoapplication.h" #include "courtroom.h" #include "file_functions.h" + #include -#include #include +#include #ifdef BASE_OVERRIDE #include "base_override.h" #endif -QString base_path = ""; + +//this is a quite broad generalization +//the most common OSes(mac and windows) are _usually_ case insensitive +//however, there do exist mac installations with case sensitive filesystems +//in that case, define CASE_SENSITIVE_FILESYSTEM and compile on a mac +#if (defined (LINUX) || defined (__linux__)) +#define CASE_SENSITIVE_FILESYSTEM +#endif QString AOApplication::get_base_path() { - if (base_path == "") - { -#ifdef BASE_OVERRIDE - base_path = base_override; -#elif defined(ANDROID) - QString sdcard_storage = getenv("SECONDARY_STORAGE"); - if (dir_exists(sdcard_storage + "/AO2/")){ - base_path = sdcard_storage + "/AO2/"; - }else{ - QString external_storage = getenv("EXTERNAL_STORAGE"); - base_path = external_storage + "/AO2/"; - } + QString base_path = ""; +#ifdef ANDROID + QString sdcard_storage = getenv("SECONDARY_STORAGE"); + if (dir_exists(sdcard_storage + "/AO2/")){ + base_path = sdcard_storage + "/AO2/"; + } + else { + QString external_storage = getenv("EXTERNAL_STORAGE"); + base_path = external_storage + "/AO2/"; + } #else base_path = QDir::currentPath() + "/base/"; #endif -} - return base_path; + + return base_path; } QString AOApplication::get_data_path() @@ -36,72 +42,121 @@ QString AOApplication::get_data_path() return get_base_path() + "data/"; } -QString AOApplication::get_theme_path() +QString AOApplication::get_default_theme_path(QString p_file) { - return get_base_path() + "themes/" + current_theme.toLower() + "/"; + QString path = get_base_path() + "themes/default/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_default_theme_path() +QString AOApplication::get_custom_theme_path(QString p_theme, QString p_file) { - return get_base_path() + "themes/default/"; + QString path = get_base_path() + "themes/" + p_theme + "/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_character_path(QString p_character) +QString AOApplication::get_theme_path(QString p_file) { - return get_base_path() + "characters/" + p_character.toLower() + "/"; + QString path = get_base_path() + "themes/" + current_theme + "/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_demothings_path() +QString AOApplication::get_character_path(QString p_char, QString p_file) { - QString default_path = "misc/demothings/"; - QString alt_path = "misc/RosterImages"; - if (dir_exists(default_path)) - return get_base_path() + default_path; - else if (dir_exists(alt_path)) - return get_base_path() + alt_path; - else - return get_base_path() + default_path; + QString path = get_base_path() + "characters/" + p_char + "/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_sounds_path() + +QString AOApplication::get_sounds_path(QString p_file) { - return get_base_path() + "sounds/general/"; + QString path = get_base_path() + "sounds/general/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } + QString AOApplication::get_music_path(QString p_song) { - return get_base_path() + "sounds/music/" + p_song.toLower(); + QString path = get_base_path() + "sounds/music/" + p_song; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_background_path() +QString AOApplication::get_background_path(QString p_file) { - if (courtroom_constructed) - return w_courtroom->get_background_path(); - //this function being called when the courtroom isn't constructed makes no sense - return ""; + QString path = get_base_path() + "background/" + w_courtroom->get_current_background() + "/" + p_file; + if (courtroom_constructed) { +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif + } + return get_default_background_path(p_file); } -QString AOApplication::get_default_background_path() +QString AOApplication::get_default_background_path(QString p_file) { - return get_base_path() + "background/default/"; + QString path = get_base_path() + "background/default/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString AOApplication::get_evidence_path() +QString AOApplication::get_evidence_path(QString p_file) { - QString default_path = "evidence/"; - QString alt_path = "items/"; - if (dir_exists(default_path)) - return get_base_path() + default_path; - else if (dir_exists(alt_path)) - return get_base_path() + alt_path; - else - return get_base_path() + default_path; + QString path = get_base_path() + "evidence/" + p_file; +#ifndef CASE_SENSITIVE_FILESYSTEM + return path; +#else + return get_case_sensitive_path(path); +#endif } -QString Courtroom::get_background_path() -{ - return ao_app->get_base_path() + "background/" + current_background.toLower() + "/"; -} +QString AOApplication::get_case_sensitive_path(QString p_file) { + //first, check to see if it's actually there (also serves as base case for recursion) + if (exists(p_file)) return p_file; -QString Courtroom::get_default_background_path() -{ - return ao_app->get_base_path() + "background/default/"; + QFileInfo file(p_file); + + QString file_basename = file.fileName(); + QString file_parent_dir = get_case_sensitive_path(file.absolutePath()); + + //second, does it exist in the new parent dir? + if (exists(file_parent_dir + "/" + file_basename)) + return file_parent_dir + "/" + file_basename; + + //last resort, dirlist parent dir and find case insensitive match + QRegExp file_rx = QRegExp(file_basename, Qt::CaseInsensitive); + QStringList files = QDir(file_parent_dir).entryList(); + + int result = files.indexOf(file_rx); + + if (result != -1) + return file_parent_dir + "/" + files.at(result); + + //if nothing is found, let the caller handle the missing file + return file_parent_dir + "/" + file_basename; } diff --git a/resources.qrc b/resources.qrc index d0c2f22..51f3693 100644 --- a/resources.qrc +++ b/resources.qrc @@ -1,5 +1,6 @@ - - resource/fonts/Ace-Attorney.ttf + + resource/fonts/Ace-Attorney.ttf + logo.png diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 1aebc35..afe8fc3 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -1,98 +1,72 @@ -#include "aoapplication.h" - -#include "file_functions.h" - -#include -#include -#include -#include -#include - -QString AOApplication::read_config(QString searchline) -{ - QString return_value = ""; - - QFile config_file(get_base_path() + "config.ini"); - if (!config_file.open(QIODevice::ReadOnly)) - return return_value; - - QTextStream in(&config_file); - - while(!in.atEnd()) - { - QString f_line = in.readLine().trimmed(); - - if (!f_line.startsWith(searchline)) - continue; - - QStringList line_elements = f_line.split("="); - - if (line_elements.at(0).trimmed() != searchline) - continue; - - if (line_elements.size() < 2) - continue; - - return_value = line_elements.at(1).trimmed(); - break; - } - - config_file.close(); - - return return_value; -} +#include "text_file_functions.h" QString AOApplication::read_theme() { - QString result = read_config("theme"); - - if (result == "") - return "default"; - else - return result; -} - -QString AOApplication::get_ooc_name() -{ - return read_config("ooc_name"); + QString result = configini->value("theme", "default").value(); + return result; } int AOApplication::read_blip_rate() { - QString result = read_config("blip_rate"); + int result = configini->value("blip_rate", 1).toInt(); + return result; +} - //note: the empty string converted to int will return 0 - if (result.toInt() <= 0) - return 1; - else - return result.toInt(); +QString AOApplication::get_ooc_name() +{ + QString result = configini->value("ooc_name").value(); + return result; } int AOApplication::get_default_music() { - QString f_result = read_config("default_music"); - - if (f_result == "") - return 50; - else return f_result.toInt(); + int result = configini->value("default_music", 50).toInt(); + return result; } int AOApplication::get_default_sfx() { - QString f_result = read_config("default_sfx"); - - if (f_result == "") - return 50; - else return f_result.toInt(); + int result = configini->value("default_sfx", 50).toInt(); + return result; } int AOApplication::get_default_blip() { - QString f_result = read_config("default_blip"); + int result = configini->value("default_blip", 50).toInt(); + return result; +} - if (f_result == "") - return 50; - else return f_result.toInt(); +int AOApplication::get_max_log_size() +{ + int result = configini->value("log_maximum", 200).toInt(); + return result; +} + +bool AOApplication::get_log_goes_downwards() +{ + QString result = configini->value("log_goes_downwards", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_showname_enabled_by_default() +{ + QString result = configini->value("show_custom_shownames", "false").value(); + return result.startsWith("true"); +} + +QString AOApplication::get_default_username() +{ + QString result = configini->value("default_username", "").value(); + if (result.isEmpty()) + return get_ooc_name(); + else + return result; +} + +QString AOApplication::get_audio_output_device() +{ + QString result = configini->value("default_audio_device", "default").value(); + return result; } QStringList AOApplication::get_call_words() @@ -174,46 +148,19 @@ QVector AOApplication::read_serverlist_txt() QString AOApplication::read_design_ini(QString p_identifier, QString p_design_path) { - QFile design_ini; - - design_ini.setFileName(p_design_path); - - if (!design_ini.open(QIODevice::ReadOnly)) - { - return ""; + QSettings settings(p_design_path, QSettings::IniFormat); + QVariant value = settings.value(p_identifier); + if (value.type() == QVariant::StringList) { + return value.toStringList().join(","); + } else { + return value.toString(); } - QTextStream in(&design_ini); - - QString result = ""; - - while (!in.atEnd()) - { - QString f_line = in.readLine().trimmed(); - - if (!f_line.startsWith(p_identifier)) - continue; - - QStringList line_elements = f_line.split("="); - - if (line_elements.at(0).trimmed() != p_identifier) - continue; - - if (line_elements.size() < 2) - continue; - - result = line_elements.at(1).trimmed(); - break; - } - - design_ini.close(); - - return result; } QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); QPoint return_value; @@ -242,8 +189,8 @@ QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); pos_size_type return_value; @@ -276,8 +223,8 @@ pos_size_type AOApplication::get_element_dimensions(QString p_identifier, QStrin int AOApplication::get_font_size(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); if (f_result == "") @@ -293,12 +240,77 @@ int AOApplication::get_font_size(QString p_identifier, QString p_file) QColor AOApplication::get_color(QString p_identifier, QString p_file) { - QString design_ini_path = get_theme_path() + p_file; - QString default_path = get_default_theme_path() + p_file; + QString design_ini_path = get_theme_path(p_file); + QString default_path = get_default_theme_path(p_file); QString f_result = read_design_ini(p_identifier, design_ini_path); + QColor return_color(0, 0, 0); + + if (f_result == "") + { + f_result = read_design_ini(p_identifier, default_path); + + if (f_result == "") + return return_color; + } + + QStringList color_list = f_result.split(","); + + if (color_list.size() < 3) + return return_color; + + return_color.setRed(color_list.at(0).toInt()); + return_color.setGreen(color_list.at(1).toInt()); + return_color.setBlue(color_list.at(2).toInt()); + + return return_color; +} + +QColor AOApplication::get_chat_color(QString p_identifier, QString p_chat) +{ QColor return_color(255, 255, 255); + if (p_identifier == "_inline_grey") + { + return_color = QColor(187, 187, 187); + } + else + { + switch (p_identifier.toInt()) { + case 1: + return_color = QColor(0, 255, 0); + break; + case 2: + return_color = QColor(255, 0, 0); + break; + case 3: + return_color = QColor(255, 165, 0); + break; + case 4: + return_color = QColor(45, 150, 255); + break; + case 5: + return_color = QColor(255, 255, 0); + break; + case 7: + return_color = QColor(255, 192, 203); + break; + case 8: + return_color = QColor(0, 255, 255); + break; + case 0: + case 6: // 6 is rainbow. + default: + return_color = QColor(255, 255, 255); + break; + } + } + + p_identifier = p_identifier.prepend("c"); + QString design_ini_path = get_base_path() + "misc/" + p_chat + "/config.ini"; + QString default_path = get_base_path() + "misc/default/config.ini"; + QString f_result = read_design_ini(p_identifier, design_ini_path); + if (f_result == "") { f_result = read_design_ini(p_identifier, default_path); @@ -321,8 +333,8 @@ QColor AOApplication::get_color(QString p_identifier, QString p_file) QString AOApplication::get_sfx(QString p_identifier) { - QString design_ini_path = get_theme_path() + "courtroom_sounds.ini"; - QString default_path = get_default_theme_path() + "courtroom_sounds.ini"; + QString design_ini_path = get_theme_path("courtroom_sounds.ini"); + QString default_path = get_default_theme_path("courtroom_sounds.ini"); QString f_result = read_design_ini(p_identifier, design_ini_path); QString return_sfx = ""; @@ -340,61 +352,46 @@ QString AOApplication::get_sfx(QString p_identifier) return return_sfx; } +QString AOApplication::get_sfx_suffix(QString sound_to_check) +{ + QString mp3_check = get_sounds_path(sound_to_check + ".mp3"); + QString opus_check = get_sounds_path(sound_to_check + ".opus"); + if (file_exists(opus_check)) + { + return sound_to_check + ".opus"; + } + else if (file_exists(mp3_check)) + { + return sound_to_check + ".mp3"; + } + return sound_to_check + ".wav"; +} + +QString AOApplication::get_image_suffix(QString path_to_check) +{ + QString apng_check = get_sounds_path(path_to_check + ".apng"); + if (file_exists(apng_check)) + { + return path_to_check + ".apng"; + } + return path_to_check + ".gif"; +} + + //returns whatever is to the right of "search_line =" within target_tag and terminator_tag, trimmed //returns the empty string if the search line couldnt be found -QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag) +QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QString target_tag) { - QString char_ini_path = get_character_path(p_char) + "char.ini"; - - QFile char_ini; - - char_ini.setFileName(char_ini_path); - - if (!char_ini.open(QIODevice::ReadOnly)) - return ""; - - QTextStream in(&char_ini); - - bool tag_found = false; - - while(!in.atEnd()) - { - QString line = in.readLine(); - - if (QString::compare(line, terminator_tag, Qt::CaseInsensitive) == 0) - break; - - if (line.startsWith(target_tag, Qt::CaseInsensitive)) - { - tag_found = true; - continue; - } - - if (!line.startsWith(p_search_line, Qt::CaseInsensitive)) - continue; - - QStringList line_elements = line.split("="); - - if (QString::compare(line_elements.at(0).trimmed(), p_search_line, Qt::CaseInsensitive) != 0) - continue; - - if (line_elements.size() < 2) - continue; - - if (tag_found) - { - char_ini.close(); - return line_elements.at(1).trimmed(); - } - } - - char_ini.close(); - return ""; + QSettings settings(get_character_path(p_char, "char.ini"), QSettings::IniFormat); + settings.beginGroup(target_tag); + QString value = settings.value(p_search_line).toString(); + settings.endGroup(); + return value; } QString AOApplication::get_char_name(QString p_char) { - QString f_result = read_char_ini(p_char, "name", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "name", "Options"); if (f_result == "") return p_char; @@ -403,8 +400,11 @@ QString AOApplication::get_char_name(QString p_char) QString AOApplication::get_showname(QString p_char) { - QString f_result = read_char_ini(p_char, "showname", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "showname", "Options"); + QString f_needed = read_char_ini(p_char, "needs_showname", "Options"); + if (f_needed.startsWith("false")) + return ""; if (f_result == "") return p_char; else return f_result; @@ -412,7 +412,7 @@ QString AOApplication::get_showname(QString p_char) QString AOApplication::get_char_side(QString p_char) { - QString f_result = read_char_ini(p_char, "side", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "side", "Options"); if (f_result == "") return "wit"; @@ -421,7 +421,7 @@ QString AOApplication::get_char_side(QString p_char) QString AOApplication::get_gender(QString p_char) { - QString f_result = read_char_ini(p_char, "gender", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "gender", "Options"); if (f_result == "") return "male"; @@ -430,22 +430,22 @@ QString AOApplication::get_gender(QString p_char) QString AOApplication::get_chat(QString p_char) { - QString f_result = read_char_ini(p_char, "chat", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "chat", "Options"); //handling the correct order of chat is a bit complicated, we let the caller do it - return f_result.toLower(); + return f_result; } QString AOApplication::get_char_shouts(QString p_char) { - QString f_result = read_char_ini(p_char, "shouts", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "shouts", "Options"); - return f_result.toLower(); + return f_result; } int AOApplication::get_preanim_duration(QString p_char, QString p_emote) { - QString f_result = read_char_ini(p_char, p_emote, "[Time]", "[Emotions]"); + QString f_result = read_char_ini(p_char, p_emote, "Time"); if (f_result == "") return -1; @@ -454,7 +454,7 @@ int AOApplication::get_preanim_duration(QString p_char, QString p_emote) int AOApplication::get_ao2_preanim_duration(QString p_char, QString p_emote) { - QString f_result = read_char_ini(p_char, "%" + p_emote, "[Time]", "[Emotions]"); + QString f_result = read_char_ini(p_char, "%" + p_emote, "Time"); if (f_result == "") return -1; @@ -463,7 +463,7 @@ int AOApplication::get_ao2_preanim_duration(QString p_char, QString p_emote) int AOApplication::get_emote_number(QString p_char) { - QString f_result = read_char_ini(p_char, "number", "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, "number", "Emotions"); if (f_result == "") return 0; @@ -472,7 +472,7 @@ int AOApplication::get_emote_number(QString p_char) QString AOApplication::get_emote_comment(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -486,7 +486,7 @@ QString AOApplication::get_emote_comment(QString p_char, int p_emote) QString AOApplication::get_pre_emote(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -500,7 +500,7 @@ QString AOApplication::get_pre_emote(QString p_char, int p_emote) QString AOApplication::get_emote(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -514,7 +514,7 @@ QString AOApplication::get_emote(QString p_char, int p_emote) int AOApplication::get_emote_mod(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -528,7 +528,7 @@ int AOApplication::get_emote_mod(QString p_char, int p_emote) int AOApplication::get_desk_mod(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -544,7 +544,7 @@ int AOApplication::get_desk_mod(QString p_char, int p_emote) QString AOApplication::get_sfx_name(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[SoundN]", "[SoundT]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "SoundN"); if (f_result == "") return "1"; @@ -553,7 +553,7 @@ QString AOApplication::get_sfx_name(QString p_char, int p_emote) int AOApplication::get_sfx_delay(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[SoundT]", "[TextDelay]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "SoundT"); if (f_result == "") return 1; @@ -562,28 +562,78 @@ int AOApplication::get_sfx_delay(QString p_char, int p_emote) int AOApplication::get_text_delay(QString p_char, QString p_emote) { - QString f_result = read_char_ini(p_char, p_emote, "[TextDelay]", "END_OF_FILE"); + QString f_result = read_char_ini(p_char, p_emote, "TextDelay"); if (f_result == "") return -1; else return f_result.toInt(); } +QString AOApplication::get_custom_realization(QString p_char) +{ + QString f_result = read_char_ini(p_char, "realization", "Options"); + + if (f_result == "") + return get_sfx("realization"); + else return f_result; +} + bool AOApplication::get_blank_blip() { - QString f_result = read_config("blank_blip"); - - return f_result.startsWith("true"); + QString result = configini->value("blank_blip", "false").value(); + return result.startsWith("true"); } bool AOApplication::is_discord_enabled() { - QString f_result = read_config("discord"); - return !f_result.startsWith("false"); + QString result = configini->value("discord", "true").value(); + return result.startsWith("true"); } -bool AOApplication::ic_scroll_down_enabled() +bool AOApplication::get_casing_enabled() { - QString f_result = read_config("ic_scroll_down"); - return f_result.startsWith("true"); -} \ No newline at end of file + QString result = configini->value("casing_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_defence_enabled() +{ + QString result = configini->value("casing_defence_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_prosecution_enabled() +{ + QString result = configini->value("casing_prosecution_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_judge_enabled() +{ + QString result = configini->value("casing_judge_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_juror_enabled() +{ + QString result = configini->value("casing_juror_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_steno_enabled() +{ + QString result = configini->value("casing_steno_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_cm_enabled() +{ + QString result = configini->value("casing_cm_enabled", "false").value(); + return result.startsWith("true"); +} + +QString AOApplication::get_casing_can_host_cases() +{ + QString result = configini->value("casing_can_host_cases", "Turnabout Check Your Settings").value(); + return result; +} diff --git a/text_file_functions.h b/text_file_functions.h new file mode 100644 index 0000000..119f38e --- /dev/null +++ b/text_file_functions.h @@ -0,0 +1,13 @@ +#ifndef TEXT_FILE_FUNCTIONS_H +#define TEXT_FILE_FUNCTIONS_H + +#include "aoapplication.h" +#include "file_functions.h" +#include +#include +#include +#include +#include +#include + +#endif // TEXT_FILE_FUNCTIONS_H