summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-06-24 21:37:15 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2013-06-24 21:37:15 +0200
commit7c2e955e1552a9c4e412ea2c936be61fc78ba010 (patch)
treeee506dfbec54f998d10c385bde3a1c3fa04e66b2 /src/ui
parente218dcfdf2c58f8841e7ebd220527d08e870a6d5 (diff)
parentb376486fd74fa02b0297ceef6d0f977b32358e5e (diff)
downloadcolobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.tar.gz
colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.tar.bz2
colobot-7c2e955e1552a9c4e412ea2c936be61fc78ba010.zip
Colobot Gold 0.1.0-alpha
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/README.txt1
-rw-r--r--src/ui/button.cpp1
-rw-r--r--src/ui/button.h1
-rw-r--r--src/ui/check.cpp1
-rw-r--r--src/ui/color.cpp1
-rw-r--r--src/ui/color.h1
-rw-r--r--src/ui/compass.cpp1
-rw-r--r--src/ui/compass.h1
-rw-r--r--src/ui/control.cpp17
-rw-r--r--src/ui/control.h1
-rw-r--r--src/ui/displayinfo.cpp11
-rw-r--r--src/ui/displayinfo.h1
-rw-r--r--src/ui/displaytext.cpp1
-rw-r--r--src/ui/edit.cpp294
-rw-r--r--src/ui/edit.h5
-rw-r--r--src/ui/editvalue.cpp1
-rw-r--r--src/ui/editvalue.h1
-rw-r--r--src/ui/gauge.cpp1
-rw-r--r--src/ui/gauge.h23
-rw-r--r--src/ui/group.cpp1
-rw-r--r--src/ui/group.h1
-rw-r--r--src/ui/image.cpp1
-rw-r--r--src/ui/image.h1
-rw-r--r--src/ui/interface.cpp33
-rw-r--r--src/ui/interface.h83
-rw-r--r--src/ui/key.cpp1
-rw-r--r--src/ui/label.cpp4
-rw-r--r--src/ui/label.h13
-rw-r--r--src/ui/list.cpp195
-rw-r--r--src/ui/list.h10
-rw-r--r--src/ui/maindialog.cpp447
-rw-r--r--src/ui/maindialog.h4
-rw-r--r--src/ui/mainmap.cpp17
-rw-r--r--src/ui/mainmap.h62
-rw-r--r--src/ui/mainshort.h47
-rw-r--r--src/ui/map.cpp45
-rw-r--r--src/ui/map.h143
-rw-r--r--src/ui/scroll.cpp1
-rw-r--r--src/ui/scroll.h65
-rw-r--r--src/ui/shortcut.cpp3
-rw-r--r--src/ui/shortcut.h21
-rw-r--r--src/ui/slider.cpp1
-rw-r--r--src/ui/slider.h69
-rw-r--r--src/ui/studio.cpp37
-rw-r--r--src/ui/target.cpp1
-rw-r--r--src/ui/target.h19
-rw-r--r--src/ui/window.cpp8
-rw-r--r--src/ui/window.h3
48 files changed, 953 insertions, 747 deletions
diff --git a/src/ui/README.txt b/src/ui/README.txt
index a159ed5..05f72a1 100644
--- a/src/ui/README.txt
+++ b/src/ui/README.txt
@@ -2,3 +2,4 @@
* \dir src/ui
* \brief 2D user interface controls
*/
+
diff --git a/src/ui/button.cpp b/src/ui/button.cpp
index a68b34d..348382d 100644
--- a/src/ui/button.cpp
+++ b/src/ui/button.cpp
@@ -245,3 +245,4 @@ bool CButton::GetRepeat()
}
}
+
diff --git a/src/ui/button.h b/src/ui/button.h
index a9aa020..b71ef4a 100644
--- a/src/ui/button.h
+++ b/src/ui/button.h
@@ -51,3 +51,4 @@ protected:
};
}
+
diff --git a/src/ui/check.cpp b/src/ui/check.cpp
index 761264d..362c930 100644
--- a/src/ui/check.cpp
+++ b/src/ui/check.cpp
@@ -163,3 +163,4 @@ void CCheck::Draw()
}
}
+
diff --git a/src/ui/color.cpp b/src/ui/color.cpp
index fd05bd9..623ff89 100644
--- a/src/ui/color.cpp
+++ b/src/ui/color.cpp
@@ -223,3 +223,4 @@ Gfx::Color CColor::GetColor()
}
+
diff --git a/src/ui/color.h b/src/ui/color.h
index ec2c537..fe96b87 100644
--- a/src/ui/color.h
+++ b/src/ui/color.h
@@ -54,3 +54,4 @@ protected:
};
}
+
diff --git a/src/ui/compass.cpp b/src/ui/compass.cpp
index ac97cb8..d0fe96f 100644
--- a/src/ui/compass.cpp
+++ b/src/ui/compass.cpp
@@ -171,3 +171,4 @@ float CCompass::GetDirection()
}
+
diff --git a/src/ui/compass.h b/src/ui/compass.h
index 18546e5..956631a 100644
--- a/src/ui/compass.h
+++ b/src/ui/compass.h
@@ -49,3 +49,4 @@ protected:
}
+
diff --git a/src/ui/control.cpp b/src/ui/control.cpp
index 6dc92cd..7c77c95 100644
--- a/src/ui/control.cpp
+++ b/src/ui/control.cpp
@@ -75,10 +75,13 @@ bool CControl::Create(Math::Point pos, Math::Point dim, int icon, EventType even
GetResource(RES_EVENT, m_eventType, text);
str_text = std::string(text);
auto p = str_text.find("\\");
- if ( p == std::string::npos ) {
+ if ( p == std::string::npos )
+ {
if ( icon != -1 )
m_tooltip = str_text;
- } else {
+ }
+ else
+ {
m_tooltip = str_text.substr(p + 1);
}
@@ -174,15 +177,18 @@ int CControl::GetIcon()
void CControl::SetName(std::string name, bool bTooltip)
{
- if ( bTooltip ) {
+ if ( bTooltip )
+ {
auto p = name.find("\\");
if ( p == std::string::npos )
m_name = name;
- else {
+ else
+ {
m_tooltip = name.substr(p + 1);
m_name = name.substr(0, p);
}
- } else
+ }
+ else
m_name = name;
}
@@ -832,3 +838,4 @@ bool CControl::Detect(Math::Point pos)
}
}
+
diff --git a/src/ui/control.h b/src/ui/control.h
index 7f5077d..aee7d1c 100644
--- a/src/ui/control.h
+++ b/src/ui/control.h
@@ -141,3 +141,4 @@ protected:
};
} // namespace Ui
+
diff --git a/src/ui/displayinfo.cpp b/src/ui/displayinfo.cpp
index fcc77db..3aa3d73 100644
--- a/src/ui/displayinfo.cpp
+++ b/src/ui/displayinfo.cpp
@@ -154,28 +154,28 @@ bool CDisplayInfo::EventProcess(const Event &event)
{
m_main->SetFontSize(9.0f);
slider = static_cast<Ui::CSlider*>(pw->SearchControl(EVENT_STUDIO_SIZE));
- if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/6.0f);
+ if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/12.0f);
ViewDisplayInfo();
}
if ( event.type == EVENT_HYPER_SIZE2 ) // size 2?
{
m_main->SetFontSize(10.0f);
slider = static_cast<Ui::CSlider*>(pw->SearchControl(EVENT_STUDIO_SIZE));
- if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/6.0f);
+ if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/12.0f);
ViewDisplayInfo();
}
if ( event.type == EVENT_HYPER_SIZE3 ) // size 3?
{
m_main->SetFontSize(12.0f);
slider = static_cast<Ui::CSlider*>(pw->SearchControl(EVENT_STUDIO_SIZE));
- if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/6.0f);
+ if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/12.0f);
ViewDisplayInfo();
}
if ( event.type == EVENT_HYPER_SIZE4 ) // size 4?
{
m_main->SetFontSize(15.0f);
slider = static_cast<Ui::CSlider*>(pw->SearchControl(EVENT_STUDIO_SIZE));
- if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/6.0f);
+ if ( slider != 0 ) slider->SetVisibleValue((m_main->GetFontSize()-9.0f)/12.0f);
ViewDisplayInfo();
}
@@ -183,7 +183,7 @@ bool CDisplayInfo::EventProcess(const Event &event)
{
slider = static_cast<Ui::CSlider*>(pw->SearchControl(EVENT_STUDIO_SIZE));
if ( slider == 0 ) return false;
- m_main->SetFontSize(9.0f+slider->GetVisibleValue()*6.0f);
+ m_main->SetFontSize(9.0f+slider->GetVisibleValue()*12.0f);
ViewDisplayInfo();
}
@@ -1214,3 +1214,4 @@ void CDisplayInfo::CreateObjectsFile()
}
+
diff --git a/src/ui/displayinfo.h b/src/ui/displayinfo.h
index ab42d62..eea50b7 100644
--- a/src/ui/displayinfo.h
+++ b/src/ui/displayinfo.h
@@ -95,3 +95,4 @@ protected:
} // namespace Ui
+
diff --git a/src/ui/displaytext.cpp b/src/ui/displaytext.cpp
index 630b385..d88674a 100644
--- a/src/ui/displaytext.cpp
+++ b/src/ui/displaytext.cpp
@@ -606,3 +606,4 @@ CObject* CDisplayText::SearchToto()
}
}
+
diff --git a/src/ui/edit.cpp b/src/ui/edit.cpp
index e60a040..6fd1735 100644
--- a/src/ui/edit.cpp
+++ b/src/ui/edit.cpp
@@ -20,6 +20,8 @@
#include "app/app.h"
+#include "clipboard/clipboard.h"
+
#include <string.h>
namespace Ui {
@@ -261,7 +263,7 @@ bool CEdit::EventProcess(const Event &event)
if ( event.type == EVENT_MOUSE_MOVE )
{
- if ( Detect(event.mousePos) &&
+ if ( Detect(event.mousePos) &&
event.mousePos.x < m_pos.x+m_dim.x-(m_bMulti?MARGX+SCROLL_WIDTH:0.0f) )
{
if ( m_bEdit )
@@ -298,55 +300,53 @@ bool CEdit::EventProcess(const Event &event)
bShift = ( (event.kmodState & KEY_MOD(SHIFT) ) != 0 );
bControl = ( (event.kmodState & KEY_MOD(CTRL) ) != 0);
- if ( (event.key.unicode == 'X' && !bShift && bControl) ||
- ((event.kmodState & KEY_MOD(CTRL)) != 0 && bShift && !bControl) )
+ if ( (event.key.key == KEY(x) && !bShift && bControl) ||
+ (event.key.key == KEY(DELETE) && bShift && !bControl) )
{
Cut();
return true;
}
- if ( (event.key.unicode == 'C' && !bShift && bControl) ||
- ((event.kmodState & KEY_MOD(CTRL)) != 0 && !bShift && bControl) )
+ if ( (event.key.key == KEY(c) && !bShift && bControl) ||
+ (event.key.key == KEY(INSERT) && !bShift && bControl) )
{
Copy();
return true;
}
- if ( (event.key.unicode == 'V' && !bShift && bControl) ||
- ((event.kmodState & KEY_MOD(CTRL)) != 0 && bShift && !bControl) )
+ if ( (event.key.key == KEY(v) && !bShift && bControl) ||
+ (event.key.key == KEY(INSERT) && bShift && !bControl) )
{
Paste();
return true;
}
- if ( event.key.unicode == 'A' && !bShift && bControl )
+ if ( event.key.key == KEY(a) && !bShift && bControl )
{
SetCursor(999999, 0);
return true;
}
- if ( event.key.unicode == 'O' && !bShift && bControl )
+ if ( event.key.key == KEY(o) && !bShift && bControl )
{
Event newEvent(EVENT_STUDIO_OPEN);
-// m_event->NewEvent(newEvent, EVENT_STUDIO_OPEN);
m_event->AddEvent(newEvent);
}
- if ( event.key.unicode == 'S' && !bShift && bControl )
+ if ( event.key.key == KEY(s) && !bShift && bControl )
{
Event newEvent( EVENT_STUDIO_SAVE );
-// m_event->MakeEvent(newEvent, EVENT_STUDIO_SAVE);
m_event->AddEvent(newEvent);
}
- if ( event.key.unicode == 'Z' && !bShift && bControl )
+ if ( event.key.key == KEY(z) && !bShift && bControl )
{
Undo();
return true;
}
- if ( event.key.unicode == 'U' && !bShift && bControl )
+ if ( event.key.key == KEY(u) && !bShift && bControl )
{
if ( MinMaj(false) ) return true;
}
- if ( event.key.unicode == 'U' && bShift && bControl )
+ if ( event.key.key == KEY(u) && bShift && bControl )
{
if ( MinMaj(true) ) return true;
}
@@ -688,7 +688,7 @@ void CEdit::MouseMove(Math::Point mouse)
int CEdit::MouseDetect(Math::Point mouse)
{
Math::Point pos;
- float indentLength, offset, size;
+ float indentLength = 0.0f, offset, size;
int i, len, c;
bool bTitle;
@@ -782,13 +782,16 @@ void CEdit::HyperJump(std::string name, std::string marker)
sMarker = marker;
//? sprintf(filename, "help\\%s.txt", name);
-
- if ( name[0] == '%' ) {
+
+ if ( name[0] == '%' )
+ {
filename = GetProfile().GetUserBasedPath(name, "") + ".txt";
- } else {
+ }
+ else
+ {
filename = std::string("help/") + CApplication::GetInstancePointer()->GetLanguageChar() + "/" + name + std::string(".txt");
}
-
+
if ( ReadText(filename) )
{
Justif();
@@ -886,7 +889,7 @@ bool CEdit::HyperGo(EventType event)
void CEdit::Draw()
{
Math::Point pos, ppos, dim, start, end;
- float size, indentLength;
+ float size = 0.0f, indentLength = 0.0f;
int i, j, beg, len, c1, c2, o1, o2, eol, iIndex, line;
if ( (m_state & STATE_VISIBLE) == 0 ) return;
@@ -1249,7 +1252,7 @@ void CEdit::SetText(const char *text, bool bNew)
{
int i, j, font;
bool bBOL;
-
+
if ( !bNew ) UndoMemorize(OPERUNDO_SPEC);
m_len = strlen(text);
@@ -1387,10 +1390,11 @@ int CEdit::GetTextLength()
std::string GetNameParam(std::string cmd, int rank)
{
- std::vector<std::string> results;
+ std::vector<std::string> results;
boost::split(results, cmd, boost::is_any_of(" ;"));
-
- if (results.size() > static_cast<unsigned int>(rank)) {
+
+ if (results.size() > static_cast<unsigned int>(rank))
+ {
return results.at(rank);
}
@@ -1402,11 +1406,12 @@ std::string GetNameParam(std::string cmd, int rank)
int GetValueParam(std::string cmd, int rank)
{
- std::vector<std::string> results;
+ std::vector<std::string> results;
boost::split(results, cmd, boost::is_any_of(" ;"));
int return_value = 0;
-
- if (results.size() > static_cast<unsigned int>(rank)) {
+
+ if (results.size() > static_cast<unsigned int>(rank))
+ {
return_value = atoi(results.at(rank).c_str());
}
@@ -1419,7 +1424,8 @@ void CEdit::FreeImage()
{
std::string filename;
- for (int i = 0 ; i < m_imageTotal; i++ ) {
+ for (int i = 0 ; i < m_imageTotal; i++ )
+ {
filename = GetProfile().GetUserBasedPath(m_image[i].name, "diagram") + ".png";
m_engine->DeleteTexture(filename);
}
@@ -1448,12 +1454,14 @@ bool CEdit::ReadText(std::string filename, int addSize)
bool bInSoluce, bBOL;
if ( filename[0] == 0 ) return false;
+
boost::replace_all(filename, "\\", "/");
-
+
/* This is ugly but doesn't require many changes in code. If file doesn't
exists it's posible filename is absolute not full path */
std::string path = filename;
- if (!fs::exists(path)) {
+ if (!fs::exists(path))
+ {
path = CApplication::GetInstancePointer()->GetDataDirPath() + "/" + filename;
}
@@ -1484,10 +1492,11 @@ bool CEdit::ReadText(std::string filename, int addSize)
m_format.clear();
m_format.reserve(m_maxChar+1);
- for (i = 0; i <= m_maxChar+1; i++) {
+ for (i = 0; i <= m_maxChar+1; i++)
+ {
m_format.push_back(0);
}
-
+
fclose(file);
bInSoluce = false;
@@ -1877,7 +1886,7 @@ bool CEdit::WriteText(std::string filename)
FILE* file;
char buffer[1000+20];
int i, j, k, n;
- float iDim;
+ float iDim = 0.0f;
if ( filename[0] == 0 ) return false;
file = fopen(filename.c_str(), "wb");
@@ -1951,7 +1960,8 @@ void CEdit::SetMaxChar(int max)
m_format.clear();
m_format.reserve(m_maxChar+1);
- for (int i = 0; i <= m_maxChar+1; i++) {
+ for (int i = 0; i <= m_maxChar+1; i++)
+ {
m_format.push_back(0);
}
@@ -2142,10 +2152,12 @@ bool CEdit::GetDisplaySpec()
void CEdit::SetMultiFont(bool bMulti)
{
m_format.clear();
-
- if (bMulti) {
+
+ if (bMulti)
+ {
m_format.reserve(m_maxChar+1);
- for (int i = 0; i <= m_maxChar+1; i++) {
+ for (int i = 0; i <= m_maxChar+1; i++)
+ {
m_format.push_back(0);
}
}
@@ -2397,7 +2409,7 @@ void CEdit::MoveChar(int move, bool bWord, bool bSelect)
void CEdit::MoveLine(int move, bool bWord, bool bSelect)
{
- float column, indentLength;
+ float column, indentLength = 0.0f;
int i, line, c;
if ( move == 0 ) return;
@@ -2501,200 +2513,113 @@ void CEdit::ColumnFix()
// Cut the selected characters or entire line.
-bool CEdit::Cut() // TODO MS Windows allocations
+bool CEdit::Cut()
{
- /* HGLOBAL hg;
- char* text;
- char c;
- int c1, c2, start, len, i, j;
-
- if ( !m_bEdit ) return false;
-
- c1 = m_cursor1;
- c2 = m_cursor2;
- if ( c1 > c2 ) Math::Swap(c1, c2); // always c1 <= c2
-
- if ( c1 == c2 )
- {
- while ( c1 > 0 )
- {
- if ( m_text[c1-1] == '\n' ) break;
- c1 --;
- }
- while ( c2 < m_len )
- {
- c2 ++;
- if ( m_text[c2-1] == '\n' ) break;
- }
- }
-
- if ( c1 == c2 ) return false;
-
- start = c1;
- len = c2-c1;
-
- if ( !(hg = GlobalAlloc(GMEM_DDESHARE, len*2+1)) )
- {
- return false;
- }
- if ( !(text = (char*)GlobalLock(hg)) )
- {
- GlobalFree(hg);
- return false;
- }
-
- j = 0;
- for ( i=start ; i<start+len ; i++ )
- {
- c = m_text[i];
- if ( c == '\n' ) text[j++] = '\r';
- text[j++] = c;
- }
- text[j] = 0;
- GlobalUnlock(hg);
-
- if ( !OpenClipboard(NULL) )
- {
- GlobalFree(hg);
- return false;
- }
- if ( !EmptyClipboard() )
- {
- GlobalFree(hg);
- return false;
- }
- if ( !SetClipboardData(CF_TEXT, hg) )
- {
- GlobalFree(hg);
- return false;
- }
- CloseClipboard();
-
UndoMemorize(OPERUNDO_SPEC);
- m_cursor1 = c1;
- m_cursor2 = c2;
+ Copy(true);
+
DeleteOne(0); // deletes the selected characters
Justif();
ColumnFix();
- SendModifEvent();*/
+ SendModifEvent();
return true;
}
// Copy the selected characters or entire line.
-bool CEdit::Copy() // TODO
+bool CEdit::Copy(bool memorize_cursor)
{
- /* HGLOBAL hg;
- char* text;
- char c;
- int c1, c2, start, len, i, j;
+ int c1, c2, start, len;
+ char *text;
c1 = m_cursor1;
c2 = m_cursor2;
- if ( c1 > c2 ) Math::Swap(c1, c2); // always c1 <= c2
+ if ( c1 > c2 )
+ {
+ Math::Swap(c1, c2); // always c1 <= c2
+ }
if ( c1 == c2 )
{
while ( c1 > 0 )
{
- if ( m_text[c1-1] == '\n' ) break;
- c1 --;
+ if ( m_text[c1 - 1] == '\n' )
+ {
+ break;
+ }
+ c1--;
}
while ( c2 < m_len )
{
- c2 ++;
- if ( m_text[c2-1] == '\n' ) break;
+ c2++;
+ if ( m_text[c2 - 1] == '\n' )
+ {
+ break;
+ }
}
}
- if ( c1 == c2 ) return false;
-
- start = c1;
- len = c2-c1;
-
- if ( !(hg = GlobalAlloc(GMEM_DDESHARE, len*2+1)) )
- {
- return false;
- }
- if ( !(text = (char*)GlobalLock(hg)) )
+ if ( c1 == c2 )
{
- GlobalFree(hg);
return false;
}
- j = 0;
- for ( i=start ; i<start+len ; i++ )
- {
- c = m_text[i];
- if ( c == '\n' ) text[j++] = '\r';
- text[j++] = c;
- }
- text[j] = 0;
- GlobalUnlock(hg);
+ start = c1;
+ len = c2 - c1;
- if ( !OpenClipboard(NULL) )
- {
- GlobalFree(hg);
- return false;
- }
- if ( !EmptyClipboard() )
- {
- GlobalFree(hg);
- return false;
- }
- if ( !SetClipboardData(CF_TEXT, hg) )
+ text = new char[len + 1];
+ strncpy(text, m_text + start, len);
+ text[len] = 0;
+ widgetSetClipboardText(text);
+ delete []text;
+
+ if (memorize_cursor)
{
- GlobalFree(hg);
- return false;
+ m_cursor1 = c1;
+ m_cursor2 = c2;
}
- CloseClipboard();
-*/
+
return true;
}
// Paste the contents of the notebook.
-bool CEdit::Paste() // TODO
+bool CEdit::Paste()
{
- /*HANDLE h;
char c;
- char* p;
-
- if ( !m_bEdit ) return false;
+ char* text;
- if ( !OpenClipboard(NULL) )
+ if ( !m_bEdit )
{
return false;
}
- if ( !(h = GetClipboardData(CF_TEXT)) )
- {
- CloseClipboard();
- return false;
- }
+ text = widgetGetClipboardText();
- if ( !(p = (char*)GlobalLock(h)) )
+ if ( text == nullptr )
{
- CloseClipboard();
return false;
}
UndoMemorize(OPERUNDO_SPEC);
-
- while ( *p != 0 )
+ for ( unsigned int i = 0; i < strlen(text); i++ )
{
- c = *p++;
- if ( c == '\r' ) continue;
- if ( c == '\t' && m_bAutoIndent ) continue;
+ c = text[i];
+ if ( c == '\r' )
+ {
+ continue;
+ }
+ if ( c == '\t' && m_bAutoIndent )
+ {
+ continue;
+ }
InsertOne(c);
}
- GlobalUnlock(h);
- CloseClipboard();
-
+ free(text);
Justif();
ColumnFix();
- SendModifEvent();*/
+ SendModifEvent();
return true;
}
@@ -2703,7 +2628,10 @@ bool CEdit::Paste() // TODO
bool CEdit::Undo()
{
- if ( !m_bEdit ) return false;
+ if ( !m_bEdit )
+ {
+ return false;
+ }
return UndoRecall();
}
@@ -2715,7 +2643,10 @@ void CEdit::Insert(char character)
{
int i, level, tab;
- if ( !m_bEdit ) return;
+ if ( !m_bEdit )
+ {
+ return;
+ }
if ( !m_bMulti ) // single-line?
{
@@ -3052,7 +2983,7 @@ bool CEdit::MinMaj(bool bMaj)
void CEdit::Justif()
{
- float width, size, indentLength;
+ float width, size, indentLength = 0.0f;
int i, j, line, indent;
bool bDual, bString, bRem;
@@ -3315,7 +3246,7 @@ bool CEdit::SetFormat(int cursor1, int cursor2, int format)
void CEdit::UpdateScroll()
{
float value;
-
+
if ( m_scroll != nullptr )
{
if ( m_lineTotal <= m_lineVisible )
@@ -3339,3 +3270,4 @@ void CEdit::UpdateScroll()
}
}
+
diff --git a/src/ui/edit.h b/src/ui/edit.h
index 1cfec80..acdf72c 100644
--- a/src/ui/edit.h
+++ b/src/ui/edit.h
@@ -184,7 +184,7 @@ public:
bool GetMultiFont();
bool Cut();
- bool Copy();
+ bool Copy(bool memorize_cursor = false);
bool Paste();
bool Undo();
@@ -239,7 +239,7 @@ protected:
void UndoFlush();
void UndoMemorize(OperUndo oper);
bool UndoRecall();
-
+
void UpdateScroll();
protected:
@@ -294,3 +294,4 @@ protected:
}
+
diff --git a/src/ui/editvalue.cpp b/src/ui/editvalue.cpp
index 6397a73..3fb9b79 100644
--- a/src/ui/editvalue.cpp
+++ b/src/ui/editvalue.cpp
@@ -369,3 +369,4 @@ float CEditValue::GetMaxValue()
}
}
+
diff --git a/src/ui/editvalue.h b/src/ui/editvalue.h
index 5d6e643..2734847 100644
--- a/src/ui/editvalue.h
+++ b/src/ui/editvalue.h
@@ -85,3 +85,4 @@ protected:
}
+
diff --git a/src/ui/gauge.cpp b/src/ui/gauge.cpp
index c98e3b6..a8ee41c 100644
--- a/src/ui/gauge.cpp
+++ b/src/ui/gauge.cpp
@@ -144,3 +144,4 @@ float CGauge::GetLevel()
}
+
diff --git a/src/ui/gauge.h b/src/ui/gauge.h
index a2b689a..3dbeef8 100644
--- a/src/ui/gauge.h
+++ b/src/ui/gauge.h
@@ -31,24 +31,23 @@ namespace Ui {
class CGauge : public CControl
{
- public:
- CGauge();
- virtual ~CGauge();
+public:
+ CGauge();
+ virtual ~CGauge();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
- bool EventProcess(const Event &event);
+ bool EventProcess(const Event &event);
- void Draw();
+ void Draw();
- void SetLevel(float level);
- float GetLevel();
+ void SetLevel(float level);
+ float GetLevel();
- protected:
-
- protected:
- float m_level;
+protected:
+ float m_level;
};
}
+
diff --git a/src/ui/group.cpp b/src/ui/group.cpp
index c3c7028..908ac19 100644
--- a/src/ui/group.cpp
+++ b/src/ui/group.cpp
@@ -639,3 +639,4 @@ void CGroup::Draw()
}
+
diff --git a/src/ui/group.h b/src/ui/group.h
index fd31716..89996cc 100644
--- a/src/ui/group.h
+++ b/src/ui/group.h
@@ -46,3 +46,4 @@ protected:
}
+
diff --git a/src/ui/image.cpp b/src/ui/image.cpp
index 94b9586..9a14789 100644
--- a/src/ui/image.cpp
+++ b/src/ui/image.cpp
@@ -151,3 +151,4 @@ void CImage::Draw()
}
+
diff --git a/src/ui/image.h b/src/ui/image.h
index c40828c..fd71e33 100644
--- a/src/ui/image.h
+++ b/src/ui/image.h
@@ -52,3 +52,4 @@ protected:
}
+
diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp
index 24d2626..845579e 100644
--- a/src/ui/interface.cpp
+++ b/src/ui/interface.cpp
@@ -47,8 +47,10 @@ CInterface::~CInterface()
void CInterface::Flush()
{
- for (int i = 0; i < MAXCONTROL; i++ ) {
- if ( m_table[i] != nullptr ) {
+ for (int i = 0; i < MAXCONTROL; i++ )
+ {
+ if ( m_table[i] != nullptr )
+ {
delete m_table[i];
m_table[i] = nullptr;
}
@@ -58,7 +60,8 @@ void CInterface::Flush()
int CInterface::GetNextFreeControl()
{
- for (int i = 10; i < MAXCONTROL-1; i++) {
+ for (int i = 10; i < MAXCONTROL-1; i++)
+ {
if (m_table[i] == nullptr)
return i;
}
@@ -92,7 +95,8 @@ CWindow* CInterface::CreateWindows(Math::Point pos, Math::Point dim, int icon, E
if (eventMsg == EVENT_NULL)
eventMsg = GetUniqueEventType();
- switch (eventMsg) {
+ switch (eventMsg)
+ {
case EVENT_WINDOW0: index = 0; break;
case EVENT_WINDOW1: index = 1; break;
case EVENT_WINDOW2: index = 2; break;
@@ -197,6 +201,9 @@ CSlider* CInterface::CreateSlider(Math::Point pos, Math::Point dim, int icon, Ev
}
// Creates a new list.
+// if expand is less then zero, then the list would try to use expand's absolute value,
+// and try to scale items to some size, so that dim of the list would not change after
+// adjusting
CList* CInterface::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand)
{
@@ -246,9 +253,12 @@ CMap* CInterface::CreateMap(Math::Point pos, Math::Point dim, int icon, EventTyp
bool CInterface::DeleteControl(EventType eventMsg)
{
- for (int i = 0; i < MAXCONTROL; i++) {
- if ( m_table[i] != nullptr ) {
- if (eventMsg == m_table[i]->GetEventType()) {
+ for (int i = 0; i < MAXCONTROL; i++)
+ {
+ if ( m_table[i] != nullptr )
+ {
+ if (eventMsg == m_table[i]->GetEventType())
+ {
delete m_table[i];
m_table[i] = nullptr;
return true;
@@ -262,8 +272,10 @@ bool CInterface::DeleteControl(EventType eventMsg)
CControl* CInterface::SearchControl(EventType eventMsg)
{
- for (int i = 0; i < MAXCONTROL; i++) {
- if (m_table[i] != nullptr) {
+ for (int i = 0; i < MAXCONTROL; i++)
+ {
+ if (m_table[i] != nullptr)
+ {
if (eventMsg == m_table[i]->GetEventType())
return m_table[i];
}
@@ -323,4 +335,5 @@ void CInterface::Draw()
}
}
-}
+} // namespace Ui
+
diff --git a/src/ui/interface.h b/src/ui/interface.h
index ebc80e7..d5734f0 100644
--- a/src/ui/interface.h
+++ b/src/ui/interface.h
@@ -55,48 +55,49 @@ const int MAXCONTROL = 100;
class CInterface
{
- public:
- CInterface();
- ~CInterface();
-
- bool EventProcess(const Event &event);
- bool GetTooltip(Math::Point pos, std::string &name);
-
- void Flush();
- CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
-
- CWindow* CreateWindows(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f);
- CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name);
-
- bool DeleteControl(EventType eventMsg);
- CControl* SearchControl(EventType eventMsg);
-
- void Draw();
-
- protected:
- int GetNextFreeControl();
- template <typename T> inline T* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
-
- CEventQueue* m_event;
- Gfx::CEngine* m_engine;
- Gfx::CCamera* m_camera;
-
- CControl* m_table[MAXCONTROL];
+public:
+ CInterface();
+ ~CInterface();
+
+ bool EventProcess(const Event &event);
+ bool GetTooltip(Math::Point pos, std::string &name);
+
+ void Flush();
+ CButton* CreateButton(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CColor* CreateColor(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CCheck* CreateCheck(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CKey* CreateKey(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CGroup* CreateGroup(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CImage* CreateImage(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CEdit* CreateEdit(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CEditValue* CreateEditValue(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CScroll* CreateScroll(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CSlider* CreateSlider(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CShortcut* CreateShortcut(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CCompass* CreateCompass(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CTarget* CreateTarget(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CMap* CreateMap(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+
+ CWindow* CreateWindows(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ CList* CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand=1.2f);
+ CLabel* CreateLabel(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, std::string name);
+
+ bool DeleteControl(EventType eventMsg);
+ CControl* SearchControl(EventType eventMsg);
+
+ void Draw();
+
+protected:
+ int GetNextFreeControl();
+ template <typename T> inline T* CreateControl(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+
+ CEventQueue* m_event;
+ Gfx::CEngine* m_engine;
+ Gfx::CCamera* m_camera;
+
+ CControl* m_table[MAXCONTROL];
};
}
+
diff --git a/src/ui/key.cpp b/src/ui/key.cpp
index b181f70..1f8cff5 100644
--- a/src/ui/key.cpp
+++ b/src/ui/key.cpp
@@ -214,3 +214,4 @@ InputBinding CKey::GetBinding()
} // namespace Ui
+
diff --git a/src/ui/label.cpp b/src/ui/label.cpp
index b5195b5..76a95f2 100644
--- a/src/ui/label.cpp
+++ b/src/ui/label.cpp
@@ -66,7 +66,8 @@ void CLabel::Draw()
pos.y = m_pos.y + m_dim.y / 2.0f;
- switch (m_textAlign) {
+ switch (m_textAlign)
+ {
case Gfx::TEXT_ALIGN_LEFT: pos.x = m_pos.x; break;
case Gfx::TEXT_ALIGN_CENTER: pos.x = m_pos.x + m_dim.x / 2.0f; break;
case Gfx::TEXT_ALIGN_RIGHT: pos.x = m_pos.x + m_dim.x; break;
@@ -76,3 +77,4 @@ void CLabel::Draw()
}
}
+
diff --git a/src/ui/label.h b/src/ui/label.h
index c9e1050..305aca2 100644
--- a/src/ui/label.h
+++ b/src/ui/label.h
@@ -29,15 +29,16 @@ namespace Ui {
class CLabel : public CControl
{
- public:
- CLabel();
- virtual ~CLabel();
+public:
+ CLabel();
+ virtual ~CLabel();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- bool EventProcess(const Event &event);
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ bool EventProcess(const Event &event);
- void Draw();
+ void Draw();
};
}
+
diff --git a/src/ui/list.cpp b/src/ui/list.cpp
index 84aa8ca..f6c3ed9 100644
--- a/src/ui/list.cpp
+++ b/src/ui/list.cpp
@@ -33,13 +33,15 @@ CList::CList() : CControl()
m_button[i] = nullptr;
m_scroll = nullptr;
- for (int i = 0; i < LISTMAXTOTAL; i++) {
+ for (int i = 0; i < LISTMAXTOTAL; i++)
+ {
m_text[i][0] = 0;
m_check[i] = false;
m_enable[i] = true;
}
- for (int i = 0; i < 10; i++) {
+ for (int i = 0; i < 10; i++)
+ {
m_tabs[i] = 0.0f;
m_justifs[i] = Gfx::TEXT_ALIGN_LEFT;
}
@@ -57,7 +59,8 @@ CList::CList() : CControl()
CList::~CList()
{
- for (int i = 0; i < LISTMAXDISPLAY; i++) {
+ for (int i = 0; i < LISTMAXDISPLAY; i++)
+ {
if (m_button[i] != nullptr)
delete m_button[i];
}
@@ -68,6 +71,9 @@ CList::~CList()
// Creates a new list.
+// if expand is less then zero, then the list would try to use expand's absolute value,
+// and try to scale items to some size, so that dim of the list would not change after
+// adjusting
bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg, float expand)
{
@@ -85,6 +91,14 @@ bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventMs
return MoveAdjust();
}
+// Should never be called
+bool CList::Create(Math::Point pos, Math::Point dim, int icon, EventType eventType)
+{
+ assert(false);
+ return false;
+}
+
+
// Adjusted after a change of dimensions.
bool CList::MoveAdjust()
@@ -92,8 +106,10 @@ bool CList::MoveAdjust()
Math::Point ipos, idim, ppos, ddim;
float marging, h;
- for (int i = 0; i < LISTMAXDISPLAY; i++) {
- if (m_button[i] != nullptr) {
+ for (int i = 0; i < LISTMAXDISPLAY; i++)
+ {
+ if (m_button[i] != nullptr)
+ {
delete m_button[i];
m_button[i] = nullptr;
}
@@ -109,21 +125,30 @@ bool CList::MoveAdjust()
idim.x = m_dim.x - marging * 2.0f / 640.f;
idim.y = m_dim.y - marging * 2.0f / 480.f;
- h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) * m_expand;
-
+ //If m_expand is less then zero, then try to apply it's absolute value
+ h = m_engine->GetText()->GetHeight(m_fontType, m_fontSize) * ((m_expand < 0) ? -m_expand : m_expand);
m_displayLine = static_cast<int>(idim.y / h);
+
if (m_displayLine == 0)
return false;
if (m_displayLine > LISTMAXDISPLAY)
m_displayLine = LISTMAXDISPLAY;
- idim.y = h * m_displayLine;
+
+ // Stretch lines to fill whole area of a list, if needed
+ if (m_expand < 0 && (idim.y - (h * m_displayLine) < h))
+ {
+ h = idim.y / m_displayLine;
+ }
+
+ idim.y = h * m_displayLine; //Here cuts list size if height of shown elements is less then designed height
m_dim.y = idim.y + marging * 2.0f / 480.f;
ppos.x = ipos.x;
ppos.y = ipos.y + idim.y - h;
ddim.x = idim.x - SCROLL_WIDTH;
ddim.y = h;
- for (int i = 0; i < m_displayLine; i++) {
+ for (int i = 0; i < m_displayLine; i++)
+ {
m_button[i] = new CButton();
m_button[i]->Create(ppos, ddim, -1, EVENT_NULL);
m_button[i]->SetTextAlign(Gfx::TEXT_ALIGN_LEFT);
@@ -135,7 +160,8 @@ bool CList::MoveAdjust()
m_eventButton[i] = m_button[i]->GetEventType();
}
- if ( m_scroll != nullptr ) {
+ if ( m_scroll != nullptr )
+ {
ppos.x = ipos.x + idim.x - SCROLL_WIDTH;
ppos.y = ipos.y;
ddim.x = SCROLL_WIDTH;
@@ -187,8 +213,10 @@ void CList::SetDim(Math::Point dim)
bool CList::SetState(int state, bool bState)
{
- if (state & STATE_ENABLE) {
- for (int i = 0; i < m_displayLine; i++) {
+ if (state & STATE_ENABLE)
+ {
+ for (int i = 0; i < m_displayLine; i++)
+ {
if (m_button[i] != nullptr)
m_button[i]->SetState(state, bState);
}
@@ -202,8 +230,10 @@ bool CList::SetState(int state, bool bState)
bool CList::SetState(int state)
{
- if (state & STATE_ENABLE) {
- for (int i = 0; i < m_displayLine; i++) {
+ if (state & STATE_ENABLE)
+ {
+ for (int i = 0; i < m_displayLine; i++)
+ {
if (m_button[i] != nullptr)
m_button[i]->SetState(state);
}
@@ -217,8 +247,10 @@ bool CList::SetState(int state)
bool CList::ClearState(int state)
{
- if (state & STATE_ENABLE) {
- for (int i = 0; i < m_displayLine; i++) {
+ if (state & STATE_ENABLE)
+ {
+ for (int i = 0; i < m_displayLine; i++)
+ {
if (m_button[i] != nullptr)
m_button[i]->ClearState(state);
}
@@ -235,15 +267,20 @@ bool CList::ClearState(int state)
bool CList::EventProcess(const Event &event)
{
int i;
- if (m_bBlink && event.type == EVENT_FRAME) {
+ if (m_bBlink && event.type == EVENT_FRAME)
+ {
i = m_selectLine-m_firstLine;
- if (i >= 0 && i < 4 && m_button[i] != nullptr) {
+ if (i >= 0 && i < 4 && m_button[i] != nullptr)
+ {
m_blinkTime += event.rTime;
- if (Math::Mod(m_blinkTime, 0.7f) < 0.3f) {
+ if (Math::Mod(m_blinkTime, 0.7f) < 0.3f)
+ {
m_button[i]->ClearState(STATE_ENABLE);
m_button[i]->ClearState(STATE_CHECK);
- } else {
+ }
+ else
+ {
m_button[i]->SetState(STATE_ENABLE);
m_button[i]->SetState(STATE_CHECK);
}
@@ -255,7 +292,8 @@ bool CList::EventProcess(const Event &event)
if ((m_state & STATE_ENABLE) == 0)
return true;
- if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_UP && Detect(event.mousePos)) {
+ if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_UP && Detect(event.mousePos))
+ {
if (m_firstLine > 0)
m_firstLine--;
UpdateScroll();
@@ -263,7 +301,8 @@ bool CList::EventProcess(const Event &event)
return true;
}
- if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_DOWN && Detect(event.mousePos)) {
+ if (event.type == EVENT_MOUSE_WHEEL && event.mouseWheel.dir == WHEEL_DOWN && Detect(event.mousePos))
+ {
if (m_firstLine < m_totalLine - m_displayLine)
m_firstLine++;
UpdateScroll();
@@ -273,9 +312,11 @@ bool CList::EventProcess(const Event &event)
CControl::EventProcess(event);
- if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos)) {
+ if (event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos))
+ {
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
- for (i = 0; i < m_displayLine; i++) {
+ for (i = 0; i < m_displayLine; i++)
+ {
if (i + m_firstLine >= m_totalLine)
break;
if (m_button[i] != nullptr)
@@ -283,16 +324,20 @@ bool CList::EventProcess(const Event &event)
}
}
- if (m_bSelectCap) {
- for (i = 0; i < m_displayLine; i++) {
+ if (m_bSelectCap)
+ {
+ for (i = 0; i < m_displayLine; i++)
+ {
if (i + m_firstLine >= m_totalLine)
break;
- if (m_button[i] != nullptr) {
+ if (m_button[i] != nullptr)
+ {
if (!m_button[i]->EventProcess(event))
return false;
- if (event.type == m_eventButton[i]) {
+ if (event.type == m_eventButton[i])
+ {
SetSelect(m_firstLine + i);
Event newEvent = event;
@@ -303,11 +348,13 @@ bool CList::EventProcess(const Event &event)
}
}
- if (m_scroll != nullptr) {
+ if (m_scroll != nullptr)
+ {
if (!m_scroll->EventProcess(event))
return false;
- if (event.type == m_eventScroll) {
+ if (event.type == m_eventScroll)
+ {
MoveScroll();
UpdateButton();
}
@@ -335,10 +382,12 @@ void CList::Draw()
dp = 0.5f / 256.0f;
- if (m_icon != -1) {
+ if (m_icon != -1)
+ {
dim = m_dim;
- if (m_icon == 0) {
+ if (m_icon == 0)
+ {
m_engine->SetTexture("button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
@@ -346,7 +395,9 @@ void CList::Draw()
uv1.y = 64.0f / 256.0f; // u-v texture
uv2.x = 160.0f / 256.0f;
uv2.y = 96.0f / 256.0f;
- } else {
+ }
+ else
+ {
m_engine->SetTexture("button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
@@ -355,7 +406,8 @@ void CList::Draw()
uv2.x = 156.0f / 256.0f;
uv2.y = 92.0f / 256.0f;
- if (m_button[0] != nullptr) {
+ if (m_button[0] != nullptr)
+ {
dim = m_button[0]->GetDim();
dim.y *= m_displayLine; // background sounds spot behind
}
@@ -371,9 +423,11 @@ void CList::Draw()
DrawIcon(m_pos, dim, uv1, uv2, corner, 8.0f / 256.0f);
}
- if ( m_totalLine < m_displayLine ) { // no buttons to the bottom?
+ if ( m_totalLine < m_displayLine ) // no buttons to the bottom?
+ {
i = m_totalLine;
- if ( m_button[i] != 0 ) {
+ if ( m_button[i] != 0 )
+ {
pos = m_button[i]->GetPos();
dim = m_button[i]->GetDim();
pos.y += dim.y * 1.1f;
@@ -394,11 +448,13 @@ void CList::Draw()
}
}
- for (i = 0; i < m_displayLine; i++) {
+ for (i = 0; i < m_displayLine; i++)
+ {
if ( i + m_firstLine >= m_totalLine )
break;
- if ( m_button[i] != nullptr ) {
+ if ( m_button[i] != nullptr )
+ {
if ( !m_bBlink && i + m_firstLine < m_totalLine )
m_button[i]->SetState(STATE_ENABLE, m_enable[i+m_firstLine] && (m_state & STATE_ENABLE) );
@@ -407,22 +463,27 @@ void CList::Draw()
// draws text in the box
pos = m_button[i]->GetPos();
dim = m_button[i]->GetDim();
- if ( m_tabs[0] == 0.0f ) {
+ if ( m_tabs[0] == 0.0f )
+ {
ppos.x = pos.x + dim.y * 0.5f;
ppos.y = pos.y + dim.y * 0.5f;
ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
ddim.x = dim.x-dim.y;
DrawCase(m_text[i + m_firstLine], ppos, ddim.x, Gfx::TEXT_ALIGN_LEFT);
- } else {
+ }
+ else
+ {
ppos.x = pos.x + dim.y * 0.5f;
ppos.y = pos.y + dim.y * 0.5f;
ppos.y -= m_engine->GetText()->GetHeight(m_fontType, m_fontSize) / 2.0f;
pb = m_text[i + m_firstLine];
- for (int j = 0; j < 10; j++) {
+ for (int j = 0; j < 10; j++)
+ {
pe = strchr(pb, '\t');
if ( pe == 0 )
strcpy(text, pb);
- else {
+ else
+ {
strncpy(text, pb, pe - pb);
text[pe - pb] = 0;
}
@@ -435,7 +496,8 @@ void CList::Draw()
}
}
- if ( (m_state & STATE_EXTEND) && i < m_totalLine) {
+ if ( (m_state & STATE_EXTEND) && i < m_totalLine)
+ {
pos = m_button[i]->GetPos();
dim = m_button[i]->GetDim();
pos.x += dim.x - dim.y * 0.75f;
@@ -445,7 +507,8 @@ void CList::Draw()
dim.x -= 4.0f / 640.0f;
dim.y -= 4.0f / 480.0f;
- if ( m_check[i + m_firstLine] ) {
+ if ( m_check[i + m_firstLine] )
+ {
m_engine->SetTexture("button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
uv1.x = 64.0f / 256.0f;
@@ -468,15 +531,20 @@ void CList::Draw()
uv2.x -= dp;
uv2.y -= dp;
DrawIcon(pos, dim, uv1, uv2); // draws v
- } else {
+ }
+ else
+ {
m_engine->SetTexture("button1.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE); // was D3DSTATETTw
- if ( i + m_firstLine == m_selectLine ) {
+ if ( i + m_firstLine == m_selectLine )
+ {
uv1.x =224.0f / 256.0f; // <
uv1.y =192.0f / 256.0f;
uv2.x =256.0f / 256.0f;
uv2.y =224.0f / 256.0f;
- } else {
+ }
+ else
+ {
uv1.x = 96.0f / 256.0f; // x
uv1.y = 32.0f / 256.0f;
uv2.x =128.0f / 256.0f;
@@ -541,7 +609,8 @@ void CList::SetSelect(int i)
{
if ( m_bSelectCap )
m_selectLine = i;
- else {
+ else
+ {
m_firstLine = i;
UpdateScroll();
}
@@ -584,8 +653,10 @@ void CList::SetBlink(bool bEnable)
i = m_selectLine-m_firstLine;
- if (i >= 0 && i < 4 && m_button[i] != nullptr) {
- if ( !bEnable ) {
+ if (i >= 0 && i < 4 && m_button[i] != nullptr)
+ {
+ if ( !bEnable )
+ {
m_button[i]->SetState(STATE_CHECK);
m_button[i]->ClearState(STATE_ENABLE);
}
@@ -600,7 +671,7 @@ bool CList::GetBlink()
// Specifies the text of a line.
-void CList::SetName(int i, const char* name)
+void CList::SetItemName(int i, const char* name)
{
if ( i < 0 || i >= LISTMAXTOTAL )
return;
@@ -619,7 +690,7 @@ void CList::SetName(int i, const char* name)
// Returns the text of a line.
-char* CList::GetName(int i)
+char* CList::GetItemName(int i)
{
if ( i < 0 || i >= m_totalLine )
return 0;
@@ -725,17 +796,21 @@ void CList::UpdateButton()
state = CControl::GetState();
j = m_firstLine;
- for (i = 0; i < m_displayLine; i++) {
+ for (i = 0; i < m_displayLine; i++)
+ {
if (m_button[i] == nullptr)
continue;
m_button[i]->SetState(STATE_CHECK, (j == m_selectLine));
- if ( j < m_totalLine ) {
+ if ( j < m_totalLine )
+ {
//? m_button[i]->SetName(m_text[j]);
m_button[i]->SetName(" "); // blank button
m_button[i]->SetState(STATE_ENABLE, (state & STATE_ENABLE));
- } else {
+ }
+ else
+ {
m_button[i]->SetName(" "); // blank button
m_button[i]->ClearState(STATE_ENABLE);
}
@@ -752,11 +827,14 @@ void CList::UpdateScroll()
if (m_scroll == nullptr)
return;
- if (m_totalLine <= m_displayLine) {
+ if (m_totalLine <= m_displayLine)
+ {
ratio = 1.0f;
value = 0.0f;
step = 0.0f;
- } else {
+ }
+ else
+ {
ratio = static_cast<float>(m_displayLine) / m_totalLine;
if ( ratio > 1.0f ) ratio = 1.0f;
@@ -797,4 +875,5 @@ void CList::MoveScroll()
}
-}
+} // namespace Ui
+
diff --git a/src/ui/list.h b/src/ui/list.h
index 97bd48c..a2e033f 100644
--- a/src/ui/list.h
+++ b/src/ui/list.h
@@ -69,8 +69,8 @@ class CList : public CControl
void SetBlink(bool bEnable);
bool GetBlink();
- void SetName(int i, const char* name);
- char* GetName(int i);
+ void SetItemName(int i, const char* name);
+ char* GetItemName(int i);
void SetCheck(int i, bool bMode);
bool GetCheck(int i);
@@ -93,6 +93,10 @@ class CList : public CControl
void MoveScroll();
void DrawCase(char *text, Math::Point pos, float width, Gfx::TextAlign justif);
+ private:
+ // Overridden to avoid warning about hiding the virtual function
+ virtual bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType) override;
+
protected:
CButton* m_button[LISTMAXDISPLAY];
CScroll* m_scroll;
@@ -117,5 +121,5 @@ class CList : public CControl
};
-}
+} // namespace Ui
diff --git a/src/ui/maindialog.cpp b/src/ui/maindialog.cpp
index 9060e8b..defff84 100644
--- a/src/ui/maindialog.cpp
+++ b/src/ui/maindialog.cpp
@@ -63,7 +63,7 @@ const int KEY_VISIBLE = 6; // number of visible keys redefinable
const int KEY_TOTAL = 21; // total number of keys redefinable
-const float WELCOME_LENGTH = 2.0f;
+const float WELCOME_LENGTH = 3.0f;
const int MAX_FNAME = 255; // TODO: remove after rewrite to std::string
@@ -174,10 +174,18 @@ CMainDialog::CMainDialog()
m_sceneDir = "levels";
- m_savegameDir = GetSystemUtils()->savegameDirectoryLocation();
+
+ #if DEV_BUILD
+ m_savegameDir = "savegame";
+ #else
+ m_savegameDir = GetSystemUtils()->GetSavegameDirectoryLocation();
+ #endif
+
m_publicDir = "program";
m_userDir = "user";
- m_filesDir = "files";
+ m_filesDir = m_savegameDir;
+
+ m_setupFull = m_app->GetVideoConfig().fullScreen;
m_bDialog = false;
}
@@ -193,7 +201,7 @@ CMainDialog::~CMainDialog()
void CMainDialog::ChangePhase(Phase phase)
{
- CWindow* pw;
+ CWindow* pw = nullptr;
CEdit* pe;
CEditValue* pv;
CLabel* pl;
@@ -358,7 +366,8 @@ pb->SetState(STATE_SHADOW);
}
// #endif
- if ( m_app->GetDebugMode() )
+ // TODO: remove?
+ if (m_app->GetProtoMode())
{
pos.x = 139.0f/640.0f;
pos.y = 313.0f/480.0f;
@@ -383,7 +392,7 @@ pb->SetState(STATE_SHADOW);
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
@@ -503,7 +512,7 @@ pb->SetState(STATE_SHADOW);
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
@@ -738,6 +747,24 @@ pb->SetState(STATE_SHADOW);
CameraPerso();
}
+ if ( m_phase != PHASE_SIMUL &&
+ m_phase != PHASE_WIN &&
+ m_phase != PHASE_LOST &&
+ m_phase != PHASE_WRITE &&
+ m_phase != PHASE_READs &&
+ m_phase != PHASE_WRITEs &&
+ m_phase != PHASE_SETUPds &&
+ m_phase != PHASE_SETUPgs &&
+ m_phase != PHASE_SETUPps &&
+ m_phase != PHASE_SETUPcs &&
+ m_phase != PHASE_SETUPss )
+ {
+ if (!m_sound->IsPlayingMusic())
+ {
+ m_sound->PlayMusic("Intro1.ogg", false);
+ }
+ }
+
if ( m_phase == PHASE_TRAINER ||
m_phase == PHASE_DEFI ||
m_phase == PHASE_MISSION ||
@@ -746,10 +773,6 @@ pb->SetState(STATE_SHADOW);
m_phase == PHASE_USER ||
m_phase == PHASE_PROTO )
{
- if (!m_sound->IsPlayingMusic()) {
- m_sound->PlayMusic(11, true);
- }
-
if ( m_phase == PHASE_TRAINER ) m_index = 0;
if ( m_phase == PHASE_DEFI ) m_index = 1;
if ( m_phase == PHASE_MISSION ) m_index = 2;
@@ -959,7 +982,7 @@ pb->SetState(STATE_SHADOW);
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
@@ -1158,7 +1181,7 @@ pb->SetState(STATE_SHADOW);
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
}
@@ -1604,7 +1627,7 @@ pos.y -= 0.048f;
}
if ( m_phase == PHASE_READ ||
- m_phase == PHASE_READs )
+ m_phase == PHASE_READs )
{
pos.x = 0.10f;
pos.y = 0.10f;
@@ -1683,7 +1706,7 @@ pos.y -= 0.048f;
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
}
@@ -1733,7 +1756,7 @@ pos.y -= 0.048f;
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
m_loadingCounter = 1; // enough time to display!
@@ -1741,9 +1764,6 @@ pos.y -= 0.048f;
if ( m_phase == PHASE_WELCOME1 )
{
- m_sound->StopMusic();
- m_sound->PlayMusic(11, false);
-
pos.x = 0.0f;
pos.y = 0.0f;
ddim.x = 0.0f;
@@ -1758,7 +1778,7 @@ pos.y -= 0.048f;
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, Math::Point(861.0f / 1024.0f, 646.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
if ( m_phase == PHASE_WELCOME2 )
@@ -1769,7 +1789,7 @@ pos.y -= 0.048f;
ddim.y = 0.0f;
pw = m_interface->CreateWindows(pos, ddim, -1, EVENT_WINDOW5);
- m_engine->SetOverColor(Gfx::Color(1.0f, 1.0f, 1.0f, 1.0f), Gfx::ENG_RSTATE_TCOLOR_BLACK); // TODO: color ok?
+ m_engine->SetOverColor(Gfx::Color(0.0f, 0.0f, 0.0f, 0.0f), Gfx::ENG_RSTATE_TCOLOR_WHITE); // TODO: color ok?
m_engine->SetOverFront(true);
m_engine->SetBackground("colobot.png",
@@ -1777,7 +1797,7 @@ pos.y -= 0.048f;
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, Math::Point(640.0f / 1024.0f, 480.0f / 512.0f));
+ true);
m_engine->SetBackForce(true);
}
if ( m_phase == PHASE_WELCOME3 )
@@ -1796,7 +1816,7 @@ pos.y -= 0.048f;
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, Math::Point(640.0f / 1024.0f, 480.0f / 512.0f));
+ true);
m_engine->SetBackForce(true);
}
@@ -1932,7 +1952,7 @@ pos.y -= 0.048f;
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, Math::Point(1.0f, 768.0f / 1024.0f));
+ true);
m_engine->SetBackForce(true);
}
@@ -2001,33 +2021,58 @@ bool CMainDialog::EventProcess(const Event &event)
//? else welcomeLength = WELCOME_LENGTH;
welcomeLength = WELCOME_LENGTH;
+ if ( m_phase != PHASE_SIMUL &&
+ m_phase != PHASE_WIN &&
+ m_phase != PHASE_LOST &&
+ m_phase != PHASE_WRITE &&
+ m_phase != PHASE_READs &&
+ m_phase != PHASE_WRITEs &&
+ m_phase != PHASE_SETUPds &&
+ m_phase != PHASE_SETUPgs &&
+ m_phase != PHASE_SETUPps &&
+ m_phase != PHASE_SETUPcs &&
+ m_phase != PHASE_SETUPss )
+ {
+ if (!m_sound->IsPlayingMusic())
+ {
+ m_sound->PlayMusic("Intro2.ogg", true);
+ }
+ }
+
if ( m_phase == PHASE_WELCOME1 ||
- m_phase == PHASE_WELCOME2 ||
- m_phase == PHASE_WELCOME3 )
+ m_phase == PHASE_WELCOME2 ||
+ m_phase == PHASE_WELCOME3 )
{
float intensity;
- int mode = Gfx::ENG_RSTATE_TCOLOR_BLACK;
+ int mode = Gfx::ENG_RSTATE_TCOLOR_WHITE;
+
+ // 1/4 of display time is animating
+ float animatingTime = welcomeLength / 4.0f;
- if ( m_phaseTime < 1.5f )
+ if ( m_phaseTime < animatingTime )
{
- intensity = 1.0f-(m_phaseTime-0.5f);
+ //appearing
+ intensity = m_phaseTime / animatingTime;
}
- else if ( m_phaseTime < welcomeLength-1.0f )
+ else if ( m_phaseTime < welcomeLength - animatingTime )
{
- intensity = 0.0f;
+ //showing
+ intensity = 1.0f;
}
else
{
- intensity = m_phaseTime-(welcomeLength-1.0f);
+ //hiding
+ intensity = (welcomeLength - m_phaseTime) / animatingTime;
}
+
if ( intensity < 0.0f ) intensity = 0.0f;
if ( intensity > 1.0f ) intensity = 1.0f;
- if ( (m_phase == PHASE_WELCOME2 && m_phaseTime > welcomeLength/2.0f) ||
- m_phase == PHASE_WELCOME3 )
+ //white first, others -> black fadding
+ if ( (m_phase == PHASE_WELCOME1) && ( m_phaseTime < welcomeLength/2.0f))
{
- intensity = 1.0f-intensity;
- mode = Gfx::ENG_RSTATE_TCOLOR_WHITE;
+ intensity = 1.0f - intensity;
+ mode = Gfx::ENG_RSTATE_TCOLOR_BLACK;
}
m_engine->SetOverColor(Gfx::Color(intensity, intensity, intensity, intensity), mode); // TODO: color ok?
@@ -2270,7 +2315,7 @@ bool CMainDialog::EventProcess(const Event &event)
if ( pw == 0 ) break;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_NLIST));
if ( pl == 0 ) break;
- StartDeleteGame(pl->GetName(pl->GetSelect()));
+ StartDeleteGame(pl->GetItemName(pl->GetSelect()));
break;
default:
@@ -2587,15 +2632,18 @@ bool CMainDialog::EventProcess(const Event &event)
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) break;
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_FULL));
- if ( pc == 0 ) break;
-
- if ( pc->TestState(STATE_CHECK) ) {
- m_setupFull = false;
- pc->ClearState(STATE_CHECK);
- } else {
- m_setupFull = true;
- pc->SetState(STATE_CHECK);
- }
+ if ( pc == 0 ) break;
+
+ if ( pc->TestState(STATE_CHECK) )
+ {
+ m_setupFull = false;
+ pc->ClearState(STATE_CHECK);
+ }
+ else
+ {
+ m_setupFull = true;
+ pc->SetState(STATE_CHECK);
+ }
UpdateApply();
break;
@@ -2607,7 +2655,7 @@ bool CMainDialog::EventProcess(const Event &event)
if ( pb == 0 ) break;
pb->ClearState(STATE_PRESS);
pb->ClearState(STATE_HILIGHT);
- // TODO: uncomment when changing display is implemented
+ // TODO: uncomment when changing display is implemented
//ChangeDisplay();
UpdateApply();
break;
@@ -3630,8 +3678,9 @@ void CMainDialog::ReadNameList()
{
fs::directory_iterator dirIt(m_savegameDir), dirEndIt;
- BOOST_FOREACH (const fs::path & p, std::make_pair(dirIt, dirEndIt))
+ for (; dirIt != dirEndIt; ++dirIt)
{
+ const fs::path& p = *dirIt;
if (fs::is_directory(p))
{
fileNames.push_back(p.leaf().string());
@@ -3648,7 +3697,7 @@ void CMainDialog::ReadNameList()
for (size_t i=0 ; i<fileNames.size() ; ++i )
{
- pl->SetName(i, fileNames.at(i).c_str());
+ pl->SetItemName(i, fileNames.at(i).c_str());
}
}
@@ -3724,7 +3773,7 @@ void CMainDialog::UpdateNameList()
for ( i=0 ; i<total ; i++ )
{
// TODO: stricmp?
- if ( strcmp(name, pl->GetName(i)) == 0 )
+ if ( strcmp(name, pl->GetItemName(i)) == 0 )
{
pl->SetSelect(i);
pl->ShowSelect(false);
@@ -3760,7 +3809,7 @@ void CMainDialog::UpdateNameEdit()
}
else
{
- name = pl->GetName(sel);
+ name = pl->GetItemName(sel);
pe->SetText(name);
pe->SetCursor(strlen(name), 0);
}
@@ -3784,7 +3833,7 @@ void CMainDialog::UpdateNameFace()
sel = pl->GetSelect();
if ( sel == -1 ) return;
- name = pl->GetName(sel);
+ name = pl->GetItemName(sel);
ReadGamerPerso(name);
}
@@ -3815,7 +3864,7 @@ void CMainDialog::NameSelect()
}
else
{
- m_main->SetGamerName(pl->GetName(sel));
+ m_main->SetGamerName(pl->GetItemName(sel));
m_main->ChangePhase(PHASE_INIT);
}
@@ -3942,7 +3991,7 @@ void CMainDialog::NameDelete()
m_sound->Play(SOUND_TZOING);
return;
}
- gamer = pl->GetName(sel);
+ gamer = pl->GetItemName(sel);
// Deletes all the contents of the file.
sprintf(dir, "%s/%s", m_savegameDir.c_str(), gamer);
@@ -4256,14 +4305,21 @@ void CMainDialog::DefPerso()
bool CMainDialog::IsIOReadScene()
{
- FILE* file;
- std::string filename;
+ fs::directory_iterator end_iter;
- filename = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + "000/data.sav";
- file = fopen(filename.c_str(), "r");
- if ( file == NULL ) return false;
- fclose(file);
- return true;
+ fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName());
+ if (fs::exists(saveDir) && fs::is_directory(saveDir))
+ {
+ for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter)
+ {
+ if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") )
+ {
+ return true;
+ }
+ }
+ }
+
+ return false;
}
// Builds the file name by default.
@@ -4283,9 +4339,9 @@ void CMainDialog::IOReadName()
int i;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw == 0 ) return;
+ if ( pw == nullptr ) return;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_IONAME));
- if ( pe == 0 ) return;
+ if ( pe == nullptr ) return;
sprintf(resume, "%s %d", m_sceneName, m_chap[m_index]+1);
BuildSceneName(filename, m_sceneName, (m_chap[m_index]+1)*100);
@@ -4337,7 +4393,8 @@ void CMainDialog::IOReadList()
CList* pl;
char line[500];
char name[100];
- int i, j;
+ int i;
+ fs::directory_iterator end_iter;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
@@ -4346,49 +4403,53 @@ void CMainDialog::IOReadList()
pl->Flush();
- for ( j=0 ; j<999 ; j++ )
- {
- std::string filename;
- std::ostringstream rankStream;
- rankStream << std::setfill('0') << std::setw(3) << j;
- filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav";
-
- // sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j);
- file = fopen(fs::path(filename).make_preferred().string().c_str(), "r");
- if ( file == NULL ) break;
+ fs::path saveDir(m_savegameDir + "/" + m_main->GetGamerName());
+ m_saveList.clear();
- while ( fgets(line, 500, file) != NULL )
+ if (fs::exists(saveDir) && fs::is_directory(saveDir))
+ {
+ for( fs::directory_iterator dir_iter(saveDir) ; dir_iter != end_iter ; ++dir_iter)
{
- for ( i=0 ; i<500 ; i++ )
+ if ( fs::is_directory(dir_iter->status()) && fs::exists(dir_iter->path() / "data.sav") )
{
- if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
- if ( line[i] == '/' && line[i+1] == '/' )
+
+ file = fopen((dir_iter->path() / "data.sav").make_preferred().string().c_str(), "r");
+ if ( file == NULL ) continue;
+
+ while ( fgets(line, 500, file) != NULL )
{
- line[i] = 0;
- break;
+ for ( i=0 ; i<500 ; i++ )
+ {
+ if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
+ if ( line[i] == '/' && line[i+1] == '/' )
+ {
+ line[i] = 0;
+ break;
+ }
+ }
+
+ if ( Cmd(line, "Title") )
+ {
+ OpString(line, "text", name);
+ break;
+ }
}
- }
+ fclose(file);
- if ( Cmd(line, "Title") )
- {
- OpString(line, "text", name);
- break;
+ pl->SetItemName(m_saveList.size(), name);
+ m_saveList.push_back(dir_iter->path());
}
}
- fclose(file);
-
- pl->SetName(j, name);
}
- if ( m_phase == PHASE_WRITE ||
- m_phase == PHASE_WRITEs )
+ // invalid index
+ if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs )
{
GetResource(RES_TEXT, RT_IO_NEW, name);
- pl->SetName(j, name);
- j ++;
+ pl->SetItemName(m_saveList.size(), name);
}
- pl->SetSelect(j-1);
+ pl->SetSelect(m_saveList.size());
pl->ShowSelect(false); // shows the selected columns
}
@@ -4403,22 +4464,20 @@ void CMainDialog::IOUpdateList()
int sel, max;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw == 0 ) return;
+ if ( pw == nullptr ) return;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
- if ( pl == 0 ) return;
+ if ( pl == nullptr ) return;
pi = static_cast<CImage*>(pw->SearchControl(EVENT_INTERFACE_IOIMAGE));
- if ( pi == 0 ) return;
+ if ( pi == nullptr ) return;
sel = pl->GetSelect();
max = pl->GetTotal();
- std::string filename;
- std::ostringstream rankStream;
- rankStream << std::setfill('0') << std::setw(3) << sel;
- filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/screen.png";
+ if (m_saveList.size() <= static_cast<unsigned int>(sel))
+ return;
- if ( m_phase == PHASE_WRITE ||
- m_phase == PHASE_WRITEs )
+ std::string filename = (m_saveList.at(sel) / "screen.png").make_preferred().string();
+ if ( m_phase == PHASE_WRITE || m_phase == PHASE_WRITEs )
{
if ( sel < max-1 )
{
@@ -4430,7 +4489,7 @@ void CMainDialog::IOUpdateList()
}
pb = static_cast<CButton*>(pw->SearchControl(EVENT_INTERFACE_IODELETE));
- if ( pb != 0 )
+ if ( pb != nullptr )
{
pb->SetState(STATE_ENABLE, sel < max-1);
}
@@ -4455,34 +4514,44 @@ void CMainDialog::IODeleteScene()
if ( pl == 0 ) return;
sel = pl->GetSelect();
- if ( sel == -1 )
+ if ( sel == -1 || m_saveList.size() <= static_cast<unsigned int>(sel))
{
m_sound->Play(SOUND_TZOING);
return;
}
-
- std::ostringstream rankStream;
- std::string fileName;
- rankStream << std::setfill('0') << std::setw(3) << sel;
- fileName = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str();
try
{
- if (fs::exists(fileName) && fs::is_directory(fileName))
+ if (fs::exists(m_saveList.at(sel)) && fs::is_directory(m_saveList.at(sel)))
{
- fs::remove_all(fileName);
+ fs::remove_all(m_saveList.at(sel));
}
}
catch (std::exception & e)
{
- GetLogger()->Error("Error on removing directory %s : %s\n", e.what());
+ GetLogger()->Error("Error removing save %s : %s\n", pl->GetItemName(sel), e.what());
}
IOReadList();
}
-// Writes the scene.
+// 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.
bool CMainDialog::IOWriteScene()
{
CWindow* pw;
@@ -4492,36 +4561,40 @@ bool CMainDialog::IOWriteScene()
int sel;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw == 0 ) return false;
+ if ( pw == nullptr ) return false;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
- if ( pl == 0 ) return false;
+ if ( pl == nullptr ) return false;
pe = static_cast<CEdit*>(pw->SearchControl(EVENT_INTERFACE_IONAME));
- if ( pe == 0 ) return false;
+ if ( pe == nullptr ) return false;
sel = pl->GetSelect();
- if ( sel == -1 ) return false;
+ if ( sel == -1 )
+ {
+ return false;
+ }
- std::string directoryName;
- std::string fileName;
- std::string fileCBot;
- std::ostringstream selectStream;
+ fs::path dir;
+ pe->GetText(info, 100);
+ if (static_cast<unsigned int>(sel) >= m_saveList.size())
+ {
+ dir = fs::path(m_savegameDir) / m_main->GetGamerName() / ("save" + clearName(info));
+ }
+ else
+ {
+ dir = m_saveList.at(sel);
+ }
- //TODO: Change this to point user dir according to operating system
- GetLogger()->Debug("Creating save directory\n");
- selectStream << std::setfill('0') << std::setw(3) << sel;
- directoryName = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + selectStream.str();
- if (!fs::exists(directoryName))
+ if (!fs::exists(dir))
{
- fs::create_directories(directoryName);
+ fs::create_directories(dir);
}
- fileName = directoryName + "/data.sav";
- fileCBot = directoryName + "/cbot.run";
- pe->GetText(info, 100);
+ std::string fileName = (dir / "data.sav").make_preferred().string();
+ std::string fileCBot = (dir / "cbot.run").make_preferred().string();
m_main->IOWriteScene(fileName.c_str(), fileCBot.c_str(), info);
m_shotDelay = 3;
- m_shotName = directoryName + "/screen.png";
+ m_shotName = (dir / "screen.png").make_preferred().string();
return true;
}
@@ -4538,26 +4611,24 @@ bool CMainDialog::IOReadScene()
int sel, i;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw == 0 ) return false;
+ if ( pw == nullptr ) return false;
pl = static_cast<CList*>(pw->SearchControl(EVENT_INTERFACE_IOLIST));
- if ( pl == 0 ) return false;
+ if ( pl == nullptr ) return false;
sel = pl->GetSelect();
- if ( sel == -1 ) return false;
-
- //TODO: Change this to point user dir according to operating system
- std::string fileName;
- std::string fileCbot;
- std::string directoryName;
- std::ostringstream selectStream;
- selectStream << std::setfill('0') << std::setw(3) << sel;
- directoryName = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + selectStream.str();
+ if ( sel == -1 || m_saveList.size() <= static_cast<unsigned int>(sel) )
+ {
+ return false;
+ }
- fileName = directoryName + "/data.sav";
- fileCbot = directoryName + "/cbot.run";
+ std::string fileName = (m_saveList.at(sel) / "data.sav").make_preferred().string();
+ std::string fileCbot = (m_saveList.at(sel) / "cbot.run").make_preferred().string();
file = fopen(fileName.c_str(), "r");
- if ( file == NULL ) return false;
+ if ( file == NULL )
+ {
+ return false;
+ }
while ( fgets(line, 500, file) != NULL )
{
@@ -4598,8 +4669,8 @@ bool CMainDialog::IOReadScene()
}
fclose(file);
- m_chap[m_index] = (m_sceneRank/100)-1;
- m_sel[m_index] = (m_sceneRank%100)-1;
+ m_chap[m_index] = (m_sceneRank / 100)-1;
+ m_sel[m_index] = (m_sceneRank % 100)-1;
m_sceneRead = fileName;
m_stackRead = fileCbot;
@@ -4676,8 +4747,9 @@ void CMainDialog::UpdateSceneChap(int &chap)
fs::directory_iterator dirIt(m_savegameDir), dirEndIt;
m_userList.clear();
- BOOST_FOREACH (const fs::path & p, std::make_pair(dirIt, dirEndIt))
+ for (; dirIt != dirEndIt; ++dirIt)
{
+ const fs::path& p = *dirIt;
if (fs::is_directory(p))
{
m_userList.push_back(p.leaf().string());
@@ -4724,7 +4796,7 @@ void CMainDialog::UpdateSceneChap(int &chap)
fclose(file);
}
- pl->SetName(j, name);
+ pl->SetItemName(j, name);
pl->SetEnable(j, true);
}
}
@@ -4777,7 +4849,7 @@ void CMainDialog::UpdateSceneChap(int &chap)
bPassed = GetGamerInfoPassed((j+1)*100);
sprintf(line, "%d: %s", j+1, name);
- pl->SetName(j, line);
+ pl->SetItemName(j, line);
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
@@ -4887,7 +4959,7 @@ void CMainDialog::UpdateSceneList(int chap, int &sel)
bPassed = GetGamerInfoPassed((chap+1)*100+(j+1));
sprintf(line, "%d: %s", j+1, name);
- pl->SetName(j, line);
+ pl->SetItemName(j, line);
pl->SetCheck(j, bPassed);
pl->SetEnable(j, true);
@@ -5016,6 +5088,9 @@ void CMainDialog::UpdateSceneResume(int rank)
{
for ( i=0 ; i<500 ; i++ )
{
+ if (line[i] == 0)
+ break;
+
if ( line[i] == '\t' ) line[i] = ' '; // replaces tab by space
if ( line[i] == '/' && line[i+1] == '/' )
{
@@ -5066,7 +5141,7 @@ void CMainDialog::UpdateDisplayDevice()
j = 0;
while ( bufDevices[i] != 0 )
{
- pl->SetName(j++, bufDevices+i);
+ pl->SetItemName(j++, bufDevices+i);
while ( bufDevices[i++] != 0 );
}
@@ -5093,10 +5168,11 @@ void CMainDialog::UpdateDisplayMode()
m_app->GetVideoResolutionList(modes, true, true);
int i = 0;
std::stringstream mode_text;
- for (Math::IntPoint mode : modes) {
- mode_text.str("");
- mode_text << mode.x << "x" << mode.y;
- pl->SetName(i++, mode_text.str().c_str());
+ for (Math::IntPoint mode : modes)
+ {
+ mode_text.str("");
+ mode_text << mode.x << "x" << mode.y;
+ pl->SetItemName(i++, mode_text.str().c_str());
}
pl->SetSelect(m_setupSelMode);
@@ -5120,12 +5196,12 @@ void CMainDialog::ChangeDisplay()
pl = static_cast<CList*>(pw->SearchControl(EVENT_LIST1));
if ( pl == 0 ) return;
m_setupSelDevice = pl->GetSelect();
- //device = pl->GetName(m_setupSelDevice);
+ //device = pl->GetItemName(m_setupSelDevice);
pl = static_cast<CList*>(pw->SearchControl(EVENT_LIST2));
if ( pl == 0 ) return;
m_setupSelMode = pl->GetSelect();
- //mode = pl->GetName(m_setupSelMode);
+ //mode = pl->GetItemName(m_setupSelMode);
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_FULL));
if ( pc == 0 ) return;
@@ -5481,6 +5557,7 @@ void CMainDialog::SetupMemorize()
GetProfile().SetLocalProfileInt("Setup", "HimselfDamage", m_bHimselfDamage);
GetProfile().SetLocalProfileInt("Setup", "CameraScroll", m_bCameraScroll);
GetProfile().SetLocalProfileInt("Setup", "CameraInvertX", m_bCameraInvertX);
+ GetProfile().SetLocalProfileInt("Setup", "CameraInvertY", m_bCameraInvertY);
GetProfile().SetLocalProfileInt("Setup", "InterfaceEffect", m_bEffect);
GetProfile().SetLocalProfileInt("Setup", "GroundShadow", m_engine->GetShadow());
GetProfile().SetLocalProfileInt("Setup", "GroundSpot", m_engine->GetGroundSpot());
@@ -5501,23 +5578,29 @@ void CMainDialog::SetupMemorize()
GetProfile().SetLocalProfileInt("Setup", "Sound3D", m_sound->GetSound3D());
GetProfile().SetLocalProfileInt("Setup", "EditIndentMode", m_engine->GetEditIndentMode());
GetProfile().SetLocalProfileInt("Setup", "EditIndentValue", m_engine->GetEditIndentValue());
-
+
/* screen setup */
if (m_setupFull)
- GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 1);
+ GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 1);
else
- GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 0);
-
+ GetProfile().SetLocalProfileInt("Setup", "Fullscreen", 0);
+
CList *pl;
CWindow *pw;
pw = static_cast<CWindow *>(m_interface->SearchControl(EVENT_WINDOW5));
- if ( pw != 0 ) {
- pl = static_cast<CList *>(pw->SearchControl(EVENT_LIST2));
- if ( pl != 0 ) {
- GetProfile().SetLocalProfileInt("Setup", "Resolution", pl->GetSelect());
- }
+ if ( pw != 0 )
+ {
+ pl = static_cast<CList *>(pw->SearchControl(EVENT_LIST2));
+ if ( pl != 0 )
+ {
+ GetProfile().SetLocalProfileInt("Setup", "Resolution", pl->GetSelect());
+ }
+ }
+ else
+ {
+ // TODO: Default value
}
-
+
std::stringstream key;
for (int i = 0; i < INPUT_SLOT_MAX; i++)
{
@@ -5730,6 +5813,11 @@ void CMainDialog::SetupRecall()
m_sound->SetMusicVolume(iValue);
}
+ if ( GetProfile().GetLocalProfileInt("Setup", "Sound3D", iValue) )
+ {
+ m_sound->SetSound3D(iValue == 1);
+ }
+
if ( GetProfile().GetLocalProfileInt("Setup", "EditIndentMode", iValue) )
{
m_engine->SetEditIndentMode(iValue);
@@ -5772,13 +5860,15 @@ void CMainDialog::SetupRecall()
{
m_bDeleteGamer = iValue;
}
-
- if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) ) {
- m_setupSelMode = iValue;
+
+ if ( GetProfile().GetLocalProfileInt("Setup", "Resolution", iValue) )
+ {
+ m_setupSelMode = iValue;
}
-
- if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) ) {
- m_setupFull = (iValue == 1);
+
+ if ( GetProfile().GetLocalProfileInt("Setup", "Fullscreen", iValue) )
+ {
+ m_setupFull = (iValue == 1);
}
}
@@ -6542,6 +6632,8 @@ void CMainDialog::WriteGamerPerso(char *gamer)
file = fopen(filename, "w");
if ( file == NULL ) return;
+ m_main->SetNumericLocale();
+
sprintf(line, "Head face=%d glasses=%d hair=%.2f;%.2f;%.2f;%.2f\n",
m_perso.face, m_perso.glasses,
m_perso.colorHair.r, m_perso.colorHair.g, m_perso.colorHair.b, m_perso.colorHair.a);
@@ -6553,6 +6645,8 @@ void CMainDialog::WriteGamerPerso(char *gamer)
fputs(line, file);
fclose(file);
+
+ m_main->RestoreNumericLocale();
}
// Reads the personalized player.
@@ -6571,6 +6665,8 @@ void CMainDialog::ReadGamerPerso(char *gamer)
file = fopen(filename, "r");
if ( file == NULL ) return;
+ m_main->SetNumericLocale();
+
while ( fgets(line, 100, file) != NULL )
{
if ( Cmd(line, "Head") )
@@ -6602,6 +6698,8 @@ void CMainDialog::ReadGamerPerso(char *gamer)
}
fclose(file);
+
+ m_main->RestoreNumericLocale();
}
// Specifies the face of the player.
@@ -6787,3 +6885,4 @@ bool CMainDialog::NextMission()
} // namespace Ui
+
diff --git a/src/ui/maindialog.h b/src/ui/maindialog.h
index a79b95e..96aff2a 100644
--- a/src/ui/maindialog.h
+++ b/src/ui/maindialog.h
@@ -26,6 +26,8 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
+#include <vector>
+
namespace fs = boost::filesystem;
@@ -260,6 +262,8 @@ protected:
Math::Point m_partiPos[10];
SceneInfo m_sceneInfo[MAXSCENE];
+
+ std::vector<fs::path> m_saveList;
};
} // namespace Ui
diff --git a/src/ui/mainmap.cpp b/src/ui/mainmap.cpp
index 1143a77..8c81160 100644
--- a/src/ui/mainmap.cpp
+++ b/src/ui/mainmap.cpp
@@ -55,7 +55,8 @@ void CMainMap::CreateMap()
Math::Point pos, dim;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW1));
- if (pw == nullptr) {
+ if (pw == nullptr)
+ {
pos.x = 0.0f;
pos.y = 0.0f;
dim.x = 0.0f;
@@ -106,7 +107,8 @@ void CMainMap::FloorColorMap(Gfx::Color floor, Gfx::Color water)
return;
pm = static_cast<CMap*>(pw->SearchControl(EVENT_OBJECT_MAP));
- if (pm != nullptr) {
+ if (pm != nullptr)
+ {
pm->SetFloorColor(floor);
pm->SetWaterColor(water);
}
@@ -124,9 +126,12 @@ void CMainMap::ShowMap(bool bShow)
if (pw == nullptr)
return;
- if (bShow) {
+ if (bShow)
+ {
DimMap();
- } else {
+ }
+ else
+ {
pm = static_cast<CMap*>(pw->SearchControl(EVENT_OBJECT_MAP));
if (pm != nullptr)
pm->ClearState(STATE_VISIBLE);
@@ -164,7 +169,8 @@ void CMainMap::DimMap()
pm->SetDim(dim);
ps = static_cast<CSlider*>(pw->SearchControl(EVENT_OBJECT_MAPZOOM));
- if (ps != nullptr) {
+ if (ps != nullptr)
+ {
ps->SetState(STATE_VISIBLE, (m_mapMode != 0));
dim.x = SCROLL_WIDTH;
@@ -392,3 +398,4 @@ void CMainMap::SetHighlight(CObject* pObj)
}
+
diff --git a/src/ui/mainmap.h b/src/ui/mainmap.h
index 9d0d72f..9b20548 100644
--- a/src/ui/mainmap.h
+++ b/src/ui/mainmap.h
@@ -34,37 +34,37 @@ namespace Ui {
class CMainMap
{
- public:
- CMainMap();
- ~CMainMap();
-
- void UpdateMap();
- void CreateMap();
- void SetFixImage(const char *filename);
- void FloorColorMap(Gfx::Color floor, Gfx::Color water);
- void ShowMap(bool bShow);
- void DimMap();
- float GetZoomMap();
- void ZoomMap(float zoom);
- void ZoomMap();
- void MapEnable(bool bEnable);
- bool GetShowMap();
- bool GetFixImage();
- CObject* DetectMap(Math::Point pos, bool &bInMap);
- void SetHighlight(CObject* pObj);
- void SetToy(bool bToy);
- void SetFixParam(float zoom, float ox, float oy, float angle, int mode, bool bDebug);
-
- protected:
- void CenterMap();
-
- protected:
- CEventQueue* m_event;
- Gfx::CEngine* m_engine;
- CInterface* m_interface;
-
- int m_mapMode;
- bool m_bFixImage;
+public:
+ CMainMap();
+ ~CMainMap();
+
+ void UpdateMap();
+ void CreateMap();
+ void SetFixImage(const char *filename);
+ void FloorColorMap(Gfx::Color floor, Gfx::Color water);
+ void ShowMap(bool bShow);
+ void DimMap();
+ float GetZoomMap();
+ void ZoomMap(float zoom);
+ void ZoomMap();
+ void MapEnable(bool bEnable);
+ bool GetShowMap();
+ bool GetFixImage();
+ CObject* DetectMap(Math::Point pos, bool &bInMap);
+ void SetHighlight(CObject* pObj);
+ void SetToy(bool bToy);
+ void SetFixParam(float zoom, float ox, float oy, float angle, int mode, bool bDebug);
+
+protected:
+ void CenterMap();
+
+protected:
+ CEventQueue* m_event;
+ Gfx::CEngine* m_engine;
+ CInterface* m_interface;
+
+ int m_mapMode;
+ bool m_bFixImage;
};
}
diff --git a/src/ui/mainshort.h b/src/ui/mainshort.h
index d679eb0..b185aed 100644
--- a/src/ui/mainshort.h
+++ b/src/ui/mainshort.h
@@ -34,29 +34,30 @@ namespace Ui {
class CMainShort
{
- public:
- CMainShort();
- ~CMainShort();
-
- void SetMode(bool bBuilding);
- void FlushShortcuts();
- bool CreateShortcuts();
- bool UpdateShortcuts();
- void SelectShortcut(EventType event);
- void SelectNext();
- CObject* DetectShort(Math::Point pos);
- void SetHighlight(CObject* pObj);
-
- protected:
-
- protected:
- CEventQueue* m_event;
- Gfx::CEngine* m_engine;
- CInterface* m_interface;
- CRobotMain* m_main;
-
- CObject* m_shortcuts[20];
- bool m_bBuilding;
+public:
+ CMainShort();
+ ~CMainShort();
+
+ void SetMode(bool bBuilding);
+ void FlushShortcuts();
+ bool CreateShortcuts();
+ bool UpdateShortcuts();
+ void SelectShortcut(EventType event);
+ void SelectNext();
+ CObject* DetectShort(Math::Point pos);
+ void SetHighlight(CObject* pObj);
+
+protected:
+
+protected:
+ CEventQueue* m_event;
+ Gfx::CEngine* m_engine;
+ CInterface* m_interface;
+ CRobotMain* m_main;
+
+ CObject* m_shortcuts[20];
+ bool m_bBuilding;
};
}
+
diff --git a/src/ui/map.cpp b/src/ui/map.cpp
index 33d0fb1..c5f0062 100644
--- a/src/ui/map.cpp
+++ b/src/ui/map.cpp
@@ -187,14 +187,17 @@ bool CMap::EventProcess(const Event &event)
if ( event.type == EVENT_FRAME )
m_time += event.rTime;
- if ( event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos) ) {
+ if ( event.type == EVENT_MOUSE_MOVE && Detect(event.mousePos) )
+ {
m_engine->SetMouseType(Gfx::ENG_MOUSE_NORM);
if ( DetectObject(event.mousePos, bInMap) != 0 )
m_engine->SetMouseType(Gfx::ENG_MOUSE_HAND);
}
- if ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.mouseButton.button == MOUSE_BUTTON_LEFT ) {
- if ( CControl::Detect(event.mousePos) ) {
+ if ( event.type == EVENT_MOUSE_BUTTON_DOWN && event.mouseButton.button == MOUSE_BUTTON_LEFT )
+ {
+ if ( CControl::Detect(event.mousePos) )
+ {
SelectObject(event.mousePos);
return false;
}
@@ -228,11 +231,13 @@ void CMap::SetHighlight(CObject* pObj)
if ( pObj == nullptr )
return;
- for (int i = 0; i < MAPMAXOBJECT; i++) {
+ for (int i = 0; i < MAPMAXOBJECT; i++)
+ {
if ( !m_map[i].bUsed )
continue;
- if ( m_map[i].object == pObj ) {
+ if ( m_map[i].object == pObj )
+ {
m_highlightRank = i;
break;
}
@@ -262,7 +267,8 @@ CObject* CMap::DetectObject(Math::Point pos, bool &bInMap)
min = 10000.0f;
best = -1;
- for (int i = MAPMAXOBJECT - 1; i >= 0; i--) {
+ for (int i = MAPMAXOBJECT - 1; i >= 0; i--)
+ {
if ( !m_map[i].bUsed )
continue;
if ( m_map[i].color == MAPCOLOR_BBOX && !m_bRadar )
@@ -273,7 +279,8 @@ CObject* CMap::DetectObject(Math::Point pos, bool &bInMap)
dist = Math::Point(m_map[i].pos.x - pos.x, m_map[i].pos.y - pos.y).Length();
if ( dist > m_half / m_zoom * 8.0f / 100.0f )
continue; // too far?
- if ( dist < min ) {
+ if ( dist < min )
+ {
min = dist;
best = i;
}
@@ -337,13 +344,15 @@ void CMap::Draw()
if ( m_map[i].bUsed ) // selection:
DrawFocus(m_map[i].pos, m_map[i].dir, m_map[i].type, m_map[i].color);
- for ( i=0 ; i<m_totalFix ; i++ ) { // fixed objects:
+ for ( i=0 ; i<m_totalFix ; i++ ) // fixed objects:
+ {
if ( i == m_highlightRank )
continue;
DrawObject(m_map[i].pos, m_map[i].dir, m_map[i].type, m_map[i].color, false, false);
}
- for ( i=MAPMAXOBJECT-2 ; i>m_totalMove ; i-- ) { // moving objects:
+ for ( i=MAPMAXOBJECT-2 ; i>m_totalMove ; i-- ) // moving objects:
+ {
if ( i == m_highlightRank )
continue;
DrawObject(m_map[i].pos, m_map[i].dir, m_map[i].type, m_map[i].color, false, false);
@@ -353,7 +362,8 @@ void CMap::Draw()
if ( m_map[i].bUsed && i != m_highlightRank ) // selection:
DrawObject(m_map[i].pos, m_map[i].dir, m_map[i].type, m_map[i].color, true, false);
- if ( m_highlightRank != -1 && m_map[m_highlightRank].bUsed ) {
+ if ( m_highlightRank != -1 && m_map[m_highlightRank].bUsed )
+ {
i = m_highlightRank;
DrawObject(m_map[i].pos, m_map[i].dir, m_map[i].type, m_map[i].color, false, true);
DrawHighlight(m_map[i].pos);
@@ -375,23 +385,27 @@ Math::Point CMap::MapInter(Math::Point pos, float dir)
p1.y -= pos.y;
limit = m_mapPos.x + m_mapDim.x - pos.x;
- if ( p1.x > limit ) { // exceeds the right?
+ if ( p1.x > limit ) // exceeds the right?
+ {
p1.y = limit*p1.y/p1.x;
p1.x = limit;
}
limit = m_mapPos.y * 0.75f + m_mapDim.y * 0.75f - pos.y;
- if ( p1.y > limit ) { // exceeds the top?
+ if ( p1.y > limit ) // exceeds the top?
+ {
p1.x = limit * p1.x / p1.y;
p1.y = limit;
}
limit = m_mapPos.x - pos.x;
- if ( p1.x < limit ) { // exceeds the left?
+ if ( p1.x < limit ) // exceeds the left?
+ {
p1.y = limit * p1.y / p1.x;
p1.x = limit;
}
limit = m_mapPos.y * 0.75f - pos.y;
- if ( p1.y < limit ) { // exceeds the bottom?
+ if ( p1.y < limit ) // exceeds the bottom?
+ {
p1.x = limit * p1.x / p1.y;
p1.y = limit;
}
@@ -1152,7 +1166,7 @@ void CMap::UpdateObject(CObject* pObj)
pos.z = ppos.y;
dir += m_angle;
}
-
+
color = MAPCOLOR_NULL;
if ( type == OBJECT_BASE )
{
@@ -1303,3 +1317,4 @@ void CMap::UpdateObject(CObject* pObj)
}
}
+
diff --git a/src/ui/map.h b/src/ui/map.h
index 258dcdf..4ebe688 100644
--- a/src/ui/map.h
+++ b/src/ui/map.h
@@ -69,78 +69,79 @@ struct MapObject
class CMap : public CControl
{
- public:
- CMap();
- ~CMap();
-
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- bool EventProcess(const Event &event);
- void Draw();
-
- void UpdateTerrain();
- void UpdateTerrain(int bx, int by, int ex, int ey);
-
- void SetFixImage(const char *filename);
- bool GetFixImage();
-
- void SetOffset(float ox, float oy);
- void SetAngle(float angle);
- void SetMode(int mode);
- void SetToy(bool bToy);
- void SetDebug(bool bDebug);
-
- void SetZoom(float value);
- float GetZoom();
-
- void SetEnable(bool bEnable);
- bool GetEnable();
-
- void SetFloorColor(Gfx::Color color);
- void SetWaterColor(Gfx::Color color);
-
- void FlushObject();
- void UpdateObject(CObject* pObj);
-
- CObject* DetectObject(Math::Point pos, bool &bInMap);
- void SetHighlight(CObject* pObj);
-
- protected:
- Math::Point AdjustOffset(Math::Point offset);
- void SelectObject(Math::Point pos);
- Math::Point MapInter(Math::Point pos, float dir);
- void DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color);
- void DrawObject(Math::Point pos, float dir, ObjectType type, MapColor color, bool bSelect, bool bHilite);
- void DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, ObjectType type, bool bHilite);
- void DrawHighlight(Math::Point pos);
- void DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2);
- void DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2);
- void DrawVertex(Math::Point uv1, Math::Point uv2, float zoom);
-
- protected:
- Gfx::CTerrain* m_terrain;
- Gfx::CWater* m_water;
- CRobotMain* m_main;
-
- bool m_bEnable;
- float m_time;
- float m_half;
- float m_zoom;
- Math::Point m_offset;
- float m_angle;
- Gfx::Color m_floorColor;
- Gfx::Color m_waterColor;
- MapObject m_map[MAPMAXOBJECT];
- int m_totalFix;
- int m_totalMove;
- int m_highlightRank;
- Math::Point m_mapPos;
- Math::Point m_mapDim;
- bool m_bRadar;
- char m_fixImage[100];
- int m_mode;
- bool m_bToy;
- bool m_bDebug;
+public:
+ CMap();
+ ~CMap();
+
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ bool EventProcess(const Event &event);
+ void Draw();
+
+ void UpdateTerrain();
+ void UpdateTerrain(int bx, int by, int ex, int ey);
+
+ void SetFixImage(const char *filename);
+ bool GetFixImage();
+
+ void SetOffset(float ox, float oy);
+ void SetAngle(float angle);
+ void SetMode(int mode);
+ void SetToy(bool bToy);
+ void SetDebug(bool bDebug);
+
+ void SetZoom(float value);
+ float GetZoom();
+
+ void SetEnable(bool bEnable);
+ bool GetEnable();
+
+ void SetFloorColor(Gfx::Color color);
+ void SetWaterColor(Gfx::Color color);
+
+ void FlushObject();
+ void UpdateObject(CObject* pObj);
+
+ CObject* DetectObject(Math::Point pos, bool &bInMap);
+ void SetHighlight(CObject* pObj);
+
+protected:
+ Math::Point AdjustOffset(Math::Point offset);
+ void SelectObject(Math::Point pos);
+ Math::Point MapInter(Math::Point pos, float dir);
+ void DrawFocus(Math::Point pos, float dir, ObjectType type, MapColor color);
+ void DrawObject(Math::Point pos, float dir, ObjectType type, MapColor color, bool bSelect, bool bHilite);
+ void DrawObjectIcon(Math::Point pos, Math::Point dim, MapColor color, ObjectType type, bool bHilite);
+ void DrawHighlight(Math::Point pos);
+ void DrawTriangle(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point uv1, Math::Point uv2);
+ void DrawPenta(Math::Point p1, Math::Point p2, Math::Point p3, Math::Point p4, Math::Point p5, Math::Point uv1, Math::Point uv2);
+ void DrawVertex(Math::Point uv1, Math::Point uv2, float zoom);
+
+protected:
+ Gfx::CTerrain* m_terrain;
+ Gfx::CWater* m_water;
+ CRobotMain* m_main;
+
+ bool m_bEnable;
+ float m_time;
+ float m_half;
+ float m_zoom;
+ Math::Point m_offset;
+ float m_angle;
+ Gfx::Color m_floorColor;
+ Gfx::Color m_waterColor;
+ MapObject m_map[MAPMAXOBJECT];
+ int m_totalFix;
+ int m_totalMove;
+ int m_highlightRank;
+ Math::Point m_mapPos;
+ Math::Point m_mapDim;
+ bool m_bRadar;
+ char m_fixImage[100];
+ int m_mode;
+ bool m_bToy;
+ bool m_bDebug;
};
}
+
diff --git a/src/ui/scroll.cpp b/src/ui/scroll.cpp
index ff7451d..b3422ec 100644
--- a/src/ui/scroll.cpp
+++ b/src/ui/scroll.cpp
@@ -467,3 +467,4 @@ float CScroll::GetArrowStep()
}
}
+
diff --git a/src/ui/scroll.h b/src/ui/scroll.h
index 57d6f8f..c115aa4 100644
--- a/src/ui/scroll.h
+++ b/src/ui/scroll.h
@@ -34,51 +34,52 @@ const float SCROLL_WIDTH = (15.0f/640.0f);
class CScroll : public CControl
{
- public:
- CScroll();
- ~CScroll();
+public:
+ CScroll();
+ ~CScroll();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- void SetPos(Math::Point pos);
- void SetDim(Math::Point dim);
+ void SetPos(Math::Point pos);
+ void SetDim(Math::Point dim);
- bool SetState(int state, bool bState);
- bool SetState(int state);
- bool ClearState(int state);
+ bool SetState(int state, bool bState);
+ bool SetState(int state);
+ bool ClearState(int state);
- bool EventProcess(const Event &event);
- void Draw();
+ bool EventProcess(const Event &event);
+ void Draw();
- void SetVisibleValue(float value);
- float GetVisibleValue();
+ void SetVisibleValue(float value);
+ float GetVisibleValue();
- void SetVisibleRatio(float value);
- float GetVisibleRatio();
+ void SetVisibleRatio(float value);
+ float GetVisibleRatio();
- void SetArrowStep(float step);
- float GetArrowStep();
+ void SetArrowStep(float step);
+ float GetArrowStep();
- protected:
- void MoveAdjust();
- void AdjustGlint();
- void DrawVertex(Math::Point pos, Math::Point dim, int icon);
+protected:
+ void MoveAdjust();
+ void AdjustGlint();
+ void DrawVertex(Math::Point pos, Math::Point dim, int icon);
- protected:
- CButton* m_buttonUp;
- CButton* m_buttonDown;
+protected:
+ CButton* m_buttonUp;
+ CButton* m_buttonDown;
- float m_visibleValue;
- float m_visibleRatio;
- float m_step;
+ float m_visibleValue;
+ float m_visibleRatio;
+ float m_step;
- bool m_bCapture;
- Math::Point m_pressPos;
- float m_pressValue;
+ bool m_bCapture;
+ Math::Point m_pressPos;
+ float m_pressValue;
- EventType m_eventUp;
- EventType m_eventDown;
+ EventType m_eventUp;
+ EventType m_eventDown;
};
}
+
diff --git a/src/ui/shortcut.cpp b/src/ui/shortcut.cpp
index 4462140..a01864a 100644
--- a/src/ui/shortcut.cpp
+++ b/src/ui/shortcut.cpp
@@ -128,7 +128,7 @@ void CShortcut::Draw()
if ( m_state & STATE_FRAME )
{
Math::Point p1, p2, c, uv1, uv2;
- float zoom, dp;
+ float dp;
m_engine->SetTexture("button2.png");
m_engine->SetState(Gfx::ENG_RSTATE_TTEXTURE_WHITE);
@@ -237,3 +237,4 @@ void CShortcut::DrawVertex(int icon, float zoom)
}
}
+
diff --git a/src/ui/shortcut.h b/src/ui/shortcut.h
index 7e7899e..6495ba0 100644
--- a/src/ui/shortcut.h
+++ b/src/ui/shortcut.h
@@ -27,22 +27,23 @@ namespace Ui {
class CShortcut : public CControl
{
- public:
- CShortcut();
- ~CShortcut();
+public:
+ CShortcut();
+ ~CShortcut();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventType);
- bool EventProcess(const Event &event);
+ bool EventProcess(const Event &event);
- void Draw();
+ void Draw();
- protected:
- void DrawVertex(int icon, float zoom);
+protected:
+ void DrawVertex(int icon, float zoom);
- protected:
- float m_time;
+protected:
+ float m_time;
};
}
+
diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp
index f516e70..33293d1 100644
--- a/src/ui/slider.cpp
+++ b/src/ui/slider.cpp
@@ -581,3 +581,4 @@ float CSlider::GetArrowStep()
}
+
diff --git a/src/ui/slider.h b/src/ui/slider.h
index 4912453..bc38aec 100644
--- a/src/ui/slider.h
+++ b/src/ui/slider.h
@@ -29,54 +29,55 @@ class CButton;
class CSlider : public CControl
{
- public:
- CSlider();
- ~CSlider();
+public:
+ CSlider();
+ ~CSlider();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- void SetPos(Math::Point pos);
- void SetDim(Math::Point dim);
+ void SetPos(Math::Point pos);
+ void SetDim(Math::Point dim);
- bool SetState(int state, bool bState);
- bool SetState(int state);
- bool ClearState(int state);
+ bool SetState(int state, bool bState);
+ bool SetState(int state);
+ bool ClearState(int state);
- bool EventProcess(const Event &event);
- void Draw();
+ bool EventProcess(const Event &event);
+ void Draw();
- void SetLimit(float min, float max);
+ void SetLimit(float min, float max);
- void SetVisibleValue(float value);
- float GetVisibleValue();
+ void SetVisibleValue(float value);
+ float GetVisibleValue();
- void SetArrowStep(float step);
- float GetArrowStep();
+ void SetArrowStep(float step);
+ float GetArrowStep();
- protected:
- void MoveAdjust();
- void AdjustGlint();
- void DrawVertex(Math::Point pos, Math::Point dim, int icon);
+protected:
+ void MoveAdjust();
+ void AdjustGlint();
+ void DrawVertex(Math::Point pos, Math::Point dim, int icon);
- protected:
- CButton* m_buttonLeft;
- CButton* m_buttonRight;
+protected:
+ CButton* m_buttonLeft;
+ CButton* m_buttonRight;
- float m_min;
- float m_max;
- float m_visibleValue;
- float m_step;
+ float m_min;
+ float m_max;
+ float m_visibleValue;
+ float m_step;
- bool m_bHoriz;
- float m_marginButton;
+ bool m_bHoriz;
+ float m_marginButton;
- bool m_bCapture;
- Math::Point m_pressPos;
- float m_pressValue;
+ bool m_bCapture;
+ Math::Point m_pressPos;
+ float m_pressValue;
- EventType m_eventUp;
- EventType m_eventDown;
+ EventType m_eventUp;
+ EventType m_eventDown;
};
}
+
diff --git a/src/ui/studio.cpp b/src/ui/studio.cpp
index 29dfebf..e44a465 100644
--- a/src/ui/studio.cpp
+++ b/src/ui/studio.cpp
@@ -167,7 +167,7 @@ bool CStudio::EventProcess(const Event &event)
{
slider = static_cast< CSlider* >(pw->SearchControl(EVENT_STUDIO_SIZE));
if ( slider == nullptr ) return false;
- m_main->SetFontSize(9.0f+slider->GetVisibleValue()*6.0f);
+ m_main->SetFontSize(9.0f+slider->GetVisibleValue()*12.0f);
ViewEditScript();
}
@@ -904,7 +904,7 @@ void CStudio::SetInfoText(std::string text, bool bClickable)
if ( list == 0 ) return;
list->Flush(); // just text
- list->SetName(0, text.c_str());
+ list->SetItemName(0, text.c_str());
if ( text[0] == 0 ) bClickable = false;
list->SetSelectCap(bClickable);
@@ -1397,7 +1397,7 @@ void CStudio::UpdateChangeList()
pe = static_cast< CEdit* >(pw->SearchControl(EVENT_DIALOG_EDIT));
if ( pe == nullptr ) return;
- strcpy(name, pl->GetName(pl->GetSelect()));
+ strcpy(name, pl->GetItemName(pl->GetSelect()));
name[pe->GetMaxChar()] = 0; // truncates according lg max editable
p = strchr(name, '\t'); // seeks first tab
if ( p != 0 ) *p = 0;
@@ -1511,7 +1511,6 @@ void CStudio::UpdateDialogList()
fs::path path;
int i = 0;
char time[100];
- char temp[100];
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == nullptr ) return;
@@ -1521,13 +1520,16 @@ void CStudio::UpdateDialogList()
path = fs::path(SearchDirectory(false));
fs::directory_iterator end_iter;
- if ( fs::exists(path) && fs::is_directory(path) ) {
- for( fs::directory_iterator file(path); file != end_iter; file++) {
- if (fs::is_regular_file(file->status()) ) {
+ if ( fs::exists(path) && fs::is_directory(path) )
+ {
+ for( fs::directory_iterator file(path); file != end_iter; file++)
+ {
+ if (fs::is_regular_file(file->status()) )
+ {
+ std::ostringstream temp;
TimeToAscii(fs::last_write_time(file->path()), time);
- sprintf(temp, "%s\t%lu \t%s", file->path().filename().string().c_str(), fs::file_size(file->path()), time);
-
- pl->SetName(i++, temp);
+ temp << file->path().filename().string() << '\t' << fs::file_size(file->path()) << " \t" << time;
+ pl->SetItemName(i++, temp.str().c_str());
}
}
}
@@ -1539,15 +1541,19 @@ void CStudio::UpdateDialogList()
std::string CStudio::SearchDirectory(bool bCreate)
{
char dir[MAX_FNAME];
- if ( m_main->GetIOPublic() ) {
+ if ( m_main->GetIOPublic() )
+ {
sprintf(dir, "%s/", m_main->GetPublicDir());
- } else {
+ }
+ else
+ {
sprintf(dir, "%s/%s/Program/", m_main->GetSavegameDir(), m_main->GetGamerName());
}
-
+
fs::path path = fs::path(dir);
-
- if ( bCreate ) {
+
+ if ( bCreate )
+ {
fs::create_directory(path);
}
@@ -1630,3 +1636,4 @@ bool CStudio::WriteProgram()
}
}
+
diff --git a/src/ui/target.cpp b/src/ui/target.cpp
index cc74750..455c530 100644
--- a/src/ui/target.cpp
+++ b/src/ui/target.cpp
@@ -272,3 +272,4 @@ CObject* CTarget::DetectFriendObject(Math::Point pos)
}
}
+
diff --git a/src/ui/target.h b/src/ui/target.h
index 054524b..2344e59 100644
--- a/src/ui/target.h
+++ b/src/ui/target.h
@@ -36,19 +36,20 @@ namespace Ui {
class CTarget : public CControl
{
- public:
- CTarget();
- ~CTarget();
+public:
+ CTarget();
+ ~CTarget();
- bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
+ bool Create(Math::Point pos, Math::Point dim, int icon, EventType eventMsg);
- bool EventProcess(const Event &event);
- void Draw();
- bool GetTooltip(Math::Point pos, std::string &name);
+ bool EventProcess(const Event &event);
+ void Draw();
+ bool GetTooltip(Math::Point pos, std::string &name);
- protected:
- CObject* DetectFriendObject(Math::Point pos);
+protected:
+ CObject* DetectFriendObject(Math::Point pos);
};
}
+
diff --git a/src/ui/window.cpp b/src/ui/window.cpp
index 6013d37..8005939 100644
--- a/src/ui/window.cpp
+++ b/src/ui/window.cpp
@@ -355,6 +355,9 @@ CSlider* CWindow::CreateSlider(Math::Point pos, Math::Point dim, int icon, Event
}
// Creates a new list.
+// if expand is less then zero, then the list would try to use expand's absolute value,
+// and try to scale items to some size, so that dim of the list would not change after
+// adjusting
CList* CWindow::CreateList(Math::Point pos, Math::Point dim, int icon, EventType eventMsg,
float expand)
@@ -573,12 +576,12 @@ bool CWindow::GetTooltip(Math::Point pos, std::string &name)
// Specifies the name for the title bar.
-void CWindow::SetName(std::string name)
+void CWindow::SetName(std::string name, bool tooltip)
{
CButton* pc;
bool bAdjust;
- CControl::SetName(name);
+ CControl::SetName(name, tooltip);
if ( m_buttonReduce != 0 )
{
@@ -1576,3 +1579,4 @@ void CWindow::DrawHach(Math::Point pos, Math::Point dim)
}
}
+
diff --git a/src/ui/window.h b/src/ui/window.h
index e39b8a9..87805e2 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -83,7 +83,7 @@ public:
EventType GetEventTypeFull();
EventType GetEventTypeClose();
- void SetName(std::string name);
+ virtual void SetName(std::string name, bool tooltip = true) override;
void SetTrashEvent(bool bTrash);
bool GetTrashEvent();
@@ -151,3 +151,4 @@ protected:
}
+