aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/menulogo.pngbin0 -> 498 bytes
-rw-r--r--src/game.cpp25
-rw-r--r--src/guiMainMenu.cpp111
-rw-r--r--src/guiMainMenu.h2
-rw-r--r--src/main.cpp57
5 files changed, 169 insertions, 26 deletions
diff --git a/data/menulogo.png b/data/menulogo.png
new file mode 100644
index 000000000..76595c48d
--- /dev/null
+++ b/data/menulogo.png
Binary files differ
diff --git a/src/game.cpp b/src/game.cpp
index 9a0fd312b..c806034f2 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -652,15 +652,33 @@ void the_game(
gui_loadingtext->remove();
return;
}
+
+ /*
+ Attempt to connect to the server
+ */
dstream<<DTIME<<"Connecting to server at ";
connect_address.print(&dstream);
dstream<<std::endl;
client.connect(connect_address);
+
+ bool could_connect = false;
try{
- while(client.connectedAndInitialized() == false)
+ float time_counter = 0.0;
+ for(;;)
{
+ if(client.connectedAndInitialized())
+ {
+ could_connect = true;
+ break;
+ }
+ // Wait for 10 seconds
+ if(time_counter >= 10.0)
+ {
+ break;
+ }
+
// Update screen
driver->beginScene(true, true, video::SColor(255,0,0,0));
guienv->drawAll();
@@ -675,12 +693,15 @@ void the_game(
// Delay a bit
sleep_ms(100);
+ time_counter += 0.1;
}
}
catch(con::PeerNotFoundException &e)
+ {}
+
+ if(could_connect == false)
{
std::cout<<DTIME<<"Timed out."<<std::endl;
- //return 0;
error_message = L"Connection timed out.";
gui_loadingtext->remove();
return;
diff --git a/src/guiMainMenu.cpp b/src/guiMainMenu.cpp
index 6c5d6553c..04341fe22 100644
--- a/src/guiMainMenu.cpp
+++ b/src/guiMainMenu.cpp
@@ -64,6 +64,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
std::wstring text_address;
std::wstring text_port;
bool creative_mode;
+ bool enable_damage;
{
gui::IGUIElement *e = getElementFromId(258);
@@ -93,6 +94,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
else
creative_mode = m_data->creative_mode;
}
+ {
+ gui::IGUIElement *e = getElementFromId(261);
+ if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+ enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
+ else
+ enable_damage = m_data->enable_damage;
+ }
/*
Remove stuff
@@ -102,32 +110,51 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
/*
Calculate new sizes and positions
*/
+
+ v2s32 size(620, 430);
+
core::rect<s32> rect(
- screensize.X/2 - 580/2,
- screensize.Y/2 - 300/2,
- screensize.X/2 + 580/2,
- screensize.Y/2 + 300/2
+ screensize.X/2 - size.X/2,
+ screensize.Y/2 - size.Y/2,
+ screensize.X/2 + size.X/2,
+ screensize.Y/2 + size.Y/2
);
-
+
DesiredRect = rect;
recalculateAbsolutePosition(false);
- v2s32 size = rect.getSize();
+ //v2s32 size = rect.getSize();
/*
Add stuff
*/
+ /*
+ Client section
+ */
+
+ v2s32 topleft_client(40, 0);
+ v2s32 size_client = size - v2s32(40, 0);
+
+ {
+ core::rect<s32> rect(0, 0, 20, 125);
+ rect += topleft_client + v2s32(-15, 60);
+ const wchar_t *text = L"C\nL\nI\nE\nN\nT";
+ //gui::IGUIStaticText *t =
+ Environment->addStaticText(text, rect, false, true, this, -1);
+ //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
+ }
+
// Nickname
{
core::rect<s32> rect(0, 0, 100, 20);
- rect = rect + v2s32(size.X/2 - 250, size.Y/2 - 100 + 6);
+ rect += topleft_client + v2s32(40, 50+6);
const wchar_t *text = L"Nickname";
Environment->addStaticText(text, rect, false, true, this, -1);
}
{
core::rect<s32> rect(0, 0, 250, 30);
- rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 100);
+ rect += topleft_client + v2s32(160, 50);
gui::IGUIElement *e =
Environment->addEditBox(text_name.c_str(), rect, true, this, 258);
if(text_name == L"")
@@ -136,13 +163,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
// Address + port
{
core::rect<s32> rect(0, 0, 100, 20);
- rect = rect + v2s32(size.X/2 - 250, size.Y/2 - 50 + 6);
+ rect += topleft_client + v2s32(40, 100+6);
const wchar_t *text = L"Address + Port";
Environment->addStaticText(text, rect, false, true, this, -1);
}
{
core::rect<s32> rect(0, 0, 250, 30);
- rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 50);
+ rect += topleft_client + v2s32(160, 100);
gui::IGUIElement *e =
Environment->addEditBox(text_address.c_str(), rect, true, this, 256);
if(text_name != L"")
@@ -150,37 +177,56 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
}
{
core::rect<s32> rect(0, 0, 100, 30);
- rect = rect + v2s32(size.X/2 - 130 + 250 + 20, size.Y/2 - 50);
+ //rect += topleft_client + v2s32(160+250+20, 125);
+ rect += topleft_client + v2s32(size_client.X-40-100, 100);
Environment->addEditBox(text_port.c_str(), rect, true, this, 257);
}
{
core::rect<s32> rect(0, 0, 400, 20);
- rect = rect + v2s32(size.X/2 - 130, size.Y/2 - 50 + 35);
+ rect += topleft_client + v2s32(160, 100+35);
const wchar_t *text = L"Leave address blank to start a local server.";
Environment->addStaticText(text, rect, false, true, this, -1);
}
- // Server parameters
+ // Start game button
{
- core::rect<s32> rect(0, 0, 100, 20);
- rect = rect + v2s32(size.X/2 - 250, size.Y/2 + 25 + 6);
- const wchar_t *text = L"Server params";
+ core::rect<s32> rect(0, 0, 180, 30);
+ //rect += topleft_client + v2s32(size_client.X/2-180/2, 225-30/2);
+ rect += topleft_client + v2s32(size_client.X-180-40, 150+25);
+ Environment->addButton(rect, this, 257, L"Start Game / Connect");
+ }
+
+ /*
+ Server section
+ */
+
+ v2s32 topleft_server(40, 250);
+ v2s32 size_server = size - v2s32(40, 0);
+
+ {
+ core::rect<s32> rect(0, 0, 20, 125);
+ rect += topleft_server + v2s32(-15, 40);
+ const wchar_t *text = L"S\nE\nR\nV\nE\nR";
+ //gui::IGUIStaticText *t =
Environment->addStaticText(text, rect, false, true, this, -1);
+ //t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
+
+ // Server parameters
{
core::rect<s32> rect(0, 0, 250, 30);
- rect = rect + v2s32(size.X/2 - 130, size.Y/2 + 25);
+ rect += topleft_server + v2s32(40, 30);
Environment->addCheckBox(creative_mode, rect, this, 259, L"Creative Mode");
}
- // Start game button
{
- core::rect<s32> rect(0, 0, 180, 30);
- rect = rect + v2s32(size.X/2-180/2, size.Y/2-30/2 + 100);
- Environment->addButton(rect, this, 257, L"Start Game / Connect");
+ core::rect<s32> rect(0, 0, 250, 30);
+ rect += topleft_server + v2s32(40, 60);
+ Environment->addCheckBox(enable_damage, rect, this, 261, L"Enable Damage");
}
// Map delete button
{
core::rect<s32> rect(0, 0, 130, 30);
- rect = rect + v2s32(size.X/2-130/2+200, size.Y/2-30/2 + 100);
+ //rect += topleft_server + v2s32(size_server.X-40-130, 100+25);
+ rect += topleft_server + v2s32(40, 100+25);
Environment->addButton(rect, this, 260, L"Delete map");
}
}
@@ -192,8 +238,22 @@ void GUIMainMenu::drawMenu()
return;
video::IVideoDriver* driver = Environment->getVideoDriver();
+ /*video::SColor bgcolor(140,0,0,0);
+ driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
+
video::SColor bgcolor(140,0,0,0);
- driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+
+ {
+ core::rect<s32> rect(0, 0, 620, 230);
+ rect += AbsoluteRect.UpperLeftCorner;
+ driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
+ }
+
+ {
+ core::rect<s32> rect(0, 250, 620, 430);
+ rect += AbsoluteRect.UpperLeftCorner;
+ driver->draw2DRectangle(bgcolor, rect, &AbsoluteClippingRect);
+ }
gui::IGUIElement::draw();
}
@@ -220,6 +280,11 @@ void GUIMainMenu::acceptInput()
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
m_data->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
}
+ {
+ gui::IGUIElement *e = getElementFromId(261);
+ if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
+ m_data->enable_damage = ((gui::IGUICheckBox*)e)->isChecked();
+ }
m_accepted = true;
}
diff --git a/src/guiMainMenu.h b/src/guiMainMenu.h
index 010d0bf6d..d003599c4 100644
--- a/src/guiMainMenu.h
+++ b/src/guiMainMenu.h
@@ -31,6 +31,7 @@ struct MainMenuData
{
MainMenuData():
creative_mode(false),
+ enable_damage(false),
delete_map(false)
{}
// These are in the native format of the gui elements
@@ -38,6 +39,7 @@ struct MainMenuData
std::wstring port;
std::wstring name;
bool creative_mode;
+ bool enable_damage;
// If map deletion is requested, this is set to true
bool delete_map;
};
diff --git a/src/main.cpp b/src/main.cpp
index 0426b6a49..429b769f7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -164,6 +164,9 @@ TODO: A setting for enabling bilinear filtering for textures
TODO: Better control of draw_control.wanted_max_blocks
+TODO: Get player texture (and some others) from the specified texture
+ directory
+
Configuration:
--------------
@@ -886,6 +889,53 @@ void SpeedTests()
}
}
+void drawMenuBackground(video::IVideoDriver* driver)
+{
+ core::dimension2d<u32> screensize = driver->getScreenSize();
+
+ video::ITexture *bgtexture =
+ driver->getTexture(porting::getDataPath("mud.png").c_str());
+ if(bgtexture)
+ {
+ s32 texturesize = 128;
+ s32 tiled_y = screensize.Height / texturesize + 1;
+ s32 tiled_x = screensize.Width / texturesize + 1;
+
+ for(s32 y=0; y<tiled_y; y++)
+ for(s32 x=0; x<tiled_x; x++)
+ {
+ core::rect<s32> rect(0,0,texturesize,texturesize);
+ rect += v2s32(x*texturesize, y*texturesize);
+ driver->draw2DImage(bgtexture, rect,
+ core::rect<s32>(core::position2d<s32>(0,0),
+ core::dimension2di(bgtexture->getSize())),
+ NULL, NULL, true);
+ }
+ }
+
+ video::ITexture *logotexture =
+ driver->getTexture(porting::getDataPath("menulogo.png").c_str());
+ if(logotexture)
+ {
+ v2s32 logosize(logotexture->getOriginalSize().Width,
+ logotexture->getOriginalSize().Height);
+ logosize *= 4;
+
+ video::SColor bgcolor(255,50,50,50);
+ core::rect<s32> bgrect(0, screensize.Height-logosize.Y-20,
+ screensize.Width, screensize.Height);
+ driver->draw2DRectangle(bgcolor, bgrect, NULL);
+
+ core::rect<s32> rect(0,0,logosize.X,logosize.Y);
+ rect += v2s32(screensize.Width/2,screensize.Height-10-logosize.Y);
+ rect -= v2s32(logosize.X/2, 0);
+ driver->draw2DImage(logotexture, rect,
+ core::rect<s32>(core::position2d<s32>(0,0),
+ core::dimension2di(logotexture->getSize())),
+ NULL, NULL, true);
+ }
+}
+
int main(int argc, char *argv[])
{
/*
@@ -1303,6 +1353,7 @@ int main(int argc, char *argv[])
menudata.name = narrow_to_wide(playername);
menudata.port = narrow_to_wide(itos(port));
menudata.creative_mode = g_settings.getBool("creative_mode");
+ menudata.enable_damage = g_settings.getBool("enable_damage");
GUIMainMenu *menu =
new GUIMainMenu(guienv, guiroot, -1,
@@ -1332,7 +1383,11 @@ int main(int argc, char *argv[])
//driver->beginScene(true, true, video::SColor(255,0,0,0));
driver->beginScene(true, true, video::SColor(255,128,128,128));
+
+ drawMenuBackground(driver);
+
guienv->drawAll();
+
driver->endScene();
}
@@ -1358,8 +1413,8 @@ int main(int argc, char *argv[])
int newport = stoi(wide_to_narrow(menudata.port));
if(newport != 0)
port = newport;
- //port = stoi(wide_to_narrow(menudata.port));
g_settings.set("creative_mode", itos(menudata.creative_mode));
+ g_settings.set("enable_damage", itos(menudata.enable_damage));
// Check for valid parameters, restart menu if invalid.
if(playername == "")