Made the main menu a bit more unique looking
parent
60a565c1d2
commit
0034744568
Binary file not shown.
After Width: | Height: | Size: 498 B |
25
src/game.cpp
25
src/game.cpp
|
@ -653,14 +653,32 @@ void the_game(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Attempt to connect to the server
|
||||||
|
*/
|
||||||
|
|
||||||
dstream<<DTIME<<"Connecting to server at ";
|
dstream<<DTIME<<"Connecting to server at ";
|
||||||
connect_address.print(&dstream);
|
connect_address.print(&dstream);
|
||||||
dstream<<std::endl;
|
dstream<<std::endl;
|
||||||
client.connect(connect_address);
|
client.connect(connect_address);
|
||||||
|
|
||||||
|
bool could_connect = false;
|
||||||
|
|
||||||
try{
|
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
|
// Update screen
|
||||||
driver->beginScene(true, true, video::SColor(255,0,0,0));
|
driver->beginScene(true, true, video::SColor(255,0,0,0));
|
||||||
guienv->drawAll();
|
guienv->drawAll();
|
||||||
|
@ -675,12 +693,15 @@ void the_game(
|
||||||
|
|
||||||
// Delay a bit
|
// Delay a bit
|
||||||
sleep_ms(100);
|
sleep_ms(100);
|
||||||
|
time_counter += 0.1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(con::PeerNotFoundException &e)
|
catch(con::PeerNotFoundException &e)
|
||||||
|
{}
|
||||||
|
|
||||||
|
if(could_connect == false)
|
||||||
{
|
{
|
||||||
std::cout<<DTIME<<"Timed out."<<std::endl;
|
std::cout<<DTIME<<"Timed out."<<std::endl;
|
||||||
//return 0;
|
|
||||||
error_message = L"Connection timed out.";
|
error_message = L"Connection timed out.";
|
||||||
gui_loadingtext->remove();
|
gui_loadingtext->remove();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -64,6 +64,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
||||||
std::wstring text_address;
|
std::wstring text_address;
|
||||||
std::wstring text_port;
|
std::wstring text_port;
|
||||||
bool creative_mode;
|
bool creative_mode;
|
||||||
|
bool enable_damage;
|
||||||
|
|
||||||
{
|
{
|
||||||
gui::IGUIElement *e = getElementFromId(258);
|
gui::IGUIElement *e = getElementFromId(258);
|
||||||
|
@ -93,6 +94,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
||||||
else
|
else
|
||||||
creative_mode = m_data->creative_mode;
|
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
|
Remove stuff
|
||||||
|
@ -102,32 +110,51 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
||||||
/*
|
/*
|
||||||
Calculate new sizes and positions
|
Calculate new sizes and positions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
v2s32 size(620, 430);
|
||||||
|
|
||||||
core::rect<s32> rect(
|
core::rect<s32> rect(
|
||||||
screensize.X/2 - 580/2,
|
screensize.X/2 - size.X/2,
|
||||||
screensize.Y/2 - 300/2,
|
screensize.Y/2 - size.Y/2,
|
||||||
screensize.X/2 + 580/2,
|
screensize.X/2 + size.X/2,
|
||||||
screensize.Y/2 + 300/2
|
screensize.Y/2 + size.Y/2
|
||||||
);
|
);
|
||||||
|
|
||||||
DesiredRect = rect;
|
DesiredRect = rect;
|
||||||
recalculateAbsolutePosition(false);
|
recalculateAbsolutePosition(false);
|
||||||
|
|
||||||
v2s32 size = rect.getSize();
|
//v2s32 size = rect.getSize();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Add stuff
|
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
|
// Nickname
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 100, 20);
|
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";
|
const wchar_t *text = L"Nickname";
|
||||||
Environment->addStaticText(text, rect, false, true, this, -1);
|
Environment->addStaticText(text, rect, false, true, this, -1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 250, 30);
|
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 =
|
gui::IGUIElement *e =
|
||||||
Environment->addEditBox(text_name.c_str(), rect, true, this, 258);
|
Environment->addEditBox(text_name.c_str(), rect, true, this, 258);
|
||||||
if(text_name == L"")
|
if(text_name == L"")
|
||||||
|
@ -136,13 +163,13 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
||||||
// Address + port
|
// Address + port
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 100, 20);
|
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";
|
const wchar_t *text = L"Address + Port";
|
||||||
Environment->addStaticText(text, rect, false, true, this, -1);
|
Environment->addStaticText(text, rect, false, true, this, -1);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 250, 30);
|
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 =
|
gui::IGUIElement *e =
|
||||||
Environment->addEditBox(text_address.c_str(), rect, true, this, 256);
|
Environment->addEditBox(text_address.c_str(), rect, true, this, 256);
|
||||||
if(text_name != L"")
|
if(text_name != L"")
|
||||||
|
@ -150,37 +177,56 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 100, 30);
|
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);
|
Environment->addEditBox(text_port.c_str(), rect, true, this, 257);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 400, 20);
|
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.";
|
const wchar_t *text = L"Leave address blank to start a local server.";
|
||||||
Environment->addStaticText(text, rect, false, true, this, -1);
|
Environment->addStaticText(text, rect, false, true, this, -1);
|
||||||
}
|
}
|
||||||
// Server parameters
|
|
||||||
{
|
|
||||||
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";
|
|
||||||
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 + 25);
|
|
||||||
Environment->addCheckBox(creative_mode, rect, this, 259, L"Creative Mode");
|
|
||||||
}
|
|
||||||
// Start game button
|
// Start game button
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 180, 30);
|
core::rect<s32> rect(0, 0, 180, 30);
|
||||||
rect = rect + v2s32(size.X/2-180/2, size.Y/2-30/2 + 100);
|
//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");
|
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 += topleft_server + v2s32(40, 30);
|
||||||
|
Environment->addCheckBox(creative_mode, rect, this, 259, L"Creative Mode");
|
||||||
|
}
|
||||||
|
{
|
||||||
|
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
|
// Map delete button
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 130, 30);
|
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");
|
Environment->addButton(rect, this, 260, L"Delete map");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,8 +238,22 @@ void GUIMainMenu::drawMenu()
|
||||||
return;
|
return;
|
||||||
video::IVideoDriver* driver = Environment->getVideoDriver();
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
||||||
|
|
||||||
|
/*video::SColor bgcolor(140,0,0,0);
|
||||||
|
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);*/
|
||||||
|
|
||||||
video::SColor bgcolor(140,0,0,0);
|
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();
|
gui::IGUIElement::draw();
|
||||||
}
|
}
|
||||||
|
@ -220,6 +280,11 @@ void GUIMainMenu::acceptInput()
|
||||||
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
|
if(e != NULL && e->getType() == gui::EGUIET_CHECK_BOX)
|
||||||
m_data->creative_mode = ((gui::IGUICheckBox*)e)->isChecked();
|
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;
|
m_accepted = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ struct MainMenuData
|
||||||
{
|
{
|
||||||
MainMenuData():
|
MainMenuData():
|
||||||
creative_mode(false),
|
creative_mode(false),
|
||||||
|
enable_damage(false),
|
||||||
delete_map(false)
|
delete_map(false)
|
||||||
{}
|
{}
|
||||||
// These are in the native format of the gui elements
|
// These are in the native format of the gui elements
|
||||||
|
@ -38,6 +39,7 @@ struct MainMenuData
|
||||||
std::wstring port;
|
std::wstring port;
|
||||||
std::wstring name;
|
std::wstring name;
|
||||||
bool creative_mode;
|
bool creative_mode;
|
||||||
|
bool enable_damage;
|
||||||
// If map deletion is requested, this is set to true
|
// If map deletion is requested, this is set to true
|
||||||
bool delete_map;
|
bool delete_map;
|
||||||
};
|
};
|
||||||
|
|
57
src/main.cpp
57
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: Better control of draw_control.wanted_max_blocks
|
||||||
|
|
||||||
|
TODO: Get player texture (and some others) from the specified texture
|
||||||
|
directory
|
||||||
|
|
||||||
Configuration:
|
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[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -1303,6 +1353,7 @@ int main(int argc, char *argv[])
|
||||||
menudata.name = narrow_to_wide(playername);
|
menudata.name = narrow_to_wide(playername);
|
||||||
menudata.port = narrow_to_wide(itos(port));
|
menudata.port = narrow_to_wide(itos(port));
|
||||||
menudata.creative_mode = g_settings.getBool("creative_mode");
|
menudata.creative_mode = g_settings.getBool("creative_mode");
|
||||||
|
menudata.enable_damage = g_settings.getBool("enable_damage");
|
||||||
|
|
||||||
GUIMainMenu *menu =
|
GUIMainMenu *menu =
|
||||||
new GUIMainMenu(guienv, guiroot, -1,
|
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,0,0,0));
|
||||||
driver->beginScene(true, true, video::SColor(255,128,128,128));
|
driver->beginScene(true, true, video::SColor(255,128,128,128));
|
||||||
|
|
||||||
|
drawMenuBackground(driver);
|
||||||
|
|
||||||
guienv->drawAll();
|
guienv->drawAll();
|
||||||
|
|
||||||
driver->endScene();
|
driver->endScene();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1358,8 +1413,8 @@ int main(int argc, char *argv[])
|
||||||
int newport = stoi(wide_to_narrow(menudata.port));
|
int newport = stoi(wide_to_narrow(menudata.port));
|
||||||
if(newport != 0)
|
if(newport != 0)
|
||||||
port = newport;
|
port = newport;
|
||||||
//port = stoi(wide_to_narrow(menudata.port));
|
|
||||||
g_settings.set("creative_mode", itos(menudata.creative_mode));
|
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.
|
// Check for valid parameters, restart menu if invalid.
|
||||||
if(playername == "")
|
if(playername == "")
|
||||||
|
|
Loading…
Reference in New Issue