Support for drawing (or not drawing) the cross hair from scripts
This commit is contained in:
parent
d0e16b29e6
commit
96319b2727
@ -33,6 +33,9 @@ namespace spades {
|
||||
/** Returns positions for player hands in view coordinate. */
|
||||
Vector3 LeftHandPosition { get; }
|
||||
Vector3 RightHandPosition { get; }
|
||||
|
||||
/** Issues draw commands to draw 2d images, such as HUD and crosshair. */
|
||||
void Draw2D();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,6 +47,8 @@ namespace spades {
|
||||
get { return muted; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
// IWeaponSkin
|
||||
|
||||
private float aimDownSightState;
|
||||
@ -127,9 +129,14 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
private Renderer@ renderer;
|
||||
private Image@ sightImage;
|
||||
|
||||
BasicViewWeapon() {
|
||||
BasicViewWeapon(Renderer@ renderer) {
|
||||
@this.renderer = renderer;
|
||||
localFireVibration = 0.f;
|
||||
@sightImage = renderer.RegisterImage
|
||||
("Gfx/Sight.tga");
|
||||
}
|
||||
|
||||
float GetLocalFireVibration() {
|
||||
@ -205,6 +212,13 @@ namespace spades {
|
||||
|
||||
void ReloadedWeapon() {
|
||||
}
|
||||
|
||||
void Draw2D() {
|
||||
renderer.Color = (Vector4(1.f, 1.f, 1.f, 1.f));
|
||||
renderer.DrawImage(sightImage,
|
||||
Vector2((renderer.ScreenWidth - sightImage.Width) * 0.5f,
|
||||
(renderer.ScreenHeight - sightImage.Height) * 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -79,12 +79,15 @@
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ model;
|
||||
private Image@ sightImage;
|
||||
|
||||
ViewBlockSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@renderer = r;
|
||||
@audioDevice = dev;
|
||||
@model = renderer.RegisterModel
|
||||
("Models/Weapons/Block/Block2.kv6");
|
||||
@sightImage = renderer.RegisterImage
|
||||
("Gfx/Sight.tga");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -122,6 +125,13 @@
|
||||
param.depthHack = true;
|
||||
renderer.AddModel(model, param);
|
||||
}
|
||||
|
||||
void Draw2D() {
|
||||
renderer.Color = (Vector4(1.f, 1.f, 1.f, 1.f));
|
||||
renderer.DrawImage(sightImage,
|
||||
Vector2((renderer.ScreenWidth - sightImage.Width) * 0.5f,
|
||||
(renderer.ScreenHeight - sightImage.Height) * 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
IBlockSkin@ CreateViewBlockSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
|
@ -79,12 +79,15 @@
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ model;
|
||||
private Image@ sightImage;
|
||||
|
||||
ViewGrenadeSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@renderer = r;
|
||||
@audioDevice = dev;
|
||||
@model = renderer.RegisterModel
|
||||
("Models/Weapons/Grenade/Grenade.kv6");
|
||||
@sightImage = renderer.RegisterImage
|
||||
("Gfx/Sight.tga");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -155,6 +158,12 @@
|
||||
}
|
||||
|
||||
}
|
||||
void Draw2D() {
|
||||
renderer.Color = (Vector4(1.f, 1.f, 1.f, 1.f));
|
||||
renderer.DrawImage(sightImage,
|
||||
Vector2((renderer.ScreenWidth - sightImage.Width) * 0.5f,
|
||||
(renderer.ScreenHeight - sightImage.Height) * 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
IGrenadeSkin@ CreateViewGrenadeSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
|
@ -23,7 +23,6 @@
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin,
|
||||
BasicViewWeapon {
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ gunModel;
|
||||
private Model@ magazineModel;
|
||||
@ -33,8 +32,8 @@
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
|
||||
ViewRifleSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@renderer = r;
|
||||
ViewRifleSkin(Renderer@ r, AudioDevice@ dev){
|
||||
super(r);
|
||||
@audioDevice = dev;
|
||||
@gunModel = renderer.RegisterModel
|
||||
("Models/Weapons/Rifle/WeaponNoMagazine.kv6");
|
||||
|
@ -23,7 +23,6 @@
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin,
|
||||
BasicViewWeapon {
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ gunModel;
|
||||
private Model@ magazineModel;
|
||||
@ -33,8 +32,8 @@
|
||||
private AudioChunk@ fireStereoSound;
|
||||
private AudioChunk@ reloadSound;
|
||||
|
||||
ViewSMGSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@renderer = r;
|
||||
ViewSMGSkin(Renderer@ r, AudioDevice@ dev){
|
||||
super(r);
|
||||
@audioDevice = dev;
|
||||
@gunModel = renderer.RegisterModel
|
||||
("Models/Weapons/SMG/WeaponNoMagazine.kv6");
|
||||
@ -152,6 +151,7 @@
|
||||
LeftHandPosition = leftHand;
|
||||
RightHandPosition = rightHand;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IWeaponSkin@ CreateViewSMGSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
|
@ -23,7 +23,6 @@
|
||||
IToolSkin, IViewToolSkin, IWeaponSkin,
|
||||
BasicViewWeapon {
|
||||
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ gunModel;
|
||||
private Model@ pumpModel;
|
||||
@ -34,8 +33,8 @@
|
||||
private AudioChunk@ reloadSound;
|
||||
private AudioChunk@ cockSound;
|
||||
|
||||
ViewShotgunSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@renderer = r;
|
||||
ViewShotgunSkin(Renderer@ r, AudioDevice@ dev){
|
||||
super(r);
|
||||
@audioDevice = dev;
|
||||
@gunModel = renderer.RegisterModel
|
||||
("Models/Weapons/Shotgun/WeaponNoPump.kv6");
|
||||
|
@ -79,12 +79,15 @@
|
||||
private Renderer@ renderer;
|
||||
private AudioDevice@ audioDevice;
|
||||
private Model@ model;
|
||||
private Image@ sightImage;
|
||||
|
||||
ViewSpadeSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
@renderer = r;
|
||||
@audioDevice = dev;
|
||||
@model = renderer.RegisterModel
|
||||
("Models/Weapons/Spade/Spade.kv6");
|
||||
@sightImage = renderer.RegisterImage
|
||||
("Gfx/Sight.tga");
|
||||
}
|
||||
|
||||
void Update(float dt) {
|
||||
@ -168,6 +171,13 @@
|
||||
param.depthHack = true;
|
||||
renderer.AddModel(model, param);
|
||||
}
|
||||
|
||||
void Draw2D() {
|
||||
renderer.Color = (Vector4(1.f, 1.f, 1.f, 1.f));
|
||||
renderer.DrawImage(sightImage,
|
||||
Vector2((renderer.ScreenWidth - sightImage.Width) * 0.5f,
|
||||
(renderer.ScreenHeight - sightImage.Height) * 0.5f));
|
||||
}
|
||||
}
|
||||
|
||||
ISpadeSkin@ CreateViewSpadeSkin(Renderer@ r, AudioDevice@ dev) {
|
||||
|
@ -880,6 +880,36 @@ namespace spades {
|
||||
}
|
||||
}
|
||||
|
||||
void ClientPlayer::Draw2D() {
|
||||
if(!ShouldRenderInThirdPersonView()) {
|
||||
asIScriptObject *skin;
|
||||
|
||||
if(currentTool == Player::ToolSpade) {
|
||||
skin = spadeViewSkin;
|
||||
}else if(currentTool == Player::ToolBlock) {
|
||||
skin = blockViewSkin;
|
||||
}else if(currentTool == Player::ToolGrenade) {
|
||||
skin = grenadeViewSkin;
|
||||
}else if(currentTool == Player::ToolWeapon) {
|
||||
skin = weaponViewSkin;
|
||||
}else{
|
||||
SPInvalidEnum("currentTool", currentTool);
|
||||
}
|
||||
|
||||
SetSkinParameterForTool(currentTool, skin);
|
||||
|
||||
SetCommonSkinParameter(skin);
|
||||
|
||||
// common process
|
||||
{
|
||||
ScriptIViewToolSkin interface(skin);
|
||||
interface.SetEyeMatrix(GetEyeMatrix());
|
||||
interface.SetSwing(viewWeaponOffset);
|
||||
interface.Draw2D();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ClientPlayer::ShouldRenderInThirdPersonView() {
|
||||
if(player != player->GetWorld()->GetLocalPlayer())
|
||||
return true;
|
||||
|
@ -76,6 +76,7 @@ namespace spades {
|
||||
|
||||
void Update(float dt);
|
||||
void AddToScene();
|
||||
void Draw2D();
|
||||
|
||||
bool IsChangingTool();
|
||||
void FiredWeapon();
|
||||
|
@ -76,6 +76,17 @@ namespace spades{
|
||||
return *reinterpret_cast<Vector3 *>(ctx->GetReturnObject());
|
||||
}
|
||||
|
||||
void ScriptIViewToolSkin::Draw2D() {
|
||||
SPADES_MARK_FUNCTION_DEBUG();
|
||||
static ScriptFunction func("IViewToolSkin",
|
||||
"void Draw2D()");
|
||||
ScriptContextHandle ctx = func.Prepare();
|
||||
int r;
|
||||
r = ctx->SetObject((void *)obj);
|
||||
ScriptManager::CheckError(r);
|
||||
ctx.ExecuteChecked();
|
||||
}
|
||||
|
||||
class IViewToolSkinRegistrar: public ScriptObjectRegistrar {
|
||||
public:
|
||||
IViewToolSkinRegistrar():
|
||||
@ -105,7 +116,10 @@ namespace spades{
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterInterfaceMethod("IViewToolSkin",
|
||||
"Vector3 get_RightHandPosition()");
|
||||
manager->CheckError(r);
|
||||
manager->CheckError(r);
|
||||
r = eng->RegisterInterfaceMethod("IViewToolSkin",
|
||||
"void Draw2D()");
|
||||
manager->CheckError(r);
|
||||
break;
|
||||
default:
|
||||
|
||||
|
@ -33,6 +33,7 @@ namespace spades {
|
||||
void SetSwing(Vector3);
|
||||
Vector3 GetLeftHandPosition();
|
||||
Vector3 GetRightHandPosition();
|
||||
void Draw2D();
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user