161 lines
4.5 KiB
C++
Executable File
161 lines
4.5 KiB
C++
Executable File
#include "UploadPhotoScreen.h"
|
|
|
|
#include "../components/Button.h"
|
|
#include "../../Minecraft.h"
|
|
#include "../../player/LocalPlayer.h"
|
|
#include "../../../world/entity/item/TripodCamera.h"
|
|
#include "../../../world/level/Level.h"
|
|
#include "../../../platform/input/Keyboard.h"
|
|
#include "../../renderer/GameRenderer.h"
|
|
#include "../../renderer/LevelRenderer.h"
|
|
|
|
UploadPhotoScreen::UploadPhotoScreen()
|
|
: hasAppliedPhotoMode(false),
|
|
oldHideGui(false),
|
|
oldThirdPerson(false),
|
|
oldFixedCamera(false),
|
|
hasOldPose(false),
|
|
oldX(0),
|
|
oldY(0),
|
|
oldZ(0),
|
|
oldYaw(0),
|
|
oldPitch(0),
|
|
photoCameraTarget(NULL),
|
|
photoCameraX(0),
|
|
photoCameraY(0),
|
|
photoCameraZ(0),
|
|
bBack(0)
|
|
{
|
|
}
|
|
|
|
UploadPhotoScreen::~UploadPhotoScreen()
|
|
{
|
|
restorePhotoMode();
|
|
delete photoCameraTarget;
|
|
delete bBack;
|
|
}
|
|
|
|
void UploadPhotoScreen::init()
|
|
{
|
|
applyPhotoMode();
|
|
|
|
if (minecraft->useTouchscreen()) {
|
|
bBack = new Touch::TButton(1, "Back");
|
|
} else {
|
|
bBack = new Button(1, "Back");
|
|
}
|
|
|
|
buttons.push_back(bBack);
|
|
tabButtons.push_back(bBack);
|
|
}
|
|
|
|
void UploadPhotoScreen::removed()
|
|
{
|
|
restorePhotoMode();
|
|
}
|
|
|
|
void UploadPhotoScreen::applyPhotoMode()
|
|
{
|
|
if (hasAppliedPhotoMode || !minecraft || !minecraft->gameRenderer) return;
|
|
|
|
if (minecraft->player) {
|
|
oldX = minecraft->player->x;
|
|
oldY = minecraft->player->y;
|
|
oldZ = minecraft->player->z;
|
|
oldYaw = minecraft->player->yRot;
|
|
oldPitch = minecraft->player->xRot;
|
|
hasOldPose = true;
|
|
}
|
|
|
|
oldHideGui = minecraft->options.getBooleanValue(OPTIONS_HIDEGUI);
|
|
oldThirdPerson = minecraft->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW);
|
|
oldFixedCamera = minecraft->options.getBooleanValue(OPTIONS_FIXED_CAMERA);
|
|
Pos spawn = minecraft->level->getSharedSpawnPos();
|
|
photoCameraX = (float) spawn.x;
|
|
photoCameraY = 128.0f;
|
|
photoCameraZ = (float) spawn.z;
|
|
if (!photoCameraTarget) {
|
|
photoCameraTarget = new TripodCamera(minecraft->level, minecraft->player, photoCameraX, photoCameraY, photoCameraZ);
|
|
}
|
|
photoCameraTarget->setPos(photoCameraX, photoCameraY, photoCameraZ);
|
|
photoCameraTarget->xo = photoCameraTarget->xOld = photoCameraX;
|
|
photoCameraTarget->yo = photoCameraTarget->yOld = photoCameraY;
|
|
photoCameraTarget->zo = photoCameraTarget->zOld = photoCameraZ;
|
|
|
|
if (!oldHideGui) minecraft->options.toggle(OPTIONS_HIDEGUI);
|
|
if (!oldThirdPerson) minecraft->options.toggle(OPTIONS_THIRD_PERSON_VIEW);
|
|
if (!oldFixedCamera) minecraft->options.toggle(OPTIONS_FIXED_CAMERA);
|
|
|
|
minecraft->gameRenderer->setPhotoModeIsometric();
|
|
minecraft->levelRenderer->allChanged();
|
|
hasAppliedPhotoMode = true;
|
|
}
|
|
|
|
void UploadPhotoScreen::tick()
|
|
{
|
|
if (!hasAppliedPhotoMode || !minecraft || !minecraft->player || !minecraft->level) return;
|
|
|
|
if (photoCameraTarget) {
|
|
photoCameraTarget->setPos(photoCameraX, photoCameraY, photoCameraZ);
|
|
photoCameraTarget->xo = photoCameraTarget->xOld = photoCameraX;
|
|
photoCameraTarget->yo = photoCameraTarget->yOld = photoCameraY;
|
|
photoCameraTarget->zo = photoCameraTarget->zOld = photoCameraZ;
|
|
photoCameraTarget->yRot = photoCameraTarget->yRotO = 45.0f;
|
|
photoCameraTarget->xRot = photoCameraTarget->xRotO = 68.0f;
|
|
minecraft->cameraTargetPlayer = photoCameraTarget;
|
|
}
|
|
}
|
|
|
|
void UploadPhotoScreen::restorePhotoMode()
|
|
{
|
|
if (!hasAppliedPhotoMode || !minecraft) return;
|
|
|
|
if (minecraft->options.getBooleanValue(OPTIONS_HIDEGUI) != oldHideGui) minecraft->options.toggle(OPTIONS_HIDEGUI);
|
|
if (minecraft->options.getBooleanValue(OPTIONS_THIRD_PERSON_VIEW) != oldThirdPerson) minecraft->options.toggle(OPTIONS_THIRD_PERSON_VIEW);
|
|
if (minecraft->options.getBooleanValue(OPTIONS_FIXED_CAMERA) != oldFixedCamera) minecraft->options.toggle(OPTIONS_FIXED_CAMERA);
|
|
minecraft->gameRenderer->clearPhotoModeIsometric();
|
|
minecraft->cameraTargetPlayer = minecraft->player;
|
|
|
|
if (hasOldPose && minecraft->player) {
|
|
minecraft->player->yRot = oldYaw;
|
|
minecraft->player->xRot = oldPitch;
|
|
}
|
|
|
|
hasAppliedPhotoMode = false;
|
|
}
|
|
|
|
void UploadPhotoScreen::keyPressed(int eventKey)
|
|
{
|
|
if (eventKey == Keyboard::KEY_ESCAPE) {
|
|
restorePhotoMode();
|
|
minecraft->setScreen(NULL);
|
|
return;
|
|
}
|
|
|
|
Screen::keyPressed(eventKey);
|
|
}
|
|
|
|
void UploadPhotoScreen::buttonClicked(Button* button)
|
|
{
|
|
if (!button || button->id != 1) return;
|
|
|
|
restorePhotoMode();
|
|
minecraft->setScreen(NULL);
|
|
}
|
|
|
|
void UploadPhotoScreen::setupPositions()
|
|
{
|
|
const int buttonWidth = 120;
|
|
const int buttonHeight = 24;
|
|
bBack->width = buttonWidth;
|
|
bBack->height = buttonHeight;
|
|
bBack->x = (width - buttonWidth) / 2;
|
|
bBack->y = height - 32;
|
|
}
|
|
|
|
void UploadPhotoScreen::render(int xm, int ym, float a)
|
|
{
|
|
drawCenteredString(font, "Photo Mode - Isometric", width / 2, 12, 0xffffff);
|
|
Screen::render(xm, ym, a);
|
|
}
|