multiworld support pt3

master
darkrose 2017-08-17 22:17:45 +10:00
parent c0b93d8ca1
commit 433e57cfe3
10 changed files with 719 additions and 52 deletions

View File

@ -297,6 +297,7 @@ set(voxelands_SRCS
clientobject.cpp
guiMainMenu.cpp
guiSettingsMenu.cpp
guiSingleplayerMenu.cpp
guiMultiplayerMenu.cpp
guiMessageMenu.cpp
guiTextInputMenu.cpp

View File

@ -80,6 +80,7 @@ typedef struct worldlist_s {
struct worldlist_s *next;
char* name;
char* path;
char* mode;
char* version;
int8_t compat;
} worldlist_t;
@ -203,6 +204,8 @@ int world_import(char* path);
void world_unload(void);
int world_init(char* name);
void world_exit(void);
worldlist_t *world_list_get(void);
void world_list_free(worldlist_t *l);
#ifdef __cplusplus
}

View File

@ -29,6 +29,7 @@
#include "main.h"
#include "guiSettingsMenu.h"
#include "guiMultiplayerMenu.h"
#include "guiSingleplayerMenu.h"
#include "debug.h"
#include "serialization.h"
#include <string>
@ -98,7 +99,7 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
Calculate new sizes and positions
*/
v2s32 size(800, 500);
v2s32 size(800, 550);
core::rect<s32> rect(
screensize.X/2 - size.X/2,
@ -171,28 +172,17 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
m_data->selected_tab = TAB_SINGLEPLAYER;
}
if (m_data->selected_tab == TAB_SINGLEPLAYER || m_data->selected_tab == TAB_MULTIPLAYER) {
if (m_data->selected_tab == TAB_MULTIPLAYER) {
GUIMultiplayerMenu *mmenu = new GUIMultiplayerMenu(env, parent, -1,m_data,menumgr,m_gamecallback);
mmenu->drop();
}
{
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 20);
gui::IGUIStaticText *t = Environment->addStaticText(narrow_to_wide(gettext("Single Player")).c_str(), rect, false, true, this, -1);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
// Start game button
{
core::rect<s32> rect(0, 0, 180, 30);
rect += topleft_content + v2s32(185, 170);
Environment->addButton(rect, this, GUI_ID_JOIN_GAME_BUTTON, narrow_to_wide(gettext("Start Game")).c_str());
}
}else if(m_data->selected_tab == TAB_CREDITS) {
if (m_data->selected_tab == TAB_MULTIPLAYER) {
GUIMultiplayerMenu *mmenu = new GUIMultiplayerMenu(env, parent, -1,m_data,menumgr,m_gamecallback);
mmenu->drop();
}else if (m_data->selected_tab == TAB_SINGLEPLAYER) {
GUISingleplayerMenu *mmenu = new GUISingleplayerMenu(env, parent, -1,menumgr,m_gamecallback);
mmenu->drop();
}else if (m_data->selected_tab == TAB_CREDITS) {
// CREDITS
{
core::rect<s32> rect(0, 0, 550, 480);
rect += topleft_content + v2s32(0, 10);
core::rect<s32> rect(0, 0, 550, 550);
rect += topleft_content + v2s32(0, 0);
std::string txt("");
txt += gettext(
@ -224,6 +214,9 @@ void GUIMainMenu::regenerateGui(v2u32 screensize)
txt += gettext("Other Contributers, and Special Thanks");
txt += "\nnadnadnad, Honeypaw, tiemay, stormchaser3000, MichaelEh?, NCC74656.\n\n";
txt += gettext("Patreon Supporters");
txt += "\nLerura.\n\n";
txt += gettext(
"Based on Minetest-C55 by Perttu Ahola <celeron55@gmail.com>\n"
"and contributors: PilzAdam, Taoki, tango_, kahrl (kaaaaaahrl?), darkrose, matttpt, erlehmann,"
@ -310,11 +303,6 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
}
if (event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED) {
switch (event.GUIEvent.Caller->getID()) {
case GUI_ID_JOIN_GAME_BUTTON: // Start game
acceptInput();
m_gamecallback->startGame();
quitMenu();
return true;
case GUI_ID_CHARACTER_CREATOR:
{
acceptInput();
@ -323,13 +311,15 @@ bool GUIMainMenu::OnEvent(const SEvent& event)
return true;
}
case GUI_ID_TAB_SINGLEPLAYER:
{
if (m_data->selected_tab == TAB_SETTINGS)
acceptInput();
m_accepted = false;
GUISingleplayerMenu *mmenu = new GUISingleplayerMenu(env, parent, -1,menumgr,m_gamecallback);
mmenu->drop();
m_data->selected_tab = TAB_SINGLEPLAYER;
config_set("client.ui.mainmenu.tab","singleplayer");
regenerateGui(m_screensize);
return true;
}
case GUI_ID_TAB_MULTIPLAYER:
{
if (m_data->selected_tab == TAB_SETTINGS)

View File

@ -35,7 +35,6 @@
enum {
GUI_ID_QUIT_BUTTON = 101,
GUI_ID_JOIN_GAME_BUTTON,
GUI_ID_CHANGE_KEYS_BUTTON,
GUI_ID_CHARACTER_CREATOR,
GUI_ID_TAB_SINGLEPLAYER,

View File

@ -116,7 +116,7 @@ void GUIMultiplayerMenu::regenerateGui(v2u32 screensize)
Calculate new sizes and positions
*/
v2s32 size(800, 500);
v2s32 size(800, 550);
core::rect<s32> rect(
screensize.X/2 - size.X/2,

569
src/guiSingleplayerMenu.cpp Normal file
View File

@ -0,0 +1,569 @@
/************************************************************************
* guiMultiplayerMenu.cpp
* voxelands - 3d voxel world sandbox game
* Copyright (C) Lisa 'darkrose' Milne 2013-2015 <lisa@ltmnet.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
* for Voxelands.
************************************************************************/
#include "guiSingleplayerMenu.h"
#include "guiSettingsMenu.h"
#include "guiMultiplayerMenu.h"
#include "debug.h"
#include "serialization.h"
#include "main.h"
#include <string>
#include <IGUICheckBox.h>
#include <IGUIEditBox.h>
#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIListBox.h>
#include <IGUIFont.h>
#include <IGUIScrollBar.h>
#include "intlGUIEditBox.h"
#include "gui_colours.h"
#include "http.h"
GUISingleplayerMenu::GUISingleplayerMenu(
gui::IGUIEnvironment* env,
gui::IGUIElement*
parent,
s32 id,
IMenuManager *menumgr,
IGameCallback *gamecallback
):
GUIModalMenu(env, parent, id, menumgr),
m_accepted(false),
config(0),
selected_row(-1),
m_gamecallback(gamecallback)
{
this->env = env;
this->parent = parent;
this->menumgr = menumgr;
worlds = NULL;
selected[0] = 0;
}
GUISingleplayerMenu::~GUISingleplayerMenu()
{
if (worlds)
world_list_free(worlds);
removeChildren();
}
void GUISingleplayerMenu::removeChildren()
{
const core::list<gui::IGUIElement*> &children = getChildren();
core::list<gui::IGUIElement*> children_copy;
for (core::list<gui::IGUIElement*>::ConstIterator i = children.begin(); i != children.end(); i++) {
children_copy.push_back(*i);
}
for (core::list<gui::IGUIElement*>::Iterator i = children_copy.begin(); i != children_copy.end(); i++) {
(*i)->remove();
}
}
void GUISingleplayerMenu::regenerateGui(v2u32 screensize)
{
m_screensize = screensize;
{
gui::IGUIElement *e = getElementFromId(GUI_ID_SP_WORLD_NAME);
if (e != NULL) {
std::wstring w_name = e->getText();
if (snprintf(selected,256,"%s",wide_to_narrow(w_name).c_str()) >= 256)
snprintf(selected,256,"New World");
}
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_SP_MAP_SEED);
if (e != NULL) {
std::wstring w_name = e->getText();
if (snprintf(fixed_seed,256,"%s",wide_to_narrow(w_name).c_str()) >= 256)
snprintf(fixed_seed,256,"0");
}
}
/*
Remove stuff
*/
removeChildren();
/*
Calculate new sizes and positions
*/
v2s32 size(800, 550);
core::rect<s32> rect(
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 topleft_content(250, 0);
{
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 10);
gui::IGUIStaticText *t = Environment->addStaticText(narrow_to_wide(gettext("Single Player")).c_str(), rect, false, true, this, -1);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
if (!config) {
gui::IGUIListBox *box = NULL;
// Main Menu button
{
core::rect<s32> rect(0, 0, 200, 40);
rect += v2s32(25, 200);
Environment->addButton(rect, this, GUI_ID_SP_MAINMENU_BUTTON, narrow_to_wide(gettext("Main Menu")).c_str());
}
{
// Create button
core::rect<s32> rect(0, 0, 200, 40);
rect += v2s32(25, 260);
Environment->addButton(rect, this, GUI_ID_SP_CREATE_BUTTON, narrow_to_wide(gettext("Create New World")).c_str());
}
// Edit button
if (selected_row > -1) {
{
core::rect<s32> rect(0, 0, 200, 40);
rect += v2s32(25, 305);
Environment->addButton(rect, this, GUI_ID_SP_EDIT_BUTTON, narrow_to_wide(gettext("Edit World")).c_str());
}
{
core::rect<s32> rect(0, 0, 200, 40);
rect += v2s32(25, 350);
Environment->addButton(rect, this, GUI_ID_SP_START_BUTTON, narrow_to_wide(gettext("Start Game")).c_str());
}
}
if (!worlds)
worlds = world_list_get();
if (!worlds) {
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 60);
gui::IGUIStaticText *t = Environment->addStaticText(narrow_to_wide(gettext("No Worlds Found")).c_str(), rect, false, true, this, -1);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}else{
worldlist_t *w;
worldlist_t *s = NULL;
core::rect<s32> rect(0, 0, 450, 400);
rect += topleft_content + v2s32(50, 60);
box = Environment->addListBox(rect, this, GUI_ID_WORLD_LIST, true);
box->setItemHeight(25);
w = worlds;
for (int i=0; w; i++) {
box->addItem(narrow_to_wide(w->name).c_str());
if (i == selected_row)
s = w;
w = w->next;
}
if (s) {
if (snprintf(selected,256,"%s",s->path) >= 256)
selected[0] = 0;
vlprintf(CN_INFO,"Selected: '%s'",selected);
box->setSelected(selected_row);
{
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 480);
gui::IGUIStaticText *t = Environment->addStaticText(narrow_to_wide(s->name).c_str(), rect, false, true, this, -1);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect<s32> rect(0, 0, 350, 20);
rect += topleft_content + v2s32(100, 510);
gui::IGUIStaticText *t = Environment->addStaticText(narrow_to_wide(s->mode).c_str(), rect, false, true, this, -1);
t->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
}
if (s->version) {
core::rect<s32> rect(0, 0, 350, 20);
rect += topleft_content + v2s32(100, 510);
gui::IGUIStaticText *t = Environment->addStaticText(narrow_to_wide(s->version).c_str(), rect, false, true, this, -1);
t->setTextAlignment(gui::EGUIA_LOWERRIGHT, gui::EGUIA_UPPERLEFT);
}
}
}
/* import */
}else if (config == 3) {
}else{
// Save button
{
core::rect<s32> rect(0, 0, 200, 40);
rect += v2s32(25, 260);
Environment->addButton(rect, this, GUI_ID_SP_SAVE_BUTTON, narrow_to_wide(gettext("Save")).c_str());
}
// Cancel button
{
core::rect<s32> rect(0, 0, 200, 40);
rect += v2s32(25, 305);
Environment->addButton(rect, this, GUI_ID_SP_CANCEL_BUTTON, narrow_to_wide(gettext("Cancel")).c_str());
}
/* create */
if (config == 1) {
{
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 40);
gui::IGUIStaticText *t = Environment->addStaticText(
narrow_to_wide(gettext("Create New World")).c_str(),
rect,
false,
true,
this,
-1
);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
// world name
{
core::rect<s32> rect(0, 0, 110, 20);
rect += topleft_content + v2s32(120, 70);
Environment->addStaticText(narrow_to_wide(gettext("World Name:")).c_str(), rect, false, true, this, -1);
}
{
core::rect<s32> rect(0, 0, 230, 30);
rect += topleft_content + v2s32(135, 90);
#if USE_FREETYPE
new gui::intlGUIEditBox(narrow_to_wide(selected).c_str(), true, Environment, this, GUI_ID_SP_WORLD_NAME, rect);
#else
Environment->addEditBox(narrow_to_wide(selected).c_str(), rect, false, this, GUI_ID_SP_WORLD_NAME);
#endif
}
/* edit */
}else if (config == 2) {
{
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 40);
gui::IGUIStaticText *t = Environment->addStaticText(
narrow_to_wide(gettext("Edit World")).c_str(),
rect,
false,
true,
this,
-1
);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
{
core::rect<s32> rect(0, 0, 550, 20);
rect += topleft_content + v2s32(0, 70);
gui::IGUIStaticText *t = Environment->addStaticText(
narrow_to_wide(selected).c_str(),
rect,
false,
true,
this,
-1
);
t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_UPPERLEFT);
}
}
{
core::rect<s32> rect(0, 0, 200, 30);
rect += topleft_content + v2s32(80, 160);
Environment->addCheckBox(
survival_mode,
rect,
this,
GUI_ID_SP_MODE_SURVIVAL,
narrow_to_wide(gettext("Survival Mode")).c_str()
);
}
{
core::rect<s32> rect(0, 0, 200, 30);
rect += topleft_content + v2s32(80, 200);
Environment->addCheckBox(
!survival_mode,
rect,
this,
GUI_ID_SP_MODE_CREATIVE,
narrow_to_wide(gettext("Creative Mode")).c_str()
);
}
{
core::rect<s32> rect(0, 0, 200, 30);
rect += topleft_content + v2s32(80, 260);
Environment->addCheckBox(
flat_map,
rect,
this,
GUI_ID_SP_MAP_FLAT,
narrow_to_wide(gettext("Flat Mapgen")).c_str()
);
}
{
core::rect<s32> rect(0, 0, 200, 30);
rect += topleft_content + v2s32(80, 300);
Environment->addCheckBox(
random_seed,
rect,
this,
GUI_ID_SP_MAP_RANDOM_SEED,
narrow_to_wide(gettext("Use Random Seed")).c_str()
);
}
if (!random_seed) {
// seed
{
core::rect<s32> rect(0, 0, 110, 20);
rect += topleft_content + v2s32(120, 330);
Environment->addStaticText(narrow_to_wide(gettext("World Seed:")).c_str(), rect, false, true, this, -1);
}
{
core::rect<s32> rect(0, 0, 230, 30);
rect += topleft_content + v2s32(135, 350);
#if USE_FREETYPE
new gui::intlGUIEditBox(narrow_to_wide(fixed_seed).c_str(), true, Environment, this, GUI_ID_SP_MAP_SEED, rect);
#else
Environment->addEditBox(narrow_to_wide(fixed_seed).c_str(), rect, false, this, GUI_ID_SP_MAP_SEED);
#endif
}
}
}
}
void GUISingleplayerMenu::drawMenu()
{
video::IVideoDriver* driver = Environment->getVideoDriver();
{
char buff[1024];
core::rect<s32> rect(
0,
0,
m_screensize.X,
m_screensize.Y
);
driver->draw2DRectangle(rect, GUI_BG_TOP, GUI_BG_BTM, GUI_BG_TOP, GUI_BG_BTM, NULL);
if (path_get((char*)"texture",(char*)"menulogo.png",1,buff,1024)) {
video::ITexture *texture = driver->getTexture(buff);
if (texture != 0) {
const core::dimension2d<u32>& img_origsize = texture->getOriginalSize();
core::rect<s32> logo(
AbsoluteRect.UpperLeftCorner.X+25,
AbsoluteRect.UpperLeftCorner.Y,
AbsoluteRect.UpperLeftCorner.X+225,
AbsoluteRect.UpperLeftCorner.Y+200
);
const video::SColor color(255,255,255,255);
const video::SColor colors[] = {color,color,color,color};
driver->draw2DImage(texture, logo, core::rect<s32>(core::position2d<s32>(0,0),img_origsize), NULL, colors, true);
}
}
}
gui::IGUIElement::draw();
}
bool GUISingleplayerMenu::OnEvent(const SEvent& event)
{
if (event.EventType==EET_KEY_INPUT_EVENT) {
if (
event.KeyInput.PressedDown
&& (
event.KeyInput.Key == KEY_ESCAPE
|| event.KeyInput.Key == KEY_RETURN
)
) {
quitMenu();
return true;
}
}
if (event.EventType == EET_GUI_EVENT) {
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST && isVisible()) {
{
gui::IGUIElement *e = getElementFromId(GUI_ID_SP_WORLD_NAME);
if (e != NULL) {
std::wstring w_name = e->getText();
if (snprintf(selected,256,"%s",wide_to_narrow(w_name).c_str()) >= 256)
snprintf(selected,256,"New World");
}
}
{
gui::IGUIElement *e = getElementFromId(GUI_ID_SP_MAP_SEED);
if (e != NULL) {
std::wstring w_name = e->getText();
if (snprintf(fixed_seed,256,"%s",wide_to_narrow(w_name).c_str()) >= 256)
snprintf(fixed_seed,256,"0");
}
}
if (!canTakeFocus(event.GUIEvent.Element)) {
// Returning true disables focus change
return true;
}
}
if (event.GUIEvent.EventType==gui::EGET_CHECKBOX_CHANGED) {
gui::IGUICheckBox *e = (gui::IGUICheckBox*)event.GUIEvent.Caller;
if (e) {
switch (event.GUIEvent.Caller->getID()) {
case GUI_ID_SP_MODE_SURVIVAL:
survival_mode = e->isChecked();
break;
case GUI_ID_SP_MODE_CREATIVE:
survival_mode = !e->isChecked();
break;
case GUI_ID_SP_MAP_FLAT:
flat_map = e->isChecked();
break;
case GUI_ID_SP_MAP_RANDOM_SEED:
random_seed = e->isChecked();
break;
}
}
m_accepted = false;
regenerateGui(m_screensize);
}
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
switch (event.GUIEvent.Caller->getID()) {
case GUI_ID_SP_START_BUTTON: // Start game
if (selected[0] != 0) {
config_set("client.world",selected);
m_gamecallback->startGame();
quitMenu();
}
return true;
case GUI_ID_SP_CREATE_BUTTON:
selected_row = -1;
loadWorld(true);
config = 1;
regenerateGui(m_screensize);
return true;
case GUI_ID_SP_EDIT_BUTTON:
if (selected[0] != 0) {
loadWorld(false);
config = 2;
}
regenerateGui(m_screensize);
return true;
case GUI_ID_SP_CANCEL_BUTTON:
config = 0;
regenerateGui(m_screensize);
return true;
case GUI_ID_SP_SAVE_BUTTON:
if (config == 1 || config == 2) {
saveWorld((config == 1));
}
config = 0;
if (worlds) {
world_list_free(worlds);
worlds = NULL;
}
regenerateGui(m_screensize);
return true;
case GUI_ID_SP_IMPORT_BUTTON:
config = 3;
regenerateGui(m_screensize);
return true;
case GUI_ID_SP_MAINMENU_BUTTON: //back
quitMenu();
return true;
}
}
if (
event.GUIEvent.EventType == gui::EGET_LISTBOX_CHANGED
|| event.GUIEvent.EventType == gui::EGET_LISTBOX_SELECTED_AGAIN
) {
if (event.GUIEvent.Caller->getID() == GUI_ID_WORLD_LIST) {
gui::IGUIListBox *e = (gui::IGUIListBox*)event.GUIEvent.Caller;
if (e != NULL) {
selected_row = e->getSelected();
}else if (selected_row > -1) {
selected_row = -1;
}
selected[0] = 0;
regenerateGui(m_screensize);
return true;
}
}
}
return Parent ? Parent->OnEvent(event) : false;
}
void GUISingleplayerMenu::saveWorld(bool create)
{
if (create) {
world_create(selected);
}else{
world_load(selected);
}
if (survival_mode) {
config_set("world.game.mode","survival");
}else{
config_set("world.game.mode","creative");
}
if (random_seed || fixed_seed[0] == 0) {
config_set("world.seed",NULL);
}else{
config_set("world.seed",fixed_seed);
}
if (flat_map) {
config_set("world.map.type","flat");
}else{
config_set("world.map.type","default");
}
if (random_seed || fixed_seed[0] == 0) {
config_set("world.seed",NULL);
}else{
config_set("world.seed",fixed_seed);
}
world_unload();
}
void GUISingleplayerMenu::loadWorld(bool create)
{
char* v;
config_clear("world");
survival_mode = true;
random_seed = true;
flat_map = false;
snprintf(fixed_seed,256,"0");
if (create) {
snprintf(selected,256,"New World");
}else{
world_load(selected);
v = config_get("world.game.mode");
if (v && !strcmp(v,"creative"))
survival_mode = false;
v = config_get("world.seed");
if (v) {
random_seed = false;
snprintf(fixed_seed,256,"%s",v);
}
v = config_get("world.name");
if (!v || snprintf(selected,256,"%s",v) >= 256)
snprintf(selected,256,"New World");
v = config_get("world.map.type");
if (v && !strcmp(v,"flat"))
flat_map = false;
world_unload();
}
}

102
src/guiSingleplayerMenu.h Normal file
View File

@ -0,0 +1,102 @@
/************************************************************************
* guiMultiplayerMenu.h
* voxelands - 3d voxel world sandbox game
* Copyright (C) Lisa 'darkrose' Milne 2013-2015 <lisa@ltmnet.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
* License updated from GPLv2 or later to GPLv3 or later by Lisa Milne
* for Voxelands.
************************************************************************/
#ifndef GUISINGLEPLAYERMENU_HEADER
#define GUISINGLEPLAYERMENU_HEADER
#include "common.h"
#include "common_irrlicht.h"
#include "utility.h"
#include "modalMenu.h"
#include "client.h"
#include "intl.h"
#include "keycode.h"
#include <string>
// For IGameCallback
#include "guiPauseMenu.h"
#include "guiMainMenu.h"
enum
{
GUI_ID_SP_START_BUTTON = 101,
GUI_ID_SP_CREATE_BUTTON,
GUI_ID_SP_EDIT_BUTTON,
GUI_ID_SP_IMPORT_BUTTON,
GUI_ID_SP_MAINMENU_BUTTON,
GUI_ID_SP_SAVE_BUTTON,
GUI_ID_SP_CANCEL_BUTTON,
GUI_ID_WORLD_LIST,
/* create/edit stuff */
GUI_ID_SP_WORLD_NAME,
GUI_ID_SP_MODE_SURVIVAL,
GUI_ID_SP_MODE_CREATIVE,
GUI_ID_SP_MAP_FLAT,
GUI_ID_SP_MAP_RANDOM_SEED,
GUI_ID_SP_MAP_SEED
};
class GUISingleplayerMenu: public GUIModalMenu
{
public:
GUISingleplayerMenu(
gui::IGUIEnvironment* env,
gui::IGUIElement* parent,
s32 id,
IMenuManager *menumgr,
IGameCallback *gamecallback
);
~GUISingleplayerMenu();
void removeChildren();
/*
Remove and re-add (or reposition) stuff
*/
void regenerateGui(v2u32 screensize);
void drawMenu();
void loadWorld(bool create);
void saveWorld(bool create);
bool OnEvent(const SEvent& event);
private:
char selected[256];
worldlist_t *worlds;
bool m_accepted;
int config;
int selected_row;
IGameCallback *m_gamecallback;
gui::IGUIEnvironment* env;
gui::IGUIElement* parent;
IMenuManager *menumgr;
v2u32 m_screensize;
bool survival_mode;
bool random_seed;
bool flat_map;
char fixed_seed[256];
};
#endif

View File

@ -223,6 +223,8 @@ double debris_amount_2d(uint64_t seed, v2s16 p)
*/
s16 find_ground_level_from_noise(BlockMakeData *data, v2s16 p2d, s16 precision)
{
if (data->type == MGT_FLAT)
return 2;
return get_ground_height(data->seed,p2d);
}

View File

@ -94,10 +94,10 @@ int str_sanitise(char* dest, int size, char* str)
dest[o] = 0;
return o;
}
if (isalnum(str[i])) {
if (isalnum(str[i]) || str[i] == '-') {
lws = 0;
dest[o++] = str[i];
}else if (!lws) {
}else if (!lws && o) {
dest[o++] = '_';
lws = 1;
}

View File

@ -31,8 +31,6 @@ static int world_exists(char* name)
if (!name)
return 0;
name = trim(name);
if (str_sanitise(nbuff,256,name) < 1)
return 0;
@ -49,11 +47,7 @@ int world_create(char* name)
char nbuff1[256];
int i;
if (!name)
name = "New World";
name = trim(name);
if (!name[0])
if (!name || !name[0])
name = "New World";
if (str_sanitise(nbuff,256,name) < 1)
@ -107,7 +101,6 @@ int world_load(char* name)
return 1;
}
name = trim(name);
if (snprintf(nbuff,256,"%s",name) >= 256)
return 1;
@ -199,6 +192,17 @@ void world_unload()
int world_init(char* name)
{
char *v;
if (!name) {
#ifdef SERVER
name = config_get("server.world");
#else
name = config_get("client.world");
#endif
if (!name)
return 1;
}
if (!world_exists(name)) {
if (world_create(name))
return 1;
@ -236,18 +240,6 @@ int8_t world_compatibility(char* version)
return 1;
}
#ifndef _HAVE_WORDLIST_TYPE
#define _HAVE_WORDLIST_TYPE
typedef struct worldlist_s {
struct worldlist_s *prev;
struct worldlist_s *next;
char* name;
char* path;
char* version;
int8_t compat;
} worldlist_t;
#endif
worldlist_t *world_list_get()
{
dirlist_t *d;
@ -256,6 +248,7 @@ worldlist_t *world_list_get()
worldlist_t *w;
char* n;
char* v;
char* m;
d = path_dirlist("worlds",NULL);
@ -267,6 +260,7 @@ worldlist_t *world_list_get()
world_load(e->name);
n = config_get("world.name");
v = config_get("world.version");
m = config_get("world.game.mode");
if (n) {
w = malloc(sizeof(worldlist_t));
if (w) {
@ -279,6 +273,11 @@ worldlist_t *world_list_get()
w->version = strdup(VERSION_STRING);
w->compat = -1;
}
if (m) {
w->mode = strdup(m);
}else{
w->mode = strdup("survival");
}
l = list_push(&l,w);
}
}
@ -302,6 +301,8 @@ void world_list_free(worldlist_t *l)
free(w->name);
if (w->path)
free(w->path);
if (w->mode)
free(w->mode);
if (w->version)
free(w->version);
free(w);