-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
253 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<class name="Listener2D" inherits="Node2D" version="3.4"> | ||
<brief_description> | ||
Overrides the location sounds are heard from. | ||
</brief_description> | ||
<description> | ||
Once added to the scene tree and enabled using [method make_current], this node will override the location sounds are heard from. Only one [Listener2D] can be current. Using [method make_current] will disable the previous [Listener2D]. | ||
If there is no active [Listener2D] in the current [Viewport], center of the screen will be used as a hearing point for the audio. [Listener2D] needs to be inside [SceneTree] to function. | ||
</description> | ||
<tutorials> | ||
</tutorials> | ||
<methods> | ||
<method name="clear_current"> | ||
<return type="void" /> | ||
<description> | ||
Disables the [Listener2D]. If it's not set as current, this method will have no effect. | ||
</description> | ||
</method> | ||
<method name="is_current" qualifiers="const"> | ||
<return type="bool" /> | ||
<description> | ||
Returns [code]true[/code] if this [Listener2D] is currently active. | ||
</description> | ||
</method> | ||
<method name="make_current"> | ||
<return type="void" /> | ||
<description> | ||
Makes the [Listener2D] active, setting it as the hearing point for the sounds. If there is already another active [Listener2D], it will be disabled. | ||
This method will have no effect if the [Listener2D] is not added to [SceneTree]. | ||
</description> | ||
</method> | ||
</methods> | ||
<constants> | ||
</constants> | ||
</class> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/*************************************************************************/ | ||
/* listener_2d.cpp */ | ||
/*************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/*************************************************************************/ | ||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ | ||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/*************************************************************************/ | ||
|
||
#include "listener_2d.h" | ||
|
||
bool Listener2D::_set(const StringName &p_name, const Variant &p_value) { | ||
if (p_name == "current") { | ||
if (p_value.operator bool()) { | ||
make_current(); | ||
} else { | ||
clear_current(); | ||
} | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
bool Listener2D::_get(const StringName &p_name, Variant &r_ret) const { | ||
if (p_name == "current") { | ||
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { | ||
r_ret = current; | ||
} else { | ||
r_ret = is_current(); | ||
} | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
void Listener2D::_get_property_list(List<PropertyInfo> *p_list) const { | ||
p_list->push_back(PropertyInfo(Variant::BOOL, "current")); | ||
} | ||
|
||
void Listener2D::_notification(int p_what) { | ||
switch (p_what) { | ||
case NOTIFICATION_ENTER_TREE: { | ||
if (!get_tree()->is_node_being_edited(this) && current) { | ||
make_current(); | ||
} | ||
} break; | ||
case NOTIFICATION_EXIT_TREE: { | ||
if (!get_tree()->is_node_being_edited(this)) { | ||
if (is_current()) { | ||
clear_current(); | ||
current = true; // Keep it true. | ||
} else { | ||
current = false; | ||
} | ||
} | ||
} break; | ||
} | ||
} | ||
|
||
void Listener2D::make_current() { | ||
current = true; | ||
if (!is_inside_tree()) { | ||
return; | ||
} | ||
get_viewport()->_listener_2d_set(this); | ||
} | ||
|
||
void Listener2D::clear_current() { | ||
current = false; | ||
if (!is_inside_tree()) { | ||
return; | ||
} | ||
get_viewport()->_listener_2d_remove(this); | ||
} | ||
|
||
bool Listener2D::is_current() const { | ||
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { | ||
return get_viewport()->get_listener_2d() == this; | ||
} else { | ||
return current; | ||
} | ||
return false; | ||
} | ||
|
||
void Listener2D::_bind_methods() { | ||
ClassDB::bind_method(D_METHOD("make_current"), &Listener2D::make_current); | ||
ClassDB::bind_method(D_METHOD("clear_current"), &Listener2D::clear_current); | ||
ClassDB::bind_method(D_METHOD("is_current"), &Listener2D::is_current); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*************************************************************************/ | ||
/* listener_2d.h */ | ||
/*************************************************************************/ | ||
/* This file is part of: */ | ||
/* GODOT ENGINE */ | ||
/* https://godotengine.org */ | ||
/*************************************************************************/ | ||
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ | ||
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ | ||
/* */ | ||
/* Permission is hereby granted, free of charge, to any person obtaining */ | ||
/* a copy of this software and associated documentation files (the */ | ||
/* "Software"), to deal in the Software without restriction, including */ | ||
/* without limitation the rights to use, copy, modify, merge, publish, */ | ||
/* distribute, sublicense, and/or sell copies of the Software, and to */ | ||
/* permit persons to whom the Software is furnished to do so, subject to */ | ||
/* the following conditions: */ | ||
/* */ | ||
/* The above copyright notice and this permission notice shall be */ | ||
/* included in all copies or substantial portions of the Software. */ | ||
/* */ | ||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ | ||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ | ||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | ||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ | ||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ | ||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ | ||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
/*************************************************************************/ | ||
|
||
#ifndef LISTENER_2D_H | ||
#define LISTENER_2D_H | ||
|
||
#include "scene/2d/node_2d.h" | ||
#include "scene/main/viewport.h" | ||
|
||
class Listener2D : public Node2D { | ||
GDCLASS(Listener2D, Node2D); | ||
|
||
private: | ||
bool current = false; | ||
|
||
friend class Viewport; | ||
|
||
protected: | ||
void _update_listener(); | ||
|
||
bool _set(const StringName &p_name, const Variant &p_value); | ||
bool _get(const StringName &p_name, Variant &r_ret) const; | ||
void _get_property_list(List<PropertyInfo> *p_list) const; | ||
void _notification(int p_what); | ||
|
||
static void _bind_methods(); | ||
|
||
public: | ||
void make_current(); | ||
void clear_current(); | ||
bool is_current() const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters