@@ -16,6 +16,7 @@ static char g_CreateWorldFilterArray[] = { '/','\n','\r','\x09','\0','\xC','`','
1616CreateWorldScreen::CreateWorldScreen () :
1717 m_textName(this , 1 , 0 , 0 , 0 , 0 , " " , " Unnamed world" ),
1818 m_textSeed(this , 2 , 0 , 0 , 0 , 0 , " " ),
19+ m_btnGameMode(5 , " Game Mode" ),
1920 m_btnBack(3 , " Cancel" ),
2021 m_btnCreate(4 , " Create New World" )
2122{
@@ -84,31 +85,40 @@ void CreateWorldScreen::_buttonClicked(Button* pButton)
8485 seed = Util::hashCode (seedThing);
8586 }
8687
87- LevelSettings levelSettings (seed);
88+ LevelSettings levelSettings (seed, m_gameMode );
8889 m_pMinecraft->selectLevel (levelUniqueName, levelNickname, levelSettings);
8990 }
91+
92+ if (pButton->getId () == m_btnGameMode.getId ())
93+ m_gameMode = static_cast <GameType>((static_cast <int >(m_gameMode) + 1 ) % (GAME_TYPES_MAX + 1 ));
9094}
9195
92- #define CRAMPED () (100 + 32 + 58 > m_height)
96+ #define CRAMPED () (100 + 32 + 58 + 16 > m_height)
9397
9498void CreateWorldScreen::init ()
9599{
96- m_textName.m_width = m_textSeed.m_width = 200 ;
100+ bool touchscreen = m_pMinecraft->isTouchscreen ();
101+
97102 m_textName.m_height = m_textSeed.m_height = 20 ;
103+
104+ // provide thicker buttons for pressing on touchscreen and match the rest of the ui
105+ if (!touchscreen)
106+ m_btnBack.m_height = m_btnCreate.m_height = m_btnGameMode.m_height = m_textName.m_height = m_textSeed.m_height = 20 ;
107+
108+ m_textName.m_width = m_textSeed.m_width = 200 ;
98109 m_textName.m_xPos = m_textSeed.m_xPos = (m_width - 200 ) / 2 ;
99110 m_textName.m_yPos = 60 ;
100111 m_textSeed.m_yPos = 100 ;
101-
112+ m_btnGameMode.m_yPos = 140 ;
113+ m_btnGameMode.m_width = 150 ;
102114 m_btnCreate.m_yPos = m_height - 56 ;
103- m_btnBack.m_yPos = m_height - 30 ;
104- m_btnBack.m_width = m_btnCreate.m_width = 200 ;
105- m_btnBack.m_height = m_btnCreate.m_height = 20 ;
106-
107- m_btnBack.m_xPos = m_width / 2 - 200 / 2 ;
108- m_btnCreate.m_xPos = m_width / 2 - 200 / 2 ;
115+ m_btnCreate.m_yPos = m_btnBack.m_yPos = m_height - 30 + ((touchscreen) ? 2 : 0 ); // on touchscreens, align the create/cancel buttons with previous screen's Y values
116+ m_btnBack.m_xPos = (m_width / 2 ) + 5 ;
117+ m_btnBack.m_width = m_btnCreate.m_width = 150 ;
109118
110119 _addElement (m_textName);
111120 _addElement (m_textSeed);
121+ _addElement (m_btnGameMode);
112122 _addElement (m_btnCreate);
113123 _addElement (m_btnBack);
114124 m_textName.init (m_pFont);
@@ -117,26 +127,46 @@ void CreateWorldScreen::init()
117127 // 100 - yPos of textSeed
118128 // 32 - offset + height of "Leave blank for random" text
119129 // 58 - approximately the Y position of the create button
130+ // 16 - extra offset for gamemode text to make sure it never overlaps with create new world / cancel
120131 bool crampedMode = CRAMPED ();
121132 if (crampedMode)
122133 {
123134 // crush everything down as much as we can
124- m_textName.m_yPos = 40 ;
125- m_textSeed.m_yPos = 80 ;
126- m_btnCreate.m_yPos += 10 ;
127- m_btnBack.m_yPos += 5 ;
135+ m_textName.m_yPos = 34 ;
136+ m_textSeed.m_yPos = 69 ;
137+ m_btnGameMode.m_yPos = m_textSeed.m_yPos + 24 ;
138+ m_btnCreate.m_width -= 50 ;
139+ m_btnBack.m_width -= 50 ;
128140 }
141+
142+ // calculate after crush
143+ m_btnGameMode.m_xPos = m_width / 2 - m_btnGameMode.m_width / 2 ;
144+ m_btnCreate.m_xPos = m_width / 2 - m_btnCreate.m_width - 5 ;
145+
146+ m_gameMode = GAME_TYPE_SURVIVAL;
129147}
130148
131149void CreateWorldScreen::render (float f)
132150{
133151 renderBackground ();
134152 Screen::render (f);
135153
154+ const std::string gameTypeStr = GameTypeConv::GameTypeDescriptionToNonLocString (m_gameMode);
155+ m_btnGameMode.setMessage (" Game Mode: " + GameTypeConv::GameTypeToNonLocString (m_gameMode));
156+
136157 drawCenteredString (*m_pFont, " Create New World" , m_width / 2 , CRAMPED () ? 10 : 30 , 0xFFFFFF );
137158 drawString (*m_pFont, " World name" , m_textName.m_xPos , m_textName.m_yPos - 10 , 0xDDDDDD );
138159 drawString (*m_pFont, " Seed for the World Generator" , m_textSeed.m_xPos , m_textSeed.m_yPos - 10 , 0xDDDDDD );
160+
161+ bool crampedMode = CRAMPED ();
162+
163+ // Extra text not necessarily needed
164+ if (crampedMode)
165+ return ;
166+
139167 drawString (*m_pFont, " Leave blank for a random seed" , m_textSeed.m_xPos , m_textSeed.m_yPos + 22 , 0x999999 );
168+ int textCenteredX = m_btnGameMode.m_xPos + (m_btnGameMode.m_width / 2 ) - (m_pFont->width (gameTypeStr.c_str ()) / 2 );
169+ drawString (*m_pFont, gameTypeStr.c_str (), textCenteredX, m_btnGameMode.m_yPos + m_btnGameMode.m_height + 3 , 0x999999 );
140170}
141171
142172bool CreateWorldScreen::handleBackEvent (bool b)
@@ -147,4 +177,4 @@ bool CreateWorldScreen::handleBackEvent(bool b)
147177 }
148178
149179 return true ;
150- }
180+ }
0 commit comments