forked from townforge/townforge
game: add user toggled light source at player position
This commit is contained in:
parent
52b6269ce5
commit
aa6ca84779
@ -522,6 +522,7 @@ and a small one for hunting bears and moose otherwise.
|
||||
<tr><td> J </td><td> Jump to the selected building </td></tr>
|
||||
<tr><td> [ </td><td> Jump to previous building (of the same role if shift pressed) </td></tr>
|
||||
<tr><td> ] </td><td> Jump to next building (of the same role if shift pressed) </td></tr>
|
||||
<tr><td> L </td><td> Toggle user light source </td></tr>
|
||||
<tr><td> Shift </td><td> Decrease motion speed while held </td></tr>
|
||||
<tr><td> Control </td><td> Increase motion speed while held </td></tr>
|
||||
</table>
|
||||
|
@ -177,6 +177,7 @@ Controls::Controls():
|
||||
actions[ACTION_JUMP_TO_BUILDING] = "Jump tp building";
|
||||
actions[ACTION_PREV_FLAG] = "Jump to previous flag (shift for same role)";
|
||||
actions[ACTION_NEXT_FLAG] = "Jump to next flag (shift for same role)";
|
||||
actions[ACTION_TOGGLE_LIGHT] = "Toggle light";
|
||||
|
||||
Set(ACTION_FORWARD, INPUT_KEY_W);
|
||||
Set(ACTION_BACKWARD, INPUT_KEY_S);
|
||||
@ -205,6 +206,7 @@ Controls::Controls():
|
||||
Set(ACTION_JUMP_TO_BUILDING, INPUT_KEY_J);
|
||||
Set(ACTION_PREV_FLAG, INPUT_KEY_LEFT_BRACKET);
|
||||
Set(ACTION_NEXT_FLAG, INPUT_KEY_RIGHT_BRACKET);
|
||||
Set(ACTION_TOGGLE_LIGHT, INPUT_KEY_L);
|
||||
}
|
||||
|
||||
void Controls::RegisterKey(Input input, Urho3D::Key key, const char *name)
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
ACTION_JUMP_TO_BUILDING,
|
||||
ACTION_PREV_FLAG,
|
||||
ACTION_NEXT_FLAG,
|
||||
ACTION_TOGGLE_LIGHT,
|
||||
NUM_ACTIONS
|
||||
};
|
||||
|
||||
|
@ -530,6 +530,8 @@ private:
|
||||
int placing_model_dy;
|
||||
int placing_model_dh;
|
||||
|
||||
bool enableUserLight_;
|
||||
|
||||
std::list<std::shared_ptr<QueuedCommand>> queued_commands;
|
||||
|
||||
struct AddBlockCommand: public QueuedCommand
|
||||
@ -618,7 +620,8 @@ CryptoCityUrho3D::CryptoCityUrho3D(Context *ctx):
|
||||
placing_model(false),
|
||||
placing_model_dx(0),
|
||||
placing_model_dy(0),
|
||||
placing_model_dh(0)
|
||||
placing_model_dh(0),
|
||||
enableUserLight_(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1876,16 +1879,19 @@ void CryptoCityUrho3D::UpdateSky()
|
||||
horizon.SetColor(ambient + sunColor * interp);
|
||||
|
||||
const float cameraLightBrightness = std::max(0.1f - sin_timeOfDay, 0.0f);
|
||||
if (cameraLightBrightness > 0.0f)
|
||||
if (enableUserLight_ || cameraLightBrightness > 0.0f)
|
||||
{
|
||||
if (!cameraLight)
|
||||
{
|
||||
cameraLight = cameraNode_->CreateComponent<Light>();
|
||||
cameraLight->SetLightType(LIGHT_POINT);
|
||||
cameraLight->SetColor(Color(.12f, .12f, .24f));
|
||||
if (enableUserLight_)
|
||||
cameraLight->SetColor(Color(.72f, .72f, .54f));
|
||||
else
|
||||
cameraLight->SetColor(Color(.12f, .12f, .24f));
|
||||
cameraLight->SetSpecularIntensity(0.0f);
|
||||
cameraLight->SetRange(120);
|
||||
cameraLight->SetCastShadows(false);
|
||||
cameraLight->SetCastShadows(enableUserLight_);
|
||||
cameraLight->SetPerVertex(true);
|
||||
}
|
||||
}
|
||||
@ -1898,7 +1904,7 @@ void CryptoCityUrho3D::UpdateSky()
|
||||
}
|
||||
}
|
||||
if (cameraLight)
|
||||
cameraLight->SetBrightness(cameraLightBrightness);
|
||||
cameraLight->SetBrightness(enableUserLight_ ? 1.0f : cameraLightBrightness);
|
||||
|
||||
Quaternion newRot(Quaternion(-90.0f, Vector3::UP) * Quaternion((timeOfDay / M_PI) * 180, Vector3(1, 0.3f, 0)));
|
||||
mainLightNode->SetRotation(-newRot); //inverted since we are looking at direction from sun
|
||||
@ -5771,6 +5777,13 @@ void CryptoCityUrho3D::HandleKeyDown(StringHash /*eventType*/, VariantMap& event
|
||||
const bool same_role = input->GetQualifierDown(QUAL_SHIFT);
|
||||
GoToNextFlag(true, same_role);
|
||||
}
|
||||
else if (action == Controls::ACTION_TOGGLE_LIGHT)
|
||||
{
|
||||
enableUserLight_ = !enableUserLight_;
|
||||
Light* cameraLight = cameraNode_->GetComponent<Light>();
|
||||
if (cameraLight)
|
||||
cameraLight->Remove();
|
||||
}
|
||||
|
||||
// console
|
||||
else if (action == Controls::ACTION_TOGGLE_CONSOLE)
|
||||
|
Loading…
Reference in New Issue
Block a user