Differential D1509 Diff 7574 ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/tools/atlas/AtlasUI/ScenarioEditor/Tools/PlaceObject.cpp
/* Copyright (C) 2013 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 20 Lines | |||||
class PlaceObject : public StateDrivenTool<PlaceObject> | class PlaceObject : public StateDrivenTool<PlaceObject> | ||||
{ | { | ||||
DECLARE_DYNAMIC_CLASS(PlaceObject); | DECLARE_DYNAMIC_CLASS(PlaceObject); | ||||
Position m_ScreenPos, m_ObjPos, m_Target; | Position m_ScreenPos, m_ObjPos, m_Target; | ||||
wxString m_ObjectID; | wxString m_ObjectID; | ||||
unsigned int m_ActorSeed; | unsigned int m_ActorSeed; | ||||
int m_RotationDirection; | |||||
public: | public: | ||||
PlaceObject() | PlaceObject(): m_RotationDirection(0) | ||||
{ | { | ||||
SetState(&Waiting); | SetState(&Waiting); | ||||
} | } | ||||
void SendObjectMsg(bool preview) | void SendObjectMsg(bool preview) | ||||
{ | { | ||||
int dragDistSq = | int dragDistSq = | ||||
(m_ScreenPos.type1.x-m_Target.type1.x)*(m_ScreenPos.type1.x-m_Target.type1.x) | (m_ScreenPos.type1.x-m_Target.type1.x)*(m_ScreenPos.type1.x-m_Target.type1.x) | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | public: | ||||
bool OnKeyOverride(wxKeyEvent& evt, KeyEventType type) | bool OnKeyOverride(wxKeyEvent& evt, KeyEventType type) | ||||
{ | { | ||||
if (type == KEY_CHAR && evt.GetKeyCode() == WXK_ESCAPE) | if (type == KEY_CHAR && evt.GetKeyCode() == WXK_ESCAPE) | ||||
{ | { | ||||
SetState(&Disabled); | SetState(&Disabled); | ||||
return true; | return true; | ||||
} | } | ||||
else if (evt.GetKeyCode() == WXK_PAGEDOWN) | |||||
{ | |||||
if (type == KEY_DOWN) | |||||
m_RotationDirection = 1; | |||||
else if (type == KEY_UP) | |||||
m_RotationDirection = 0; | |||||
else | |||||
return false; | |||||
return true; | |||||
} | |||||
else if (evt.GetKeyCode() == WXK_PAGEUP) | |||||
{ | |||||
if (type == KEY_DOWN) | |||||
m_RotationDirection = -1; | |||||
else if (type == KEY_UP) | |||||
m_RotationDirection = 0; | |||||
else | |||||
return false; | |||||
return true; | |||||
} | |||||
else | else | ||||
return false; | return false; | ||||
} | } | ||||
void RotateTick(float dt) | void RotateTick(float dt) | ||||
{ | { | ||||
int dir = 0; | if (m_RotationDirection) | ||||
if (wxGetKeyState(WXK_PAGEDOWN)) ++dir; // page-down key | |||||
if (wxGetKeyState(WXK_PAGEUP)) --dir; // page-up key | |||||
if (dir) | |||||
{ | { | ||||
float speed = M_PI/2.f * ScenarioEditor::GetSpeedModifier(); // radians per second | float speed = M_PI/2.f * ScenarioEditor::GetSpeedModifier(); // radians per second | ||||
g_DefaultAngle += (dir * dt * speed); | g_DefaultAngle += (m_RotationDirection * dt * speed); | ||||
SendObjectMsg(true); | SendObjectMsg(true); | ||||
} | } | ||||
} | } | ||||
void RandomizeActorSeed() | void RandomizeActorSeed() | ||||
{ | { | ||||
m_ActorSeed = (unsigned int)floor((rand() / (float)RAND_MAX) * 65535.f); | m_ActorSeed = (unsigned int)floor((rand() / (float)RAND_MAX) * 65535.f); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator