Compare commits
6 Commits
876f91d38d
...
2d6d280f8c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d6d280f8c | ||
|
|
14e37e62df | ||
|
|
a83be73177 | ||
|
|
f0481bef17 | ||
|
|
db19733c82 | ||
|
|
7efa2e992a |
@ -118,6 +118,8 @@ set(CLIENT_ONLY_SOURCES
|
||||
"src/gui/font.cpp"
|
||||
"src/gui/menu.hpp"
|
||||
"src/gui/menu.cpp"
|
||||
"src/gui/use_target_hud.hpp"
|
||||
"src/gui/use_target_hud.cpp"
|
||||
"src/utils/files.cpp"
|
||||
)
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ void App::Frame()
|
||||
params.env.clear_color = glm::vec3(0.1f);
|
||||
|
||||
dlist_.Clear();
|
||||
gui_.Begin();
|
||||
gui_.Begin(viewport_size_);
|
||||
|
||||
// draw session
|
||||
if (session_)
|
||||
|
||||
@ -40,7 +40,7 @@ public:
|
||||
void Input(game::PlayerInputType in, bool pressed, bool repeated);
|
||||
void MouseMove(const glm::vec2& delta);
|
||||
|
||||
float GetTime() const { return time_; }
|
||||
const float& GetTime() const { return time_; }
|
||||
float GetDeltaTime() const { return delta_time_; }
|
||||
|
||||
game::view::ClientSession* GetSession() { return session_.get(); }
|
||||
|
||||
@ -19,7 +19,7 @@ bool game::DrivableVehicle::QueryUseTarget(PlayerCharacter& character, uint32_t
|
||||
res.error_text = nullptr;
|
||||
|
||||
bool seat_occupied = seats_[target_id].occupant != nullptr;
|
||||
res.delay = seat_occupied ? 2.0f : 0.0f;
|
||||
res.delay = seat_occupied ? 2.0f : 0.25f;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -71,8 +71,28 @@ game::DrivableVehicle::~DrivableVehicle()
|
||||
}
|
||||
}
|
||||
|
||||
static char HexChar(uint32_t val)
|
||||
{
|
||||
if (val < 10)
|
||||
return '0' + val;
|
||||
|
||||
return 'a' + (val - 10);
|
||||
}
|
||||
|
||||
static std::string GetColorTextPrefix(uint32_t color)
|
||||
{
|
||||
std::string res = "^000";
|
||||
res[1] = HexChar((color >> 4) & 0xF);
|
||||
res[2] = HexChar((color >> 12) & 0xF);
|
||||
res[3] = HexChar((color >> 20) & 0xF);
|
||||
return res;
|
||||
}
|
||||
|
||||
void game::DrivableVehicle::InitSeats()
|
||||
{
|
||||
uint32_t color = GetTuning().primary_color;
|
||||
std::string prefix = "vlízt do " + GetColorTextPrefix(color) + GetModelName() + "^r";
|
||||
|
||||
const auto& veh = *GetModel();
|
||||
for (char c = '0'; c <= '9'; ++c)
|
||||
{
|
||||
@ -82,9 +102,10 @@ void game::DrivableVehicle::InitSeats()
|
||||
|
||||
VehicleSeat seat{};
|
||||
seat.position = trans->position;
|
||||
seat.position.z += 1.0f; // the original pos is for animated character which is under vehicle
|
||||
seats_.emplace_back(seat);
|
||||
|
||||
uint32_t id = seats_.size() - 1;
|
||||
use_targets_.emplace_back(this, id, seat.position, "vlízt do " + GetModelName() + " (místo " + std::to_string(id) + ")");
|
||||
use_targets_.emplace_back(this, id, seat.position, prefix + " (místo " + std::to_string(id + 1) + ")");
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,6 +69,14 @@ void game::Player::SendChat(const std::string& text)
|
||||
msg.Write(chatm);
|
||||
}
|
||||
|
||||
void game::Player::SetUseTarget(const std::string& text, const std::string& error_text, float delay)
|
||||
{
|
||||
auto msg = BeginMsg(net::MSG_USETARGET);
|
||||
msg.Write(net::UseTargetName(text));
|
||||
msg.Write(net::UseTargetName(error_text));
|
||||
msg.Write<net::UseDelayQ>(delay);
|
||||
}
|
||||
|
||||
game::Player::~Player()
|
||||
{
|
||||
game_.PlayerLeft(*this);
|
||||
|
||||
@ -32,6 +32,7 @@ public:
|
||||
|
||||
void SetCamera(net::EntNum entnum);
|
||||
void SendChat(const std::string& text);
|
||||
void SetUseTarget(const std::string& text, const std::string& error_text, float delay);
|
||||
|
||||
const std::string& GetName() const { return name_; }
|
||||
|
||||
|
||||
@ -7,13 +7,14 @@ game::PlayerCharacter::PlayerCharacter(World& world, Player& player, const Chara
|
||||
VehicleChanged();
|
||||
|
||||
SetNametag(player.GetName());
|
||||
|
||||
SendUseTargetInfo();
|
||||
}
|
||||
|
||||
void game::PlayerCharacter::Update()
|
||||
{
|
||||
Super::Update();
|
||||
|
||||
UpdateUseTarget();
|
||||
Super::Update();
|
||||
}
|
||||
|
||||
void game::PlayerCharacter::VehicleChanged()
|
||||
@ -38,23 +39,7 @@ void game::PlayerCharacter::ProcessInput(PlayerInputType type, bool enabled)
|
||||
switch (type)
|
||||
{
|
||||
case IN_USE:
|
||||
if (enabled)
|
||||
{
|
||||
if (!vehicle_)
|
||||
{
|
||||
UseTargetQueryResult res;
|
||||
auto use_target = world_.GetBestUseTarget(*this, res);
|
||||
if (use_target)
|
||||
{
|
||||
use_target->usable->Use(*this, use_target->id);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SetVehicle(nullptr, 0);
|
||||
}
|
||||
|
||||
}
|
||||
UseChanged(enabled);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -123,4 +108,73 @@ void game::PlayerCharacter::UpdateInputs()
|
||||
}
|
||||
}
|
||||
|
||||
void game::PlayerCharacter::UpdateUseTarget() {}
|
||||
void game::PlayerCharacter::UpdateUseTarget()
|
||||
{
|
||||
UseTargetQueryResult res{};
|
||||
auto new_use_target = world_.GetBestUseTarget(*this, res);
|
||||
|
||||
if (new_use_target != use_target_ || res.enabled != use_enabled_ || res.error_text != use_error_ || res.delay != use_delay_)
|
||||
{
|
||||
use_target_ = new_use_target;
|
||||
use_enabled_ = res.enabled;
|
||||
use_delay_ = res.delay;
|
||||
use_error_ = res.error_text;
|
||||
use_progress_ = 0.0f;
|
||||
using_ = false;
|
||||
|
||||
SendUseTargetInfo();
|
||||
}
|
||||
|
||||
if (use_target_ && use_enabled_ && using_)
|
||||
{
|
||||
use_progress_ += 0.04f;
|
||||
if (use_progress_ >= use_delay_)
|
||||
{
|
||||
using_ = false;
|
||||
use_progress_ = 0.0f;
|
||||
use_target_->usable->Use(*this, use_target_->id);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void game::PlayerCharacter::UseChanged(bool enabled)
|
||||
{
|
||||
if (!use_target_)
|
||||
{
|
||||
if (vehicle_ && enabled)
|
||||
SetVehicle(nullptr, 0);// no use target and in vehicle -> exit
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
use_progress_ = 0.0f;
|
||||
|
||||
if (!use_enabled_)
|
||||
return;
|
||||
|
||||
bool change = using_ != enabled;
|
||||
using_ = enabled;
|
||||
|
||||
if (change)
|
||||
SendUseTargetInfo();
|
||||
|
||||
}
|
||||
|
||||
void game::PlayerCharacter::SendUseTargetInfo()
|
||||
{
|
||||
if (!player_)
|
||||
return;
|
||||
|
||||
if (!use_target_)
|
||||
{
|
||||
player_->SetUseTarget(std::string(), std::string(), 0.0f);
|
||||
return;
|
||||
}
|
||||
|
||||
std::string error_text;
|
||||
if (use_error_)
|
||||
error_text = use_error_;
|
||||
|
||||
player_->SetUseTarget(use_target_->desc, error_text, using_ ? use_delay_ - use_progress_ : 0.0f);
|
||||
}
|
||||
|
||||
@ -26,10 +26,21 @@ public:
|
||||
|
||||
private:
|
||||
void UpdateInputs();
|
||||
|
||||
void UpdateUseTarget();
|
||||
void UseChanged(bool enabled);
|
||||
void SendUseTargetInfo();
|
||||
|
||||
private:
|
||||
Player* player_;
|
||||
|
||||
// use target
|
||||
const UseTarget* use_target_ = nullptr;
|
||||
bool use_enabled_ = false;
|
||||
float use_delay_ = 0.0f;
|
||||
const char* use_error_ = nullptr;
|
||||
bool using_ = false; // not drugs lol
|
||||
float use_progress_ = 0.0f;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -134,7 +134,7 @@ struct UseTargetAabbCallback : public btBroadphaseAabbCallback
|
||||
glm::vec3 pos_world = matrix * glm::vec4(target.position, 1.0f);
|
||||
|
||||
float dist = glm::distance(pos, pos_world);
|
||||
if (dist < 3.0f && dist < best_dist)
|
||||
if (dist < 2.0f && dist < best_dist)
|
||||
{
|
||||
if (!usable->QueryUseTarget(character, target.id, best_res))
|
||||
continue;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
#include "vehicleview.hpp"
|
||||
#include "utils/version.hpp"
|
||||
|
||||
game::view::ClientSession::ClientSession(App& app) : app_(app)
|
||||
game::view::ClientSession::ClientSession(App& app) : app_(app), use_target_hud_(app.GetTime())
|
||||
{
|
||||
// send login
|
||||
auto msg = BeginMsg(net::MSG_ID);
|
||||
@ -46,6 +46,9 @@ bool game::view::ClientSession::ProcessSingleMessage(net::MessageType type, net:
|
||||
case net::MSG_CHAT:
|
||||
return ProcessChatMsg(msg);
|
||||
|
||||
case net::MSG_USETARGET:
|
||||
return ProcessUseTargetMsg(msg);
|
||||
|
||||
default:
|
||||
// try pass the msg to world
|
||||
if (world_ && world_->ProcessMsg(type, msg))
|
||||
@ -97,6 +100,8 @@ void game::view::ClientSession::Draw(gfx::DrawList& dlist, gfx::DrawListParams&
|
||||
{
|
||||
DrawWorld(dlist, params, gui);
|
||||
}
|
||||
|
||||
use_target_hud_.Draw(gui);
|
||||
}
|
||||
|
||||
void game::view::ClientSession::GetViewInfo(glm::vec3& eye, glm::mat4& view) const
|
||||
@ -166,6 +171,18 @@ bool game::view::ClientSession::ProcessChatMsg(net::InMessage& msg)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool game::view::ClientSession::ProcessUseTargetMsg(net::InMessage& msg)
|
||||
{
|
||||
net::UseTargetName text, error_text;
|
||||
float delay;
|
||||
|
||||
if (!msg.Read(text) || !msg.Read(error_text) || !msg.Read<net::UseDelayQ>(delay))
|
||||
return false;
|
||||
|
||||
use_target_hud_.SetData(text, error_text, delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
void game::view::ClientSession::DrawWorld(gfx::DrawList& dlist, gfx::DrawListParams& params, gui::Context& gui)
|
||||
{
|
||||
// glm::mat4 view = glm::lookAt(glm::vec3(15.0f, 0.0f, 1.0f), glm::vec3(0.0f, 0.0f, -13.0f), glm::vec3(0.0f,
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include "net/inmessage.hpp"
|
||||
#include "net/msg_producer.hpp"
|
||||
#include "game/player_input.hpp"
|
||||
#include "gui/use_target_hud.hpp"
|
||||
|
||||
class App;
|
||||
|
||||
@ -39,6 +40,7 @@ private:
|
||||
bool ProcessWorldMsg(net::InMessage& msg);
|
||||
bool ProcessCameraMsg(net::InMessage& msg);
|
||||
bool ProcessChatMsg(net::InMessage& msg);
|
||||
bool ProcessUseTargetMsg(net::InMessage& msg);
|
||||
|
||||
void DrawWorld(gfx::DrawList& dlist, gfx::DrawListParams& params, gui::Context& gui);
|
||||
|
||||
@ -56,6 +58,8 @@ private:
|
||||
net::ViewYawQ view_yaw_q_;
|
||||
net::ViewPitchQ view_pitch_q_;
|
||||
float last_send_time_ = 0.0f;
|
||||
|
||||
gui::UseTargetHud use_target_hud_;
|
||||
};
|
||||
|
||||
} // namespace game::view
|
||||
@ -10,11 +10,13 @@ gui::Context::Context(gfx::DrawList& dlist, std::shared_ptr<const Font> default_
|
||||
white_tex_ = assets::CacheManager::GetTexture("data/white.png");
|
||||
}
|
||||
|
||||
void gui::Context::Begin()
|
||||
void gui::Context::Begin(const glm::vec2& viewport_size)
|
||||
{
|
||||
vertices_.clear();
|
||||
indices_.clear();
|
||||
ranges_.clear();
|
||||
|
||||
viewport_size_ = viewport_size;
|
||||
}
|
||||
|
||||
void gui::Context::DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color)
|
||||
|
||||
@ -32,7 +32,7 @@ class Context
|
||||
public:
|
||||
Context(gfx::DrawList& dlist, std::shared_ptr<const Font> default_font);
|
||||
|
||||
void Begin();
|
||||
void Begin(const glm::vec2& viewport_size);
|
||||
|
||||
void DrawRect(const glm::vec2& p0, const glm::vec2& p1, uint32_t color);
|
||||
|
||||
@ -43,6 +43,8 @@ public:
|
||||
void Render();
|
||||
|
||||
const std::shared_ptr<const Font>& GetFont() const { return font_; }
|
||||
|
||||
const glm::vec2& GetViewportSize() const { return viewport_size_; }
|
||||
|
||||
private:
|
||||
void BeginTexture(const gfx::Texture* texture);
|
||||
@ -61,7 +63,7 @@ private:
|
||||
std::vector<uint32_t> indices_;
|
||||
std::vector<GuiRange> ranges_;
|
||||
|
||||
|
||||
glm::vec2 viewport_size_ = glm::vec2(1.0f);
|
||||
};
|
||||
|
||||
|
||||
|
||||
88
src/gui/use_target_hud.cpp
Normal file
88
src/gui/use_target_hud.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
#include "use_target_hud.hpp"
|
||||
|
||||
gui::UseTargetHud::UseTargetHud(const float& time) : time_(time) {}
|
||||
|
||||
void gui::UseTargetHud::SetData(std::string text, std::string error_text, float delay)
|
||||
{
|
||||
text_ = std::move(text);
|
||||
|
||||
if (error_text.empty())
|
||||
error_text_.clear();
|
||||
else
|
||||
error_text_ = "(" + error_text + ")";
|
||||
|
||||
start_time_ = time_;
|
||||
end_time_ = delay > 0.01f ? start_time_ + delay : start_time_;
|
||||
}
|
||||
|
||||
void gui::UseTargetHud::Draw(Context& ctx) const
|
||||
{
|
||||
if (text_.empty())
|
||||
return;
|
||||
|
||||
bool active = start_time_ != end_time_;
|
||||
uint32_t text_color = (!error_text_.empty()) ? 0xFFCCCCCC : (active ? 0xFF00FFFF : 0xFFFFFFFF);
|
||||
|
||||
const float spacing = 10.0f;
|
||||
glm::vec2 key_size(30.0f);
|
||||
glm::vec2 text_size = ctx.MeasureText(text_);
|
||||
float total_width = key_size.x + spacing + text_size.x;
|
||||
|
||||
glm::vec2 error_size(0.0f);
|
||||
if (!error_text_.empty())
|
||||
{
|
||||
error_size = ctx.MeasureText(error_text_);
|
||||
total_width += spacing + error_size.x;
|
||||
}
|
||||
|
||||
glm::vec2 progress_size(60.0f, 10.0f);
|
||||
if (active)
|
||||
{
|
||||
total_width += spacing + progress_size.x;
|
||||
}
|
||||
|
||||
auto& viewport_size = ctx.GetViewportSize();
|
||||
float center_x = viewport_size.x * 0.5f;
|
||||
float center_y = viewport_size.y - 50.0f;
|
||||
float x = center_x - total_width * 0.5f;
|
||||
|
||||
// draw key bg
|
||||
glm::vec2 bg_p0(x, center_y - key_size.y * 0.5f);
|
||||
glm::vec2 bg_p1 = bg_p0 + key_size;
|
||||
ctx.DrawRect(bg_p0, bg_p1, 0x77000000);
|
||||
|
||||
// draw key text
|
||||
static constexpr std::string_view key_text = "E";
|
||||
ctx.DrawTextAligned(key_text, bg_p0 + key_size * 0.5f, glm::vec2(-0.5f, -0.5f), text_color);
|
||||
|
||||
x += key_size.x + spacing;
|
||||
|
||||
// draw text
|
||||
glm::vec2 text_p(x, center_y - text_size.y * 0.5f);
|
||||
ctx.DrawText(text_, text_p, text_color);
|
||||
|
||||
x += text_size.x + spacing;
|
||||
|
||||
// draw error text
|
||||
if (!error_text_.empty())
|
||||
{
|
||||
glm::vec2 error_text_p(x, center_y - error_size.y * 0.5f);
|
||||
ctx.DrawText(error_text_, error_text_p, 0xFF7777FF);
|
||||
|
||||
x += error_size.x + spacing;
|
||||
}
|
||||
|
||||
// draw progress bar
|
||||
if (active)
|
||||
{
|
||||
float t = (time_ - start_time_) / (end_time_ - start_time_);
|
||||
t = glm::clamp(t, 0.0f, 1.0f);
|
||||
|
||||
glm::vec2 progress_p0(x, center_y - progress_size.y * 0.5f);
|
||||
glm::vec2 progress_p1 = progress_p0 + progress_size;
|
||||
glm::vec2 progress_p1_bar = progress_p0 + glm::vec2(t * progress_size.x, progress_size.y);
|
||||
|
||||
ctx.DrawRect(progress_p0, progress_p1, 0x77000000);
|
||||
ctx.DrawRect(progress_p0, progress_p1_bar, 0xFF00FFFF);
|
||||
}
|
||||
}
|
||||
28
src/gui/use_target_hud.hpp
Normal file
28
src/gui/use_target_hud.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "context.hpp"
|
||||
|
||||
namespace gui
|
||||
{
|
||||
|
||||
class UseTargetHud
|
||||
{
|
||||
public:
|
||||
UseTargetHud(const float& time);
|
||||
|
||||
void SetData(std::string text, std::string error_text, float delay);
|
||||
|
||||
void Draw(Context& ctx) const;
|
||||
|
||||
private:
|
||||
const float& time_;
|
||||
std::string text_;
|
||||
std::string error_text_;
|
||||
float start_time_ = 0.0f;
|
||||
float end_time_ = 0.0f;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
@ -34,6 +34,9 @@ enum MessageType : uint8_t
|
||||
// CAM <EntNum>
|
||||
MSG_CAM,
|
||||
|
||||
// USETARGET ...
|
||||
MSG_USETARGET,
|
||||
|
||||
/*~~~~~~~~ Entity ~~~~~~~~*/
|
||||
// ENTSPAWN <EntNum> <EntType> data...
|
||||
MSG_ENTSPAWN,
|
||||
@ -132,11 +135,13 @@ using ObjCount = ObjNum;
|
||||
using NumTexels = uint16_t;
|
||||
|
||||
// version
|
||||
|
||||
using Version = uint32_t;
|
||||
|
||||
// tuning
|
||||
|
||||
using TuningPartIdx = uint8_t;
|
||||
|
||||
// use target
|
||||
using UseTargetName = FixedStr<128>;
|
||||
using UseDelayQ = Quantized<uint8_t, 0, 10>;
|
||||
|
||||
} // namespace net
|
||||
@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define FEKAL_VERSION 2026032101
|
||||
#define FEKAL_VERSION 2026032201
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user