Split CMainDialog

master
krzys-h 2015-08-04 23:28:58 +02:00
parent c2387b4b56
commit 54254e2158
29 changed files with 5339 additions and 4318 deletions

View File

@ -205,6 +205,18 @@ set(BASE_SOURCES
script/scriptfunc.cpp
sound/sound.cpp
sound/sound_type.cpp
ui/screen/screen.cpp
ui/screen/screen_apperance.cpp
ui/screen/screen_io.cpp
ui/screen/screen_io_read.cpp
ui/screen/screen_io_write.cpp
ui/screen/screen_level_list.cpp
ui/screen/screen_loading.cpp
ui/screen/screen_main_menu.cpp
ui/screen/screen_player_select.cpp
ui/screen/screen_setup.cpp
ui/screen/screen_quit.cpp
ui/screen/screen_welcome.cpp
ui/button.cpp
ui/check.cpp
ui/color.cpp

View File

@ -398,9 +398,33 @@ void CRobotMain::LoadConfigFile()
m_settings->LoadSettings();
}
bool IsInSimulationConfigPhase(Phase phase)
{
return (phase >= PHASE_SETUPds && phase <= PHASE_SETUPss) || phase == PHASE_READs || phase == PHASE_WRITEs;
}
bool IsPhaseWithWorld(Phase phase)
{
if (phase == PHASE_SIMUL ) return true;
if (phase == PHASE_WIN ) return true;
if (phase == PHASE_LOST ) return true;
if (phase == PHASE_APPERANCE) return true;
if (phase == PHASE_LOADING ) return true;
if (IsInSimulationConfigPhase(phase)) return true;
return false;
}
//! Changes phase
void CRobotMain::ChangePhase(Phase phase)
{
if (!IsPhaseWithWorld(m_phase) || IsInSimulationConfigPhase(m_phase) || IsInSimulationConfigPhase(phase))
{
m_phase = phase;
m_dialog->ChangePhase(m_phase);
return;
}
GetLogger()->Info("Resseting world on scene change...\n");
m_missionTimerEnabled = m_missionTimerStarted = false;
m_missionTimer = 0.0f;
@ -435,6 +459,7 @@ void CRobotMain::ChangePhase(Phase phase)
m_editLock = false;
m_freePhoto = false;
m_resetCreate = false;
m_infoObject = nullptr;
ChangePause(PAUSE_NONE);
FlushDisplayInfo();
@ -1501,20 +1526,39 @@ void CRobotMain::SetDisplayInfoPosition(int index, int pos)
//! Beginning of a dialogue during the game
void CRobotMain::StartSuspend()
{
m_sound->MuteAll(true);
ClearInterface();
m_suspendInitPause = m_pause->GetPauseType();
m_pause->SetPause(PAUSE_DIALOG);
m_engine->SetOverFront(false); // over flat behind
CreateShortcuts();
m_map->ShowMap(false);
m_infoObject = DeselectAll(); // removes the control buttons
m_displayText->HideText(true);
m_suspendInitCamera = m_camera->GetType();
m_camera->SetType(Gfx::CAM_TYPE_DIALOG);
m_suspend = true;
}
//! End of dialogue during the game
void CRobotMain::StopSuspend()
{
SelectObject(m_infoObject, false); // gives the command buttons
m_sound->MuteAll(false);
ClearInterface();
m_pause->SetPause(m_suspendInitPause);
m_engine->SetOverFront(true); // over flat front
CreateShortcuts();
if(m_infoObject != nullptr)
SelectObject(m_infoObject, false); // gives the command buttons
m_map->ShowMap(m_mapShow);
m_displayText->HideText(false);
m_camera->SetType(m_suspendInitCamera);
m_suspend = false;
}

View File

@ -29,6 +29,7 @@
#include "common/global.h"
#include "common/singleton.h"
#include "graphics/engine/camera.h"
#include "graphics/engine/particle.h"
#include "object/drive_type.h"
@ -61,14 +62,15 @@ enum Phase
PHASE_SETUPps,
PHASE_SETUPcs,
PHASE_SETUPss,
PHASE_WRITE,
PHASE_READ,
PHASE_WRITEs,
PHASE_READ,
PHASE_READs,
PHASE_WIN,
PHASE_LOST,
PHASE_QUIT_SCREEN,
};
bool IsInSimulationConfigPhase(Phase phase);
bool IsPhaseWithWorld(Phase phase);
class CController;
@ -492,13 +494,16 @@ protected:
bool m_editFull; // edition in full screen?
bool m_hilite;
bool m_trainerPilot; // remote trainer?
bool m_suspend;
bool m_friendAim;
bool m_resetCreate;
bool m_mapShow;
bool m_mapImage;
char m_mapFilename[100];
bool m_suspend;
PauseType m_suspendInitPause;
Gfx::CameraType m_suspendInitCamera;
Math::Point m_tooltipPos;
std::string m_tooltipName;
float m_tooltipTime;

File diff suppressed because it is too large Load Diff

View File

@ -20,9 +20,9 @@
#include "app/pausemanager.h"
#include "graphics/core/color.h"
#include "common/singleton.h"
#include "graphics/engine/camera.h"
#include "graphics/core/color.h"
#include "object/level_category.h"
#include "object/robotmain.h"
@ -47,9 +47,11 @@ class CInterface;
class CWindow;
class CControl;
class CScreen;
class CMainDialog
class CMainDialog : public CSingleton<CMainDialog>
{
public:
CMainDialog();
@ -71,11 +73,8 @@ public:
void StopDialog();
bool IsDialog();
void StartSuspend();
void StopSuspend();
void UpdateChapterPassed();
bool NextMission();
void NextMission();
bool GetGamerOnlyHead();
float GetPersoAngle();
@ -93,35 +92,7 @@ protected:
void GlintMove();
void FrameParticle(float rTime);
void NiceParticle(Math::Point mouse, bool bPress);
void ReadNameList();
void UpdateNameList();
void UpdateNameEdit();
void UpdateNameControl();
void NameSelect();
bool NameCreate();
void NameDelete();
void UpdatePerso();
void CameraPerso();
void FixPerso(int rank, int index);
void ColorPerso();
void IOReadName();
void IOReadList();
void IOUpdateList();
void IODeleteScene();
void IOWriteScene();
void IOReadScene();
int GetChapPassed();
void UpdateSceneChap(int &chap);
void UpdateSceneList(int chap, int &sel);
void UpdateSceneResume(int chap, int rank);
void UpdateDisplayMode();
void ChangeDisplay();
void UpdateApply();
void UpdateSetupButtons();
void ChangeSetupButtons();
void ChangeSetupQuality(int quality);
void UpdateKey();
void ChangeKey(EventType event);
protected:
CApplication* m_app;
@ -135,35 +106,16 @@ protected:
CPauseManager* m_pause;
CSettings* m_settings;
std::unique_ptr<CScreen> m_screen;
Phase m_phase; // copy of CRobotMain
Phase m_phaseSetup; // tab selected
float m_phaseTime;
int m_apperanceTab; // perso: tab selected
float m_apperanceAngle; // perso: angle of presentation
LevelCategory m_category;
LevelCategory m_listCategory;
std::map<LevelCategory, int> m_chap; // selected chapter (0..8)
std::map<LevelCategory, int> m_sel; // chosen mission (0..98)
int m_maxList;
int m_accessChap;
bool m_bSceneSoluce; // shows the solution
bool m_bSimulSetup; // adjustment during the game
std::vector<std::string> m_customLevelList;
int m_shotDelay; // number of frames before copy
std::string m_shotName; // generate a file name
int m_setupSelMode;
bool m_setupFull;
Math::Point m_glintMouse;
float m_glintTime;
int m_loadingCounter;
bool m_bDialog; // this dialogue?
bool m_bDialogFire; // setting on fire?
bool m_bDialogDelete;
@ -171,14 +123,10 @@ protected:
Math::Point m_dialogDim;
float m_dialogParti;
float m_dialogTime;
PauseType m_bInitPause;
Gfx::CameraType m_initCamera;
int m_partiPhase[10];
float m_partiTime[10];
Math::Point m_partiPos[10];
std::vector<std::string> m_saveList;
};
} // namespace Ui

52
src/ui/screen/screen.cpp Normal file
View File

@ -0,0 +1,52 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen.h"
#include "app/app.h"
#include "graphics/engine/engine.h"
#include "object/robotmain.h"
namespace Ui {
CRobotMain* CScreen::m_main = nullptr;
CScreen::CScreen()
{
m_main = CRobotMain::GetInstancePointer();
m_interface = m_main->GetInterface();
m_app = CApplication::GetInstancePointer();
m_eventQueue = m_app->GetEventQueue();
m_engine = Gfx::CEngine::GetInstancePointer();
m_sound = m_app->GetSound();
}
void CScreen::SetBackground(const std::string& filename, bool scaled)
{
m_engine->SetBackground(filename,
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f),
true, scaled);
m_engine->SetBackForce(true);
}
} // namespace Ui

61
src/ui/screen/screen.h Normal file
View File

@ -0,0 +1,61 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "common/event.h"
#include <string>
class CRobotMain;
class CApplication;
class CEventQueue;
class CSoundInterface;
namespace Gfx
{
class CEngine;
}
namespace Ui {
class CInterface;
class CScreen
{
public:
CScreen();
virtual void CreateInterface() = 0;
virtual bool EventProcess(const Event &event) = 0;
protected:
void SetBackground(const std::string& filename, bool scaled = false);
protected:
static CRobotMain* m_main;
CInterface* m_interface;
CApplication* m_app;
CEventQueue* m_eventQueue;
Gfx::CEngine* m_engine;
CSoundInterface* m_sound;
const Math::Point dim = Math::Point(32.0f/640.0f, 32.0f/480.0f);
const float ox = 3.0f/640.0f, oy = 3.0f/480.0f;
const float sx = (32.0f+2.0f)/640.0f, sy = (32.0f+2.0f)/480.0f;
};
} // namespace Ui

View File

@ -0,0 +1,692 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_apperance.h"
#include "app/app.h"
#include "object/player_profile.h"
#include "object/robotmain.h"
#include "graphics/engine/camera.h"
#include "ui/button.h"
#include "ui/color.h"
#include "ui/interface.h"
#include "ui/label.h"
#include "ui/slider.h"
#include "ui/window.h"
namespace Ui {
static int perso_color[3*10*3] =
{
// hair:
193, 221, 226, // white
255, 255, 181, // yellow
204, 155, 84, // blond
165, 48, 10, // red
140, 75, 84, // brown
83, 64, 51, // brown
90, 95, 85, // black
85, 48, 9, // brown
60, 0, 23, // black
0, 0, 0, //
// spacesuit:
203, 206, 204, // dirty white
0, 205, 203, // bluish
108, 176, 0, // greenish
207, 207, 32, // yellow
170, 141, 0, // orange
108, 84, 0, // brown
0, 84, 136, // bluish
56, 61, 146, // bluish
56, 56, 56, // black
0, 0, 0, //
// strips:
255, 255, 255, // white
255, 255, 0, // yellow
255, 132, 1, // orange
255, 0, 255, // magenta
255, 0, 0, // red
0, 255, 0, // green
0, 255, 255, // cyan
0, 0, 255, // blue
70, 51, 84, // dark
0, 0, 0, //
};
CScreenApperance::CScreenApperance()
{
}
void CScreenApperance::CreateInterface()
{
CWindow* pw;
CLabel* pl;
CButton* pb;
CColor* pco;
CSlider* psl;
Math::Point pos, ddim;
std::string name;
pos.x = 0.10f;
pos.y = 0.10f;
ddim.x = 0.80f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 12, EVENT_WINDOW5);
GetResource(RES_TEXT, RT_TITLE_PERSO, name);
pw->SetName(name);
pos.x = 0.10f;
pos.y = 0.40f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.40f;
pos.y = 0.10f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
pos.x = 95.0f/640.0f;
pos.y = 108.0f/480.0f;
ddim.x = 220.0f/640.0f;
ddim.y = 274.0f/480.0f;
pw->CreateGroup(pos, ddim, 17, EVENT_NULL); // frame
pos.x = 100.0f/640.0f;
pos.y = 364.0f/480.0f;
ddim.x = 210.0f/640.0f;
ddim.y = 14.0f/480.0f;
pw->CreateGroup(pos, ddim, 3, EVENT_NULL); // transparent -> gray
pos.x = 120.0f/640.0f;
pos.y = 364.0f/480.0f;
ddim.x = 80.0f/640.0f;
ddim.y = 28.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PHEAD);
pb->SetState(STATE_SHADOW);
pb->SetState(STATE_CARD);
pos.x = 210.0f/640.0f;
pos.y = 364.0f/480.0f;
ddim.x = 80.0f/640.0f;
ddim.y = 28.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PBODY);
pb->SetState(STATE_SHADOW);
pb->SetState(STATE_CARD);
pos.x = 100.0f/640.0f;
pos.y = 354.0f/480.0f;
ddim.x = 210.0f/640.0f;
ddim.y = 10.0f/480.0f;
pw->CreateGroup(pos, ddim, 1, EVENT_INTERFACE_GLINTb); // orange bar
pos.x = 100.0f/640.0f;
pos.y = 154.0f/480.0f;
ddim.x = 210.0f/640.0f;
ddim.y = 200.0f/480.0f;
pw->CreateGroup(pos, ddim, 2, EVENT_INTERFACE_GLINTu); // orange -> transparent
// Face
pos.x = 340.0f/640.0f;
pos.y = 356.0f/480.0f;
ddim.x = 200.0f/640.0f;
ddim.y = 16.0f/480.0f;
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL11, "");
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.x = 340.0f/640.0f;
pos.y = 312.0f/480.0f;
ddim.x = 44.0f/640.0f;
ddim.y = 44.0f/480.0f;
pb = pw->CreateButton(pos, ddim, 43, EVENT_INTERFACE_PFACE1);
pb->SetState(STATE_SHADOW);
pos.x += 50.0f/640.0f;
pb = pw->CreateButton(pos, ddim, 46, EVENT_INTERFACE_PFACE4);
pb->SetState(STATE_SHADOW);
pos.x += 50.0f/640.0f;
pb = pw->CreateButton(pos, ddim, 45, EVENT_INTERFACE_PFACE3);
pb->SetState(STATE_SHADOW);
pos.x += 50.0f/640.0f;
pb = pw->CreateButton(pos, ddim, 44, EVENT_INTERFACE_PFACE2);
pb->SetState(STATE_SHADOW);
// Glasses
pos.x = 340.0f/640.0f;
pos.y = 270.0f/480.0f;
ddim.x = 200.0f/640.0f;
ddim.y = 16.0f/480.0f;
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL12, "");
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.x = 340.0f/640.0f;
pos.y = 240.0f/480.0f;
ddim.x = 30.0f/640.0f;
ddim.y = 30.0f/480.0f;
for ( int i=0 ; i<6 ; i++ )
{
int ti[6] = {11, 179, 180, 181, 182, 183};
pb = pw->CreateButton(pos, ddim, ti[i], static_cast<EventType>(EVENT_INTERFACE_PGLASS0+i));
pb->SetState(STATE_SHADOW);
pos.x += (30.0f+2.8f)/640.0f;
}
// Color A
pos.x = 340.0f/640.0f;
pos.y = 300.0f/480.0f;
ddim.x = 200.0f/640.0f;
ddim.y = 16.0f/480.0f;
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL14, "");
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.y = 282.0f/480.0f;
ddim.x = 18.0f/640.0f;
ddim.y = 18.0f/480.0f;
for ( int j=0 ; j<3 ; j++ )
{
pos.x = 340.0f/640.0f;
for ( int i=0 ; i<3 ; i++ )
{
pco = pw->CreateColor(pos, ddim, -1, static_cast<EventType>(EVENT_INTERFACE_PC0a+j*3+i));
pco->SetState(STATE_SHADOW);
pos.x += 20.0f/640.0f;
}
pos.y -= 20.0f/480.0f;
}
pos.x = 420.0f/640.0f;
pos.y = 282.0f/480.0f;
ddim.x = 100.0f/640.0f;
ddim.y = 18.0f/480.0f;
for ( int i=0 ; i<3 ; i++ )
{
psl = pw->CreateSlider(pos, ddim, 0, static_cast<EventType>(EVENT_INTERFACE_PCRa+i));
psl->SetState(STATE_SHADOW);
psl->SetLimit(0.0f, 255.0f);
psl->SetArrowStep(16.0f);
pos.y -= 20.0f/480.0f;
}
// Color B
pos.x = 340.0f/640.0f;
pos.y = 192.0f/480.0f;
ddim.x = 200.0f/640.0f;
ddim.y = 16.0f/480.0f;
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL13, "");
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.y = 174.0f/480.0f;
ddim.x = 18.0f/640.0f;
ddim.y = 18.0f/480.0f;
for ( int j=0 ; j<3 ; j++ )
{
pos.x = 340.0f/640.0f;
for ( int i=0 ; i<3 ; i++ )
{
pco = pw->CreateColor(pos, ddim, -1, static_cast<EventType>(EVENT_INTERFACE_PC0b+j*3+i));
pco->SetState(STATE_SHADOW);
pos.x += 20.0f/640.0f;
}
pos.y -= 20.0f/480.0f;
}
pos.x = 420.0f/640.0f;
pos.y = 174.0f/480.0f;
ddim.x = 100.0f/640.0f;
ddim.y = 18.0f/480.0f;
for ( int i=0 ; i<3 ; i++ )
{
psl = pw->CreateSlider(pos, ddim, 0, static_cast<EventType>(EVENT_INTERFACE_PCRb+i));
psl->SetState(STATE_SHADOW);
psl->SetLimit(0.0f, 255.0f);
psl->SetArrowStep(16.0f);
pos.y -= 20.0f/480.0f;
}
// Rotation
pos.x = 100.0f/640.0f;
pos.y = 113.0f/480.0f;
ddim.x = 20.0f/640.0f;
ddim.y = 20.0f/480.0f;
pb = pw->CreateButton(pos, ddim, 55, EVENT_INTERFACE_PLROT); // <
pb->SetState(STATE_SHADOW);
pb->SetRepeat(true);
pos.x = 290.0f/640.0f;
pos.y = 113.0f/480.0f;
ddim.x = 20.0f/640.0f;
ddim.y = 20.0f/480.0f;
pb = pw->CreateButton(pos, ddim, 48, EVENT_INTERFACE_PRROT); // >
pb->SetState(STATE_SHADOW);
pb->SetRepeat(true);
pos.x = 100.0f/640.0f;
pos.y = 70.0f/480.0f;
ddim.x = 100.0f/640.0f;
ddim.y = 32.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_POK);
pb->SetState(STATE_SHADOW);
pos.x = 210.0f/640.0f;
pos.y = 70.0f/480.0f;
ddim.x =100.0f/640.0f;
ddim.y = 32.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PCANCEL);
pb->SetState(STATE_SHADOW);
pos.x = 340.0f/640.0f;
pos.y = 70.0f/480.0f;
ddim.x =194.0f/640.0f;
ddim.y = 32.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PDEF);
pb->SetState(STATE_SHADOW);
m_apperanceTab = 0;
m_apperanceAngle = -0.6f;
m_main->GetPlayerProfile()->LoadApperance();
UpdatePerso();
m_main->ScenePerso();
CameraPerso();
}
bool CScreenApperance::EventProcess(const Event &event)
{
PlayerApperance& apperance = m_main->GetPlayerProfile()->GetApperance();
switch( event.type )
{
case EVENT_KEY_DOWN:
if ( event.key.key == KEY(RETURN) )
{
m_main->ChangePhase(PHASE_MAIN_MENU);
}
if ( event.key.key == KEY(ESCAPE) )
{
m_main->ChangePhase(PHASE_PLAYER_SELECT);
}
break;
case EVENT_INTERFACE_PHEAD:
m_apperanceTab = 0;
UpdatePerso();
m_main->ScenePerso();
CameraPerso();
break;
case EVENT_INTERFACE_PBODY:
m_apperanceTab = 1;
UpdatePerso();
m_main->ScenePerso();
CameraPerso();
break;
case EVENT_INTERFACE_PFACE1:
case EVENT_INTERFACE_PFACE2:
case EVENT_INTERFACE_PFACE3:
case EVENT_INTERFACE_PFACE4:
apperance.face = event.type-EVENT_INTERFACE_PFACE1;
UpdatePerso();
m_main->ScenePerso();
break;
case EVENT_INTERFACE_PGLASS0:
case EVENT_INTERFACE_PGLASS1:
case EVENT_INTERFACE_PGLASS2:
case EVENT_INTERFACE_PGLASS3:
case EVENT_INTERFACE_PGLASS4:
case EVENT_INTERFACE_PGLASS5:
case EVENT_INTERFACE_PGLASS6:
case EVENT_INTERFACE_PGLASS7:
case EVENT_INTERFACE_PGLASS8:
case EVENT_INTERFACE_PGLASS9:
apperance.glasses = event.type-EVENT_INTERFACE_PGLASS0;
UpdatePerso();
m_main->ScenePerso();
break;
case EVENT_INTERFACE_PC0a:
case EVENT_INTERFACE_PC1a:
case EVENT_INTERFACE_PC2a:
case EVENT_INTERFACE_PC3a:
case EVENT_INTERFACE_PC4a:
case EVENT_INTERFACE_PC5a:
case EVENT_INTERFACE_PC6a:
case EVENT_INTERFACE_PC7a:
case EVENT_INTERFACE_PC8a:
case EVENT_INTERFACE_PC9a:
FixPerso(event.type-EVENT_INTERFACE_PC0a, 0);
UpdatePerso();
m_main->ScenePerso();
break;
case EVENT_INTERFACE_PC0b:
case EVENT_INTERFACE_PC1b:
case EVENT_INTERFACE_PC2b:
case EVENT_INTERFACE_PC3b:
case EVENT_INTERFACE_PC4b:
case EVENT_INTERFACE_PC5b:
case EVENT_INTERFACE_PC6b:
case EVENT_INTERFACE_PC7b:
case EVENT_INTERFACE_PC8b:
case EVENT_INTERFACE_PC9b:
FixPerso(event.type-EVENT_INTERFACE_PC0b, 1);
UpdatePerso();
m_main->ScenePerso();
break;
case EVENT_INTERFACE_PCRa:
case EVENT_INTERFACE_PCGa:
case EVENT_INTERFACE_PCBa:
case EVENT_INTERFACE_PCRb:
case EVENT_INTERFACE_PCGb:
case EVENT_INTERFACE_PCBb:
ColorPerso();
UpdatePerso();
m_main->ScenePerso();
break;
case EVENT_INTERFACE_PDEF:
apperance.DefPerso();
UpdatePerso();
m_main->ScenePerso();
break;
case EVENT_INTERFACE_PLROT:
m_apperanceAngle += 0.2f;
break;
case EVENT_INTERFACE_PRROT:
m_apperanceAngle -= 0.2f;
break;
case EVENT_INTERFACE_POK:
m_main->GetPlayerProfile()->SaveApperance();
m_main->ChangePhase(PHASE_MAIN_MENU);
break;
case EVENT_INTERFACE_PCANCEL:
m_main->GetPlayerProfile()->LoadApperance(); // reload apperance from file
m_main->ChangePhase(PHASE_PLAYER_SELECT);
break;
default:
return true;
}
return false;
}
bool CScreenApperance::GetGamerOnlyHead()
{
return m_apperanceTab == 0;
}
float CScreenApperance::GetPersoAngle()
{
return m_apperanceAngle;
}
// Tests whether two colors are equal or nearly are.
bool EqColor(const Gfx::Color &c1, const Gfx::Color &c2)
{
return (fabs(c1.r-c2.r) < 0.01f &&
fabs(c1.g-c2.g) < 0.01f &&
fabs(c1.b-c2.b) < 0.01f );
}
// Updates all the buttons for the character.
void CScreenApperance::UpdatePerso()
{
CWindow* pw;
CLabel* pl;
CButton* pb;
CColor* pc;
CSlider* ps;
Gfx::Color color;
std::string name;
int i;
PlayerApperance& apperance = m_main->GetPlayerProfile()->GetApperance();
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_PHEAD));
if ( pb != 0 )
{
pb->SetState(STATE_CHECK, m_apperanceTab==0);
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_PBODY));
if ( pb != 0 )
{
pb->SetState(STATE_CHECK, m_apperanceTab==1);
}
pl = static_cast<CLabel*>(pw->SearchControl(EVENT_LABEL11));
if ( pl != 0 )
{
if ( m_apperanceTab == 0 )
{
pl->SetState(STATE_VISIBLE);
GetResource(RES_TEXT, RT_PERSO_FACE, name);
pl->SetName(name);
}
else
{
pl->ClearState(STATE_VISIBLE);
}
}
pl = static_cast<CLabel*>(pw->SearchControl(EVENT_LABEL12));
if ( pl != 0 )
{
if ( m_apperanceTab == 0 )
{
pl->SetState(STATE_VISIBLE);
GetResource(RES_TEXT, RT_PERSO_GLASSES, name);
pl->SetName(name);
}
else
{
pl->ClearState(STATE_VISIBLE);
}
}
pl = static_cast<CLabel*>(pw->SearchControl(EVENT_LABEL13));
if ( pl != 0 )
{
if ( m_apperanceTab == 0 ) GetResource(RES_TEXT, RT_PERSO_HAIR, name);
else GetResource(RES_TEXT, RT_PERSO_BAND, name);
pl->SetName(name);
}
pl = static_cast<CLabel*>(pw->SearchControl(EVENT_LABEL14));
if ( pl != 0 )
{
if ( m_apperanceTab == 0 )
{
pl->ClearState(STATE_VISIBLE);
}
else
{
pl->SetState(STATE_VISIBLE);
GetResource(RES_TEXT, RT_PERSO_COMBI, name);
pl->SetName(name);
}
}
for ( i=0 ; i<4 ; i++ )
{
pb = static_cast<CButton*>(pw->SearchControl(static_cast<EventType>(EVENT_INTERFACE_PFACE1+i)));
if ( pb == 0 ) break;
pb->SetState(STATE_VISIBLE, m_apperanceTab==0);
pb->SetState(STATE_CHECK, i==apperance.face);
}
for ( i=0 ; i<10 ; i++ )
{
pb = static_cast<CButton*>(pw->SearchControl(static_cast<EventType>(EVENT_INTERFACE_PGLASS0+i)));
if ( pb == 0 ) break;
pb->SetState(STATE_VISIBLE, m_apperanceTab==0);
pb->SetState(STATE_CHECK, i==apperance.glasses);
}
for ( i=0 ; i<3*3 ; i++ )
{
pc = static_cast<CColor*>(pw->SearchControl(static_cast<EventType>(EVENT_INTERFACE_PC0a+i)));
if ( pc == 0 ) break;
if ( m_apperanceTab == 0 )
{
pc->ClearState(STATE_VISIBLE);
}
else
{
pc->SetState(STATE_VISIBLE);
color.r = perso_color[3*10*1+3*i+0]/255.0f;
color.g = perso_color[3*10*1+3*i+1]/255.0f;
color.b = perso_color[3*10*1+3*i+2]/255.0f;
color.a = 0.0f;
pc->SetColor(color);
pc->SetState(STATE_CHECK, EqColor(color, apperance.colorCombi));
}
pc = static_cast<CColor*>(pw->SearchControl(static_cast<EventType>(EVENT_INTERFACE_PC0b+i)));
if ( pc == 0 ) break;
color.r = perso_color[3*10*2*m_apperanceTab+3*i+0]/255.0f;
color.g = perso_color[3*10*2*m_apperanceTab+3*i+1]/255.0f;
color.b = perso_color[3*10*2*m_apperanceTab+3*i+2]/255.0f;
color.a = 0.0f;
pc->SetColor(color);
pc->SetState(STATE_CHECK, EqColor(color, m_apperanceTab?apperance.colorBand:apperance.colorHair));
}
for ( i=0 ; i<3 ; i++ )
{
ps = static_cast<CSlider*>(pw->SearchControl(static_cast<EventType>(EVENT_INTERFACE_PCRa+i)));
if ( ps == 0 ) break;
ps->SetState(STATE_VISIBLE, m_apperanceTab==1);
}
if ( m_apperanceTab == 1 )
{
color = apperance.colorCombi;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCRa));
if ( ps != 0 ) ps->SetVisibleValue(color.r*255.0f);
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCGa));
if ( ps != 0 ) ps->SetVisibleValue(color.g*255.0f);
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCBa));
if ( ps != 0 ) ps->SetVisibleValue(color.b*255.0f);
}
if ( m_apperanceTab == 0 ) color = apperance.colorHair;
else color = apperance.colorBand;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCRb));
if ( ps != 0 ) ps->SetVisibleValue(color.r*255.0f);
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCGb));
if ( ps != 0 ) ps->SetVisibleValue(color.g*255.0f);
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCBb));
if ( ps != 0 ) ps->SetVisibleValue(color.b*255.0f);
}
// Updates the camera for the character.
void CScreenApperance::CameraPerso()
{
Gfx::CCamera* camera = m_main->GetCamera();
if ( m_apperanceTab == 0 )
{
//? camera->Init(Math::Vector(4.0f, 0.0f, 0.0f),
//? Math::Vector(0.0f, 0.0f, 1.0f), 0.0f);
camera->Init(Math::Vector(6.0f, 0.0f, 0.0f),
Math::Vector(0.0f, 0.2f, 1.5f), 0.0f);
}
else
{
camera->Init(Math::Vector(18.0f, 0.0f, 4.5f),
Math::Vector(0.0f, 1.6f, 4.5f), 0.0f);
}
camera->SetType(Gfx::CAM_TYPE_SCRIPT);
camera->FixCamera();
}
// Sets a fixed color.
void CScreenApperance::FixPerso(int rank, int index)
{
PlayerApperance& apperance = m_main->GetPlayerProfile()->GetApperance();
if ( m_apperanceTab == 0 )
{
if ( index == 1 )
{
apperance.colorHair.r = perso_color[3*10*0+rank*3+0]/255.0f;
apperance.colorHair.g = perso_color[3*10*0+rank*3+1]/255.0f;
apperance.colorHair.b = perso_color[3*10*0+rank*3+2]/255.0f;
}
}
if ( m_apperanceTab == 1 )
{
if ( index == 0 )
{
apperance.colorCombi.r = perso_color[3*10*1+rank*3+0]/255.0f;
apperance.colorCombi.g = perso_color[3*10*1+rank*3+1]/255.0f;
apperance.colorCombi.b = perso_color[3*10*1+rank*3+2]/255.0f;
}
if ( index == 1 )
{
apperance.colorBand.r = perso_color[3*10*2+rank*3+0]/255.0f;
apperance.colorBand.g = perso_color[3*10*2+rank*3+1]/255.0f;
apperance.colorBand.b = perso_color[3*10*2+rank*3+2]/255.0f;
}
}
}
// Updates the color of the character.
void CScreenApperance::ColorPerso()
{
CWindow* pw;
CSlider* ps;
Gfx::Color color;
PlayerApperance& apperance = m_main->GetPlayerProfile()->GetApperance();
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
color.a = 0.0f;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCRa));
if ( ps != 0 ) color.r = ps->GetVisibleValue()/255.0f;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCGa));
if ( ps != 0 ) color.g = ps->GetVisibleValue()/255.0f;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCBa));
if ( ps != 0 ) color.b = ps->GetVisibleValue()/255.0f;
if ( m_apperanceTab == 1 ) apperance.colorCombi = color;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCRb));
if ( ps != 0 ) color.r = ps->GetVisibleValue()/255.0f;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCGb));
if ( ps != 0 ) color.g = ps->GetVisibleValue()/255.0f;
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_INTERFACE_PCBb));
if ( ps != 0 ) color.b = ps->GetVisibleValue()/255.0f;
if ( m_apperanceTab == 0 ) apperance.colorHair = color;
else apperance.colorBand = color;
}
} // namespace Ui

View File

@ -0,0 +1,46 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
namespace Ui {
class CScreenApperance : public CScreen
{
public:
CScreenApperance();
void CreateInterface();
bool EventProcess(const Event &event);
bool GetGamerOnlyHead();
float GetPersoAngle();
protected:
void UpdatePerso();
void CameraPerso();
void FixPerso(int rank, int index);
void ColorPerso();
protected:
int m_apperanceTab; // perso: tab selected
float m_apperanceAngle; // perso: angle of presentation
};
} // namespace Ui

252
src/ui/screen/screen_io.cpp Normal file
View File

@ -0,0 +1,252 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_io.h"
#include "common/logger.h"
#include "common/stringutils.h"
#include "object/level/parser.h"
#include "object/player_profile.h"
#include "object/robotmain.h"
#include "ui/screen/screen_level_list.h"
#include "ui/button.h"
#include "ui/edit.h"
#include "ui/interface.h"
#include "ui/image.h"
#include "ui/window.h"
#include <ctime>
#include <cstring>
namespace Ui {
// Builds the file name by default.
void CScreenIO::IOReadName()
{
CWindow* pw;
CEdit* pe;
std::string resume;
char line[100];
char name[100];
time_t now;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == nullptr ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_IONAME));
if ( pe == nullptr ) return;
resume = GetLevelCategoryDir(m_main->GetLevelCategory()) + " " + StrUtils::ToString<int>(m_main->GetLevelChap());
CLevelParser levelParser(m_main->GetLevelCategory(), m_main->GetLevelChap(), 0);
try
{
levelParser.Load();
resume = levelParser.Get("Title")->GetParam("resume")->AsString();
}
catch (CLevelParserException& e)
{
GetLogger()->Warn("%s\n", e.what());
}
time(&now);
TimeToAsciiClean(now, line);
sprintf(name, "%s - %s %d", line, resume.c_str(), m_main->GetLevelRank());
pe->SetText(name);
pe->SetCursor(strlen(name), 0);
m_interface->SetFocus(pe);
}
// Updates the list of games recorded on disk.
void CScreenIO::IOReadList(bool isWrite)
{
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if (pw == nullptr) return;
CList* pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
if (pl == nullptr) return;
pl->Flush();
m_saveList.clear();
for(const SavedScene& save : m_main->GetPlayerProfile()->GetSavedSceneList())
{
pl->SetItemName(m_saveList.size(), save.name.c_str());
m_saveList.push_back(save.path);
}
// invalid index
if ( isWrite )
{
std::string nameStr;
GetResource(RES_TEXT, RT_IO_NEW, nameStr);
pl->SetItemName(m_saveList.size(), nameStr.c_str());
}
pl->SetSelect(m_saveList.size());
pl->ShowSelect(false); // shows the selected columns
for (unsigned int i = 0; i < m_saveList.size(); i++)
{
m_engine->DeleteTexture(m_saveList.at(i) + "/screen.png");
}
}
// Updates the buttons according to the selected part in the list.
void CScreenIO::IOUpdateList(bool isWrite)
{
CWindow* pw;
CList* pl;
CButton* pb;
CImage* pi;
int sel, max;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == nullptr ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
if ( pl == nullptr ) return;
pi = static_cast<CImage*>(pw->SearchControl(EVENT_INTERFACE_IOIMAGE));
if ( pi == nullptr ) return;
sel = pl->GetSelect();
max = pl->GetTotal();
if (m_saveList.size() <= static_cast<unsigned int>(sel))
return;
std::string filename = m_saveList.at(sel) + "/screen.png";
if ( isWrite )
{
if ( sel < max-1 )
{
pi->SetFilenameImage(filename.c_str());
}
else
{
pi->SetFilenameImage("");
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_IODELETE));
if ( pb != nullptr )
{
pb->SetState(STATE_ENABLE, sel < max-1);
}
}
else
{
pi->SetFilenameImage(filename.c_str());
}
}
// Deletes the selected scene.
void CScreenIO::IODeleteScene()
{
CWindow* pw;
CList* pl;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
if ( pl == 0 ) return;
int sel = pl->GetSelect();
if (sel < 0 || sel >= static_cast<int>(m_saveList.size())) return;
if (!m_main->GetPlayerProfile()->DeleteScene(m_saveList.at(sel)))
{
m_sound->Play(SOUND_TZOING);
return;
}
}
// clears filename only to leave letter or numbers
std::string clearName(char *name)
{
std::string ret;
int len = strlen(name);
for (int i = 0; i < len; i++)
{
if (isalnum(name[i]))
{
ret += name[i];
}
}
return ret;
}
// Writes the scene.
void CScreenIO::IOWriteScene()
{
CWindow* pw;
CList* pl;
CEdit* pe;
char info[100];
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == nullptr ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
if ( pl == nullptr ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_IONAME));
if ( pe == nullptr ) return;
int sel = pl->GetSelect();
if ( sel == -1 ) return;
std::string dir;
pe->GetText(info, 100);
if (static_cast<unsigned int>(sel) >= m_saveList.size())
{
dir = m_main->GetPlayerProfile()->GetSaveFile("save"+clearName(info));
}
else
{
dir = m_saveList.at(sel);
}
m_main->GetPlayerProfile()->SaveScene(dir, info);
}
// Reads the scene.
void CScreenIO::IOReadScene()
{
CWindow* pw;
CList* pl;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == nullptr ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
if ( pl == nullptr ) return;
int sel = pl->GetSelect();
if (sel < 0 || sel >= static_cast<int>(m_saveList.size())) return;
m_main->GetPlayerProfile()->LoadScene(m_saveList.at(sel));
CScreenLevelList::SetSelection(m_main->GetLevelCategory(), m_main->GetLevelChap()-1, m_main->GetLevelRank()-1);
}
} // namespace Ui

42
src/ui/screen/screen_io.h Normal file
View File

@ -0,0 +1,42 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
#include <string>
#include <vector>
namespace Ui {
class CScreenIO : public CScreen
{
protected:
void IOReadName();
void IOReadList(bool isWrite);
void IOUpdateList(bool isWrite);
void IODeleteScene();
void IOWriteScene();
void IOReadScene();
protected:
std::vector<std::string> m_saveList;
};
} // namespace Ui

View File

@ -0,0 +1,170 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_io_read.h"
#include "app/app.h"
#include "ui/button.h"
#include "ui/interface.h"
#include "ui/image.h"
#include "ui/list.h"
#include "ui/window.h"
namespace Ui {
CScreenIORead::CScreenIORead(bool inSimulation)
: m_inSimulation(inSimulation)
{
}
void CScreenIORead::CreateInterface()
{
CWindow* pw;
CButton* pb;
CList* pli;
CImage* pi;
Math::Point pos, ddim;
std::string name;
pos.x = 0.10f;
pos.y = 0.10f;
ddim.x = 0.80f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 14, EVENT_WINDOW5);
pw->SetClosable(true);
GetResource(RES_TEXT, RT_TITLE_READ, name);
pw->SetName(name);
pos.x = 0.10f;
pos.y = 0.40f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.40f;
pos.y = 0.10f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
pos.x = 290.0f/640.0f;
ddim.x = 245.0f/640.0f;
pos.y = 160.0f/480.0f;
ddim.y = 190.0f/480.0f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_IOLIST);
pli->SetState(STATE_SHADOW);
pos.y = oy+sy*2;
ddim.y = dim.y*1;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_IOREAD);
pb->SetState(STATE_SHADOW);
if ( m_inSimulation )
{
pb->SetState(STATE_WARNING);
}
pos.x = 105.0f/640.0f;
pos.y = 160.0f/480.0f;
ddim.x = 170.0f/640.0f;
ddim.y = dim.y*1;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_IODELETE);
pb->SetState(STATE_SHADOW);
pos.x = 105.0f/640.0f;
pos.y = 220.0f/480.0f;
ddim.x = 170.0f/640.0f;
ddim.y = 128.0f/480.0f;
pi = pw->CreateImage(pos, ddim, 0, EVENT_INTERFACE_IOIMAGE);
pi->SetState(STATE_SHADOW);
ddim.x = dim.x*4;
ddim.y = dim.y*1;
pos.x = ox+sx*3;
pos.y = oy+sy*2;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK);
pb->SetState(STATE_SHADOW);
IOReadList(false);
IOUpdateList(false);
if ( !m_inSimulation )
{
SetBackground("textures/interface/interface.png");
}
}
bool CScreenIORead::EventProcess(const Event &event)
{
if (!m_inSimulation)
{
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return false;
if ( event.type == pw->GetEventTypeClose() ||
event.type == EVENT_INTERFACE_BACK ||
(event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) )
{
m_main->ChangePhase(PHASE_LEVEL_LIST);
return false;
}
}
else
{
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return false;
if ( event.type == pw->GetEventTypeClose() ||
event.type == EVENT_INTERFACE_BACK ||
(event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) )
{
m_interface->DeleteControl(EVENT_WINDOW5);
m_main->ChangePhase(PHASE_SIMUL);
m_main->StopSuspend();
return false;
}
}
if ( event.type == EVENT_INTERFACE_IOLIST )
{
IOUpdateList(false);
return false;
}
if ( event.type == EVENT_INTERFACE_IODELETE )
{
IODeleteScene();
IOReadList(false);
IOUpdateList(false);
return false;
}
if ( event.type == EVENT_INTERFACE_IOREAD )
{
IOReadScene();
if(m_inSimulation)
{
m_main->StopSuspend();
m_main->ChangePhase(PHASE_LOADING);
}
return false;
}
return true;
}
} // namespace Ui

View File

@ -0,0 +1,36 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen_io.h"
namespace Ui {
class CScreenIORead : public CScreenIO
{
public:
CScreenIORead(bool inSimulation);
void CreateInterface();
bool EventProcess(const Event &event);
protected:
bool m_inSimulation;
};
} // namespace Ui

View File

@ -0,0 +1,160 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_io_write.h"
#include "app/app.h"
#include "ui/button.h"
#include "ui/edit.h"
#include "ui/interface.h"
#include "ui/image.h"
#include "ui/label.h"
#include "ui/list.h"
#include "ui/window.h"
namespace Ui {
CScreenIOWrite::CScreenIOWrite()
{
}
void CScreenIOWrite::CreateInterface()
{
CWindow* pw;
CButton* pb;
CList* pli;
CLabel* pl;
CImage* pi;
CEdit* pe;
Math::Point pos, ddim;
std::string name;
pos.x = 0.10f;
pos.y = 0.10f;
ddim.x = 0.80f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 13, EVENT_WINDOW5);
pw->SetClosable(true);
GetResource(RES_TEXT, RT_TITLE_WRITE, name);
pw->SetName(name);
pos.x = 0.10f;
pos.y = 0.40f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.40f;
pos.y = 0.10f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
pos.x = 290.0f/640.0f;
ddim.x = 245.0f/640.0f;
pos.y = 146.0f/480.0f;
ddim.y = 18.0f/480.0f;
GetResource(RES_EVENT, EVENT_INTERFACE_IOLABEL, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_INTERFACE_IOLABEL, name);
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.y = 130.0f/480.0f;
ddim.y = 18.0f/480.0f;
pe = pw->CreateEdit(pos, ddim, 0, EVENT_INTERFACE_IONAME);
pe->SetState(STATE_SHADOW);
pe->SetFontType(Gfx::FONT_COLOBOT);
pe->SetMaxChar(35);
IOReadName();
pos.y = 190.0f/480.0f;
ddim.y = 190.0f/480.0f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_IOLIST);
pli->SetState(STATE_SHADOW);
pos.y = oy+sy*2;
ddim.y = dim.y*1;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_IOWRITE);
pb->SetState(STATE_SHADOW);
pos.x = 105.0f/640.0f;
pos.y = 190.0f/480.0f;
ddim.x = 170.0f/640.0f;
ddim.y = dim.y*1;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_IODELETE);
pb->SetState(STATE_SHADOW);
pos.x = 105.0f/640.0f;
pos.y = 250.0f/480.0f;
ddim.x = 170.0f/640.0f;
ddim.y = 128.0f/480.0f;
pi = pw->CreateImage(pos, ddim, 0, EVENT_INTERFACE_IOIMAGE);
pi->SetState(STATE_SHADOW);
ddim.x = dim.x*4;
ddim.y = dim.y*1;
pos.x = ox+sx*3;
pos.y = oy+sy*2;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK);
pb->SetState(STATE_SHADOW);
IOReadList(true);
IOUpdateList(true);
}
bool CScreenIOWrite::EventProcess(const Event &event)
{
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return false;
if ( event.type == pw->GetEventTypeClose() ||
event.type == EVENT_INTERFACE_BACK ||
(event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) )
{
m_interface->DeleteControl(EVENT_WINDOW5);
m_main->ChangePhase(PHASE_SIMUL);
m_main->StopSuspend();
return false;
}
if ( event.type == EVENT_INTERFACE_IOLIST )
{
IOUpdateList(true);
return false;
}
if ( event.type == EVENT_INTERFACE_IODELETE )
{
IODeleteScene();
IOReadList(true);
IOUpdateList(true);
return false;
}
if ( event.type == EVENT_INTERFACE_IOWRITE )
{
IOWriteScene();
m_interface->DeleteControl(EVENT_WINDOW5);
m_main->ChangePhase(PHASE_SIMUL);
m_main->StopSuspend();
return false;
}
return true;
}
} // namespace Ui

View File

@ -0,0 +1,33 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen_io.h"
namespace Ui {
class CScreenIOWrite : public CScreenIO
{
public:
CScreenIOWrite();
void CreateInterface();
bool EventProcess(const Event &event);
};
} // namespace Ui

View File

@ -0,0 +1,598 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_level_list.h"
#include "app/app.h"
#include "common/resources/resourcemanager.h"
#include "common/settings.h"
#include "object/level/parser.h"
#include "object/player_profile.h"
#include "ui/button.h"
#include "ui/check.h"
#include "ui/edit.h"
#include "ui/interface.h"
#include "ui/label.h"
#include "ui/list.h"
#include "ui/window.h"
namespace Ui {
LevelCategory CScreenLevelList::m_category;
LevelCategory CScreenLevelList::m_listCategory = LevelCategory::Missions;
std::map<LevelCategory, int> CScreenLevelList::m_chap;
std::map<LevelCategory, int> CScreenLevelList::m_sel;
int CScreenLevelList::m_maxList = 0;
bool CScreenLevelList::m_bSceneSoluce = 0;
std::vector<std::string> CScreenLevelList::m_customLevelList;
CScreenLevelList::CScreenLevelList(LevelCategory category)
{
m_category = category;
if ( static_cast<int>(m_category) >= static_cast<int>(LevelCategory::Max) )
{
m_category = m_listCategory;
}
else
{
m_listCategory = m_category;
}
}
void CScreenLevelList::CreateInterface()
{
CWindow* pw;
CEdit* pe;
CLabel* pl;
CButton* pb;
CCheck* pc;
CList* pli;
Math::Point pos, ddim;
int res;
std::string name;
if ( m_category == LevelCategory::FreeGame )
{
m_accessChap = m_main->GetPlayerProfile()->GetChapPassed(LevelCategory::Missions);
}
pos.x = 0.10f;
pos.y = 0.10f;
ddim.x = 0.80f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 12, EVENT_WINDOW5);
pw->SetClosable(true);
if ( m_category == LevelCategory::Exercises ) res = RT_TITLE_TRAINER;
if ( m_category == LevelCategory::Challenges ) res = RT_TITLE_DEFI;
if ( m_category == LevelCategory::Missions ) res = RT_TITLE_MISSION;
if ( m_category == LevelCategory::FreeGame ) res = RT_TITLE_FREE;
if ( m_category == LevelCategory::CustomLevels ) res = RT_TITLE_USER;
GetResource(RES_TEXT, res, name);
pw->SetName(name);
pos.x = 0.10f;
pos.y = 0.40f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.40f;
pos.y = 0.10f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
// Displays a list of chapters:
pos.x = ox+sx*3;
pos.y = oy+sy*10.5f;
ddim.x = dim.x*7.5f;
ddim.y = dim.y*0.6f;
if ( m_category == LevelCategory::Exercises ) res = RT_PLAY_CHAPt;
if ( m_category == LevelCategory::Challenges ) res = RT_PLAY_CHAPd;
if ( m_category == LevelCategory::Missions ) res = RT_PLAY_CHAPm;
if ( m_category == LevelCategory::FreeGame ) res = RT_PLAY_CHAPf;
if ( m_category == LevelCategory::CustomLevels ) res = RT_PLAY_CHAPu;
GetResource(RES_TEXT, res, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL11, name);
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.y = oy+sy*6.7f;
ddim.y = dim.y*4.5f;
ddim.x = dim.x*6.5f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_CHAP);
pli->SetState(STATE_SHADOW);
m_chap[m_category] = m_main->GetPlayerProfile()->GetSelectedChap(m_category)-1;
UpdateSceneChap(m_chap[m_category]);
if ( m_category != LevelCategory::CustomLevels ) pli->SetState(STATE_EXTEND);
// Displays a list of missions:
pos.x = ox+sx*9.5f;
pos.y = oy+sy*10.5f;
ddim.x = dim.x*7.5f;
ddim.y = dim.y*0.6f;
if ( m_category == LevelCategory::Exercises ) res = RT_PLAY_LISTt;
if ( m_category == LevelCategory::Challenges ) res = RT_PLAY_LISTd;
if ( m_category == LevelCategory::Missions ) res = RT_PLAY_LISTm;
if ( m_category == LevelCategory::FreeGame ) res = RT_PLAY_LISTf;
if ( m_category == LevelCategory::CustomLevels ) res = RT_PLAY_LISTu;
GetResource(RES_TEXT, res, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL12, name);
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.y = oy+sy*6.7f;
ddim.y = dim.y*4.5f;
ddim.x = dim.x*6.5f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_LIST);
pli->SetState(STATE_SHADOW);
m_sel[m_category] = m_main->GetPlayerProfile()->GetSelectedRank(m_category)-1;
UpdateSceneList(m_chap[m_category], m_sel[m_category]);
if ( m_category != LevelCategory::CustomLevels ) pli->SetState(STATE_EXTEND);
pos = pli->GetPos();
ddim = pli->GetDim();
// Displays the summary:
pos.x = ox+sx*3;
pos.y = oy+sy*5.4f;
ddim.x = dim.x*6.5f;
ddim.y = dim.y*0.6f;
GetResource(RES_TEXT, RT_PLAY_RESUME, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL13, name);
pl->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
pos.x = ox+sx*3;
pos.y = oy+sy*3.6f;
ddim.x = dim.x*13.4f;
ddim.y = dim.y*1.9f;
pe = pw->CreateEdit(pos, ddim, 0, EVENT_INTERFACE_RESUME);
pe->SetState(STATE_SHADOW);
pe->SetMaxChar(500);
pe->SetEditCap(false); // just to see
pe->SetHighlightCap(false);
// Button displays the "soluce":
if ( m_category != LevelCategory::Exercises &&
m_category != LevelCategory::FreeGame )
{
pos.x = ox+sx*9.5f;
pos.y = oy+sy*5.8f;
ddim.x = dim.x*6.5f;
ddim.y = dim.y*0.5f;
pc = pw->CreateCheck(pos, ddim, -1, EVENT_INTERFACE_SOLUCE);
pc->SetState(STATE_SHADOW);
pc->ClearState(STATE_CHECK);
}
m_bSceneSoluce = false;
UpdateSceneResume(m_chap[m_category]+1, m_sel[m_category]+1);
if ( m_category == LevelCategory::Missions ||
m_category == LevelCategory::FreeGame ||
m_category == LevelCategory::CustomLevels )
{
pos.x = ox+sx*9.5f;
pos.y = oy+sy*2;
ddim.x = dim.x*3.7f;
ddim.y = dim.y*1;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PLAY);
pb->SetState(STATE_SHADOW);
if ( m_maxList == 0 )
{
pb->ClearState(STATE_ENABLE);
}
pos.x += dim.x*4.0f;
ddim.x = dim.x*2.5f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_READ);
pb->SetState(STATE_SHADOW);
if ( !m_main->GetPlayerProfile()->HasAnySavedScene() ) // no file to read?
{
pb->ClearState(STATE_ENABLE);
}
}
else
{
pos.x = ox+sx*9.5f;
pos.y = oy+sy*2;
ddim.x = dim.x*6.5f;
ddim.y = dim.y*1;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PLAY);
pb->SetState(STATE_SHADOW);
if ( m_maxList == 0 )
{
pb->ClearState(STATE_ENABLE);
}
}
pos.x = ox+sx*3;
ddim.x = dim.x*4;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_BACK);
pb->SetState(STATE_SHADOW);
SetBackground("textures/interface/interface.png");
}
bool CScreenLevelList::EventProcess(const Event &event)
{
CWindow* pw;
CList* pl;
CButton* pb;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return false;
if ( event.type == pw->GetEventTypeClose() ||
event.type == EVENT_INTERFACE_BACK ||
(event.type == EVENT_KEY_DOWN && event.key.key == KEY(ESCAPE)) )
{
m_main->ChangePhase(PHASE_MAIN_MENU);
return false;
}
switch( event.type )
{
case EVENT_INTERFACE_CHAP:
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_CHAP));
if ( pl == 0 ) break;
m_chap[m_category] = pl->GetSelect();
m_main->GetPlayerProfile()->SetSelectedChap(m_category, m_chap[m_category]+1);
UpdateSceneList(m_chap[m_category], m_sel[m_category]);
UpdateSceneResume(m_chap[m_category]+1, m_sel[m_category]+1);
break;
case EVENT_INTERFACE_LIST:
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_LIST));
if ( pl == 0 ) break;
m_sel[m_category] = pl->GetSelect();
m_main->GetPlayerProfile()->SetSelectedRank(m_category, m_sel[m_category]+1);
UpdateSceneResume(m_chap[m_category]+1, m_sel[m_category]+1);
break;
case EVENT_INTERFACE_SOLUCE:
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_SOLUCE));
if ( pb == 0 ) break;
m_bSceneSoluce = !m_bSceneSoluce;
pb->SetState(STATE_CHECK, m_bSceneSoluce);
break;
case EVENT_INTERFACE_PLAY:
m_main->SetLevel(m_category, m_chap[m_category]+1, m_sel[m_category]+1);
m_main->ChangePhase(PHASE_LOADING);
break;
case EVENT_INTERFACE_READ:
m_main->ChangePhase(PHASE_READ);
break;
default:
return true;
}
return false;
}
void CScreenLevelList::SetSelection(LevelCategory category, int chap, int rank)
{
m_chap[category] = chap;
m_sel[category] = rank;
}
// Updates the lists according to the cheat code.
void CScreenLevelList::AllMissionUpdate()
{
UpdateSceneChap(m_chap[m_category]);
UpdateSceneList(m_chap[m_category], m_sel[m_category]);
}
// Whether to show the solution.
bool CScreenLevelList::GetSceneSoluce()
{
return m_bSceneSoluce;
}
// Updates the chapters of exercises or missions.
void CScreenLevelList::UpdateSceneChap(int &chap)
{
CWindow* pw;
CList* pl;
std::string fileName;
char line[500];
bool bPassed;
memset(line, 0, 500);
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_CHAP));
if ( pl == 0 ) return;
pl->Flush();
unsigned int j;
if ( m_category == LevelCategory::CustomLevels )
{
UpdateCustomLevelList();
for ( j=0 ; j<m_customLevelList.size() ; j++ )
{
try
{
CLevelParser levelParser("custom", j+1, 0);
levelParser.Load();
pl->SetItemName(j, levelParser.Get("Title")->GetParam("text")->AsString().c_str());
pl->SetEnable(j, true);
}
catch (CLevelParserException& e)
{
pl->SetItemName(j, (std::string("[ERROR]: ")+e.what()).c_str());
pl->SetEnable(j, false);
}
}
}
else
{
for ( j=0 ; j<MAXSCENE ; j++ )
{
CLevelParser levelParser(m_category, j+1, 0);
if (!levelParser.Exists())
break;
try
{
levelParser.Load();
sprintf(line, "%d: %s", j+1, levelParser.Get("Title")->GetParam("text")->AsString().c_str());
}
catch (CLevelParserException& e)
{
sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str());
}
bPassed = m_main->GetPlayerProfile()->GetLevelPassed(m_category, j+1, 0);
pl->SetItemName(j, line);
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
if ( m_category == LevelCategory::Missions && !m_main->GetShowAll() && !bPassed )
{
j ++;
break;
}
if ( m_category == LevelCategory::FreeGame && j == m_accessChap )
{
j ++;
break;
}
}
}
if ( chap > j-1 ) chap = j-1;
pl->SetSelect(chap);
pl->ShowSelect(false); // shows the selected columns
}
// Updates the list of exercises or missions.
void CScreenLevelList::UpdateSceneList(int chap, int &sel)
{
CWindow* pw;
CList* pl;
std::string fileName;
char line[500];
int j;
bool bPassed;
memset(line, 0, 500);
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_LIST));
if ( pl == 0 ) return;
pl->Flush();
bool readAll = true;
for ( j=0 ; j<MAXSCENE ; j++ )
{
CLevelParser levelParser(m_category, chap+1, j+1);
if (!levelParser.Exists())
{
readAll = true;
break;
}
else
{
if (!readAll)
break;
}
try
{
levelParser.Load();
sprintf(line, "%d: %s", j+1, levelParser.Get("Title")->GetParam("text")->AsString().c_str());
}
catch (CLevelParserException& e)
{
sprintf(line, "%s", (std::string("[ERROR]: ")+e.what()).c_str());
}
bPassed = m_main->GetPlayerProfile()->GetLevelPassed(m_category, chap+1, j+1);
pl->SetItemName(j, line);
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
if ( m_category == LevelCategory::Missions && !m_main->GetShowAll() && !bPassed )
{
readAll = false;
}
}
if (readAll)
{
m_maxList = j;
}
else
{
m_maxList = j+1; // this is not the last!
}
if ( sel > j-1 ) sel = j-1;
pl->SetSelect(sel);
pl->ShowSelect(false); // shows the selected columns
}
// Updates the button "solution" according to cheat code.
void CScreenLevelList::ShowSoluceUpdate()
{
CWindow* pw;
CEdit* pe;
CCheck* pc;
m_bSceneSoluce = false;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_RESUME));
if ( pe == 0 ) return;
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_SOLUCE));
if ( pc == 0 ) return;
if ( m_main->GetShowSoluce() )
{
pc->SetState(STATE_VISIBLE);
pc->SetState(STATE_CHECK);
m_bSceneSoluce = true;
}
else
{
pc->ClearState(STATE_VISIBLE);
pc->ClearState(STATE_CHECK);
m_bSceneSoluce = false;
}
}
// Updates a summary of exercise or mission.
void CScreenLevelList::UpdateSceneResume(int chap, int rank)
{
CWindow* pw;
CEdit* pe;
CCheck* pc;
std::string fileName;
int numTry;
bool bPassed, bVisible;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_RESUME));
if ( pe == 0 ) return;
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_SOLUCE));
if ( pc == 0 )
{
m_bSceneSoluce = false;
}
else
{
numTry = m_main->GetPlayerProfile()->GetLevelTryCount(m_category, chap, rank);
bPassed = m_main->GetPlayerProfile()->GetLevelPassed(m_category, chap, rank);
bVisible = ( numTry > 2 || bPassed || m_main->GetShowSoluce() );
if ( !CSettings::GetInstancePointer()->GetSoluce4() ) bVisible = false;
pc->SetState(STATE_VISIBLE, bVisible);
if ( !bVisible )
{
pc->ClearState(STATE_CHECK);
m_bSceneSoluce = false;
}
}
if(chap == 0 || rank == 0) return;
try
{
CLevelParser levelParser(m_category, chap, rank);
levelParser.Load();
pe->SetText(levelParser.Get("Resume")->GetParam("text")->AsString().c_str());
}
catch (CLevelParserException& e)
{
pe->SetText((std::string("[ERROR]: ")+e.what()).c_str());
}
}
void CScreenLevelList::UpdateChapterPassed()
{
// TODO: CScreenLevelList is a bad place for this function
bool bAll = true;
for ( int i=0 ; i<m_maxList ; i++ )
{
if (!m_main->GetPlayerProfile()->GetLevelPassed(m_category, m_chap[m_category]+1, i+1))
{
bAll = false;
break;
}
}
m_main->GetPlayerProfile()->IncrementLevelTryCount(m_category, m_chap[m_category]+1, 0);
m_main->GetPlayerProfile()->SetLevelPassed(m_category, m_chap[m_category]+1, 0, bAll);
}
// Passes to the next mission, and possibly in the next chapter.
void CScreenLevelList::NextMission()
{
m_sel[m_category] ++; // next mission
if ( m_sel[m_category] >= m_maxList ) // last mission of the chapter?
{
m_chap[m_category] ++; // next chapter
m_sel[m_category] = 0; // first mission
}
m_main->GetPlayerProfile()->SetSelectedChap(m_category, m_chap[m_category]+1);
m_main->GetPlayerProfile()->SetSelectedRank(m_category, m_sel[m_category]+1);
}
// TODO: Separate class for userlevels?
void CScreenLevelList::UpdateCustomLevelList()
{
auto userLevelDirs = CResourceManager::ListDirectories("levels/custom/");
std::sort(userLevelDirs.begin(), userLevelDirs.end());
m_customLevelList = userLevelDirs;
}
std::string CScreenLevelList::GetCustomLevelName(int id)
{
if(id < 1 || id > m_customLevelList.size()) return "";
return m_customLevelList[id-1];
}
const std::vector<std::string>& CScreenLevelList::GetCustomLevelList()
{
return m_customLevelList;
}
} // namespace Ui

View File

@ -0,0 +1,71 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
#include "object/level_category.h"
#include <map>
#include <vector>
namespace Ui {
class CScreenLevelList : public CScreen
{
public:
CScreenLevelList(LevelCategory category);
void CreateInterface();
bool EventProcess(const Event &event);
static void SetSelection(LevelCategory category, int chap, int rank);
static bool GetSceneSoluce();
void AllMissionUpdate();
void ShowSoluceUpdate();
static void UpdateChapterPassed();
static void NextMission();
static void UpdateCustomLevelList();
static std::string GetCustomLevelName(int id);
static const std::vector<std::string>& GetCustomLevelList();
protected:
void UpdateSceneChap(int &chap);
void UpdateSceneList(int chap, int &sel);
void UpdateSceneResume(int chap, int rank);
protected:
static LevelCategory m_category;
static LevelCategory m_listCategory;
static bool m_bSceneSoluce;
static std::map<LevelCategory, int> m_chap; // selected chapter (0..8)
static std::map<LevelCategory, int> m_sel; // chosen mission (0..98)
static int m_maxList;
static std::vector<std::string> m_customLevelList;
int m_accessChap;
};
} // namespace Ui

View File

@ -0,0 +1,93 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_loading.h"
#include "app/app.h"
#include "ui/button.h"
#include "ui/edit.h"
#include "ui/interface.h"
#include "ui/label.h"
#include "ui/window.h"
namespace Ui {
CScreenLoading::CScreenLoading()
{
}
void CScreenLoading::CreateInterface()
{
CWindow* pw;
CLabel* pl;
CGroup* pg;
Math::Point pos, ddim;
std::string name;
pos.x = 0.35f;
pos.y = 0.10f;
ddim.x = 0.30f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 10, EVENT_WINDOW5);
pw->SetName(" ");
pos.x = 0.35f;
pos.y = 0.60f;
ddim.x = 0.30f;
ddim.y = 0.30f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.35f;
pos.y = 0.10f;
ddim.x = 0.30f;
ddim.y = 0.30f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
pos.x = 254.0f/640.0f;
pos.y = 208.0f/480.0f;
ddim.x = 132.0f/640.0f;
ddim.y = 42.0f/480.0f;
pg = pw->CreateGroup(pos, ddim, 22, EVENT_NULL);
pg->SetState(STATE_SHADOW);
pos.x = 220.0f/640.0f;
pos.y = 210.0f/480.0f;
ddim.x = 200.0f/640.0f;
ddim.y = 20.0f/480.0f;
GetResource(RES_TEXT, RT_DIALOG_LOADING, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name);
pl->SetFontSize(12.0f);
pl->SetTextAlign(Gfx::TEXT_ALIGN_CENTER);
SetBackground("textures/interface/interface.png");
m_loadingCounter = 1; // enough time to display!
}
bool CScreenLoading::EventProcess(const Event &event)
{
if ( m_loadingCounter == 0 )
{
m_main->ChangePhase(PHASE_SIMUL);
}
m_loadingCounter --;
return true;
}
} // namespace Ui

View File

@ -0,0 +1,36 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
namespace Ui {
class CScreenLoading : public CScreen
{
public:
CScreenLoading();
void CreateInterface();
bool EventProcess(const Event &event);
protected:
int m_loadingCounter;
};
} // namespace Ui

View File

@ -0,0 +1,221 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_main_menu.h"
#include "app/app.h"
#include "common/logger.h"
#include "object/level/parser.h"
#include "ui/screen/screen_setup.h"
#include "ui/button.h"
#include "ui/group.h"
#include "ui/interface.h"
#include "ui/label.h"
#include "ui/window.h"
namespace Ui {
CScreenMainMenu::CScreenMainMenu()
{
}
void CScreenMainMenu::CreateInterface()
{
CWindow* pw;
CLabel* pl;
CButton* pb;
CGroup* pg;
Math::Point pos, ddim;
std::string name;
pos.x = 0.35f;
pos.y = 0.10f;
ddim.x = 0.30f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 10, EVENT_WINDOW5);
GetResource(RES_TEXT, RT_TITLE_INIT, name);
pw->SetName(name);
pos.x = 0.35f;
pos.y = 0.60f;
ddim.x = 0.30f;
ddim.y = 0.30f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.35f;
pos.y = 0.10f;
ddim.x = 0.30f;
ddim.y = 0.30f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
ddim.x = 0.20f;
ddim.y = dim.y*2.4f;
pos.x = 0.40f;
pos.y = oy+sy*9.1f;
pg = pw->CreateGroup(pos, ddim, 23, EVENT_LABEL1); // yellow
pg->SetState(STATE_SHADOW);
pos.y = oy+sy*6.8f;
pg = pw->CreateGroup(pos, ddim, 24, EVENT_LABEL1); // orange
pg->SetState(STATE_SHADOW);
pos.y = oy+sy*3.9f;
pg = pw->CreateGroup(pos, ddim, 25, EVENT_LABEL1); // orange
pg->SetState(STATE_SHADOW);
ddim.y = dim.y*1.2f;
pos.y = oy+sy*1.9f;
pg = pw->CreateGroup(pos, ddim, 26, EVENT_LABEL1); // red
pg->SetState(STATE_SHADOW);
ddim.x = 0.18f;
ddim.y = dim.y*1;
pos.x = 0.41f;
pos.y = oy+sy*10.3f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_MISSION);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*9.2f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_FREE);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*8.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_TRAINER);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*6.9f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_DEFI);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*5.1f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_SETUP);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*4.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_NAME);
pb->SetState(STATE_SHADOW);
pos.y = oy+sy*2.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_QUIT);
pb->SetState(STATE_SHADOW);
pos.x = 447.0f/640.0f;
pos.y = 313.0f/480.0f;
ddim.x = 0.09f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_USER);
pb->SetState(STATE_SHADOW);
try
{
CLevelParser levelParser("levels/custom/config.txt");
if (levelParser.Exists())
{
levelParser.Load();
CLevelParserLine* line = levelParser.Get("Button");
if (line->GetParam("name")->IsDefined())
pb->SetName(line->GetParam("name")->AsString());
if (line->GetParam("tooltip")->IsDefined())
pb->SetTooltip(line->GetParam("tooltip")->AsString());
}
}
catch (CLevelParserException& e)
{
GetLogger()->Error("Failed loading userlevel button name: %s\n", e.what());
}
/*pos.x = 139.0f/640.0f;
pos.y = 313.0f/480.0f;
ddim.x = 0.09f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PROTO);
pb->SetState(STATE_SHADOW);*/
pos.x = 0.40f;
ddim.x = 0.20f;
pos.y = 26.0f/480.0f;
ddim.y = 12.0f/480.0f;
pg = pw->CreateGroup(pos, ddim, 1, EVENT_LABEL1);
pg->SetState(STATE_SHADOW);
pos.y -= 5.0f/480.0f;
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, "TerranovaTeam");
pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
SetBackground("textures/interface/interface.png");
}
bool CScreenMainMenu::EventProcess(const Event &event)
{
switch( event.type )
{
case EVENT_KEY_DOWN:
if ( event.key.key == KEY(ESCAPE) )
{
m_sound->Play(SOUND_TZOING);
m_main->ChangePhase(PHASE_QUIT_SCREEN);
return false;
}
return true;
break;
case EVENT_INTERFACE_QUIT:
m_sound->Play(SOUND_TZOING);
m_main->ChangePhase(PHASE_QUIT_SCREEN);
break;
case EVENT_INTERFACE_TRAINER:
m_main->SetLevel(LevelCategory::Exercises, 0, 0);
m_main->ChangePhase(PHASE_LEVEL_LIST);
break;
case EVENT_INTERFACE_DEFI:
m_main->SetLevel(LevelCategory::Challenges, 0, 0);
m_main->ChangePhase(PHASE_LEVEL_LIST);
break;
case EVENT_INTERFACE_MISSION:
m_main->SetLevel(LevelCategory::Missions, 0, 0);
m_main->ChangePhase(PHASE_LEVEL_LIST);
break;
case EVENT_INTERFACE_FREE:
m_main->SetLevel(LevelCategory::FreeGame, 0, 0);
m_main->ChangePhase(PHASE_LEVEL_LIST);
break;
case EVENT_INTERFACE_USER:
m_main->SetLevel(LevelCategory::CustomLevels, 0, 0);
m_main->ChangePhase(PHASE_LEVEL_LIST);
break;
case EVENT_INTERFACE_SETUP:
m_main->ChangePhase(CScreenSetup::GetSetupTab());
break;
case EVENT_INTERFACE_NAME:
m_main->ChangePhase(PHASE_PLAYER_SELECT);
break;
default:
return true;
}
return false;
}
} // namespace Ui

View File

@ -0,0 +1,33 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
namespace Ui {
class CScreenMainMenu : public CScreen
{
public:
CScreenMainMenu();
void CreateInterface();
bool EventProcess(const Event &event);
};
} // namespace Ui

View File

@ -0,0 +1,457 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_player_select.h"
#include "app/app.h"
#include "common/logger.h"
#include "object/player_profile.h"
#include "ui/button.h"
#include "ui/edit.h"
#include "ui/interface.h"
#include "ui/label.h"
#include "ui/list.h"
#include "ui/maindialog.h"
#include "ui/window.h"
namespace Ui {
CScreenPlayerSelect::CScreenPlayerSelect()
{
}
void CScreenPlayerSelect::CreateInterface()
{
CWindow* pw;
CEdit* pe;
CLabel* pl;
CButton* pb;
CList* pli;
CGroup* pg;
Math::Point pos, ddim;
std::string name;
pos.x = 0.10f;
pos.y = 0.10f;
ddim.x = 0.80f;
ddim.y = 0.80f;
pw = m_interface->CreateWindows(pos, ddim, 12, EVENT_WINDOW5);
GetResource(RES_TEXT, RT_TITLE_NAME, name);
pw->SetName(name);
pos.x = 0.10f;
pos.y = 0.40f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 5, EVENT_INTERFACE_GLINTl); // orange corner
pos.x = 0.40f;
pos.y = 0.10f;
ddim.x = 0.50f;
ddim.y = 0.50f;
pw->CreateGroup(pos, ddim, 4, EVENT_INTERFACE_GLINTr); // blue corner
pos.x = 60.0f/640.0f;
pos.y = 313.0f/480.0f;
ddim.x = 120.0f/640.0f;
ddim.y = 32.0f/480.0f;
GetResource(RES_EVENT, EVENT_INTERFACE_NLABEL, name);
pl = pw->CreateLabel(pos, ddim, -1, EVENT_INTERFACE_NLABEL, name);
pl->SetTextAlign(Gfx::TEXT_ALIGN_RIGHT);
pos.x = 200.0f/640.0f;
pos.y = 320.0f/480.0f;
ddim.x = 160.0f/640.0f;
ddim.y = 32.0f/480.0f;
pg = pw->CreateGroup(pos, ddim, 7, EVENT_LABEL1);
pg->SetState(STATE_SHADOW);
pos.x = 207.0f/640.0f;
pos.y = 328.0f/480.0f;
ddim.x = 144.0f/640.0f;
ddim.y = 18.0f/480.0f;
pe = pw->CreateEdit(pos, ddim, 0, EVENT_INTERFACE_NEDIT);
pe->SetMaxChar(15);
if(m_main->GetPlayerProfile() != nullptr)
{
name = m_main->GetPlayerProfile()->GetName();
}
else
{
name = CPlayerProfile::GetLastName();
}
pe->SetText(name.c_str());
pe->SetCursor(name.length(), 0);
m_interface->SetFocus(pe);
pos.x = 380.0f/640.0f;
pos.y = 320.0f/480.0f;
ddim.x =100.0f/640.0f;
ddim.y = 32.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_NOK);
pb->SetState(STATE_SHADOW);
pos.x = 380.0f/640.0f;
pos.y = 250.0f/480.0f;
ddim.x =100.0f/640.0f;
ddim.y = 52.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_PERSO);
pb->SetState(STATE_SHADOW);
pos.x = 200.0f/640.0f;
pos.y = 150.0f/480.0f;
ddim.x = 160.0f/640.0f;
ddim.y = 160.0f/480.0f;
pli = pw->CreateList(pos, ddim, 0, EVENT_INTERFACE_NLIST);
pli->SetState(STATE_SHADOW);
pos.x = 200.0f/640.0f;
pos.y = 100.0f/480.0f;
ddim.x = 160.0f/640.0f;
ddim.y = 32.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_NDELETE);
pb->SetState(STATE_SHADOW);
pos.x = 380.0f/640.0f;
pos.y = 100.0f/480.0f;
ddim.x =100.0f/640.0f;
ddim.y = 32.0f/480.0f;
pb = pw->CreateButton(pos, ddim, -1, EVENT_INTERFACE_NCANCEL);
pb->SetState(STATE_SHADOW);
ReadNameList();
UpdateNameList();
UpdateNameControl();
SetBackground("textures/interface/interface.png");
}
bool CScreenPlayerSelect::EventProcess(const Event &event)
{
CWindow* pw;
CButton* pb;
CList* pl;
switch( event.type )
{
case EVENT_KEY_DOWN:
if ( event.key.key == KEY(RETURN) )
{
NameSelect();
}
if ( event.key.key == KEY(ESCAPE) )
{
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) break;
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NCANCEL));
if ( pb == 0 ) break;
if ( pb->TestState(STATE_ENABLE) )
{
m_main->ChangePhase(PHASE_MAIN_MENU);
}
}
break;
case EVENT_INTERFACE_NEDIT:
UpdateNameList();
UpdateNameControl();
break;
case EVENT_INTERFACE_NLIST:
UpdateNameEdit();
break;
case EVENT_INTERFACE_NOK:
NameSelect();
break;
case EVENT_INTERFACE_PERSO:
NameSelect();
m_main->ChangePhase(PHASE_APPERANCE);
break;
case EVENT_INTERFACE_NCANCEL:
m_main->ChangePhase(PHASE_MAIN_MENU);
break;
case EVENT_INTERFACE_NDELETE:
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) break;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) break;
CMainDialog::GetInstancePointer()->StartDeleteGame(pl->GetItemName(pl->GetSelect()));
break;
default:
return true;
}
return false;
}
// Updates the list of players after checking the files on disk.
void CScreenPlayerSelect::ReadNameList()
{
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if (pw == nullptr) return;
CList* pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if (pl == nullptr) return;
pl->Flush();
auto players = CPlayerProfile::GetPlayerList();
for (int i = 0; i < static_cast<int>(players.size()); ++i)
{
pl->SetItemName(i, players.at(i).c_str());
}
}
// Updates the controls of the players.
void CScreenPlayerSelect::UpdateNameControl()
{
CWindow* pw;
CList* pl;
CButton* pb;
CEdit* pe;
char name[100];
int total, sel;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == 0 ) return;
std::string gamer = m_main->GetPlayerProfile()->GetName();
total = pl->GetTotal();
sel = pl->GetSelect();
pe->GetText(name, 100);
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NCANCEL));
if ( pb != 0 )
{
pb->SetState(STATE_ENABLE, !gamer.empty());
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NDELETE));
if ( pb != 0 )
{
pb->SetState(STATE_ENABLE, total>0 && sel!=-1);
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_NOK));
if ( pb != 0 )
{
pb->SetState(STATE_ENABLE, name[0]!=0 || sel!=-1);
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_PERSO));
if ( pb != 0 )
{
pb->SetState(STATE_ENABLE, name[0]!=0 || sel!=-1);
}
}
// Updates the list of players by name frape.
void CScreenPlayerSelect::UpdateNameList()
{
CWindow* pw;
CList* pl;
CEdit* pe;
char name[100];
int total, i;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == 0 ) return;
pe->GetText(name, 100);
total = pl->GetTotal();
for ( i=0 ; i<total ; i++ )
{
// TODO: stricmp?
if ( strcmp(name, pl->GetItemName(i)) == 0 )
{
pl->SetSelect(i);
pl->ShowSelect(false);
return;
}
}
pl->SetSelect(-1);
}
// Updates the player's name and function of the selected list.
void CScreenPlayerSelect::UpdateNameEdit()
{
CWindow* pw;
CList* pl;
CEdit* pe;
char* name;
int sel;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == 0 ) return;
sel = pl->GetSelect();
if ( sel == -1 )
{
pe->SetText("");
pe->SetCursor(0, 0);
}
else
{
name = pl->GetItemName(sel);
pe->SetText(name);
pe->SetCursor(strlen(name), 0);
}
UpdateNameControl();
}
// Selects a player.
void CScreenPlayerSelect::NameSelect()
{
CWindow* pw;
CList* pl;
CEdit* pe;
char name[100];
int sel;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == 0 ) return;
pe->GetText(name, 100);
sel = pl->GetSelect();
if ( sel == -1 )
{
NameCreate();
}
else
{
m_main->SelectPlayer(pl->GetItemName(sel));
}
m_main->ChangePhase(PHASE_MAIN_MENU);
}
// Creates a new player.
bool CScreenPlayerSelect::NameCreate()
{
CWindow* pw;
CEdit* pe;
char name[100];
char c;
int len, i, j;
GetLogger()->Info("Creating new player\n");
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return false;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_NEDIT));
if ( pe == 0 ) return false;
pe->GetText(name, 100);
if ( name[0] == 0 )
{
m_sound->Play(SOUND_TZOING);
return false;
}
len = strlen(name);
j = 0;
for ( i=0 ; i<len ; i++ )
{
c = GetNoAccent(GetToLower(name[i]));
if ( (c >= '0' && c <= '9') ||
(c >= 'a' && c <= 'z') ||
c == ' ' ||
c == '-' ||
c == '_' ||
c == '.' ||
c == ',' ||
c == '\'' )
{
name[j++] = name[i];
}
}
name[j] = 0;
if ( j == 0 )
{
m_sound->Play(SOUND_TZOING);
return false;
}
m_main->SelectPlayer(name);
m_main->GetPlayerProfile()->Create();
return true;
}
// Removes a player.
void CScreenPlayerSelect::NameDelete()
{
CWindow* pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if (pw == nullptr) return;
CList* pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if (pl == nullptr) return;
int sel = pl->GetSelect();
if (sel == -1)
{
m_sound->Play(SOUND_TZOING);
return;
}
char* gamer = pl->GetItemName(sel);
m_main->SelectPlayer(gamer);
if (!m_main->GetPlayerProfile()->Delete())
{
m_sound->Play(SOUND_TZOING);
return;
}
pl->SetSelect(-1);
ReadNameList();
UpdateNameList();
UpdateNameControl();
}
} // namespace Ui

View File

@ -0,0 +1,43 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
namespace Ui {
class CScreenPlayerSelect : public CScreen
{
public:
CScreenPlayerSelect();
void CreateInterface();
bool EventProcess(const Event &event);
void NameDelete(); // called by CMainDialog
protected:
void ReadNameList();
void UpdateNameList();
void UpdateNameEdit();
void UpdateNameControl();
void NameSelect();
bool NameCreate();
};
} // namespace Ui

View File

@ -0,0 +1,133 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_quit.h"
#include "app/app.h"
#include "ui/button.h"
#include "ui/edit.h"
#include "ui/interface.h"
#include "ui/label.h"
#include "ui/window.h"
namespace Ui {
CScreenQuit::CScreenQuit()
{
}
void CScreenQuit::CreateInterface()
{
CWindow* pw;
CEdit* pe;
CLabel* pl;
CButton* pb;
Math::Point pos, ddim;
std::string name;
pos.x = 0.0f;
pos.y = 0.0f;
ddim.x = 0.0f;
ddim.y = 0.0f;
pw = m_interface->CreateWindows(pos, ddim, -1, EVENT_WINDOW5);
pos.x = 80.0f/640.0f;
pos.y = 190.0f/480.0f;
ddim.x = 490.0f/640.0f;
ddim.y = 160.0f/480.0f;
pe = pw->CreateEdit(pos, ddim, 0, EVENT_EDIT1);
pe->SetGenericMode(true);
pe->SetEditCap(false);
pe->SetHighlightCap(false);
pe->SetFontType(Gfx::FONT_COURIER);
pe->SetFontSize(Gfx::FONT_SIZE_SMALL);
pe->ReadText(std::string("help/") + m_app->GetLanguageChar() + std::string("/authors.txt"));
pos.x = 40.0f/640.0f;
pos.y = 83.0f/480.0f;
ddim.x = 246.0f/640.0f;
ddim.y = 16.0f/480.0f;
GetResource(RES_TEXT, RT_GENERIC_DEV1, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL1, name);
pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
pos.y = 13.0f/480.0f;
GetResource(RES_TEXT, RT_GENERIC_DEV2, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL2, name);
pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
pos.x = 355.0f/640.0f;
pos.y = 83.0f/480.0f;
ddim.x = 246.0f/640.0f;
ddim.y = 16.0f/480.0f;
GetResource(RES_TEXT, RT_GENERIC_EDIT1, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL3, name);
pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
pos.y = 13.0f/480.0f;
GetResource(RES_TEXT, RT_GENERIC_EDIT2, name);
pl = pw->CreateLabel(pos, ddim, 0, EVENT_LABEL4, name);
pl->SetFontType(Gfx::FONT_COURIER);
pl->SetFontSize(Gfx::FONT_SIZE_SMALL);
pos.x = 306.0f/640.0f;
pos.y = 17.0f/480.0f;
ddim.x = 30.0f/640.0f;
ddim.y = 30.0f/480.0f;
pb = pw->CreateButton(pos, ddim, 49, EVENT_INTERFACE_ABORT);
pb->SetState(STATE_SHADOW);
SetBackground("textures/interface/generico.png");
}
bool CScreenQuit::EventProcess(const Event &event)
{
if ( event.type == EVENT_INTERFACE_ABORT )
{
m_main->ChangePhase(PHASE_MAIN_MENU);
return false;
}
if ( event.type == EVENT_KEY_DOWN )
{
if ( event.key.key == KEY(ESCAPE) )
{
m_main->ChangePhase(PHASE_MAIN_MENU);
return false;
}
else
{
m_eventQueue->AddEvent(Event(EVENT_QUIT));
return false;
}
}
if ( event.type == EVENT_MOUSE_BUTTON_DOWN )
{
m_eventQueue->AddEvent(Event(EVENT_QUIT));
return false;
}
return true;
}
} // namespace Ui

View File

@ -0,0 +1,33 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
namespace Ui {
class CScreenQuit : public CScreen
{
public:
CScreenQuit();
void CreateInterface();
bool EventProcess(const Event &event);
};
} // namespace Ui

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,64 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
#include "object/robotmain.h"
class CSettings;
namespace Gfx
{
class CCamera;
}
namespace Ui {
class CScreenSetup : public CScreen
{
public:
CScreenSetup(Phase tab, bool simulationSetup);
void CreateInterface();
bool EventProcess(const Event &event);
static Phase GetSetupTab();
protected:
void UpdateDisplayMode();
void ChangeDisplay();
void UpdateApply();
void UpdateSetupButtons();
void ChangeSetupButtons();
void ChangeSetupQuality(int quality);
void UpdateKey();
void ChangeKey(EventType event);
protected:
CSettings* m_settings;
Gfx::CCamera* m_camera;
static Phase m_tab;
bool m_simulationSetup;
int m_setupSelMode;
bool m_setupFull;
};
} // namespace Ui

View File

@ -0,0 +1,110 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#include "ui/screen/screen_welcome.h"
#include "app/app.h"
#include "common/stringutils.h"
#include "graphics/engine/engine.h"
#include "ui/interface.h"
#include "ui/window.h"
namespace Ui {
const float WELCOME_LENGTH = 3.0f;
CScreenWelcome::CScreenWelcome(int imageIndex)
: m_imageIndex(imageIndex)
, m_time(0.0f)
{
}
void CScreenWelcome::CreateInterface()
{
Math::Point pos, ddim;
pos.x = 0.0f;
pos.y = 0.0f;
ddim.x = 0.0f;
ddim.y = 0.0f;
m_interface->CreateWindows(pos, ddim, -1, EVENT_WINDOW5);
if ( m_imageIndex == 0 )
m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK);
else
m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE);
m_engine->SetOverFront(true);
SetBackground("textures/interface/intro"+StrUtils::ToString<int>(m_imageIndex+1)+".png", true);
}
bool CScreenWelcome::EventProcess(const Event &event)
{
if (event.type == EVENT_FRAME)
{
m_time += event.rTime;
// 1/4 of display time is animating
float animatingTime = WELCOME_LENGTH / 4.0f;
float intensity;
if (m_time < animatingTime)
{
// appearing
intensity = m_time / animatingTime;
}
else if (m_time < WELCOME_LENGTH - animatingTime)
{
// showing
intensity = 1.0f;
}
else
{
// hiding
intensity = (WELCOME_LENGTH - m_time) / animatingTime;
}
if ( intensity < 0.0f ) intensity = 0.0f;
if ( intensity > 1.0f ) intensity = 1.0f;
// white first, others -> black fading
int mode = Gfx::ENG_RSTATE_TCOLOR_WHITE;
if ((m_imageIndex == 0) && (m_time < WELCOME_LENGTH/2.0f))
{
intensity = 1.0f - intensity;
mode = Gfx::ENG_RSTATE_TCOLOR_BLACK;
}
m_engine->SetOverColor(Gfx::Color(intensity, intensity, intensity, intensity), mode);
}
if (m_time >= WELCOME_LENGTH ||
event.type == EVENT_KEY_DOWN ||
event.type == EVENT_MOUSE_BUTTON_DOWN )
{
m_main->ChangePhase(static_cast<Phase>(PHASE_WELCOME1+m_imageIndex+1));
return false;
}
return true;
}
} // namespace Ui

View File

@ -0,0 +1,37 @@
/*
* This file is part of the Colobot: Gold Edition source code
* Copyright (C) 2001-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
* http://epsiteс.ch; http://colobot.info; http://github.com/colobot
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://gnu.org/licenses
*/
#pragma once
#include "ui/screen/screen.h"
namespace Ui {
class CScreenWelcome : public CScreen
{
public:
CScreenWelcome(int imageIndex);
void CreateInterface();
bool EventProcess(const Event &event);
protected:
int m_imageIndex;
float m_time;
};
} // namespace Ui