Skip to content

Commit

Permalink
Add back message colors. Fix some warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
vE5li committed Apr 28, 2024
1 parent 172026b commit 5f9bf67
Show file tree
Hide file tree
Showing 16 changed files with 1,178 additions and 1,985 deletions.
728 changes: 727 additions & 1 deletion Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use korangar_interface::state::PlainRemote;

use super::Chat;
use crate::loaders::FontLoader;
use crate::network::ChatMessage;
use crate::ChatMessage;

/// Type state [`Chat`] builder. This builder utilizes the type system to
/// prevent calling the same method multiple times and calling
Expand Down
15 changes: 11 additions & 4 deletions korangar/src/interface/elements/miscellanious/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::interface::application::InterfaceSettings;
use crate::interface::layout::{ScreenClip, ScreenPosition};
use crate::interface::theme::InterfaceTheme;
use crate::loaders::FontLoader;
use crate::network::ChatMessage;
use crate::ChatMessage;

pub struct Chat {
messages: PlainRemote<Vec<ChatMessage>>,
Expand Down Expand Up @@ -58,7 +58,7 @@ impl Element<InterfaceSettings> for Chat {
.font_loader
.borrow()
.get_text_dimensions(
message.stamped_text(self.stamp),
&message.text,
theme.chat.font_size.get().scaled(application.get_scaling()),
placement_resolver.get_available().width,
)
Expand Down Expand Up @@ -94,7 +94,7 @@ impl Element<InterfaceSettings> for Chat {
let mut offset = 0.0;

for message in self.messages.get().iter() {
let text = message.stamped_text(self.stamp);
let text = &message.text;

renderer.render_text(
text,
Expand All @@ -106,12 +106,19 @@ impl Element<InterfaceSettings> for Chat {
theme.chat.font_size.get(),
);

let message_color = match message.color {
korangar_networking::MessageColor::Rgb { red, green, blue } => Color::rgb_u8(red, green, blue),
korangar_networking::MessageColor::Broadcast => theme.chat.broadcast_color.get(),
korangar_networking::MessageColor::Server => theme.chat.server_color.get(),
korangar_networking::MessageColor::Error => theme.chat.broadcast_color.get(),
};

// NOTE: Dividing by the scaling is done to counteract the scaling being applied
// twice per message. It's not the cleanest solution but it works.
offset += renderer.render_text(
text,
ScreenPosition::only_top(offset),
message.color,
message_color,
theme.chat.font_size.get(),
) / application.get_scaling_factor();
}
Expand Down
21 changes: 21 additions & 0 deletions korangar/src/interface/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,13 +850,19 @@ impl korangar_interface::theme::InputTheme<InterfaceSettings> for InputTheme {
pub struct ChatTheme {
pub background_color: Mutable<Color, Render>,
pub font_size: MutableRange<FontSize, Render>,
pub broadcast_color: Mutable<Color, Render>,
pub server_color: Mutable<Color, Render>,
pub error_color: Mutable<Color, Render>,
}

impl ThemeDefault<DefaultMenu> for ChatTheme {
fn default() -> Self {
Self {
background_color: Mutable::new(Color::rgba_u8(0, 0, 0, 170)),
font_size: MutableRange::new(FontSize::new(14.0), FontSize::new(6.0), FontSize::new(50.0)),
broadcast_color: Mutable::new(Color::rgb_u8(210, 210, 210)),
server_color: Mutable::new(Color::rgb_u8(255, 255, 210)),
error_color: Mutable::new(Color::rgb_u8(255, 150, 150)),
}
}
}
Expand All @@ -866,6 +872,9 @@ impl ThemeDefault<DefaultMain> for ChatTheme {
Self {
background_color: Mutable::new(Color::rgba_u8(0, 0, 0, 170)),
font_size: MutableRange::new(FontSize::new(14.0), FontSize::new(6.0), FontSize::new(50.0)),
broadcast_color: Mutable::new(Color::rgb_u8(210, 210, 210)),
server_color: Mutable::new(Color::rgb_u8(255, 255, 210)),
error_color: Mutable::new(Color::rgb_u8(255, 150, 150)),
}
}
}
Expand All @@ -878,6 +887,18 @@ impl korangar_interface::theme::ChatTheme<InterfaceSettings> for ChatTheme {
fn font_size(&self) -> FontSize {
self.font_size.get()
}

fn broadcast_color(&self) -> Color {
self.broadcast_color.get()
}

fn server_color(&self) -> Color {
self.server_color.get()
}

fn error_color(&self) -> Color {
self.error_color.get()
}
}

#[derive(Serialize, Deserialize, PrototypeElement)]
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/windows/account/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::interface::application::InterfaceSettings;
use crate::interface::layout::ScreenSize;
use crate::interface::theme::InterfaceThemeKind;
use crate::interface::windows::WindowCache;
use crate::loaders::client::LoginSettings;
use crate::loaders::ClientInfo;
use crate::network::LoginSettings;

#[derive(new)]
pub struct LoginWindow<'a> {
Expand Down
1 change: 0 additions & 1 deletion korangar/src/interface/windows/debug/maps.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use cgmath::Vector2;
use korangar_interface::elements::{ButtonBuilder, ElementWrap};
use korangar_interface::size_bound;
use korangar_interface::windows::{PrototypeWindow, Window, WindowBuilder};
Expand Down
2 changes: 1 addition & 1 deletion korangar/src/interface/windows/generic/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::interface::layout::ScreenSize;
use crate::interface::theme::InterfaceTheme;
use crate::interface::windows::WindowCache;
use crate::loaders::FontLoader;
use crate::network::ChatMessage;
use crate::ChatMessage;

#[derive(new)]
pub struct ChatWindow {
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions korangar/src/loaders/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod action;
mod archive;
pub mod client;
pub mod color;
mod effect;
mod font;
Expand Down
42 changes: 30 additions & 12 deletions korangar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ mod graphics;
mod interface;
mod inventory;
mod loaders;
mod network;
mod world;

use std::cell::RefCell;
Expand All @@ -34,7 +33,7 @@ use std::rc::Rc;
use std::str::FromStr;
use std::sync::Arc;

use cgmath::{Vector2, Vector3, Zero};
use cgmath::{Vector2, Vector3};
use image::io::Reader as ImageReader;
use image::{EncodableLayout, ImageFormat};
#[cfg(feature = "debug")]
Expand All @@ -46,7 +45,7 @@ use korangar_debug::profiling::Profiler;
use korangar_interface::application::{Application, FocusState, FontSizeTrait, FontSizeTraitExt, PositionTraitExt};
use korangar_interface::state::{PlainTrackedState, Remote, RemoteClone, TrackedState, TrackedStateVec};
use korangar_interface::Interface;
use korangar_networking::{LoginServerLoginData, NetworkEvent, NetworkingSystem2};
use korangar_networking::{LoginServerLoginData, MessageColor, NetworkEvent, NetworkingSystem};
use ragnarok_networking::{SkillId, SkillType, TilePosition, UnitId, WorldPosition};
use vulkano::device::{Device, DeviceCreateInfo, QueueCreateInfo};
#[cfg(feature = "debug")]
Expand All @@ -66,6 +65,8 @@ use crate::input::{InputSystem, UserEvent};
use crate::interface::application::InterfaceSettings;
use crate::interface::cursor::{MouseCursor, MouseCursorState};
use crate::interface::dialog::DialogSystem;
#[cfg(feature = "debug")]
use crate::interface::elements::PacketEntry;
use crate::interface::layout::{ScreenPosition, ScreenSize};
use crate::interface::resource::{ItemSource, Move, SkillSource};
use crate::interface::windows::{
Expand All @@ -77,12 +78,24 @@ use crate::interface::windows::{
use crate::interface::windows::{CommandsWindow, MapsWindow, ProfilerWindow, RenderSettingsWindow, TimeWindow};
use crate::inventory::{Hotbar, Inventory, SkillTree};
use crate::loaders::*;
use crate::network::ChatMessage;
#[cfg(feature = "debug")]
use crate::system::vulkan_message_callback;
use crate::system::{choose_physical_device, get_device_extensions, get_layers, GameTimer};
use crate::world::*;

// Networking related code.
// TODO: Move?
#[cfg(feature = "debug")]
pub type PacketMetadata = Vec<PacketEntry>;
#[cfg(not(feature = "debug"))]
pub type PacketMetadata = ();

#[derive(Debug, Clone)]
pub struct ChatMessage {
pub text: String,
pub color: MessageColor,
}

const ROLLING_CUTTER_ID: SkillId = SkillId(2036);

// Create the `threads` module.
Expand Down Expand Up @@ -342,7 +355,7 @@ fn main() {
let timer = Timer::new("initialize interface");

let mut application = InterfaceSettings::load_or_default();
let mut interface = korangar_interface::Interface::new(swapchain_holder.window_screen_size());
let mut interface = Interface::new(swapchain_holder.window_screen_size());
let mut focus_state = FocusState::default();
let mut mouse_cursor = MouseCursor::new(&mut game_file_loader, &mut sprite_loader, &mut action_loader);
let mut dialog_system = DialogSystem::default();
Expand Down Expand Up @@ -378,9 +391,10 @@ fn main() {
let timer = Timer::new("initialize networking");

let client_info = load_client_info(&mut game_file_loader);
let mut networking_system = NetworkingSystem2::<network::PacketMetadata>::new();
let mut networking_system = NetworkingSystem::<PacketMetadata>::new();
let mut saved_login_data: Option<LoginServerLoginData> = None;
let mut saved_characters: PlainTrackedState<Vec<ragnarok_networking::CharacterInformation>> = PlainTrackedState::default();
let mut saved_player_name = String::new();
let mut move_request: PlainTrackedState<Option<usize>> = PlainTrackedState::default();
let mut saved_slot_count = 0;

Expand All @@ -400,8 +414,10 @@ fn main() {
"Welcome to ^ffff00★^000000 ^ff8800Korangar^000000 ^ffff00★^000000 version ^ff8800{}^000000!",
env!("CARGO_PKG_VERSION")
);
let welcome_message = ChatMessage::new(welcome_string, Color::monochrome_u8(255));
let mut chat_messages = PlainTrackedState::new(vec![welcome_message]);
let mut chat_messages = PlainTrackedState::new(vec![ChatMessage {
text: welcome_string,
color: MessageColor::Server,
}]);

let thread_pool = rayon::ThreadPoolBuilder::new().num_threads(3).build().unwrap();

Expand Down Expand Up @@ -598,6 +614,8 @@ fn main() {
)
.unwrap();

saved_player_name = character_information.name.clone();

let player = Player::new(
&mut game_file_loader,
&mut sprite_loader,
Expand Down Expand Up @@ -700,15 +718,15 @@ fn main() {
mouse_cursor.set_start_time(client_tick);
}
NetworkEvent::SetPlayerPosition(player_position) => {
let player_position = Vector2::new(player_position.x as usize, player_position.y as usize);
let player_position = Vector2::new(player_position.x, player_position.y);
entities[0].set_position(&map, player_position, client_tick);
player_camera.set_focus_point(entities[0].get_position());
}
NetworkEvent::UpdateClientTick(client_tick) => {
game_timer.set_client_tick(client_tick);
}
NetworkEvent::ChatMessage { text } => {
chat_messages.push(ChatMessage::new(text, Color::rgb_u8(200, 200, 100)) );
NetworkEvent::ChatMessage { text, color } => {
chat_messages.push(ChatMessage { text, color });
}
NetworkEvent::UpdateEntityDetails(entity_id, name) => {
let entity = entities.iter_mut().find(|entity| entity.get_entity_id() == entity_id);
Expand Down Expand Up @@ -1015,7 +1033,7 @@ fn main() {
networking_system.request_warp_to_map(map_name, position)
},
UserEvent::SendMessage(message) => {
networking_system.send_chat_message("foobar", &message);
networking_system.send_chat_message(&saved_player_name, &message);
// TODO: maybe find a better solution for unfocusing the message box if
// this becomes problematic
focus_state.remove_focus();
Expand Down
Loading

0 comments on commit 5f9bf67

Please sign in to comment.