Initial commit of Dink Smallwood HD source. See the "Programmer readme.txt" for information on how to set it up.

git-svn-id: svn://rtsoft.com/rtsvn/projects/RTDink@1469 353e56fe-9613-0410-8469-b96ad8e6f29c
This commit is contained in:
seth 2017-09-12 04:57:47 +00:00
parent dfbc2348a5
commit d4f66a5d2e
115 changed files with 37737 additions and 0 deletions

5
app_info_setup.bat Normal file
View file

@ -0,0 +1,5 @@
REM ** Make sure american code page is used, otherwise the %DATE environmental var might be wrong
CHCP 437
#just a batch file so any other batch files in windows can snag the name of this project. Used by batch files in /android and /html5
set APP_NAME=RTDink

BIN
bin/zlib1.dll Normal file

Binary file not shown.

BIN
bin/zlibwapi.dll Normal file

Binary file not shown.

17
dinkhd_license.txt Normal file
View file

@ -0,0 +1,17 @@
The Dink HD source code license
Copyright (C) 1997-2017 Seth A. Robinson All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
2. Any software using source code from this distribution must contain the text "This product includes software developed by Seth A. Robinson ( www.rtsoft.com )" inside the app in an easily accessible position and sufficiently legible font.
3. Except as contained in this notice, the name of Seth A. Robinson shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior authorization from Seth A. Robinson.
4. The name "Dink Smallwood" and "Dink Smallwood HD" are copyrighted by Robinson Technologies Corporation and shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior authorization from Seth A. Robinson.
5. Media such as graphics/audio are not included in this license. Please ask Seth if you'd like to distribute Dink HD specific media in a port.
THIS SOFTWARE IS PROVIDED 'AS IS' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SETH A. ROBINSON BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
dxsdk/Lib/x64/dxguid.lib Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
dxsdk/Lib/x86/dxguid.lib Normal file

Binary file not shown.

16
programmer_readme.txt Normal file
View file

@ -0,0 +1,16 @@
Dink Smallwood HD
-- How to compile and run:
* First, be able to compile and run the proton example RTSimpleApp. More info at www.protonsdk.com on installing and setting up proton
* Move the RTDink directory checkout to a sub directory of your proton dir. (it works exactly like a proton example - you can still svn update/commit like normal, svn allows you to move around dirs like that)
* Sign up at fmod.com and download FMod Studio for Windows. Unzip to <proton dir>\shared\win\fmodstudio, so you should have a proton\shared\win\fmodstudio\api dir, etc.
* Install Visual Studio 2017 (Community version works fine and is free) and open RTDink\windows_vs2017\iPhoneRTDink.sln
* Set the profile to "Release GL" and "Win32". (or "Debug GL" is ok too) Compile. If it worked, you should have a dink.exe created in DinkHD/bin.
* Install DinkHD from rtsoft.com. (media is not svn, so this is a way to get it..) Overwrite its dink.exe with your new one. It should run!
Use the "Debug GL" or "Release GL" solution configuations.
--- Have a bugfix or patch?! Please send it over to Seth! Please note that any submission (code, media, translations, ect) must be 100% compatible with the license as listed in dinkhd_license.txt
See script/installer/readme.txt for what's new info.

View file

@ -0,0 +1,72 @@
REM ** Make sure american code page is used, otherwise the %DATE environmental var might be wrong
CHCP 437
REM first clean out any bogus files
cd ..\
cd media
set NO_PAUSE=1
:call update_media.bat
cd ..
cd script
:setup for VS 2017
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\"vcvars32.bat
set C_TARGET_EXE=..\bin\dink.exe
REM erase it so we know it got built right
del %C_TARGET_EXE% > NUL
set CL=/DRT_SCRIPT_BUILD
:This would need to be "Release GL|x64" for the 64 bit build. But I don't think we really need to do one yet
:for full rebuild
devenv ..\windows_vs2017\iphoneRTDink.sln /rebuild "Release GL|Win32"
:for no rebuild
:devenv ..\windows_vs2017\iphoneRTDink.sln /build "Release GL|Win32"
REM Make sure the file compiled ok
if not exist %C_TARGET_EXE% beeper.exe /p
:Sign it with the RTsoft cert (optional)
call sign.bat %C_TARGET_EXE%
REM Do a little cleanup in the dink bin dir as well
del ..\bin\dink\continue_state.dat
del ..\bin\dink\save*.dat
del ..\bin\dink\quicksave.dat
//make the windows installer part
SET C_FILENAME=DinkSmallwoodHDInstaller.exe
del %C_FILENAME% > NUL
REM get version information from the source code
echo Grabbing version # information from source code.
ctoenv.exe ..\source\App.cpp "m_version = " C_VERSION /r
if errorlevel 1 beeper.exe /p
call setenv.bat
del setenv.bat
ctoenv.exe ..\source\App.cpp "m_versionString = \"" C_TEXT_VERSION_TEMP
if errorlevel 1 beeper.exe /p
call setenv.bat
del setenv.bat
SET C_TEXT_VERSION=%C_TEXT_VERSION_TEMP%
REM done with temp var, kill it
SET C_TEXT_VERSION_TEMP=
echo Building installer: %C_FILENAME% %C_TEXT_VERSION%
cd win_installer
..\..\..\..\util\NSIS\makensis.exe dink.nsi
cd ..
set d_fname=%C_FILENAME%
call sign.bat %C_FILENAME%
:call FTPToSiteWin.bat
cd script
pause

View file

@ -0,0 +1,11 @@
cd ..\android
call build.bat
@ECHO ON
set D_FILE_NAME=%APP_NAME%-unprotected.apk
del ..\%D_FILE_NAME%
copy bin\%APP_NAME%-debug.apk ..\%D_FILE_NAME%
cd ..
set d_fname=%D_FILE_NAME%
call script\FTPToSite.bat
cd script
pause

View file

@ -0,0 +1,48 @@
Dink Smallwood HD for Windows 7, 8, 10.
Requires OpenGL, if you have any problems running this, try installing the latest video drivers for your video card/chip.
To change screen size, drag the window borders around. (Hold shift while dragging to toggle aspect-ratio lock)
To toggle a psuedo full screen mode, click Full Screen Toggle in the options. (Or hit Alt-Enter)
------------- BETA VERSION -----------------
This is a beta version which means it probably has bugs and isn't ready for general consumption. However, it means you've been recruited to help us make it better!
To report a bug, find or post a thread about Dink HD on dinknetwork.com and and please include the following information if you can:
- Dink files are installed to C:\Users\<user name>\AppData\Local\DinkSmallwoodHD by default.
- Description of the bug and how to recreate it
- If the bug takes work to get to, it would be great if you could "Quick save" in the game and add a URL to download the quicksave.dat file.
quicksave.dat should be located in C:\Users\<user name>\AppData\Local\DinkSmallwoodHD for the main game and C:\Users\<user name>\AppData\Local\DinkSmallwoodHD\dmods\<dmod dir> for DMODs.
- The DMOD name (and URL to download it if possible)
- Windows version you're playing on
- Screen mode/resolution
- If the game crashes, please include the log.txt file as it may contain information about the crash.
-Seth (seth@rtsoft.com)
www.rtsoft.com
------ Change log for 1.7.0 ----------
* Upgraded source projects to Visual Studio 2017 (free community edition works fine)
* (bugfix) No longer forces reload of all graphics when saving the state
* (bugfix) No longer forces reload of all graphics and audio when losing focus/going into the background
* (bugfix) Fixed issue where screen scrolling could bug out if window was resized on windows
* Latest state data to "Continue" persists even if the game crashes now
* Added support for 64 bit builds (still fully compatible with existing save states/games)
* Added support for aspect ratio correction (can be disabled by enabling "Fullscreen stretch" in the options)
* Added IPV6 support
* (DinkC) Goto statements no longer require a ; at the end to work
* (iOS) Now compatible with iOS 11
* (Windows) Installer no longer requires admin privileges, now installs to local user's appdata dir (C:\UserName\AppData\Local\DinkSmallwoodHD)
* (Windows) .exe and installer are now signed with RTsoft's distribution certificate
* (Windows) Now checks for new versions on startup
* (Windows) Now writes the stack trace to log.txt if the game crashes (helps debug problems)
------ Change log for 1.7.1 ----------
* (Windows) Fixed app icon

877
source/App.cpp Normal file
View file

@ -0,0 +1,877 @@
/*
* App.cpp
* Created by Seth Robinson on 3/6/09.
* For license info, check the license.txt file that should have come with this.
*
*/
#include "PlatformPrecomp.h"
#include "App.h"
#include "GUI/MainMenu.h"
#include "Entity/EntityUtils.h"//create the classes that our globally library expects to exist somewhere.
#include "dink/dink.h"
#include "GUI/GameMenu.h"
#include "util/archive/TarHandler.h"
#include "Renderer/SoftSurface.h"
#include "GUI/BrowseMenu.h"
#include "Entity/SliderComponent.h"
#include "GUI/OptionsMenu.h"
#include "FileSystem/FileSystemZip.h"
#include "Entity/ArcadeInputComponent.h"
#include "GUI/ExpiredMenu.h"
#include <time.h>
#include "Gamepad/GamepadManager.h"
#include "Gamepad/GamepadProvideriCade.h"
#ifdef WINAPI
#include "StackWalker/StackUtils.h"
#endif
extern Surface g_transitionSurf;
#ifdef RT_MOGA_ENABLED
#include "Gamepad/GamepadProviderMoga.h"
#endif
#ifdef RT_CHARTBOOST_ENABLED
#include "Ad/AdProviderChartBoost.h"
#endif
#ifdef RT_IOS_60BEAT_GAMEPAD_SUPPORT
#include "Gamepad/GamepadProvider60Beat.h"
#endif
//#define FORCE_DMOD_SUPPORT
MessageManager g_messageManager;
MessageManager * GetMessageManager() {return &g_messageManager;}
FileManager g_fileManager;
FileManager * GetFileManager() {return &g_fileManager;}
GamepadManager g_gamepadManager;
GamepadManager * GetGamepadManager() {return &g_gamepadManager;}
#ifdef __APPLE__
#if TARGET_OS_IPHONE == 1
//it's an iPhone or iPad
//#include "Audio/AudioManagerOS.h"
//AudioManagerOS g_audioManager;
//#include "Audio/AudioManagerDenshion.h"
//AudioManagerDenshion g_audioManager;
#include "Audio/AudioManagerFMODStudio.h"
AudioManagerFMOD g_audioManager;
#else
//it's being compiled as a native OSX app
#include "Audio/AudioManagerFMODStudio.h"
AudioManagerFMOD g_audioManager; //dummy with no sound
//in theory, CocosDenshion should work for the Mac builds, but right now it seems to want a big chunk of
//Cocos2d included so I'm not fiddling with it for now
//#include "Audio/AudioManagerDenshion.h"
//AudioManagerDenshion g_audioManager;
#endif
#else
#if defined RT_WEBOS || defined RTLINUX
#include "Audio/AudioManagerSDL.h"
AudioManagerSDL g_audioManager; //sound in windows and WebOS
//AudioManager g_audioManager; //to disable sound
#elif defined ANDROID_NDK
#include "Audio/AudioManagerAndroid.h"
AudioManagerAndroid g_audioManager; //sound for android
#elif defined PLATFORM_BBX
#include "Audio/AudioManagerBBX.h"
//AudioManager g_audioManager; //to disable sound
AudioManagerBBX g_audioManager;
#elif defined PLATFORM_HTML5
#include "Audio/AudioManagerSDL.h"
//AudioManager g_audioManager; //to disable sound
AudioManagerSDL g_audioManager;
#elif defined PLATFORM_FLASH
//AudioManager g_audioManager; //to disable sound
#include "Audio/AudioManagerFlash.h"
AudioManagerFlash g_audioManager;
#else
//in windows
//AudioManager g_audioManager; //to disable sound
#ifdef RT_FLASH_TEST
#include "Audio/AudioManagerFlash.h"
AudioManagerFlash g_audioManager;
#else
// #include "Audio/AudioManagerAudiere.h"
// AudioManagerAudiere g_audioManager; //Use Audiere for audio
#include "Gamepad/GamepadProviderDirectX.h"
#include "Audio/AudioManagerFMODStudio.h"
AudioManagerFMOD g_audioManager; //if we wanted FMOD sound in windows
#endif
#endif
#endif
#ifdef ANDROID_NDK
void SetPreferSDCardForStorage(bool bNew);
#endif
AudioManager * GetAudioManager(){return &g_audioManager;}
App *g_pApp = NULL;
BaseApp * GetBaseApp()
{
if (!g_pApp)
{
g_pApp = new App;
}
return g_pApp;
}
App * GetApp()
{
return g_pApp;
}
const char * GetAppName() {return "Dink Smallwood HD";};
App::App()
{
http://www.rtsoft.com
#ifdef ANDROID_NDK
SetPreferSDCardForStorage(true);
#endif
m_bDidPostInit = false;
m_bHasDMODSupport = true;
//for mobiles
m_version = 1.71f;
m_versionString = "V1.7.1";
m_build = 1;
m_bCheatsEnabled = false;
//for Win/mac
m_desktopVersion = m_version;
m_desktopVersionString = m_versionString;
m_desktopBuild = 1;
m_bForceAspectRatio = true;
}
App::~App()
{
//L_ParticleSystem::deinit();
}
void App::AddIcadeProvider()
{
GamepadProvider * pProv = GetGamepadManager()->AddProvider(new GamepadProvideriCade); //use iCade, this actually should work with any platform...
GetBaseApp()->SetAllowScreenDimming(false);
if (pProv)
{
pProv->m_sig_failed_to_connect.connect(1, boost::bind(&App::OniCadeDisconnected, this, _1));
}
}
bool App::GetForceAspectRatio()
{
return m_bForceAspectRatio;
}
void App::OniCadeDisconnected(GamepadProvider *pProvider)
{
LogMsg("Dealing with icade disconnect");
GetGamepadManager()->RemoveProviderByName("iCade");
GetApp()->RemoveAndroidKeyboardKeys();
GetApp()->GetVar("check_icade")->Set(uint32(0));
Entity *pOptions = GetEntityRoot()->GetEntityByName("OptionsMenu");
if (pOptions)
{
LogMsg("Found options");
Entity *pCheckBox = pOptions->GetEntityByName("check_icade");
if (pCheckBox)
{
LogMsg("Found checkbox");
SetCheckBoxChecked(pCheckBox, false, true);
}
}
}
bool App::Init()
{
#ifdef WINAPI
InitUnhandledExceptionFilter();
#endif
SetDefaultButtonStyle(Button2DComponent::BUTTON_STYLE_CLICK_ON_TOUCH_RELEASE);
SetManualRotationMode(false);
bool bScaleScreenActive = true; //if true, we'll stretch every screen to the coords below
int scaleToX = 480;
int scaleToY = 320;
if (IsTabletSize())
{
scaleToX = 1024;
scaleToY = 768;
}
/*
if (IsIphoneSize || IsIphone4Size || IsIPADSize)
{
bScaleScreenActive = false;
}
*/
switch (GetEmulatedPlatformID())
{
//special handling for certain platforms to tweak the video settings
case PLATFORM_ID_WEBOS:
//if we do this, everything will be stretched/zoomed to fit the screen
if (IsIPADSize)
{
//doesn't need rotation
SetLockedLandscape(false); //because it's set in the app manifest, we don't have to rotate ourselves
SetupScreenInfo(GetPrimaryGLX(), GetPrimaryGLY(), ORIENTATION_PORTRAIT);
if (bScaleScreenActive)
SetupFakePrimaryScreenSize(scaleToX,scaleToY); //game will think it's this size, and will be scaled up
}
else
{
//but the phones do
SetLockedLandscape(true); //we don't allow portrait mode for this game
if (bScaleScreenActive)
SetupFakePrimaryScreenSize(scaleToX,scaleToY); //game will think it's this size, and will be scaled up
}
break;
case PLATFORM_ID_IOS:
SetLockedLandscape(true); //we stay in portrait but manually rotate, gives better fps on older devices
if (bScaleScreenActive)
SetupFakePrimaryScreenSize(scaleToX,scaleToY); //game will think it's this size, and will be scaled up
break;
default:
//Default settings for other platforms
SetLockedLandscape(false); //we don't allow portrait mode for this game
SetupScreenInfo(GetPrimaryGLX(), GetPrimaryGLY(), ORIENTATION_PORTRAIT);
if (bScaleScreenActive)
SetupFakePrimaryScreenSize(scaleToX,scaleToY); //game will think it's this size, and will be scaled up
}
//L_ParticleSystem::init(2000);
SetInputMode(INPUT_MODE_SEPARATE_MOVE_TOUCHES); //this game has so much move touching, I handle them separately for performance reasons
if (m_bInitted)
{
return true;
}
if (!BaseApp::Init())
{
return false;
}
m_adManager.Init();
#ifdef RT_CHARTBOOST_ENABLED
AdProviderChartBoost *pProvider = new AdProviderChartBoost;
#ifdef PLATFORM_ANDROID
assert(!"No longer using chartboost!");
pProvider->SetupInfo("", ""); //Dink HD Android
#else
pProvider->SetupInfo("", ""); //Dink HD iOS
#endif
m_adManager.AddProvider(pProvider);
pProvider->CacheShowInterstitial();
// pProvider->CacheShowMoreApps();
m_adManager.GetProviderByType(AD_PROVIDER_CHARTBOOST)->ShowInterstitial();
//m_adManager.GetProviderByType(AD_PROVIDER_CHARTBOOST)->ShowMoreApps();
#endif
LogMsg("Save path is %s", GetSavePath().c_str());
if (GetEmulatedPlatformID() == PLATFORM_ID_HTML5)
{
g_dglo.m_bUsingDinkPak = true;
}
if (g_dglo.m_bUsingDinkPak)
{
FileSystemZip *pFileSystem = new FileSystemZip();
if (!pFileSystem->Init(GetBaseAppPath()+ "dink/dink.pak"))
{
LogMsg("Error finding APK file to load resources");
}
//pFileSystem->SetRootDirectory("dink");
GetFileManager()->MountFileSystem(pFileSystem);
}
if (GetPlatformID() != PLATFORM_ID_ANDROID)
{
/*
FileSystemZip *pFileSystem = new FileSystemZip();
if (!pFileSystem->Init(GetBaseAppPath()+ "dink/dink.pak"))
{
LogMsg("Error finding APK file to load resources");
}
GetFileManager()->MountFileSystem(pFileSystem);
*/
/*
vector<string> contents = pFileSystem->GetContents();
LogMsg("Listing all %d files.", contents.size());
for (int i=0; i < contents.size(); i++)
{
LogMsg("%s", contents[i].c_str());
}
*/
RemoveFile(GetDMODRootPath()+"temp.dmod");
RemoveFile("temp.dmod");
}
switch (GetPlatformID())
{
case PLATFORM_ID_WINDOWS:
case PLATFORM_ID_BBX:
case PLATFORM_ID_WEBOS:
case PLATFORM_ID_HTML5:
CreateDirectoryRecursively("", GetDMODRootPath());
break;
default:
CreateAppCacheDirIfNeeded();
break;
}
if (IsLargeScreen())
{
if (!GetFont(FONT_SMALL)->Load("interface/font_normalx2.rtfont")) return false;
if (!GetFont(FONT_LARGE)->Load("interface/font_bigx2.rtfont")) return false;
} else
{
if (!GetFont(FONT_SMALL)->Load("interface/font_normal.rtfont")) return false;
if (!GetFont(FONT_LARGE)->Load("interface/font_big.rtfont")) return false;
}
//GetFont(FONT_SMALL)->SetSmoothing(false);
#ifndef FORCE_DMOD_SUPPORT
if (GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
//m_bHasDMODSupport = false;
}
#endif
#ifdef _DEBUG
GetBaseApp()->SetFPSVisible(true);
#endif
bool bFileExisted;
m_varDB.Load("save.dat", &bFileExisted);
GetApp()->GetVarWithDefault("smoothing",uint32(1))->GetUINT32();
GetApp()->GetVarWithDefault("buttons",uint32(0));
GetApp()->GetVarWithDefault("music_vol",1.0f)->GetFloat();
GetApp()->GetVarWithDefault("gui_transparency",0.35f)->GetFloat();
#ifdef PLATFORM_WINDOWS
//If you don't have directx, just comment out this and remove the dx lib dependency, directx is only used for the
//gamepad input on windows
GetGamepadManager()->AddProvider(new GamepadProviderDirectX); //use directx joysticks
#endif
#ifdef RT_MOGA_ENABLED
GetGamepadManager()->AddProvider( new GamepadProviderMoga);
GetBaseApp()->SetAllowScreenDimming(false);
#endif
if (GetVar("check_icade")->GetUINT32() != 0)
{
AddIcadeProvider();
}
#if defined(PLATFORM_IOS) && defined(RT_IOS_60BEAT_GAMEPAD_SUPPORT)
//startup the 60beat gamepad stuff.. really, we should only do this if they've checked to use it in options
//or such because their driver may slow us down.. unsure
if (GetVar("check_60beat")->GetUINT32() != 0)
{
//startup the 60beat gamepad stuff
GetGamepadManager()->AddProvider(new GamepadProvider60Beat);
GetBaseApp()->SetAllowScreenDimming(false);
}
#endif
if (GetEmulatedPlatformID() == PLATFORM_ID_WINDOWS || GetEmulatedPlatformID() == PLATFORM_ID_OSX || GetEmulatedPlatformID() == PLATFORM_ID_HTML5)
{
//should we draw that onscreen GUI stuff for Dink?
m_bUsingTouchScreen = false;
} else
{
m_bUsingTouchScreen = true;
}
if (IsIPADSize && GetEmulatedPlatformID() != PLATFORM_ID_WEBOS)
{
GetApp()->GetVarWithDefault("fpsLimit", Variant(uint32(VIDEO_FPS_LIMIT_OFF)))->GetUINT32();
}
UpdateVideoSettings();
//preload audio
if (GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
//use our own DLS, as iPhone/iPad don't have any midi system
g_audioManager.SetDLS("dink/midi/TimGM6mbTiny.dls");
}
#ifdef _DEBUG
GetApp()->SetCheatsEnabled(true);
#endif
#ifdef _WIN32
//temporary while I make movies
//GetApp()->SetCheatsEnabled(true);
#endif
bool bSound = m_varDB.GetVarWithDefault("sound", uint32(1))->GetUINT32() != 0;
GetAudioManager()->SetSoundEnabled(bSound);
//GetAudioManager()->SetMusicEnabled(!GetApp()->GetVar("musicDisabled")->GetUINT32());
GetAudioManager()->SetMusicVol(GetApp()->GetVar("music_vol")->GetFloat());
GetAudioManager()->Preload("audio/click.wav");
InitDinkPaths(GetBaseAppPath(), "dink", "");
GetBaseApp()->m_sig_pre_enterbackground.connect(1, boost::bind(&App::OnPreEnterBackground, this, _1));
GetBaseApp()->m_sig_loadSurfaces.connect(1, boost::bind(&App::OnLoadSurfaces, this));
//when screen size changes we'll unload surfaces
GetBaseApp()->m_sig_unloadSurfaces.connect(1, boost::bind(&App::OnUnloadSurfaces, this));
return true;
}
void App::OnPreEnterBackground(VariantList *pVList)
{
SaveAllData();
}
void App::OnExitApp(VariantList *pVarList)
{
LogMsg("Exiting the app");
OSMessage o;
o.m_type = OSMessage::MESSAGE_FINISH_APP;
GetBaseApp()->AddOSMessage(o);
}
void App::Kill()
{
if (!IsInBackground())
{
SaveAllData();
}
finiObjects();
BaseApp::Kill();
g_pApp = NULL; //make sure nobody elses access this
}
void App::RemoveAndAttachAllAvailableGamepads()
{
ArcadeInputComponent *pComp = (ArcadeInputComponent*) GetEntityRoot()->GetComponentByName("ArcadeInput");
assert(pComp);
for (int i=0; i < GetGamepadManager()->GetGamepadCount(); i++)
{
Gamepad *pPad = GetGamepadManager()->GetGamepad((eGamepadID)i);
pPad->ConnectToArcadeComponent(pComp, true, true);
//if we cared about the analog sticks too, we'd do this:
//pPad->m_sig_left_stick.connect(1, boost::bind(&OnGamepadStickUpdate, this, _1));
//pPad->m_sig_right_stick.connect(1, boost::bind(&OnGamepadStickUpdate, this, _1));
}
}
void App::RemoveAndroidKeyboardKeys()
{
ArcadeInputComponent *pComp = (ArcadeInputComponent*) GetEntityRoot()->GetComponentByName("ArcadeInput");
//first clear out all old ones to be safe
VariantList vList((string)"Keyboard");
pComp->GetFunction("RemoveKeyBindingsStartingWith")->sig_function(&vList);
}
void App::AddDroidKeyboardKeys()
{
if (GetEmulatedPlatformID() == PLATFORM_ID_ANDROID)
{
ArcadeInputComponent *pComp = (ArcadeInputComponent*) GetEntityRoot()->GetComponentByName("ArcadeInput");
RemoveAndroidKeyboardKeys();
//I think the ASWZ binding thing is for the control pad on the xperia play??
AddKeyBinding(pComp, "KeyboardLeft",'A', VIRTUAL_KEY_DIR_LEFT);
AddKeyBinding(pComp, "KeyboardRight",'S', VIRTUAL_KEY_DIR_RIGHT);
AddKeyBinding(pComp, "KeyboardUp", 'W', VIRTUAL_KEY_DIR_UP);
AddKeyBinding(pComp, "KeyboardDown", 'Z', VIRTUAL_KEY_DIR_DOWN);
AddKeyBinding(pComp, "KeyboardAltMagic", 8, VIRTUAL_KEY_GAME_MAGIC);
AddKeyBinding(pComp, "KeyboardInventory", 'I', VIRTUAL_KEY_GAME_INVENTORY);
AddKeyBinding(pComp, "KeyboardAltTalk", 13, VIRTUAL_KEY_GAME_TALK);
AddKeyBinding(pComp, "KeyboardFire", VIRTUAL_KEY_DIR_CENTER, VIRTUAL_KEY_GAME_FIRE);
AddKeyBinding(pComp, "KeyboardFire2", 'X', VIRTUAL_KEY_GAME_FIRE);
// AddKeyBinding(pComp, "KeyboardAltFire", VIRTUAL_KEY_SHIFT, VIRTUAL_KEY_GAME_FIRE);
}
}
void App::Update()
{
BaseApp::Update();
m_adManager.Update();
g_gamepadManager.Update();
if (!m_bDidPostInit)
{
m_bDidPostInit = true;
m_special = GetSystemData() != C_PIRATED_NO;
//build a GUI node
Entity *pGUIEnt = GetEntityRoot()->AddEntity(new Entity("GUI"));
#ifdef RT_EXPIRING
time_t rawtime, expiretime;
time(&rawtime);
expiretime = 1290050035 + ((3600)*24)*8; //expire in 8 days from Nov 18
bool bExpired = expiretime < rawtime;
if (bExpired)
{
ExpiredMenuCreate(pGUIEnt);
return;
}
#endif
ArcadeInputComponent *pComp = (ArcadeInputComponent*) GetEntityRoot()->AddComponent(new ArcadeInputComponent);
RemoveAndAttachAllAvailableGamepads();
//add key bindings, I may want to move these later if I add a custom key config...
AddKeyBinding(pComp, "Left", VIRTUAL_KEY_DIR_LEFT, VIRTUAL_KEY_DIR_LEFT);
AddKeyBinding(pComp, "Right", VIRTUAL_KEY_DIR_RIGHT, VIRTUAL_KEY_DIR_RIGHT);
AddKeyBinding(pComp, "Up", VIRTUAL_KEY_DIR_UP, VIRTUAL_KEY_DIR_UP);
AddKeyBinding(pComp, "Down", VIRTUAL_KEY_DIR_DOWN, VIRTUAL_KEY_DIR_DOWN);
AddKeyBinding(pComp, "Talk", ' ', VIRTUAL_KEY_GAME_TALK);
AddKeyBinding(pComp, "GamePadInventory", VIRTUAL_DPAD_SELECT, VIRTUAL_KEY_GAME_INVENTORY);
AddKeyBinding(pComp, "GamePadInventory2", VIRTUAL_DPAD_BUTTON_UP, VIRTUAL_KEY_GAME_INVENTORY);
AddKeyBinding(pComp, "GamePadEscape", VIRTUAL_DPAD_START, VIRTUAL_KEY_BACK, true);
AddKeyBinding(pComp, "GamePadFire", VIRTUAL_DPAD_BUTTON_DOWN, VIRTUAL_KEY_GAME_FIRE);
AddKeyBinding(pComp, "GamePadTalk", VIRTUAL_DPAD_BUTTON_RIGHT, VIRTUAL_KEY_GAME_TALK);
AddKeyBinding(pComp, "GamePadMagic", VIRTUAL_DPAD_BUTTON_LEFT, VIRTUAL_KEY_GAME_MAGIC);
AddKeyBinding(pComp, "GamePadSpeedup", VIRTUAL_DPAD_LBUTTON, 'M', true);
AddKeyBinding(pComp, "GamePadSpeedup2", VIRTUAL_DPAD_RBUTTON, 9);
AddKeyBinding(pComp, "GamePadInventory3", VIRTUAL_DPAD_LTRIGGER, VIRTUAL_KEY_GAME_INVENTORY);
AddKeyBinding(pComp, "GamePadPause", VIRTUAL_DPAD_RTRIGGER, VIRTUAL_KEY_BACK, true);
//if (IsDesktop())
{
AddKeyBinding(pComp, "Inventory", 13, VIRTUAL_KEY_GAME_INVENTORY);
AddKeyBinding(pComp, "Magic", VIRTUAL_KEY_SHIFT, VIRTUAL_KEY_GAME_MAGIC);
AddKeyBinding(pComp, "Fire", VIRTUAL_KEY_CONTROL, VIRTUAL_KEY_GAME_FIRE);
AddKeyBinding(pComp, "Speedup", 9, 9); //handle tab
AddKeyBinding(pComp, "Quicksave", VIRTUAL_KEY_F1, VIRTUAL_KEY_F1);
AddKeyBinding(pComp, "Quickload", VIRTUAL_KEY_F8, VIRTUAL_KEY_F8);
}
if (GetVar("check_icade")->GetUINT32() == 0)
{
AddDroidKeyboardKeys();
}
MainMenuCreate(pGUIEnt);
}
}
void App::Draw()
{
BaseApp::Draw();
}
void App::OnScreenSizeChange()
{
#ifdef _DEBUG
LogMsg("Got OnScreenSizeChange");
#endif
BaseApp::OnScreenSizeChange();
if (GetPrimaryGLX() != 0)
{
SetupOrtho();
DinkOnForeground(); //rebuild lost surfaces
if (GetDinkGameState() != DINK_GAME_STATE_PLAYING)
{
PrepareForGL();
}
}
}
void App::GetServerInfo( string &server, uint32 &port )
{
#if defined (_DEBUG) && defined(WIN32)
// server = "localhost";
// port = 8080;
server = "rtsoft.com";
port = 80;
#else
server = "rtsoft.com";
port = 80;
#endif
}
int App::GetSpecial()
{
return m_special; //1 means pirated copy
}
Variant * App::GetVar( const string &keyName )
{
return GetShared()->GetVar(keyName);
}
std::string App::GetVersionString()
{
if (IsDesktop()) return m_desktopVersionString;
return m_versionString;
}
float App::GetVersion()
{
if (IsDesktop()) return m_desktopVersion;
return m_version;
}
int App::GetBuild()
{
if (IsDesktop()) return m_desktopBuild;
return m_build;
}
void App::OnMemoryWarning()
{
BaseApp::OnMemoryWarning();
GetAudioManager()->KillCachedSounds(false, true, 0, 1, false);
DinkUnloadUnusedGraphicsByUsageTime(100); //unload anything not used in the last second
}
void App::UpdateVideoSettings()
{
eVideoFPS v = (eVideoFPS)GetApp()->GetVarWithDefault("fpsLimit", Variant(uint32(VIDEO_FPS_LIMIT_OFF)))->GetUINT32();
OSMessage o;
o.m_type = OSMessage::MESSAGE_SET_FPS_LIMIT;
switch (v)
{
case VIDEO_FPS_LIMIT_ON:
o.m_x = 30;
break;
case VIDEO_FPS_LIMIT_OFF:
o.m_x = 2000;
break;
}
GetBaseApp()->AddOSMessage(o);
};
void App::SaveAllData()
{
if (GetDinkGameState() == DINK_GAME_STATE_PLAYING)
{
// SaveState(GetSavePath()+"state.dat");
SaveState(g_dglo.m_savePath+"continue_state.dat");
WriteLastPathSaved(g_dglo.m_savePath); //so we know what to reload
}
//GetAudioManager()->StopMusic();
m_varDB.Save("save.dat");
}
void App::OnEnterBackground()
{
//SaveAllData();
// DinkUnloadGraphicsCache();
/*
//I don't think we really need to uncache everything. If low memory is a problem we could though..
GetAudioManager()->KillCachedSounds(false, true, 0, 1, false);
LogMsg("Unloading some graphics");
DinkUnloadUnusedGraphicsByUsageTime(0); //unload anything not used in the last second
*/
BaseApp::OnEnterBackground();
}
void App::OnEnterForeground()
{
if (GetPrimaryGLX() == 0) return; //not ready, probably minimized on Windows
BaseApp::OnEnterForeground();
}
bool App::GetIconsOnLeft()
{
return GetShared()->GetVar("buttons")->GetUINT32() != 0;
}
//below is a sort of hack that allows "release" builds on windows to override the settings of whatever the shared main.cpp is telling
//us for window sizes
#ifdef _WINDOWS_
#include "win/app/main.h"
#endif
extern int g_winVideoScreenX;
extern int g_winVideoScreenY;
bool App::OnPreInitVideo()
{
if (!BaseApp::OnPreInitVideo()) return false;
#ifdef PLATFORM_HTML5
g_winVideoScreenX = 1024;
g_winVideoScreenY = 768;
#endif
//#if !defined(_DEBUG) && defined(WINAPI)
#ifdef WINAPI
#ifdef RT_SCRIPT_BUILD
SetEmulatedPlatformID(PLATFORM_ID_WINDOWS);
g_winVideoScreenX = 1024;
g_winVideoScreenY = 768;
#endif
// g_winVideoScreenX = 800;
// g_winVideoScreenY = 1280;
#endif
return true;
}
//for palm webos and android
const char * GetBundlePrefix()
{
char * bundlePrefix = "com.rtsoft.";
return bundlePrefix;
}
//applicable to Palm WebOS builds only
const char * GetBundleName()
{
char * bundleName = "rtdink";
return bundleName;
}
void App::OnMessage( Message &m )
{
m_adManager.OnMessage(m); //gives the AdManager a way to handle messages
BaseApp::OnMessage(m);
}
void App::OnLoadSurfaces()
{
LogMsg("Reloading dink engine surfaces");
DinkOnForeground();
}
void App::OnUnloadSurfaces()
{
LogMsg("Unloading dink engine surfaces");
DinkUnloadUnusedGraphicsByUsageTime(0);
//g_transitionSurf.Kill();
}

116
source/App.h Normal file
View file

@ -0,0 +1,116 @@
/*
* App.h
* Created by Seth Robinson on 3/6/09.
* For license info, check the license.txt file that should have come with this.
*
*/
#pragma once
#include "BaseApp.h"
#include "Manager/AdManager.h"
#define RT_IS_BETA 1
#ifdef RT_SCRIPT_BUILD
//this is being build from the command line, enable special flags here
#endif
class GamepadProvider;
enum eControlStyle
{
CONTROLS_JOYPAD,
CONTROLS_DRAG_ANYWHERE,
CONTROLS_FLING
};
enum eVideoFPS
{
VIDEO_FPS_LIMIT_ON,
VIDEO_FPS_LIMIT_OFF
};
#ifndef __APPLE__
//#define RT_EXPIRING
#endif
//#define RT_CHARTBOOST_ENABLED
class App: public BaseApp
{
public:
App();
virtual ~App();
virtual bool Init();
virtual void Kill();
virtual bool OnPreInitVideo();
virtual void Draw();
virtual void OnScreenSizeChange();
virtual void Update();
virtual void OnMemoryWarning();
virtual void OnEnterBackground();
virtual void OnEnterForeground();
string GetVersionString();
float GetVersion();
int GetBuild();
void GetServerInfo(string &server, uint32 &port);
VariantDB * GetShared() {return &m_varDB;}
Variant * GetVar(const string &keyName );
Variant * GetVarWithDefault(const string &varName, const Variant &var) {return m_varDB.GetVarWithDefault(varName, var);}
int GetSpecial();
void UpdateVideoSettings();
bool GetUsingTouchScreen() {return m_bUsingTouchScreen;}
bool CanDownloadDMODS() {return m_bHasDMODSupport;}
void SetCheatsEnabled(bool bCheatsEnabled) {m_bCheatsEnabled = bCheatsEnabled;}
bool GetCheatsEnabled() {return m_bCheatsEnabled;}
void OnExitApp(VariantList *pVarList);
bool GetIconsOnLeft();
void RemoveAndAttachAllAvailableGamepads();
AdManager * GetAdManager() {return &m_adManager;}
void OnMessage( Message &m );
void OnLoadSurfaces();
void OnUnloadSurfaces();
void AddDroidKeyboardKeys();
void RemoveAndroidKeyboardKeys();
void AddIcadeProvider();
bool GetForceAspectRatio();
private:
AdManager m_adManager;
bool m_bDidPostInit;
VariantDB m_varDB; //holds all data we want to save/load
int m_special;
bool m_bUsingTouchScreen;
bool m_bForceAspectRatio;
void SaveAllData();
void OnPreEnterBackground(VariantList *pVList);
void OniCadeDisconnected(GamepadProvider *pProvider);
float m_version;
string m_versionString;
int m_build;
float m_desktopVersion;
string m_desktopVersionString;
int m_desktopBuild;
bool m_bHasDMODSupport;
bool m_bCheatsEnabled;
};
App * GetApp();
const char * GetAppName();
const char * GetBundleName();
const char * GetBundlePrefix();

View file

@ -0,0 +1,169 @@
#include "PlatformPrecomp.h"
#include "ActionButtonComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
#include "../dink/dink.h"
ActionButtonComponent::ActionButtonComponent()
{
SetName("ActionButton");
m_mode = MODE_MAGIC;
}
ActionButtonComponent::~ActionButtonComponent()
{
}
void ActionButtonComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
if (GetParent()->GetName() != "magic")
{
m_mode = MODE_WEAPON;
}
/*
m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
m_pScale = &GetParent()->GetShared()->GetVarWithDefault("scale", Variant(1.0f))->GetFloat();
m_pRotation = &GetParent()->GetVar("rotation")->GetFloat(); //in degrees
m_pColor = &GetParent()->GetShared()->GetVarWithDefault("color", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pColorMod = &GetParent()->GetShared()->GetVarWithDefault("colorMod", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pAlignment = &GetParent()->GetVar("alignment")->GetUINT32();
*/
m_pAlpha = &GetParent()->GetShared()->GetVarWithDefault("alpha", Variant(1.0f))->GetFloat();
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&ActionButtonComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&ActionButtonComponent::OnUpdate, this, _1));
UpdateIcon();
}
void ActionButtonComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void ActionButtonComponent::OnRender(VariantList *pVList)
{
CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
Surface *pSurf;
switch (m_mode)
{
case MODE_MAGIC:
pSurf = DinkGetMagicIconImage();
break;
case MODE_WEAPON:
pSurf = DinkGetWeaponIconImage();
break;
}
if (pSurf)
{
rtRectf srcRect = pSurf->GetRectf();
rtRectf dstRect = srcRect;
if (IsLargeScreen())
{
dstRect = rtRectf(0,0, 90,90);
} else
{
dstRect = rtRectf(0,0, 44,39);
}
dstRect.AdjustPosition(vFinalPos.x, vFinalPos.y);
if (IsLargeScreen())
{
dstRect.AdjustPosition(19, 25);
} else
{
dstRect.AdjustPosition(9, 12);
}
pSurf->BlitEx(dstRect, srcRect, MAKE_RGBA(255* *m_pAlpha,255* *m_pAlpha,255* *m_pAlpha,255* *m_pAlpha));
if (g_dglo.GetActiveView() == DinkGlobals::VIEW_ZOOMED)
{
int alpha = int(255.0f * *m_pAlpha);
if (alpha > 2)
{
if (m_mode ==MODE_MAGIC)
{
float percent = DinkGetMagicChargePercent();
if (percent > 0)
{
//LogMsg("Magic: %.2f", DinkGetMagicChargePercent());
rtRectf rBar(0,0, iPhoneMapX2X(54)*percent, iPhoneMapY2X(3));
rBar.AdjustPosition(vFinalPos.x, vFinalPos.y);
rBar.AdjustPosition(iPhoneMapX2X(6), iPhoneMapY2X(-4));
if (percent == 1)
{
DrawFilledRect(rBar, MAKE_RGBA(0, 180, 0, 255* *m_pAlpha));
DrawRect(rBar, MAKE_RGBA(0, 255, 0, 255* *m_pAlpha));
} else
{
DrawFilledRect(rBar, MAKE_RGBA(0, 100, 0, 255* *m_pAlpha));
DrawRect(rBar, MAKE_RGBA(0, 255, 0, 170* *m_pAlpha));
}
}
} else
{
float percent = DinkGetHealthPercent();
//LogMsg("Magic: %.2f", DinkGetMagicChargePercent());
rtRectf rBar(0,0, iPhoneMapX2X(54)*percent, iPhoneMapY2X(3));
rBar.AdjustPosition(vFinalPos.x, vFinalPos.y);
rBar.AdjustPosition(iPhoneMapX2X(6), iPhoneMapY2X(-4));
DrawFilledRect(rBar, MAKE_RGBA(180, 0, 0, 255* *m_pAlpha));
DrawRect(rBar, MAKE_RGBA(255, 0, 0, 255* *m_pAlpha));
}
}
}
}
}
void ActionButtonComponent::OnUpdate(VariantList *pVList)
{
}
void ActionButtonComponent::UpdateIcon()
{
}
Entity * CreateActionButtonEntity(Entity *pParentEnt, string name, string fileName, float x, float y)
{
Entity *pButtonEnt = CreateOverlayButtonEntity(pParentEnt, name, fileName, x, y);
pButtonEnt->AddComponent(new ActionButtonComponent);
return pButtonEnt;
}

View file

@ -0,0 +1,56 @@
// ***************************************************************
// ActionButtonComponent - Creation date: 3/15/2010
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2010 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef ActionButtonComponent_h__
#define ActionButtonComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "Renderer/SurfaceAnim.h"
class ActionButtonComponent: public EntityComponent
{
public:
ActionButtonComponent();
virtual ~ActionButtonComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
enum eMode
{
MODE_MAGIC,
MODE_WEAPON
};
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
bool IsMagic() {return m_mode == MODE_MAGIC;}
void UpdateIcon();
CL_Vec2f *m_pPos2d;
/*
CL_Vec2f *m_pSize2d;
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
float *m_pAlpha;
eMode m_mode;
};
Entity * CreateActionButtonEntity(Entity *pParentEnt, string name, string fileName, float x, float y);
#endif // ActionButtonComponent_h__

View file

@ -0,0 +1,87 @@
#include "PlatformPrecomp.h"
#include "CursorComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
CursorComponent::CursorComponent()
{
SetName("Cursor");
}
CursorComponent::~CursorComponent()
{
}
void CursorComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pArrowEnt = NULL;
m_bDisable = false;
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&CursorComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&CursorComponent::OnUpdate, this, _1));
AddInputMovementFocusIfNeeded(GetParent());
GetParent()->GetFunction("OnInput")->sig_function.connect(1, boost::bind(&CursorComponent::OnInput, this, _1));
GetParent()->GetParent()->GetFunction("OnKillingControls")->sig_function.connect(1, boost::bind(&CursorComponent::OnKillingControls, this, _1));
}
void CursorComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void CursorComponent::OnKillingControls(VariantList *pVList)
{
RemoveFocusIfNeeded(this->GetParent());
m_bDisable = true;
}
void CursorComponent::OnUpdatePos(CL_Vec2f vPos)
{
//LogMsg("Got %s", PrintVector2(vPos).c_str());
DinkSetCursorPosition(NativeToDinkCoords(vPos));
}
void CursorComponent::OnRender(VariantList *pVList)
{
//CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void CursorComponent::OnUpdate(VariantList *pVList)
{
}
void CursorComponent::OnInput( VariantList *pVList )
{
//0 = message type, 1 = parent coordinate offset
CL_Vec2f pt = pVList->Get(1).GetVector2();
//pt += GetAlignmentOffset(*m_pSize2d, eAlignment(*m_pAlignment));
switch (eMessageType( int(pVList->Get(0).GetFloat())))
{
case MESSAGE_TYPE_GUI_CLICK_START:
//HandleClickStart(pt);
OnUpdatePos(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_END:
if (!m_bDisable)
{
OnUpdatePos(pt);
g_dglo.m_dirInput[DINK_INPUT_BUTTON1] = true;
g_dglo.m_dirInputFinished[DINK_INPUT_BUTTON1] = true;
}
//HandleClickEnd(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_MOVE:
case MESSAGE_TYPE_GUI_CLICK_MOVE_RAW:
OnUpdatePos(pt);
break;
}
}

View file

@ -0,0 +1,51 @@
// ***************************************************************
// CursorComponent - Creation date: ?/?/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef CursorComponent_h__
#define CursorComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
class CursorComponent: public EntityComponent
{
public:
CursorComponent();
virtual ~CursorComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnInput( VariantList *pVList );
void OnUpdatePos(CL_Vec2f vPos);
void OnKillingControls(VariantList *pVList);
CL_Vec2f *m_pPos2d;
/*
CL_Vec2f *m_pSize2d;
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
float *m_pAlpha;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
Entity *m_pArrowEnt;
bool m_bDisable;
};
#endif // CursorComponent_h__

View file

@ -0,0 +1,332 @@
#include "PlatformPrecomp.h"
#include "DragControlComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
#include "Entity/ArcadeInputComponent.h"
#include "GUI/GameMenu.h"
DragControlComponent::DragControlComponent()
{
SetName("DragControl");
SAMPLE_COUNT = 8; //unused
LENGTH_REQUIRED_FOR_MOVE = 16;
if (IsIphoneSize || IsIphone4Size) LENGTH_REQUIRED_FOR_MOVE = 32; //the screen is tiny, need a few more pixels
if (IsIphone4Size)
{
LENGTH_REQUIRED_FOR_MOVE *= 2;
}
}
DragControlComponent::~DragControlComponent()
{
}
void DragControlComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
m_pSize2d = &GetParent()->GetVar("size2d")->GetVector2();
if (IsIPAD())
{
*m_pPos2d =(CL_Vec2f(0,29));
} else
{
*m_pPos2d = (iPhoneMap(0,29));
}
//fit the active area to match the active dink screen layout
if (g_dglo.GetActiveView() != DinkGlobals::VIEW_ZOOMED && IsDrawingDinkStatusBar())
{
if (IsIPAD())
{
*m_pSize2d = CL_Vec2f(865, 584);
} else
{
*m_pSize2d = iPhoneMap(380, 237);
}
} else
{
if (IsIPAD())
{
*m_pSize2d = CL_Vec2f(866, 715);
} else
{
*m_pSize2d = iPhoneMap(380, 286);
}
}
if (GetApp()->GetIconsOnLeft())
{
m_pPos2d->x += GetScreenSizeXf()-m_pSize2d->x;
}
m_lastTouch = CL_Vec2f(0,0);
/*
m_pScale = &GetParent()->GetShared()->GetVarWithDefault("scale", Variant(1.0f))->GetFloat();
m_pRotation = &GetParent()->GetVar("rotation")->GetFloat(); //in degrees
m_pColor = &GetParent()->GetShared()->GetVarWithDefault("color", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pColorMod = &GetParent()->GetShared()->GetVarWithDefault("colorMod", Variant(MAKE_RGBA(255,255,255,255)))->GetUINT32();
m_pAlpha = &GetParent()->GetShared()->GetVarWithDefault("alpha", Variant(1.0f))->GetFloat();
m_pAlignment = &GetParent()->GetVar("alignment")->GetUINT32();
*/
//register ourselves to render if the parent does
//GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&DragControlComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&DragControlComponent::OnUpdate, this, _1));
GetBaseApp()->m_sig_arcade_input.connect(1, boost::bind(&DragControlComponent::OnArcadeInput, this, _1));
GetParent()->GetVar("ignoreTouchesOutsideRect")->Set(uint32(1));
EntityComponent *pTouch = GetParent()->AddComponent(new TouchHandlerComponent);
//movement arrows
//for speed, we've disabled movement message handling in App.cpp, but we actually want them just here, so we'll hardwire it
AddInputMovementFocusIfNeeded(GetParent());
GetParent()->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&DragControlComponent::OnOverStart, this, _1));
GetParent()->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&DragControlComponent::OnOverEnd, this, _1));
GetParent()->GetFunction("OnOverMove")->sig_function.connect(1, boost::bind(&DragControlComponent::OnOverMove, this, _1));
GetParent()->GetParent()->GetFunction("OnKillingControls")->sig_function.connect(1, boost::bind(&DragControlComponent::OnKillingControls, this, _1));
/*
EntityComponent *pFilter = m_pArrowEnt->AddComponent(new FilterInputComponent);
pFilter->GetVar("mode")->Set(uint32(FilterInputComponent::MODE_CLIP_INPUT_TO_ABSOLUTE_CLIP_RECT_AND_DISABLE_INPUT_CHILDREN));
pFilter->GetVar("clipRect")->Set(CL_Rectf(0,43,397, GetScreenSizeY()));
m_timeOfLastTouch = GetTick(TIMER_SYSTEM);
SetAlignmentEntity(m_pArrowEnt, ALIGNMENT_CENTER);
m_pArrowEnt->GetVar("pos2d")->Set(CL_Vec2f(80, 240));
m_vArrowImageSizeOver2 = m_pArrowEnt->GetVar("size2d")->GetVector2()/2;
*/
VariantList vTemp;
OnOverEnd(&vTemp);
}
void DragControlComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void DragControlComponent::SendKey(eDinkInput key, bool bIsDown)
{
if (bIsDown)
{
g_dglo.m_dirInput[key] = true;
g_dglo.m_dirInputFinished[key] = false; //make sure it wasn't scheduled to stop pressing
} else
{
g_dglo.m_dirInputFinished[key] = true;
}
}
void DragControlComponent::OnKillingControls(VariantList *pVList)
{
RemoveFocusIfNeeded(GetParent());
}
void DragControlComponent::AddSample(DragUnit v)
{
if (DinkIsDoingScreenTransition()) return;
m_samples.push_back(v);
/*
if (m_samples.size() > SAMPLE_COUNT)
{
m_samples.pop_front();
}
*/
}
void DragControlComponent::OnOverStart(VariantList *pVList)
{
m_samples.clear();
m_lastTouch = pVList->Get(0).GetVector2();
}
void DragControlComponent::OnOverEnd(VariantList *pVList)
{
// CL_Vec2f vPos = pVList->Get(0).GetVector2();
// LogMsg("Got over end: %s", PrintVector2(vPos).c_str());
m_samples.clear();
m_lastTouch = CL_Vec2f(0,0);
ClearKeyInput();
}
void DragControlComponent::OnOverMove(VariantList *pVList)
{
AddSample( DragUnit(pVList->Get(0).GetVector2() - m_lastTouch, GetTick(TIMER_GAME)));
//SetPosition(pVList->Get(0).GetVector2());
m_lastTouch = pVList->Get(0).GetVector2();
}
void DragControlComponent::ClearKeyInput()
{
SendKey(DINK_INPUT_UP, false);
SendKey(DINK_INPUT_DOWN, false);
SendKey(DINK_INPUT_LEFT, false);
SendKey(DINK_INPUT_RIGHT, false);
}
void DragControlComponent::OnRender(VariantList *pVList)
{
CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void DragControlComponent::ProcessLastJoystickReading()
{
if (m_samples.size() == 0) return;
//first, lets figure out what direction we want
CL_Vec2f vDir = CL_Vec2f(0,0);
std::deque< DragUnit> sampleTemp;
for (int i=m_samples.size()-1; i >= 0;)
{
//if (m_samples.size() < SAMPLE_COUNT) break;
/*
if (1)
//if (m_samples.at(i).m_timeMade+100 < GetTick(TIMER_GAME))
{
vDir = CL_Vec2f(0,0);
//would removing this stop us from moving?
for (int h=1; h < m_samples.size();h++)
{
vDir += m_samples[h].m_vPos;
}
if (vDir.length() < LENGTH_REQUIRED_FOR_MOVE)
{
//yes it would. Just let it be, for now.
//break;
} else
{
//it's not needed
}
m_samples.erase(m_samples.begin()+i);
continue;
} else
{
break;
}
*/
vDir += m_samples[i].m_vPos;
sampleTemp.push_front( m_samples[i]);
if (vDir.length() >= LENGTH_REQUIRED_FOR_MOVE)
{
//all done
break;
}
i--;
}
m_samples = sampleTemp;
//vDir = CL_Vec2f(0,0);
/*
for (unsigned int i=0; i < m_samples.size();i++)
{
vDir += m_samples[i].m_vPos;
}
*/
ClearKeyInput();
//LogMsg("vDir length is %.2f", vDir.length());
if (vDir.length() < LENGTH_REQUIRED_FOR_MOVE) return;
vDir.normalize();
//recalculate the points
sampleTemp.clear();
//sampleTemp.push_front(m_samples[m_samples.size()-1]);
sampleTemp.push_front(DragUnit( (vDir*LENGTH_REQUIRED_FOR_MOVE)*1.1, 0));
m_samples = sampleTemp;
#ifdef _DEBUG
//LogMsg("Dir is %s (%d samples)", PrintVector2(vDir).c_str(), m_samples.size());
#endif
//convert to 360 degrees
int dir = (int(RAD2DEG(atan2(vDir.y, vDir.x))+(90)));
const int maxDirections = 8;
int finaldir = mod(dir+ (360/ (maxDirections*2)), 360)/ (360/maxDirections);
//nah, let's do 8 actually
//LogMsg("Pressing %s, which is dir %d (final: %d)", PrintVector2(m_lastTouchDir).c_str(), dir, finaldir);
switch (finaldir)
{
case 0: SendKey(DINK_INPUT_UP, true); break;
case 1: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_UP, true); break;
case 2: SendKey(DINK_INPUT_RIGHT, true); break;
case 3: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_DOWN, true); break;
case 4: SendKey(DINK_INPUT_DOWN, true); break;
case 5: SendKey(DINK_INPUT_DOWN, true); SendKey(DINK_INPUT_LEFT, true); break;
case 6: SendKey(DINK_INPUT_LEFT, true); break;
case 7: SendKey(DINK_INPUT_LEFT, true); SendKey(DINK_INPUT_UP, true); break;
}
}
void DragControlComponent::OnArcadeInput(VariantList *pVList)
{
int vKey = pVList->Get(0).GetUINT32();
bool bIsDown = pVList->Get(1).GetUINT32() != 0;
//LogMsg("Key %d, down is %d", vKey, int(bIsDown));
switch (vKey)
{
case VIRTUAL_KEY_DIR_LEFT:
SendKey(DINK_INPUT_LEFT, bIsDown);
break;
case VIRTUAL_KEY_DIR_RIGHT:
SendKey(DINK_INPUT_RIGHT, bIsDown);
break;
case VIRTUAL_KEY_DIR_UP:
SendKey(DINK_INPUT_UP, bIsDown);
break;
case VIRTUAL_KEY_DIR_DOWN:
SendKey(DINK_INPUT_DOWN, bIsDown);
break;
}
}
void DragControlComponent::OnUpdate(VariantList *pVList)
{
ProcessLastJoystickReading();
}

View file

@ -0,0 +1,77 @@
// ***************************************************************
// DragControlComponent - Creation date: 4/27/2010
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef DragControlComponent_h__
#define DragControlComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
class DragUnit
{
public:
DragUnit(CL_Vec2f vPos, unsigned int time)
{
m_vPos = vPos;
m_timeMade = time;
}
CL_Vec2f m_vPos;
unsigned int m_timeMade; //in game ticks
};
class DragControlComponent: public EntityComponent
{
public:
DragControlComponent();
virtual ~DragControlComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnStripUpdate(VariantList *pVList);
void SendKey(eDinkInput key, bool bIsDown);
void OnOverStart(VariantList *pVList);
void OnOverEnd(VariantList *pVList);
void OnOverMove(VariantList *pVList);
void ClearKeyInput();
void ProcessLastJoystickReading();
void ProcessArrowInput(CL_Vec2f vDir);
void OnKillingControls(VariantList *pVList);
void AddSample(DragUnit v);
void OnArcadeInput(VariantList *pVList);
CL_Vec2f *m_pPos2d;
CL_Vec2f *m_pSize2d;
/*
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
float *m_pAlpha;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
CL_Vec2f m_lastTouch;
unsigned int m_timeOfLastTouch;
std::deque< DragUnit> m_samples;
float SAMPLE_COUNT;
float LENGTH_REQUIRED_FOR_MOVE;
};
#endif // DragControlComponent_h__

View file

@ -0,0 +1,271 @@
#include "PlatformPrecomp.h"
#include "FPSControlComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
#include "GUI/GameMenu.h"
#define C_GUI_FADE_OUT_TIMER 400
#define C_GUI_FADE_IN_TIMER 150
FPSControlComponent::FPSControlComponent()
{
SetName("FPSControl");
}
FPSControlComponent::~FPSControlComponent()
{
}
void FPSControlComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pArrowEnt = NULL;
m_pCenterBall = NULL;
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
m_lastTouchDir = CL_Vec2f(0, 0); //the middle
m_bTouchingArrows = false;
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnUpdate, this, _1));
float guiTrans = GetApp()->GetVar("gui_transparency")->GetFloat();
GetApp()->GetVar("gui_transparency")->Set(guiTrans);
GetBaseApp()->m_sig_arcade_input.connect(1, boost::bind(&FPSControlComponent::OnArcadeInput, this, _1));
m_arrowMinTransparency = guiTrans;
m_arrowMaxTransparency = rt_max(0.5f, guiTrans);
//movement arrows?
if (GetApp()->GetUsingTouchScreen())
{
m_pArrowEnt = CreateOverlayEntity(GetParent(), "arrow_gui", ReplaceWithDeviceNameInFileName("interface/iphone/arrows.rttex"), 0, 0);
EntityComponent *pStripComp = m_pArrowEnt->AddComponent(new TouchStripComponent);
m_pArrowEnt->GetVarWithDefault(string("touchPadding"), Variant(CL_Rectf(100, 100, 100, 100)))->GetRect();
//m_pArrowEnt->AddComponent(new TouchHandlerComponent);
//for speed, we've disabled movement message handling in App.cpp, but we actually want them just here, so we'll hardwire it
AddInputMovementFocusIfNeeded(m_pArrowEnt);
m_pArrowEnt->GetFunction("OnTouchStripUpdate")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnStripUpdate, this, _1));
m_pArrowEnt->GetFunction("OnOverStart")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnOverStart, this, _1));
m_pArrowEnt->GetFunction("OnOverEnd")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnOverEnd, this, _1));
GetParent()->GetParent()->GetFunction("OnKillingControls")->sig_function.connect(1, boost::bind(&FPSControlComponent::OnKillingControls, this, _1));
SetAlphaEntity(m_pArrowEnt, 0);
FadeEntity(m_pArrowEnt, true, m_arrowMinTransparency, 300, 0);
//limit it to touches only on the left side of the screen
//m_pCenterBall = CreateOverlayEntity(m_pArrowEnt, "center_ball", "interface/center_ball.rttex",0,0);
if (m_pCenterBall)
{
m_pCenterBall->GetVar("color")->Set(MAKE_RGBA(255,255,255,0));
//SetAlphaEntity(m_pCenterBall, 0);
SetAlignmentEntity(m_pCenterBall, ALIGNMENT_CENTER);
}
m_timeOfLastTouch = GetTick(TIMER_SYSTEM);
SetAlignmentEntity(m_pArrowEnt, ALIGNMENT_CENTER);
CL_Vec2f vArrowPos = FlipXIfNeeded(iPhoneMap(CL_Vec2f(80, 240)));
if (IsIPAD())
{
if (IsInFlingMode())
{
vArrowPos = CL_Vec2f( FlipXIfNeeded(149-30), C_FLING_JOYSTICK_Y);
} else
{
vArrowPos = FlipXIfNeeded(CL_Vec2f(137-20, 651-80));
}
}
m_pArrowEnt->GetVar("pos2d")->Set(vArrowPos);
m_vArrowImageSizeOver2 = m_pArrowEnt->GetVar("size2d")->GetVector2()/2;
VariantList vList;
OnOverEnd(&vList);
}
}
void FPSControlComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void SendKey(eDinkInput key, bool bIsDown)
{
if (bIsDown)
{
g_dglo.m_dirInput[key] = true;
g_dglo.m_dirInputFinished[key] = false; //make sure it wasn't scheduled to stop pressing
} else
{
g_dglo.m_dirInputFinished[key] = true;
}
}
void FPSControlComponent::ProcessLastJoystickReading()
{
CL_Vec2f vDir = m_lastTouchDir;
vDir.normalize();
if (m_pCenterBall)
m_pCenterBall->GetVar("pos2d")->Set(m_vArrowImageSizeOver2+vDir* (rt_min(m_lastTouchDir.length(), 1) * 58));
float deadSpace = 0.25f/2;
if (IsInFlingMode())
{
deadSpace *= 1.4f;
} else
{
if (IsIPADSize) deadSpace *= 2;
}
if (m_lastTouchDir.length() < deadSpace)
{
//dead space
if (m_pCenterBall)
{
m_pCenterBall->GetVar("pos2d")->Set(m_vArrowImageSizeOver2);
}
return;
}
//convert to 360 degrees
int dir = (int(RAD2DEG(atan2(m_lastTouchDir.y, m_lastTouchDir.x))+(90)));
const int maxDirections = 8;
int finaldir = mod(dir+ (360/ (maxDirections*2)), 360)/ (360/maxDirections);
//nah, let's do 8 actually
//LogMsg("Pressing %s, which is dir %d (final: %d)", PrintVector2(m_lastTouchDir).c_str(), dir, finaldir);
switch (finaldir)
{
case 0: SendKey(DINK_INPUT_UP, true); break;
case 1: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_UP, true); break;
case 2: SendKey(DINK_INPUT_RIGHT, true); break;
case 3: SendKey(DINK_INPUT_RIGHT, true); SendKey(DINK_INPUT_DOWN, true); break;
case 4: SendKey(DINK_INPUT_DOWN, true); break;
case 5: SendKey(DINK_INPUT_DOWN, true); SendKey(DINK_INPUT_LEFT, true); break;
case 6: SendKey(DINK_INPUT_LEFT, true); break;
case 7: SendKey(DINK_INPUT_LEFT, true); SendKey(DINK_INPUT_UP, true); break;
}
}
void FPSControlComponent::OnKillingControls(VariantList *pVList)
{
RemoveFocusIfNeeded(m_pArrowEnt);
}
void FPSControlComponent::OnArcadeInput(VariantList *pVList)
{
int vKey = pVList->Get(0).GetUINT32();
bool bIsDown = pVList->Get(1).GetUINT32() != 0;
//LogMsg("Key %d, down is %d", vKey, int(bIsDown));
switch (vKey)
{
case VIRTUAL_KEY_DIR_LEFT:
SendKey(DINK_INPUT_LEFT, bIsDown);
break;
case VIRTUAL_KEY_DIR_RIGHT:
SendKey(DINK_INPUT_RIGHT, bIsDown);
break;
case VIRTUAL_KEY_DIR_UP:
SendKey(DINK_INPUT_UP, bIsDown);
break;
case VIRTUAL_KEY_DIR_DOWN:
SendKey(DINK_INPUT_DOWN, bIsDown);
break;
}
}
void FPSControlComponent::OnOverStart(VariantList *pVList)
{
}
void FPSControlComponent::OnOverEnd(VariantList *pVList)
{
m_bTouchingArrows = false;
ClearKeyInput();
if (m_pCenterBall)
m_pCenterBall->GetVar("color")->Set(MAKE_RGBA(255,255,255,0));
//m_pArrowEnt->GetVar("alpha")->Set(1.0f);
FadeEntity(m_pArrowEnt, false, m_arrowMinTransparency, C_GUI_FADE_OUT_TIMER);
if (m_pCenterBall)
FadeEntity(m_pCenterBall, false, 0.0, C_GUI_FADE_OUT_TIMER/3);
}
void FPSControlComponent::ClearKeyInput()
{
SendKey(DINK_INPUT_UP, false);
SendKey(DINK_INPUT_DOWN, false);
SendKey(DINK_INPUT_LEFT, false);
SendKey(DINK_INPUT_RIGHT, false);
}
void FPSControlComponent::ProcessArrowInput(CL_Vec2f vDir)
{
if (m_bTouchingArrows || 1)
{
m_lastTouchDir = vDir*2 - CL_Vec2f(1, 1);
//update current position
ClearKeyInput();
ProcessLastJoystickReading();
} else
{
// m_lastTouchDir = CL_Vec2f(0,0);
if (m_pCenterBall)
m_pCenterBall->GetVar("pos2d")->Set(m_lastTouchDir);
}
}
void FPSControlComponent::OnStripUpdate(VariantList *pVList)
{
if (!m_bTouchingArrows)
{
m_bTouchingArrows = true;
//m_pArrowEnt->GetVar("pos2d")->Set( ConvertEntityClickToScreenCoords(pVList->Get(0).GetVector2(), pVList->Get(1).GetEntity()));
//ProcessArrowInput(pVList->Get(1).GetVector2());
if (m_pCenterBall)
m_pCenterBall->GetVar("color")->Set(MAKE_RGBA(255,255,255,255));
FadeEntity(m_pArrowEnt, false, m_arrowMaxTransparency, C_GUI_FADE_IN_TIMER);
if (m_pCenterBall)
FadeEntity(m_pCenterBall, false, m_arrowMaxTransparency, C_GUI_FADE_OUT_TIMER/3);
}
ProcessArrowInput(pVList->Get(1).GetVector2());
}
void FPSControlComponent::OnRender(VariantList *pVList)
{
CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void FPSControlComponent::OnUpdate(VariantList *pVList)
{
}

View file

@ -0,0 +1,65 @@
// ***************************************************************
// FPSControlComponent - Creation date: ?/?/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef FPSControlComponent_h__
#define FPSControlComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
#define C_FLING_JOYSTICK_Y (520+50)
class FPSControlComponent: public EntityComponent
{
public:
FPSControlComponent();
virtual ~FPSControlComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnStripUpdate(VariantList *pVList);
void OnOverStart(VariantList *pVList);
void OnOverEnd(VariantList *pVList);
void ClearKeyInput();
void ProcessLastJoystickReading();
void ProcessArrowInput(CL_Vec2f vDir);
void OnKillingControls(VariantList *pVList);
void OnArcadeInput(VariantList *pVList);
CL_Vec2f *m_pPos2d;
/*
CL_Vec2f *m_pSize2d;
float *m_pScale;
uint32 *m_pColor;
uint32 *m_pColorMod;
float *m_pAlpha;
uint32 *m_pAlignment;
float *m_pRotation; //in degrees
*/
Entity *m_pArrowEnt;
Entity *m_pCenterBall; //will be a child of the arrowEnt
CL_Vec2f m_lastTouchDir;
unsigned int m_timeOfLastTouch;
bool m_bTouchingArrows;
CL_Vec2f m_vArrowImageSizeOver2;
float m_arrowMinTransparency;
float m_arrowMaxTransparency;
};
void SendKey(eDinkInput key, bool bIsDown);
#endif // FPSControlComponent_h__

View file

@ -0,0 +1,112 @@
#include "PlatformPrecomp.h"
#include "InventoryComponent.h"
#include "util/GLESUtils.h"
#include "Entity/EntityUtils.h"
#include "BaseApp.h"
InventoryComponent::InventoryComponent()
{
m_activeFinger = -1;
SetName("Inventory");
}
InventoryComponent::~InventoryComponent()
{
}
void InventoryComponent::OnAdd(Entity *pEnt)
{
EntityComponent::OnAdd(pEnt);
m_pArrowEnt = NULL;
m_bGotFirstClick = false;
m_pPos2d = &GetParent()->GetVar("pos2d")->GetVector2();
//register ourselves to render if the parent does
GetParent()->GetFunction("OnRender")->sig_function.connect(1, boost::bind(&InventoryComponent::OnRender, this, _1));
GetParent()->GetFunction("OnUpdate")->sig_function.connect(1, boost::bind(&InventoryComponent::OnUpdate, this, _1));
AddInputMovementFocusIfNeeded(GetParent());
GetParent()->GetFunction("OnInput")->sig_function.connect(1, boost::bind(&InventoryComponent::OnInput, this, _1));
}
void InventoryComponent::OnRemove()
{
EntityComponent::OnRemove();
}
void InventoryComponent::OnUpdatePos(CL_Vec2f vPos)
{
//LogMsg("Got %s", PrintVector2(vPos).c_str());
DinkSetInventoryPosition(NativeToDinkCoords(vPos));
}
void InventoryComponent::OnRender(VariantList *pVList)
{
//CL_Vec2f vFinalPos = pVList->m_variant[0].GetVector2()+*m_pPos2d;
}
void InventoryComponent::OnUpdate(VariantList *pVList)
{
}
void InventoryComponent::OnInput( VariantList *pVList )
{
//0 = message type, 1 = parent coordinate offset
CL_Vec2f pt = pVList->Get(1).GetVector2();
//pt += GetAlignmentOffset(*m_pSize2d, eAlignment(*m_pAlignment));
switch (eMessageType( int(pVList->Get(0).GetFloat())))
{
case MESSAGE_TYPE_GUI_CLICK_START:
{
uint32 fingerID = pVList->Get(2).GetUINT32();
TouchTrackInfo *pTouch = GetBaseApp()->GetTouch(fingerID);
if (pTouch->WasHandled()) return;
pTouch->SetWasHandled(true);
m_activeFinger = fingerID;
}
OnUpdatePos(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_END:
{
uint32 fingerID = pVList->Get(2).GetUINT32();
if (fingerID == m_activeFinger)
{
OnUpdatePos(pt);
/*
if (!m_bGotFirstClick)
{
//ignore this, they are just releasing from the previous menu's button
m_bGotFirstClick = true;
} else
{
*/
if (DinkSetInventoryPosition(NativeToDinkCoords(pt)))
{
g_dglo.m_dirInput[DINK_INPUT_BUTTON1] = true;
g_dglo.m_dirInputFinished[DINK_INPUT_BUTTON1] = true;
}
}
}
//HandleClickEnd(pt);
break;
case MESSAGE_TYPE_GUI_CLICK_MOVE:
{
uint32 fingerID = pVList->Get(2).GetUINT32();
if (fingerID == m_activeFinger) OnUpdatePos(pt);
}
break;
}
}

View file

@ -0,0 +1,42 @@
// ***************************************************************
// InventoryComponent - Creation date: ?/?/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef InventoryComponent_h__
#define InventoryComponent_h__
#include "Entity/Component.h"
#include "Entity/Entity.h"
#include "../dink/dink.h"
class InventoryComponent: public EntityComponent
{
public:
InventoryComponent();
virtual ~InventoryComponent();
virtual void OnAdd(Entity *pEnt);
virtual void OnRemove();
private:
void OnRender(VariantList *pVList);
void OnUpdate(VariantList *pVList);
void OnInput( VariantList *pVList );
void OnUpdatePos(CL_Vec2f vPos);
CL_Vec2f *m_pPos2d;
int m_activeFinger;
Entity *m_pArrowEnt;
bool m_bGotFirstClick;
};
#endif // InventoryComponent_h__

553
source/GUI/AboutMenu.cpp Normal file
View file

@ -0,0 +1,553 @@
#include "PlatformPrecomp.h"
#include "AboutMenu.h"
#include "MainMenu.h"
#include "Entity/EntityUtils.h"
#include "PopUpMenu.h"
void AboutMenuAddScrollContent(Entity *pParent);
void AboutMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
Entity *pMenu = GetEntityRoot()->GetEntityByName("AboutMenu");
//LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[0].Print().c_str());
if (pEntClicked->GetName() == "Back")
{
DisableAllButtonsEntity(pEntClicked->GetParent());
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
MainMenuCreate(pEntClicked->GetParent()->GetParent());
return;
}
if (pEntClicked->GetName() == "mindwall_ad")
{
string url = "http://www.codedojo.com/?p=138";
if (GetEmulatedPlatformID() == PLATFORM_ID_ANDROID)
{
url = "market://details?id=com.rtsoft.rtmindwall";
} else if (GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
url = "http://www.rtsoft.com/mindwall/purchase.php";
}
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to check out `wMind Wall?``", url,
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "dink_ad")
{
string url = "http://www.rtsoft.com/pages/dink.php";
switch (GetEmulatedPlatformID())
{
case PLATFORM_ID_WEBOS:
// url = "http://www.rtsoft.com/mindwall/purchase_webos.php";
break;
case PLATFORM_ID_IOS:
break;
case PLATFORM_ID_OSX:
url = "http://itunes.apple.com/us/app/dink-smallwood-hd/id391690243?mt=8";
break;
case PLATFORM_ID_ANDROID:
url = "market://details?id=com.rtsoft.rtdink";
break;
}
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Leave the game and check out Dink Smallwood HD?", url,
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "fling_ad")
{
string url = "http://tenonedesign.com/fling";
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to visit Ten One Design's webpage and learn more about the `wFling``?", url,
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "ds_ad")
{
string url = "http://www.rtsoft.com/pages/dscroll.php";
if (GetEmulatedPlatformID() == PLATFORM_ID_ANDROID)
{
url = "market://details?id=com.rtsoft.rtdscroll";
} else if (GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
url = "http://www.rtsoft.com/dscroll_iphone/purchase.php";
}
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to check out `wDungeon Scroll``?", url,
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "dinknetwork")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to check out `wThe Dink Network``?", "http://www.dinknetwork.com?device="+toString(GetEmulatedPlatformID()),
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "email")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to email `wsupport@rtsoft.com now``?", "mailto:support@rtsoft.com",
"cancel", "`wCancel", "url", "`wEmail", true);
return;
}
if (pEntClicked->GetName() == "twitter")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "View the `wRTsoft twitter page``?", "http://twitter.com/rtsoft",
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "list")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to enter your email to subscribe to the `wRTsoft Newsletter``?", "http://www.rtsoft.com/lists/?p=subscribe",
"cancel", "`wCancel", "url", "`wOh yeah!", true);
return;
}
if (pEntClicked->GetName() == "forums")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to visit the `wRTsoft Dink Forums``?", "http://www.rtsoft.com/forums/forumdisplay.php?6-Dink-Smallwood",
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
/*
if (pEntClicked->GetName() == "rtsoft")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Leave the game and visit `wrtsoft.com``?", "http://www.rtsoft.com/iphone",
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
*/
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
void AddBlurb(Entity* pParent, float x, float y, string fileName, string msg)
{
Entity * pLogo = CreateOverlayButtonEntity(pParent, fileName, string("interface/")+fileName+".rttex", x, y);
EntityRetinaRemapIfNeeded(pLogo, false, false, true);
pLogo->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
CL_Vec2f imageSize = pLogo->GetVar("size2d")->GetVector2();
float imagePaddingX = iPhoneMapX(20);
CL_Vec2f vTextBoxPos(iPhoneMapX(x)+imageSize.x+imagePaddingX,y);
CL_Vec2f vTextBounds(iPhoneMapX(400)-imageSize.x+imagePaddingX , iPhoneMapY(200));
Entity *pEnt = CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, msg);
}
void AboutMenuAddScrollContent(Entity *pParent)
{
pParent = pParent->GetEntityByName("scroll_child");
pParent->RemoveAllEntities();
float x = 5;
float y = 0;
float ySpacer = iPhoneMapY(27);
Entity *pTitle = CreateTextLabelEntity(pParent, "Title", x, 0, "About & Help");
SetupTextEntity(pTitle, FONT_LARGE);
y += iPhoneMapY(30);
float blurbSpacingY = iPhoneMapX(27);
if (IsIPAD())
{
AddBlurb(pParent, x, y, "fling_ad", "`6This game is compatible with the `wFling analog joystick``. Tap the Fling logo to visit Ten One Design to learn more.");
y += iPhoneMapY(blurbSpacingY);
//y += ySpacer;
}
CL_Vec2f vTextBoxPos(iPhoneMapX(x),y);
CL_Vec2f vTextBounds(iPhoneMapX(434), iPhoneMapY(200));
string msg =
GetAppName()+string("`$ ")+GetApp()->GetVersionString()+" Build "+toString(GetApp()->GetBuild())+"``\nCopyright (c) 2012 Robinson Technologies\n"\
"\nDink Script Version: `$1.10``\n\n"\
;
if (IsDesktop())
{
msg += \
"Keyboard controls:\n\n"\
"Esc ``-`8 Bring up the game menu/pause``\n"\
"Arrow keys ``-`8 Movement/menu selections``\n"\
"Ctrl ``- `8Attack\n``"\
"Shift ``- `8Magic\n``"\
"Enter ``- `8Inventory screen/Inventory select\n``"\
"M ``- `8Show map\n\n``"\
"TAB ``- `8Speed up game (hold it down)\n``"\
"F1 ``- `8Quick state save\n``"\
"F8 ``- `8Quick state load\n``"\
"Alt-Enter ``- `8Toggle fullscreen\n``"\
"Drag window corners ``- `8Changes screensize. Hold Shift to allow any aspect ratio\n``"\
"\n`6Stuck? Try visiting `wdinknetwork.com`` or use google to find a walkthrough.\n"\
"\n`wFPS Lock``: If enabled, the game is limited to 30 frames per second. This should be enabled on most devices for more consistent gameplay.\n"\
"\n`wPushing:`` If you make Dink walk against an object for one second, he will begin to push it. Useful when you see rocks blocking cave entrances.\n"\
"\n`wTrees:`` Some trees can be burned down with magic to reveal secrets.\n"\
"\n`wSave Machines:`` Use Save Machines frequently and don't only rely on quick saves as they may sometimes put you in a difficult spot.\n"\
"\n`wAuto Save:`` Your game is automatically saved every five minutes to save slot 10 as long as you have more than 30% health.\n"\
"\n`wQuick save/load:`` In addition to the full auto state save whenever you exit the game, and the normal save system, you can use `wQuick Save/Load`` from the pause menu. It's very useful to beat a tough boss. Each add-on you install will also remember its own unique save states as well.\n"\
"\n`wTo use an existing DMOD directory:`` Start the game with a command line parm of `w-dmodpath <dmod dir path>`` to use it instead of the default dmod directory.\n"\
"";
} else if (GetEmulatedPlatformID() == PLATFORM_ID_ANDROID)
{
//android
msg += \
"`6Thanks for buying `wDink Smallwood HD`` for Android. Here are some tips and info to get started.\n"\
"\n`wControl mode - Virtual Joypad:`` This is the default control method, simple to use.\n"\
"\n`wControl mode - Drag Anywhere:`` This control scheme allows you to draw an angle with your finger and dink will walk in that angle. It doesn't matter where you draw it on the screen. As long as you don't let your finger up, he'll keep moving.\n"\
"\n`wTrackball:`` You can also use the trackball to move. You may wish to reverse the action icon positions from the Option menu.\n"\
"\n`wiCade:`` Pair the iCade with your device, then start the game. Choose `$Use iCade Controller Mode`` from the options menu.\n"\
"\n`wXperia Play:`` Explode the pay and play, no special setup required. Note that the shoulder buttons map to the map and speed-up.\n"\
"\n`wHW Keyboard:`` If your device has a hardware keyboard, you can use WASZ to move, I for inventory, shift for punch, enter/menu for magic, space to talk.\n"\
"\n`wPushing:`` If you make Dink walk against an object for one second, he will begin to push it. Useful when you see rocks blocking cave entrances.\n"\
"\n`wTrees:`` Some trees can be burned down with magic to reveal secrets.\n"\
"\n`wQuick save/load:`` In addition to the full auto state save whenever you exit the game, and the normal save system, you can use `wQuick Save/Load`` from the pause menu. It's very useful to beat a tough boss.\n"\
"\n`wSave Machines:`` Use Save Machines frequently and don't only rely on quick saves as they may sometimes put you in a difficult spot.\n"\
"\n`wAuto Save:`` Your game is automatically saved every five minutes to save slot 10 as long as you have more than 30% health.\n"\
"\n`wFPS Lock:`` If enabled, the game is limited to 30 frames per second. This should be enabled on slower devices for smoother gameplay.\n"\
"\n`wInstalling DMODS by Browse:`` Click Browse from the Add-On menu to see a selection of recommended DMODs to install.\n"\
"\n`wInstalling DMODS from URL:`` Click Install from URL from the Add-On menu.\n"\
"\n`wInstalling DMODS from SD card:`` Place a .dmod file on your SD card in `w/Android/data/com.rtsoft.dink/files`` and it will be installed the next time you play.\n"\
"\n`wIf the game is slow:`` Try turning Pic Smoothing to off in the options menu.\n"\
"\n`wMulti-touch:`` Multi touch is supported when possible. Please note that many HTC phones such as the Nexus One only partially support multi-touch resulting in strange behavior when two fingers are on the screen.\n"\
;
} else if ( GetEmulatedPlatformID() == PLATFORM_ID_WEBOS || GetEmulatedPlatformID() == PLATFORM_ID_BBX)
{
//android
msg += \
"`6Thanks for buying `wDink Smallwood HD``. Here are some tips and info to get started.\n"\
"\n`wControl mode - Virtual Joypad:`` This is the default control method, simple to use.\n"\
"\n`wControl mode - Drag Anywhere:`` This control scheme allows you to draw an angle with your finger and dink will walk in that angle. It doesn't matter where you draw it on the screen. As long as you don't let your finger up, he'll keep moving.\n"\
"\n`wPushing:`` If you make Dink walk against an object for one second, he will begin to push it. Useful when you see rocks blocking cave entrances.\n"\
"\n`wTrees:`` Some trees can be burned down with magic to reveal secrets.\n"\
"\n`wQuick save/load:`` In addition to the full auto state save whenever you exit the game, and the normal save system, you can use `wQuick Save/Load`` from the pause menu. It's very useful to beat a tough boss.\n"\
"\n`wSave Machines:`` Use Save Machines frequently and don't only rely on quick saves as they may sometimes put you in a difficult spot.\n"\
"\n`wAuto Save:`` Your game is automatically saved every five minutes to save slot 10 as long as you have more than 30% health.\n"\
"\n`wFPS Lock:`` If enabled, the game is limited to 30 frames per second. This should be enabled on slower devices for smoother gameplay.\n"\
"\n`wInstalling DMODS by Browse:`` Click Browse from the Add-On menu to see a selection of recommended DMODs to install.\n"\
"\n`wInstalling DMODS from URL:`` Click Install from URL from the Add-On menu.\n"\
"\n`wIf the game is slow:`` Try turning Pic Smoothing to off in the options menu.\n"\
;
} else
{
if (IsIPADSize)
{
//iphone
msg += \
"`6Thanks for buying `wDink Smallwood HD`` for iPhone, iPod Touch, and iPad. Here are some tips and info to get started.\n"\
"\n`wControls - Virtual Joypad:`` This is the default control method, simple to use.\n"\
"\n`wControls - Drag Anywhere:`` This control scheme allows you to draw an angle with your finger and dink will walk in that angle. It doesn't matter where you draw it on the screen. As long as you don't let your finger up, he'll keep moving.\n"\
"\n`wControls - Fling Mode:`` This control scheme is optimized for the Fling analog joystick for iPad from Ten One Design.\n"\
"\n`wPushing:`` If you make Dink walk against an object for one second, he will begin to push it. Useful when you see rocks blocking cave entrances.\n"\
"\n`wTrees:`` Some trees can be burned down with magic to reveal secrets.\n"\
"\n`wQuick save/load:`` In addition to the full auto state save whenever you exit the game, and the normal save system, you can use `wQuick Save/Load`` from the pause menu. It's very useful to beat a tough boss.\n"\
"\n`wSave Machines:`` Use Save Machines frequently and don't only rely on quick saves as they may sometimes put you in a difficult spot.\n"\
"\n`wAuto Save:`` Your game is automatically saved every five minutes to save slot 10 as long as you have more than 30% health.\n"\
"\n`wFPS Lock:`` If enabled, the game is limited to 30 frames per second. This should be enabled on slower devices for smoother gameplay.\n"\
"\n`wHow to import saves from desktop (iOS 3.2+):`` Drag and drop a save<num>.dat file in the Dink HD Documents file sharing area in iTunes. Import happens when the main menu is visited. Use save<num>_<dmod dir name>.dat to import a save to an installed DMOD.\n"\
;
} else
{
msg += \
"`6Thanks for buying `wDink Smallwood HD`` for iPhone, iPod Touch, and iPad. Here are some tips and info to get started.\n"\
"\n`wControls - Virtual Joypad:`` This is the default control method, simple to use.\n"\
"\n`wControls - Drag Anywhere:`` This control scheme allows you to draw an angle with your finger and dink will walk in that angle. It doesn't matter where you draw it on the screen. As long as you don't let your finger up, he'll keep moving.\n"\
"\n`wPushing:`` If you make Dink walk against an object for one second, he will begin to push it. Useful when you see rocks blocking cave entrances.\n"\
"\n`wTrees:`` Some trees can be burned down with magic to reveal secrets.\n"\
"\n`wQuick save/load:`` In addition to the full auto state save whenever you exit the game, and the normal save system, you can use `wQuick Save/Load`` from the pause menu. It's very useful to beat a tough boss.\n"\
"\n`wSave Machines:`` Use Save Machines frequently and don't only rely on quick saves as they may sometimes put you in a difficult spot.\n"\
"\n`wAuto Save:`` Your game is automatically saved every five minutes to save slot 10 as long as you have more than 30% health.\n"\
"\n`wFPS Lock:`` If enabled, the game is limited to 30 frames per second. This should be enabled on slower devices for smoother gameplay.\n"\
"\n`wHow to import saves from desktop (iOS 3.2+):`` Drag and drop a save<num>.dat file in the Dink HD Documents file sharing area in iTunes. Import happens when the main menu is visited. Use save<num>_<dmod dir name>.dat to import a save to an installed DMOD.\n"\
;
}
}
if (!IsDesktop())
{
msg += \
"\n`wAdd-on warning:`` Depending on your device's speed and memory not all quest add-ons may be smoothly playable.\n"\
"\n`wOutdated instructions warning:`` Sometimes quest add-ons will refer to controls not available, like pressing a specific key. Keep in mind most add-ons were developed for the Windows version of the game.\n"\
"\n`wKeyboard:`` You can work around these issues by using the in-game keyboard option, available from the pause menu.\n";
}
Entity *pEnt = CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, msg);
y += pEnt->GetVar("size2d")->GetVector2().y;
y += ySpacer;
//some special links:
Entity *pButton;
pButton = CreateTextButtonEntity(pParent, "email", iPhoneMapX(x), y, "Have a suggestion, bug report, or need help? Tap here to email us", true);
pButton->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
y += pButton->GetVar("size2d")->GetVector2().y;
y += ySpacer;
pButton = CreateTextButtonEntity(pParent, "list", iPhoneMapX(x), y, "Subscribe to the RTsoft Newsletter", true);
pButton->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
y += pButton->GetVar("size2d")->GetVector2().y;
y += ySpacer;
pButton = CreateTextButtonEntity(pParent, "twitter", iPhoneMapX(x), y, "Click here for the RTsoft twitter page", true);
pButton->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
y += pButton->GetVar("size2d")->GetVector2().y;
y += ySpacer;
pButton = CreateTextButtonEntity(pParent, "forums", iPhoneMapX(x), y, "Visit the official RTsoft Dink Forums", true);
pButton->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
y += pButton->GetVar("size2d")->GetVector2().y;
y += ySpacer;
if (GetApp()->CanDownloadDMODS())
{
pButton = CreateTextButtonEntity(pParent, "dinknetwork", iPhoneMapX(x), y, "Want to download/make DMODs? Tap here to visit the Dink Network", true);
pButton->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
y += pButton->GetVar("size2d")->GetVector2().y;
y += ySpacer;
}
"\nFound a bug or have a question? Email us at `wsupport@rtsoft.com``.\n"\
"\nCheck out our other wacky games:\n";
vTextBoxPos = CL_Vec2f(iPhoneMapX(x),y);
msg = "\nIf you like Dink, please check out our other games:\n";
pEnt = CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, msg);
y += pEnt->GetVar("size2d")->GetVector2().y;
y += ySpacer;
if (!IsLargeScreen())
{
blurbSpacingY = iPhoneMapX(95); //for whatever reason we need more on the small iphone screen
}
AddBlurb(pParent, x, y, "mindwall_ad", "`wMind Wall```8 is a unique 3D arcade puzzler that is instantly understood, beautifully simple to control, and diabolically difficult to master.");
y += iPhoneMapY(blurbSpacingY);
y += ySpacer;
AddBlurb(pParent, x, y, "ds_ad", "`wDungeon Scroll```8 - If a word game and a dungeon crawler had a baby, this would be it. Arrange tiles to create magic words and blast rats, spiders and skeletons. But beware, a great evil looms beneath the depths.");
y += iPhoneMapY(blurbSpacingY);
y += ySpacer;
if (IsDesktop())
{
string adText = "`wDink Smallwood HD for iOS```8 - Love Dink? Then get it on your iPhone and iPad!";
if (GetEmulatedPlatformID() == PLATFORM_ID_WINDOWS)
{
adText = "`wDink Smallwood HD for mobile```8 - Love Dink? Then get it for your iPhone, iPad, or Android device!";
}
AddBlurb(pParent, x, y, "dink_ad", adText);
y += iPhoneMapY(blurbSpacingY);
y += ySpacer;
}
//credits:
pTitle = CreateTextLabelEntity(pParent, "Title", x, y, "Credits");
SetupTextEntity(pTitle, FONT_LARGE);
y += pTitle->GetVar("size2d")->GetVector2().y;
y += ySpacer;
vTextBoxPos = CL_Vec2f(iPhoneMapX(x),y);
msg = "`8`$Dink Smallwood HD`` was created by `wSeth A. Robinson`` (code) and `wJustin Martin`` (graphics).\n\n"\
"`8The original `$Dink Smallwood`` was created by `wSeth A. Robinson`` (engine/scripting/music), `wJustin Martin`` (graphics), `wGreg Smith`` (scripting/music), and `wShawn Teal``. It also featured music by `wJoel Bakker``."\
"\n\nSpecial thanks to `wDan Walma`` and the `wdinksmallwood.net`` community for their `$Dink`` improvements."\
"\n\n"\
"This product is less buggy thanks to:\n\n`w"\
"Shawn Teal\n"\
"Myra Russell\n"\
"David Stathis\n"\
"Steve Gargolinski\n"\
"Linus Lindberg\n"\
"Phil Hassey\n"\
"Kyle/Ragura\n"\
"John H. Anthony\n"\
"L McMillan\n"\
"scratcher\n"\
"Skull\n"\
"Yeoldetoast\n"\
"metatarasal\n"\
"Sparrowhawk\n"\
"ToKu\n"\
"synbi\n"\
"Impact\n"\
"Andrew Perry\n"\
"Rob, Marcus, Davor\n"\
"Brett Profitt\n"\
"Chris Black\n"\
"Erik Harrison\n"\
"James Hutt\n";
if (GetEmulatedPlatformID() == PLATFORM_ID_WINDOWS || GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
msg += "`8\nFMOD Sound System, copyright (c) Firelight Technologies Pty, Ltd., 1994-2010.";
}
pEnt = CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, msg);
y += pEnt->GetVar("size2d")->GetVector2().y;
y += ySpacer;
//ads
/*
Entity *pLogo;
if (IsLargeScreen())
{
pLogo = CreateOverlayButtonEntity(pParent, "logo", "interface/logo_88_88.rttex", x, y);
} else
{
pLogo = CreateOverlayButtonEntity(pParent, "logo", "interface/rtsoft_logo.rttex", x, y);
}
pLogo->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
y += iPhoneMapY(86);
//add the dscroll ad
pLogo = CreateOverlayButtonEntity(pParent, "dscroll", "interface/ds_ad.rttex", x, y);
EntityRetinaRemapIfNeeded(pLogo, false, true, true);
pLogo->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
float textX = iPhoneMapX(170);
//some text to go with the ad
Entity * pTextEnt = CreateTextLabelEntity(pParent, "text", textX-20, y, "Do you like word games and\nkilling things? Then tap the\n"\
"icon on the left to check out\nDungeon Scroll for iPhone!");
SetupTextEntity(pTextEnt, FONT_SMALL, 0.8f);
y += iPhoneMapY(120);
//add the blip ad
pLogo = CreateOverlayButtonEntity(pParent, "blip", "interface/ba_ad.rttex", x, y);
EntityRetinaRemapIfNeeded(pLogo, false, true, true);
pLogo->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
//some text to go with the ad
pTextEnt = CreateTextLabelEntity(pParent, "text", textX-20, y, "Three player on one iPhone\nis now possible! Tap the icon\nto see Blip Arcade!");
SetupTextEntity(pTextEnt, FONT_SMALL, 0.8f);
y += iPhoneMapY(120);
*/
VariantList vList(pParent->GetParent());
ResizeScrollBounds(&vList);
}
Entity * AboutMenuCreate( Entity *pParentEnt)
{
Entity *pBG = NULL;
pBG = CreateOverlayEntity(pParentEnt, "AboutMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
pBG->SetName("AboutMenu");
AddFocusIfNeeded(pBG, true, 500);
pBG->AddComponent(new FocusRenderComponent);
//add the header
CL_Vec2f vTextAreaPos = iPhoneMap(2,10);
float offsetFromBottom = iPhoneMapY(42);
float offsetFromRight = iPhoneMapY(0);
CL_Vec2f vTextAreaBounds = (GetScreenSize()- CL_Vec2f(offsetFromRight,offsetFromBottom))-vTextAreaPos;
Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
pScroll->GetVar("pos2d")->Set(vTextAreaPos);
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);
EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position
//pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255));
Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
pScrollComp->GetVar("fingerTracking")->Set(uint32(1));
/*
//too slow/broken on Android, we'll do it another way
EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
*/
Entity *pOverlay = CreateOverlayEntity(pBG, "", ReplaceWithDeviceNameInFileName("interface/iphone/bg_stone_overlay.rttex"), 0, GetScreenSizeYf());
SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
AboutMenuAddScrollContent(pBG);
// ZoomFromPositionEntity(pBG, CL_Vec2f(0, -GetScreenSizeYf()), 500);
//the continue button
Entity *pEnt;
//pEnt = CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 320), MAKE_RGBA(0,0,0,100));
eFont fontID = FONT_SMALL;
pEnt = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(5), iPhoneMapY(BACK_BUTTON_Y), "Back", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&AboutMenuOnSelect);
SetupTextEntity(pEnt, fontID);
AddHotKeyToButton(pEnt, VIRTUAL_KEY_BACK);
SlideScreen(pBG, true, 500);
// pBG->GetFunction("OnPostIntroTransition")->sig_function.connect(&OnPostIntroTransition);
// GetMessageManager()->CallEntityFunction(pBG, 1000, "OnPostIntroTransition", &VariantList(pBG, string("")));
return pBG;
}

7
source/GUI/AboutMenu.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef AboutMenu_h__
#define AboutMenu_h__
#include "BaseApp.h"
Entity * AboutMenuCreate(Entity *pParentEnt);
#endif // AboutMenu_h__

369
source/GUI/BrowseMenu.cpp Normal file
View file

@ -0,0 +1,369 @@
#include "PlatformPrecomp.h"
#include "BrowseMenu.h"
#include "MainMenu.h"
#include "DMODInstallMenu.h"
#include "GameMenu.h"
#include "Entity/EntityUtils.h"
#include "dink/dink.h"
#include "PopUpMenu.h"
#include "util/TextScanner.h"
#include "EnterURLMenu.h"
#include "Renderer/SoftSurface.h"
#include "QuickTipMenu.h"
#include "DMODMenu.h"
#include "Network/NetHTTP.h"
#include "Entity/HTTPComponent.h"
struct DMODEntry
{
string m_name;
string m_url;
string m_author;
float m_size;
float m_rating;
string m_description;
uint32 m_date;
float m_version;
};
void BrowseMenuAddScrollContent(Entity *pParent, TextScanner &t);
Entity * ShowScoreMessage(Entity *pMenu, string msg);
void BrowseMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
Entity *pMenu = GetEntityRoot()->GetEntityByName("BrowseMenu");
//LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[0].Print().c_str());
if (pEntClicked->GetName() == "Back")
{
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
DMODMenuCreate(pEntClicked->GetParent()->GetParent(), true);
return;
}
//they must have clicked on a DMOD if they got this far
if (pEntClicked->GetName() == "install")
{
//save position of the scroll bar first
EntityComponent *pScrollerComp = pMenu->GetEntityByName("scroll")->GetComponentByName("Scroll");
//GetApp()->GetVar("DMODProgress2d")->Set(pScrollerComp->GetVar("progress2d")->GetVector2());
string dmodurl = pEntClicked->GetParent()->GetVar("dmodurl")->GetString();
string dmodName = pEntClicked->GetParent()->GetVar("dmodtitle")->GetString();
SendFakeInputMessageToEntity(GetEntityRoot(), MESSAGE_TYPE_GUI_CLICK_END, pVList->m_variant[0].GetVector2()); //otherwise the menu may never get the touch release message
DisableAllButtonsEntity(pMenu);
SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
DMODInstallMenuCreate(pEntClicked->GetParent()->GetParent()->GetParent()->GetParent()->GetParent(), dmodurl, GetDMODRootPath() , "", true, dmodName);
}
/*
if (pEntClicked->GetName() == "rtsoft")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Leave the game and visit `wrtsoft.com``?", "http://www.rtsoft.com/iphone",
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
*/
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
string VersionToString(float v)
{
char tmp[32];
sprintf(tmp, "%.2f", v);
if (tmp[3] == '0')
{
//cut off this, not needed
tmp[3] = 0;
}
return string(tmp);
}
void AddEntryBar(Entity *pParent, float &x, float &y, DMODEntry &s, int count)
{
Entity *pBG = CreateOverlayEntity(pParent, s.m_name, ReplaceWithLargeInFileName("interface/iphone/browse_dmod_bar.rttex"),x, y);
y += pBG->GetVar("size2d")->GetVector2().y;
pBG->GetVar("dmodurl")->Set(s.m_url); //save for later
pBG->GetVar("dmodtitle")->Set(s.m_name); //save for later
//title
char stTemp[512];
sprintf(stTemp, "`6%s ``V%s`6%s - ``%.2f mb``", s.m_name.c_str(), VersionToString(s.m_version).c_str(), s.m_author.c_str(), s.m_size);
Entity *pTitle = CreateTextLabelEntity(pBG, "title", iPhoneMapX2X( 16) ,iPhoneMapY2X( 13), stTemp);
Entity *pDescription = CreateTextBoxEntity(pBG, "descrip", iPhoneMap2X(16, 34), iPhoneMap2X(425, 54), "`6"+s.m_description);
//Entity *pIcon = CreateButtonHotspot(pBG, "icon_hotspot", GetDMODBarIconOffset(), GetDMODBarIconSize(), Button2DComponent::BUTTON_STYLE_CLICK_ON_TOUCH_IGNORE_DRAGGING);
//SetTouchPaddingEntity(pIcon, CL_Rectf(0,iPhoneMapY2X(5),0,iPhoneMapY2X(5)));
//pIcon->GetFunction("OnButtonSelected")->sig_function.connect(&BrowseMenuOnSelect);
//processing the icon image might be slow, lets do it a bit later, sequencing the timing by using the y, which should be going up
//the delete icon part
{
CL_Vec2f iconPos = iPhoneMap2X(379,10);
//CL_Vec2f iconSize = iPhoneMap2X(27, 27);
Entity *pIcon = CreateOverlayButtonEntity(pBG, "install", ReplaceWithLargeInFileName("interface/iphone/browse_install.rttex"), iconPos.x, iconPos.y);
SetButtonStyleEntity(pIcon, Button2DComponent::BUTTON_STYLE_CLICK_ON_TOUCH_IGNORE_DRAGGING);
SetTouchPaddingEntity(pIcon, CL_Rectf(0,0,0,0));
pIcon->GetFunction("OnButtonSelected")->sig_function.connect(&BrowseMenuOnSelect);
}
//add animation effect
ZoomToPositionFromThisOffsetEntity(pBG, CL_Vec2f(GetScreenSizeXf(), 0), 500, INTERPOLATE_EASE_TO, 10);
}
void BrowseMenuAddScrollContent(Entity *pParent, TextScanner &t)
{
pParent = pParent->GetEntityByName("scroll_child");
pParent->RemoveAllEntities();
float x = iPhoneMapX(5);
float y = 0;
//Entity *pEnt;
int dmodsAdded = 0;
string msg = t.GetMultipleLineStrings("msg", "|");
vector<string> p = StringTokenize(msg, "|");
if (p.size() == 2 && p[1].length() > 1)
{
StringReplace("<cr>", "\n", p[1]);
//add a message we just downloaded
CL_Vec2f vTextBoxPos(x+iPhoneMapX(5),y);
CL_Vec2f vTextBounds(iPhoneMapX(434), iPhoneMapY(200));
Entity *pEnt = CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, p[1]);
y += pEnt->GetVar("size2d")->GetVector2().y;
y += iPhoneMapY(5);
}
string line;
while ( string(line = t.GetMultipleLineStrings("add", "|")).length() > 0)
{
//LogMsg(line.c_str());
vector<string> p = StringTokenize(line, "|");
if (p.size() < 7)
{
continue;
}
DMODEntry s;
s.m_name = p[1];
s.m_url = p[2];
s.m_author = p[3];
s.m_size = atof(p[4].c_str());
s.m_rating = atof(p[5].c_str());
s.m_description = p[6];
s.m_version = atof(p[7].c_str());
// s.m_date = atol(p[5].c_str());
//m_onlineScores.push_back(s);
AddEntryBar(pParent, x, y,s, dmodsAdded);
dmodsAdded++;
y += iPhoneMapY(5);
}
VariantList vList(pParent->GetParent());
ResizeScrollBounds(&vList);
DisableHorizontalScrolling(pParent->GetParent());
}
void OnDownloadError(VariantList *pVList)
{
NetHTTP::eError e = (NetHTTP::eError)pVList->m_variant[1].GetUINT32();
string msg = "`4Unable to connect. Try later. ("+toString(e)+")";
if (e == NetHTTP::ERROR_COMMUNICATION_TIMEOUT)
{
msg = "`4Connection timed out. Try Later.";
}
ShowScoreMessage(pVList->m_variant[0].GetComponent()->GetParent(), msg);
}
Entity * ShowScoreMessage(Entity *pMenu, string msg)
{
Entity *pInfo = pMenu->GetEntityByName("Info");
if (pInfo)
{
pInfo->GetComponentByName("TextRender")->GetVar("text")->Set(msg);
pInfo->RemoveComponentByName("Typer"); // a thing that types stuff
} else
{
pInfo = CreateTextLabelEntity(pMenu, "Info", iPhoneMapX(130), iPhoneMapY(220), msg);
}
return pInfo;
}
void OnDownloadHTTPFinish(VariantList *pVList)
{
Entity *pMenu = pVList->m_variant[0].GetComponent()->GetParent();
TextScanner t((char*)pVList->m_variant[1].GetString().c_str());
string line;
// ShowScoreMessage(pMenu, t.GetParmString("msg",1));
ShowScoreMessage(pMenu, "");
//GetApp()->GetVar("score_msg")->Set(t.GetParmString("msg",1));
//GetHighScoreManager()->SetupOnlineScores(t);
//GetApp()->GetVar("cur_score")->Set(uint32(0)); //reset score drawing
//ScoresAddStuffToScroll(NULL);
BrowseMenuAddScrollContent(pMenu, t);
// AddHighScores(pMenu, -1);
}
void DownloadDMODList(Entity *pMenu)
{
pMenu->RemoveComponentByName("HTTP"); //just in case it already exists
//get the internet stuff going
EntityComponent *pComp = pMenu->AddComponent(new HTTPComponent);
VariantList vPostData;
vPostData.m_variant[0].Set("version");
vPostData.m_variant[1].Set(toString(GetApp()->GetVersion()));
pComp->GetFunction("AddPostData")->sig_function(&vPostData);
vPostData.m_variant[0].Set("build");
vPostData.m_variant[1].Set(toString(GetApp()->GetBuild()));
pComp->GetFunction("AddPostData")->sig_function(&vPostData);
vPostData.m_variant[0].Set("platform");
vPostData.m_variant[1].Set(toString(GetEmulatedPlatformID()));
pComp->GetFunction("AddPostData")->sig_function(&vPostData);
VariantList v;
string url;
uint32 port;
GetApp()->GetServerInfo(url, port);
v.m_variant[0].Set(url);
v.m_variant[1].Set(port);
v.m_variant[2].Set("dink/getaddons.php");
pComp->GetFunction("Init")->sig_function(&v);
pComp->GetFunction("OnError")->sig_function.connect(&OnDownloadError);
pComp->GetFunction("OnFinish")->sig_function.connect(&OnDownloadHTTPFinish);
Entity *pEnt = ShowScoreMessage(pMenu, "`6");
EntityComponent *pTyper = pEnt->AddComponent(new TyperComponent);
pTyper->GetVar("text")->Set("Downloading add-on list...");
pTyper->GetVar("speedMS")->Set(uint32(50));
//KillScores();
}
void BrowseOnPostIntroTransition(VariantList *pVList)
{
Entity *pBG = pVList->Get(0).GetEntity();
DownloadDMODList(pBG);
//CreateQuickTipFirstTimeOnly(pBG, "interface/iphone/quicktip_dmod.rttex", false);
}
Entity * BrowseMenuCreate( Entity *pParentEnt )
{
//GetMessageManager()->SendGame(MESSAGE_TYPE_PLAY_MUSIC, "audio/title.mp3", 200);
GetBaseApp()->ClearError();
Entity *pBG = NULL;
if (IsLargeScreen())
{
pBG = CreateOverlayEntity(pParentEnt, "BrowseMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
} else
{
//pBG = CreateOverlayEntity(pParentEnt, "BrowseMenu", "interface/iphone/dmod_bg.rttex", 0,0);
pBG = CreateOverlayEntity(pParentEnt, "BrowseMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
}
pBG->SetName("BrowseMenu");
AddFocusIfNeeded(pBG, true, 500);
pBG->AddComponent(new FocusRenderComponent);
CL_Vec2f vTextAreaPos = iPhoneMap(2,10);
float offsetFromBottom = iPhoneMapY(42);
float offsetFromRight = iPhoneMapY(0);
CL_Vec2f vTextAreaBounds = (GetScreenSize()- CL_Vec2f(offsetFromRight,offsetFromBottom))-vTextAreaPos;
Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
pScroll->GetVar("pos2d")->Set(vTextAreaPos);
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);
/*
Entity *pLabel = CreateTextLabelEntity(pBG, "scanning", GetScreenSizeXf()/2, GetScreenSizeYf()/2, "Updating add-on browse list...");
SetAlignmentEntity(pLabel, ALIGNMENT_CENTER);
FadeOutAndKillEntity(pLabel, true, 300, 501);
*/
EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position
//pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255));
Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
pScrollComp->GetVar("fingerTracking")->Set(uint32(1));
//EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
//pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
Entity *pOverlay = CreateOverlayEntity(pBG, "", ReplaceWithDeviceNameInFileName("interface/iphone/bg_stone_overlay.rttex"), 0, GetScreenSizeYf());
SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
// ZoomFromPositionEntity(pBG, CL_Vec2f(0, -GetScreenSizeYf()), 500);
//the continue button
Entity *pEnt;
//pEnt = CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 320), MAKE_RGBA(0,0,0,100));
eFont fontID = FONT_SMALL;
pEnt = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(25), iPhoneMapY(BACK_BUTTON_Y), "Back", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&BrowseMenuOnSelect);
SetupTextEntity(pEnt, fontID);
AddHotKeyToButton(pEnt, VIRTUAL_KEY_BACK);
SlideScreen(pBG, true, 500);
pBG->GetFunction("OnPostIntroTransition")->sig_function.connect(&BrowseOnPostIntroTransition);
VariantList vList(pBG, string(""));
GetMessageManager()->CallEntityFunction(pBG, 500, "OnPostIntroTransition", &vList);
return pBG;
}

7
source/GUI/BrowseMenu.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef BrowseMenu_h__
#define BrowseMenu_h__
#include "BaseApp.h"
Entity * BrowseMenuCreate(Entity *pParentEnt);
#endif // BrowseMenu_h__

View file

@ -0,0 +1,348 @@
#include "PlatformPrecomp.h"
#include "DMODInstallMenu.h"
#include "Entity/EntityUtils.h"
#include "DMODMenu.h"
#include "dink/dink.h"
#include "GameMenu.h"
#include "Entity/UnpackArchiveComponent.h"
#include "Network/NetUtils.h"
#include "MainMenu.h"
#include "BrowseMenu.h"
#include "Network/NetHTTP.h"
#include "Entity/HTTPComponent.h"
void DMODInstallMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
Entity *pMenu = pEntClicked->GetParent();
LogMsg("Clicked %s entity", pEntClicked->GetName().c_str());
if (pEntClicked->GetName() == "Back")
{
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
if (pMenu->GetVar("exitto")->GetString() == "main")
{
MainMenuCreate(pMenu->GetParent());
} else if (pMenu->GetVar("exitto")->GetString() == "browse")
{
BrowseMenuCreate(pEntClicked->GetParent()->GetParent());
} else if (pMenu->GetVar("exitto")->GetString() == "play")
{
InitDinkPaths(GetBaseAppPath(), "dink", pMenu->GetVar("dmoddir")->GetString());
GameCreate(pMenu->GetParent(), 0, "");
} else
{
DMODMenuCreate(pEntClicked->GetParent()->GetParent());
}
}
GetEntityRoot()->PrintTreeAsText(); //useful for Loading
}
void DMODInstallUpdateStatus(Entity *pMenu, string msg)
{
if (!pMenu)
{
pMenu = GetEntityRoot()->GetEntityByName("DMODInstall");
}
Entity *pStatus = pMenu->GetEntityByName("status");
if (pStatus)
{
pStatus->GetComponentByName("TextRender")->GetVar("text")->Set(msg);
}
}
void DMODInstallShowMsg(Entity *pMenu, string myMsg, bool bSuccess = false)
{
Entity *pMsg = pMenu->GetEntityByName("status");
Entity *pLabel = pMenu->GetEntityByName("title_label");
if (pLabel)
{
pLabel->RemoveComponentByName("Typer"); // a thing that types stuff
if (!bSuccess)
{
pLabel->GetComponentByName("TextRender")->GetVar("text")->Set("Error!");
} else
{
pLabel->GetComponentByName("TextRender")->GetVar("text")->Set("Success!");
}
}
if (pMsg)
{
pMsg->RemoveComponentByName("Typer"); // a thing that types stuff
pMsg->GetComponentByName("TextRender")->GetVar("text")->Set(myMsg);
}
Entity *pSkip = pMenu->GetEntityByName("Back");
if (pSkip)
{
pSkip->GetComponentByName("TextRender")->GetVar("text")->Set("`wContinue");
}
}
void DMODSetTitleLabel(Entity *pMenu, string myMsg)
{
Entity *pLabel = pMenu->GetEntityByName("title_label");
if (pLabel)
{
//pLabel->RemoveComponentByName("Typer"); // a thing that types stuff
pLabel->GetComponentByName("TextRender")->GetVar("text")->Set(myMsg);
}
}
void DMODInstallOnError(VariantList *pVList)
{
NetHTTP::eError e = (NetHTTP::eError)pVList->m_variant[1].GetUINT32();
string msg = "`4Unable to connect to the\nnetwork.``\nPlease try again later.";
switch (e)
{
case NetHTTP::ERROR_COMMUNICATION_TIMEOUT:
msg = "`4Connection timed out. Try Later?";
break;
case NetHTTP::ERROR_CANT_RESOLVE_URL:
msg = "`4Can't find website. Bad url?";
break;
case NetHTTP::ERROR_WRITING_FILE:
msg = "`4Error writing file. Out of space?";
break;
case NetHTTP::ERROR_404_FILE_NOT_FOUND:
msg = "`4Server gave a 404: File not found. Bad url?";
break;
}
DMODInstallShowMsg(pVList->m_variant[0].GetComponent()->GetParent(), msg);
}
void DMODUnpackOnError(VariantList *pVList)
{
int error = pVList->m_variant[1].GetUINT32();
string msg = "`4Error "+toString(error)+" unpacking. Out of space or malformed .dmod file?";
DMODInstallShowMsg(pVList->m_variant[0].GetComponent()->GetParent(), msg);
}
void DMODInstallSetProgressBar(float progress)
{
Entity *pBar = GetEntityRoot()->GetEntityByName("bar");
if (pBar)
{
pBar->GetComponentByName("ProgressBar")->GetVar("progress")->Set(progress);
}
}
void OnDMODUnpackStatusUpdate(VariantList *pVList)
{
int curBytes = pVList->Get(1).GetUINT32();
int totalBytes = pVList->Get(2).GetUINT32();
int barSize = 1024*1024*5; //5 megs of unpacking will fill up one bar
float progress = float( (curBytes%barSize)) /float(barSize);
//LogMsg("prog: %.2f", progress);
DMODInstallUpdateStatus(NULL, "Writing "+toString(curBytes/1024)+"K");
DMODInstallSetProgressBar(progress);
}
void OnDMODUnpackFinish(VariantList *pVList)
{
Entity *pMenu = pVList->m_variant[0].GetComponent()->GetParent();
DMODInstallSetProgressBar(1);
DMODInstallShowMsg(pMenu, pMenu->GetVar("originalFileName")->GetString()+" installed. Tap continue.", true);
RemoveFile(GetDMODRootPath()+"temp.dmod");
RemoveFile("temp.dmod");
if (pMenu->GetVar("autoplay")->GetUINT32() == 1)
{
pMenu->GetVar("exitto")->Set("play");
pMenu->GetVar("dmoddir")->Set(GetDMODRootPath()+ pVList->m_variant[0].GetComponent()->GetVar("firstDirCreated")->GetString());
}
}
void OnDMODInstallHTTPFinish(VariantList *pVList)
{
Entity *pMenu = pVList->m_variant[0].GetComponent()->GetParent();
#ifdef _DEBUG
LogMsg("Finish signal received");
#endif
DMODSetTitleLabel(pMenu, string("Installing ")+pMenu->GetVar("originalFileName")->GetString()+"...");
EntityComponent *pUnpack = pMenu->AddComponent(new UnpackArchiveComponent);
pUnpack->GetVar("sourceFileName")->Set(pMenu->GetVar("tempFileName")->GetString());
pUnpack->GetVar("deleteSourceOnFinish")->Set(uint32(1));
pUnpack->GetVar("destDirectory")->Set(pMenu->GetVar("installDirectory")->GetString());
DMODInstallSetProgressBar(0);
pUnpack->GetFunction("OnError")->sig_function.connect(&DMODUnpackOnError);
pUnpack->GetFunction("OnFinish")->sig_function.connect(&OnDMODUnpackFinish);
pUnpack->GetFunction("OnStatusUpdate")->sig_function.connect(&OnDMODUnpackStatusUpdate);
}
void OnDMODInstallStatusUpdate(VariantList *pVList)
{
int curBytes = pVList->Get(1).GetUINT32();
int totalBytes = pVList->Get(2).GetUINT32();
if (totalBytes == 0)
{
DMODInstallUpdateStatus(NULL, "Network active, getting file data...");
} else
{
DMODInstallUpdateStatus(NULL, ""+toString(curBytes/1024)+"K/"+toString(totalBytes/1024)+"K");
}
//also update the progress bar thingie
if (totalBytes == 0) totalBytes = 1; //avoid /1 error
DMODInstallSetProgressBar(float(curBytes)/float(totalBytes));
}
void InitNetStuff(VariantList *pVList)
{
Entity *pMenu = pVList->m_variant[0].GetEntity();
//get the internet stuff going
EntityComponent *pComp = pMenu->AddComponent(new HTTPComponent);
string url = pMenu->GetVar("dmodURL")->GetString();
string tempFileName = pMenu->GetVar("tempFileName")->GetString();
string domain;
string request;
int port = 80;
BreakDownURLIntoPieces(url, domain, request, port);
VariantList v;
v.m_variant[0].Set(tempFileName);
pComp->GetFunction("SetFileOutput")->sig_function(&v);
v.Reset();
v.m_variant[0].Set(domain);
v.m_variant[1].Set(uint32(port));
v.m_variant[2].Set(request);
pComp->GetFunction("Init")->sig_function(&v);
pComp->GetFunction("OnError")->sig_function.connect(&DMODInstallOnError);
pComp->GetFunction("OnFinish")->sig_function.connect(&OnDMODInstallHTTPFinish);
pComp->GetFunction("OnStatusUpdate")->sig_function.connect(&OnDMODInstallStatusUpdate);
}
Entity * DMODInstallMenuCreate(Entity *pParentEnt, string dmodURL, string installDirectory, string sourceFileName, bool bFromBrowseMenu, string dmodName)
{
Entity *pBG = CreateOverlayEntity(pParentEnt, "DMODInstall", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
AddFocusIfNeeded(pBG, true);
Entity *pButtonEntity;
float x = GetScreenSizeXf()/2;
float yStart = iPhoneMapY(230);
float y = yStart;
float ySpacer = iPhoneMapY(50);
Entity *pProgressBar = pBG->AddEntity(new Entity("bar"));
Entity *pTitleLabel = CreateTextLabelEntity(pBG, "title_label", iPhoneMapX(100), iPhoneMapY(80), "Please wait");
//save these for later
pBG->GetVar("dmodURL")->Set(dmodURL);
pBG->GetVar("dmodName")->Set(dmodName);
pBG->GetVar("installDirectory")->Set(installDirectory);
pBG->GetVar("tempFileName")->Set(GetDMODRootPath()+"temp.dmod");
pBG->GetVar("originalFileName")->Set(GetFileNameFromString(dmodURL));
pBG->GetVar("fromBrowseMenu")->Set(uint32(bFromBrowseMenu));
if (IsLargeScreen())
{
//SetupTextEntity(pTitleLabel, FONT_LARGE);
}
//SetAlignmentEntity(pTitleLabel, ALIGNMENT_CENTER);
EntityComponent *pTyper = pTitleLabel->AddComponent(new TyperComponent);
pTyper->GetVar("text")->Set(".......");
pTyper->GetVar("speedMS")->Set(uint32(500));
EntityComponent *pBar = pProgressBar->AddComponent(new ProgressBarComponent);
pProgressBar->GetVar("pos2d")->Set(CL_Vec2f(iPhoneMapX(80),iPhoneMapY(120)));
pProgressBar->GetVar("size2d")->Set(CL_Vec2f(iPhoneMapX(310),iPhoneMapY(15)));
pProgressBar->GetVar("color")->Set(MAKE_RGBA(200,200,0,60));
pBar->GetVar("interpolationTimeMS")->Set(uint32(1)); //update faster
pBar->GetVar("borderColor")->Set(MAKE_RGBA(200,200,0,180));
pButtonEntity = CreateTextButtonEntity(pBG, "Back", x, y, "Cancel"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DMODInstallMenuOnSelect);
SetAlignmentEntity(pButtonEntity, ALIGNMENT_CENTER);
AddHotKeyToButton(pButtonEntity, VIRTUAL_KEY_BACK);
Entity *pStatus = CreateTextLabelEntity(pBG, "status", x, iPhoneMapY(180), "Initializing...");
SetAlignmentEntity(pStatus, ALIGNMENT_CENTER);
if (bFromBrowseMenu)
{
Entity *pStatus = CreateTextLabelEntity(pBG, "title", x, iPhoneMapY(30), "-= Installing "+dmodName+" =-");
SetAlignmentEntity(pStatus, ALIGNMENT_CENTER);
pBG->GetVar("exitto")->Set("browse");
}
if (!sourceFileName.empty())
{
//don't download, we already have the file
pBG->GetVar("tempFileName")->Set(sourceFileName);
pBG->GetVar("originalFileName")->Set(GetFileNameFromString(sourceFileName));
EntityComponent *pCrapComp = pBG->AddComponent(new EntityComponent("CRAP")); //I don't need this, but the function want a component and gets the parent for the menu, so fine
pBG->GetVar("exitto")->Set("main");
//start the install in 500 ms, so we don't lag out the screen transition
pBG->GetFunction("StartInstall")->sig_function.connect(&OnDMODInstallHTTPFinish);
VariantList vList(pCrapComp);
GetMessageManager()->CallEntityFunction(pBG, 500, "StartInstall", &vList);
pStatus->GetVar("text")->Set("New .dmod file detected");
} else
{
pBG->GetVar("autoplay")->Set(uint32(1));
pBG->GetFunction("InitNetStuff")->sig_function.connect(&InitNetStuff);
VariantList vList(pBG);
GetMessageManager()->CallEntityFunction(pBG, 500, "InitNetStuff", &vList);
}
SlideScreen(pBG, true, 500);
return pBG;
}

View file

@ -0,0 +1,7 @@
#ifndef DMODInstallMenu_h__
#define DMODInstallMenu_h__
#include "App.h"
Entity * DMODInstallMenuCreate(Entity *pParentEnt, string dmodURL, string installDirectory, string sourceFileName = "", bool bFromBrowseMenu = false, string dmodName = "");
#endif // DMODInstallMenu_h__

605
source/GUI/DMODMenu.cpp Normal file
View file

@ -0,0 +1,605 @@
#include "PlatformPrecomp.h"
#include "DMODMenu.h"
#include "MainMenu.h"
#include "DMODInstallMenu.h"
#include "GameMenu.h"
#include "Entity/EntityUtils.h"
#include "dink/dink.h"
#include "PopUpMenu.h"
#include "util/TextScanner.h"
#include "EnterURLMenu.h"
#include "Renderer/SoftSurface.h"
#include "QuickTipMenu.h"
#include "BrowseMenu.h"
#include "ReadTextMenu.h"
void DMODMenuAddScrollContent(Entity *pParent);
void DMODMenuOnRemoveDMOD(VariantList *pVList)
{
Entity *pMenu = pVList->Get(0).GetEntity();
string dmodDirToDelete = pMenu->GetVar("dmodDirToDelete")->GetString();
if (!dmodDirToDelete.empty())
{
RemoveDirectoryRecursively(dmodDirToDelete);
DMODMenuAddScrollContent(pMenu);
}
LogMsg("Removing DMOD");
}
void DMODMenuOnSessionNew(VariantList *pVList)
{
Entity *pMenu = pVList->Get(0).GetEntity();
DisableAllButtonsEntity(pMenu);
SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
GameCreate(pMenu->GetParent(), 0, "");
}
void DMODMenuOnSessionContinue(VariantList *pVList)
{
Entity *pMenu = pVList->Get(0).GetEntity();
DisableAllButtonsEntity(pMenu);
SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
GameCreate(pMenu->GetParent(), 0, g_dglo.m_savePath+"continue_state.dat");
}
void DMODMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
Entity *pMenu = GetEntityRoot()->GetEntityByName("DMODMenu");
//LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[0].Print().c_str());
if (pEntClicked->GetName() == "Back")
{
DisableAllButtonsEntity(pMenu);
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
MainMenuCreate(pEntClicked->GetParent()->GetParent());
return;
}
if (pEntClicked->GetName() == "getmore")
{
DisableAllButtonsEntity(pMenu);
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
EnterURLMenuCreate(pEntClicked->GetParent()->GetParent());
return;
}
if (pEntClicked->GetName() == "browse")
{
DisableAllButtonsEntity(pMenu);
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
BrowseMenuCreate(pEntClicked->GetParent()->GetParent());
return;
}
//they must have clicked on a DMOD if they got this far
if (pEntClicked->GetName() == "icon_hotspot")
{
//save position of the scroll bar first
string dmoddir = pEntClicked->GetParent()->GetVar("dmodgamedir")->GetString();
SendFakeInputMessageToEntity(GetEntityRoot(), MESSAGE_TYPE_GUI_CLICK_END, pVList->m_variant[0].GetVector2()); //otherwise the menu may never get the touch release message
//first check to see if it's a valid dmod
if (!FileExists(dmoddir+"/dmod.diz"))
{
//don't look valid..
PopUpCreate(pMenu, "This add-on appears to be missing or damaged. Delete and re-install.", "", "cancel", "Continue", "", "", true);
return;
}
InitDinkPaths(GetBaseAppPath(), "dink", dmoddir);
pMenu = GetEntityRoot()->GetEntityByName("DMODMenu");
//next, see if there is a save-on-quit save state existing for this dmod
if (FileExists(g_dglo.m_savePath+"/continue_state.dat"))
{
PopUpCreate(pMenu, "Continue your last playing session?", "", "cancel", "Abort", "SessionContinue", "Continue", true,"SessionNew", "No" );
return;
}
DisableAllButtonsEntity(pMenu);
SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
GameCreate(pMenu->GetParent(), 0, "");
}
if (pEntClicked->GetName() == "delete_hotspot")
{
EntityComponent *pScrollerComp = pMenu->GetEntityByName("scroll")->GetComponentByName("Scroll");
GetApp()->GetVar("DMODProgress2d")->Set(pScrollerComp->GetVar("progress2d")->GetVector2());
string dmoddir = pEntClicked->GetParent()->GetVar("dmodgamedir")->GetString();
string dmodtitle = pEntClicked->GetParent()->GetVar("dmodtitle")->GetString();
SendFakeInputMessageToEntity(GetEntityRoot(), MESSAGE_TYPE_GUI_CLICK_END, pVList->m_variant[0].GetVector2()); //otherwise the menu may never get the touch release message
if (!dmoddir.empty())
{
Entity *pMenu = GetEntityRoot()->GetEntityByName("DMODMenu");
pMenu->GetVar("dmodDirToDelete")->Set(dmoddir);
PopUpCreate(pMenu, "Remove "+dmodtitle+" and its saved games?", "", "cancel", "Cancel", "RemoveDMOD", "Remove", true);
}
}
if (pEntClicked->GetName() == "view_info")
{
DisableAllButtonsEntity(pMenu);
SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
string textfile = pEntClicked->GetParent()->GetVar("textfile")->GetString();
ReadTextMenuCreate(pMenu->GetParent(), textfile, "file");
}
/*
if (pEntClicked->GetName() == "rtsoft")
{
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Leave the game and visit `wrtsoft.com``?", "http://www.rtsoft.com/iphone",
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
*/
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
CL_Vec2f GetDMODBarIconOffset()
{
if (IsLargeScreen())
{
return CL_Vec2f(44,20); //fix a slight offset problem
}
return iPhoneMap2X(23,11);
}
CL_Vec2f GetDMODBarIconSize()
{
return iPhoneMap2X(99, 74);
}
void DMODSetupExtra(VariantList *pVList)
{
Entity *pBG = pVList->Get(0).GetEntity();
//locate the file
string dmodDir = pBG->GetVar("dmodgamedir")->GetString()+"/";
string iconFile = dmodDir+"preview.bmp";
if (!FileExists(iconFile))
{
//try again
iconFile = dmodDir+"graphics/title-01.bmp";
if (!FileExists(iconFile))
{
iconFile = dmodDir+"graphics/title/title-01.bmp";
}
}
if (!FileExists(iconFile))
{
//give up, nothing to show
return;
}
SoftSurface s8bit;
if (!s8bit.LoadFile(iconFile, SoftSurface::COLOR_KEY_NONE, false))
{
return;
}
//if it was 8bit, this will convert it to 32
SoftSurface s;
s.Init(s8bit.GetWidth(),s8bit.GetHeight(), SoftSurface::SURFACE_RGBA);
s.Blit(0,0, &s8bit);
s.FlipY();
SurfaceAnim *pSurf;
pSurf = new SurfaceAnim;
pSurf->SetTextureType(Surface::TYPE_DEFAULT); //insure no mipmaps are created
pSurf->InitBlankSurface(s.GetWidth(),s.GetHeight());
pSurf->UpdateSurfaceRect(rtRect(0,0, s.GetWidth(), s.GetHeight()), s.GetPixelData());
//add the icon
Entity *pEnt = CreateOverlayEntity(pBG, "icon", "", GetDMODBarIconOffset().x,GetDMODBarIconOffset().y);
OverlayRenderComponent *pOverlay = (OverlayRenderComponent*) pEnt->GetComponentByName("OverlayRender");
pOverlay->SetSurface(pSurf, true);
EntitySetScaleBySize(pEnt,GetDMODBarIconSize());
}
void AddDMODBar(Entity *pParent, float &x, float &y, string title, string description, string iconFileName, float dmodSize, string dmodgamedir, int count)
{
Entity *pBG = CreateOverlayEntity(pParent, dmodgamedir, ReplaceWithLargeInFileName("interface/iphone/dmod_bar.rttex"), iPhoneMapX(x), iPhoneMapY(y));
if (IsLargeScreen())
{
y += pBG->GetVar("size2d")->GetVector2().y/2;
} else
{
y += pBG->GetVar("size2d")->GetVector2().y;
}
pBG->GetVar("dmodgamedir")->Set(dmodgamedir); //save for later
pBG->GetVar("dmodtitle")->Set(title); //save for later
//title
Entity *pTitle = CreateTextLabelEntity(pBG, "title", iPhoneMapX2X( 130) ,iPhoneMapY2X( 10), title);
Entity *pDescription = CreateTextBoxEntity(pBG, "descrip", iPhoneMap2X(129, 33), iPhoneMap2X(277, 53), description, 0.7f);
Entity *pIcon = CreateButtonHotspot(pBG, "icon_hotspot", GetDMODBarIconOffset(), GetDMODBarIconSize(), Button2DComponent::BUTTON_STYLE_CLICK_ON_TOUCH_IGNORE_DRAGGING);
SetTouchPaddingEntity(pIcon, CL_Rectf(0,iPhoneMapY2X(5),0,iPhoneMapY2X(5)));
pIcon->GetFunction("OnButtonSelected")->sig_function.connect(&DMODMenuOnSelect);
//processing the icon image might be slow, lets do it a bit later, sequencing the timing by using the y, which should be going up
pBG->GetFunction("SetupExtra")->sig_function.connect(&DMODSetupExtra);
VariantList vList(pBG);
GetMessageManager()->CallEntityFunction(pBG, 800+count*200, "SetupExtra", &vList);
//the delete icon part
bool bCanDelete = true;
if (!GetDMODStaticRootPath().empty())
{
if (GetPathFromString(dmodgamedir) == GetDMODStaticRootPath())
{
//we better not let people delete this..
bCanDelete = false;
}
}
if (bCanDelete)
{
CL_Vec2f iconPos = iPhoneMap2X(408,10);
//Entity *pIcon = CreateButtonHotspot(pBG, "delete_hotspot", iconPos, Button2DComponent::BUTTON_STYLE_CLICK_ON_TOUCH_IGNORE_DRAGGING);
Entity *pIcon = CreateOverlayButtonEntity(pBG, "delete_hotspot", ReplaceWithLargeInFileName("interface/iphone/dmod_delete_button.rttex"), iconPos.x, iconPos.y);
SetTouchPaddingEntity(pIcon, CL_Rectf(0,0,0,0));
pIcon->GetFunction("OnButtonSelected")->sig_function.connect(&DMODMenuOnSelect);
}
//add an "info" icon?
string dmodDir = dmodgamedir+"/";
string infoFile = dmodDir+"readme.txt";
if (!FileExists(infoFile))
{
infoFile = dmodDir+"read me please.txt";
}
if (!FileExists(infoFile))
{
infoFile = dmodDir+"credits.txt";
}
if (!FileExists(infoFile))
{
infoFile = dmodDir+"dmod.diz";
}
if (FileExists(infoFile))
{
pBG->GetVar("textfile")->Set(infoFile); //save for later
CL_Vec2f iconPos = iPhoneMap2X(405,56);
Entity *pIcon = CreateOverlayButtonEntity(pBG, "view_info", ReplaceWithLargeInFileName("interface/iphone/dmod_info_button.rttex"), iconPos.x, iconPos.y);
SetButtonStyleEntity(pIcon, Button2DComponent::BUTTON_STYLE_CLICK_ON_TOUCH_IGNORE_DRAGGING);
SetTouchPaddingEntity(pIcon, CL_Rectf(0,0,0,0));
pIcon->GetFunction("OnButtonSelected")->sig_function.connect(&DMODMenuOnSelect);
}
//add animation effect
ZoomToPositionFromThisOffsetEntity(pBG, CL_Vec2f(GetScreenSizeXf(), 0), 500, INTERPOLATE_EASE_TO, 10);
}
void GetParsedDMODInfo(string dmodPath, string &nameOut, float versionOut, string &copyright, string &dmodwebsite, string &description)
{
TextScanner t(dmodPath+"/dmod.diz", false);
if (!t.IsLoaded())
{
//error, unable to load DMOD diz
nameOut = GetFileNameFromString(dmodPath);
copyright = "No dmod.diz found. Corrupted?";
versionOut = 0;
return;
}
nameOut = t.GetLine(0);
int maxNameChars = 39;
if (nameOut.length() > maxNameChars)
{
TruncateString(nameOut, maxNameChars);
description += "...";
}
description.clear();
for (int i=1; i < t.m_lines.size(); i++)
{
description += t.GetLine(i);
if (i == 1)
{
description = TrimLeft(description);
}
if (description.length() > 400)
{
break;
}
if (i < t.m_lines.size()-1 && description.size()>0)
{
description += " ";
}
}
int maxChars = 205;
if (description.length() > maxChars)
{
TruncateString(description, maxChars);
description += "...";
}
}
void DMODMenuAddScrollContent(Entity *pParent)
{
pParent = pParent->GetEntityByName("scroll_child");
pParent->RemoveAllEntities();
float x = 5;
float y = 0;
//Entity *pEnt;
vector<string> temp = GetDirectoriesAtPath(GetDMODRootPath());
vector<string> files;
//actually, you know what? Let's add the path to each one
for (int i=0; i < temp.size(); i++)
{
temp[i] = GetDMODRootPath()+temp[i];
if (FileExists(temp[i]+"/dink.dat"))
{
//looks valid
files.push_back(temp[i]);
}
}
if (!GetDMODStaticRootPath().empty())
{
vector<string> staticFiles = GetDirectoriesAtPath(GetDMODStaticRootPath());
for (int i=0; i < staticFiles.size(); i++)
{
//merge in if not a duplicate
for (int n=0; n < files.size(); n++)
{
if (GetFileNameFromString(files[n]) == staticFiles[i])
{
//duplicate
continue;
}
}
files.push_back(GetDMODStaticRootPath()+staticFiles[i]);
}
}
int dmodsAdded = 0;
for (unsigned int i=0; i < files.size(); i++)
{
#ifdef WIN32
if ( IsInString(files[i], "/audio") || IsInString(files[i],"/dink" )|| IsInString(files[i] ,"/game") || IsInString(files[i],"/interface")) continue;
if (IsInString(files[i] ,"/develop") ) continue;
#else
if (IsInString(files[i],"/Snapshot") || IsInString(files[i], "/Snapshots")) continue;
#endif
string dmodName, dmodCopyright, dmodwebsite, description;
float version = 0;
GetParsedDMODInfo(files[i], dmodName, version, dmodCopyright, dmodwebsite, description );
AddDMODBar(pParent, x, y, dmodName, description, "", 20.3f, files[i], dmodsAdded);
dmodsAdded++;
}
if (dmodsAdded == 0)
{
CL_Vec2f vTextBoxPos(iPhoneMapX(20),iPhoneMapY(y));
CL_Vec2f vTextBounds(iPhoneMapX(434), iPhoneMapY(200));
string msg = "`6No add-on stories are currently installed. Click ``Browse`6 below to get some.";
if (!GetApp()->CanDownloadDMODS())
{
//a better message would be:
msg = "`6No add-on stories are currently available.";
}
CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, msg);
}
VariantList vList(pParent->GetParent());
ResizeScrollBounds(&vList);
DisableHorizontalScrolling(pParent->GetParent());
}
void OnDMODMenuDelete(Entity *pMenu)
{
if (IsBaseAppInitted())
{
EntityComponent *pScrollerComp = pMenu->GetEntityByName("scroll")->GetComponentByName("Scroll");
if (pScrollerComp)
{
GetApp()->GetVar("DMODProgress2d")->Set(pScrollerComp->GetVar("progress2d")->GetVector2());
}
}
}
void OnPostIntroTransition(VariantList *pVList)
{
Entity *pBG = pVList->Get(0).GetEntity();
DMODMenuAddScrollContent(pBG);
if (GetEmulatedPlatformID() == PLATFORM_ID_WEBOS)
{
CreateQuickTipFirstTimeOnly(pBG, "interface/generic/quicktip_dmod.rttex", true);
} else
if (GetEmulatedPlatformID() == PLATFORM_ID_BBX)
{
CreateQuickTipFirstTimeOnly(pBG, "interface/generic/quicktip_dmod.rttex", true);
} else
if (GetEmulatedPlatformID() == PLATFORM_ID_ANDROID)
{
CreateQuickTipFirstTimeOnly(pBG, "interface/android/quicktip_dmod.rttex", true);
} else if (GetEmulatedPlatformID() == PLATFORM_ID_WINDOWS)
{
CreateQuickTipFirstTimeOnly(pBG, "interface/win/quicktip_dmod.rttex", true);
} else if (GetEmulatedPlatformID() == PLATFORM_ID_OSX)
{
CreateQuickTipFirstTimeOnly(pBG, "interface/osx/quicktip_dmod.rttex", true);
} else
{
CreateQuickTipFirstTimeOnly(pBG, "interface/iphone/quicktip_dmod.rttex", true);
}
//get notified when this is deleted so we can save the default settings
pBG->sig_onRemoved.connect(&OnDMODMenuDelete);
}
Entity * DMODMenuCreate( Entity *pParentEnt, bool bFadeIn /*= false*/ )
{
//GetMessageManager()->SendGame(MESSAGE_TYPE_PLAY_MUSIC, "audio/title.mp3", 200);
GetBaseApp()->ClearError();
Entity *pBG = NULL;
if (IsLargeScreen())
{
pBG = CreateOverlayEntity(pParentEnt, "DMODMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
} else
{
pBG = CreateOverlayEntity(pParentEnt, "DMODMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
}
pBG->SetName("DMODMenu");
AddFocusIfNeeded(pBG, true, 500);
pBG->AddComponent(new FocusRenderComponent);
CL_Vec2f vTextAreaPos = iPhoneMap(2,10);
float offsetFromBottom = iPhoneMapY(42);
float offsetFromRight = iPhoneMapY(0);
CL_Vec2f vTextAreaBounds = (GetScreenSize()- CL_Vec2f(offsetFromRight,offsetFromBottom))-vTextAreaPos;
Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
pScroll->GetVar("pos2d")->Set(vTextAreaPos);
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);
Entity *pLabel = CreateTextLabelEntity(pBG, "scanning", GetScreenSizeXf()/2, GetScreenSizeYf()/2, "Preparing quest list...");
SetAlignmentEntity(pLabel, ALIGNMENT_CENTER);
FadeOutAndKillEntity(pLabel, true, 300, 501);
EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position
//pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255));
Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
pScrollComp->GetVar("fingerTracking")->Set(uint32(1));
//EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
//pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
Entity *pOverlay = CreateOverlayEntity(pBG, "", ReplaceWithDeviceNameInFileName("interface/iphone/bg_stone_overlay.rttex"), 0, GetScreenSizeYf());
SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
// ZoomFromPositionEntity(pBG, CL_Vec2f(0, -GetScreenSizeYf()), 500);
//the continue button
Entity *pEnt;
//pEnt = CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 320), MAKE_RGBA(0,0,0,100));
eFont fontID = FONT_SMALL;
pEnt = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(25), iPhoneMapY(BACK_BUTTON_Y), "Back", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&DMODMenuOnSelect);
SetupTextEntity(pEnt, fontID);
AddHotKeyToButton(pEnt, VIRTUAL_KEY_BACK);
if (GetApp()->CanDownloadDMODS())
{
pEnt = CreateTextButtonEntity(pBG, "getmore", iPhoneMapX(330), iPhoneMapY(BACK_BUTTON_Y), "Install by URL", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&DMODMenuOnSelect);
SetupTextEntity(pEnt, fontID);
pEnt = CreateTextButtonEntity(pBG, "browse", iPhoneMapX(170), iPhoneMapY(BACK_BUTTON_Y), "Browse", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&DMODMenuOnSelect);
SetupTextEntity(pEnt, fontID);
}
pBG->GetFunction("RemoveDMOD")->sig_function.connect(&DMODMenuOnRemoveDMOD);
pBG->GetFunction("SessionNew")->sig_function.connect(&DMODMenuOnSessionNew);
pBG->GetFunction("SessionContinue")->sig_function.connect(&DMODMenuOnSessionContinue);
if (bFadeIn)
{
// FadeInEntity(pBG, true, 500);
SlideScreen(pBG, true, 500);
} else
{
SlideScreen(pBG, true, 500);
}
VariantList vList(GetApp()->GetVar("DMODProgress2d")->GetVector2());
GetMessageManager()->CallComponentFunction(pScrollComp, 501, "SetProgress", &vList);
pBG->GetFunction("OnPostIntroTransition")->sig_function.connect(&OnPostIntroTransition);
VariantList vTemp(pBG, string(""));
GetMessageManager()->CallEntityFunction(pBG, 500, "OnPostIntroTransition", &vTemp);
return pBG;
}

7
source/GUI/DMODMenu.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef DMODMenu_h__
#define DMODMenu_h__
#include "BaseApp.h"
Entity * DMODMenuCreate(Entity *pParentEnt, bool bFadeIn = false);
#endif // DMODMenu_h__

163
source/GUI/DebugMenu.cpp Normal file
View file

@ -0,0 +1,163 @@
#include "PlatformPrecomp.h"
#include "DebugMenu.h"
#include "Entity/EntityUtils.h"
#include "dink/dink.h"
#include "LogMenu.h"
void DebugMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity", pEntClicked->GetName().c_str());
if (pEntClicked->GetName() == "FPS")
{
GetBaseApp()->SetFPSVisible(!GetBaseApp()->GetFPSVisible());
}
if (pEntClicked->GetName() == "music_on")
{
GetAudioManager()->Play("audio/intro.ogg", true, true);
}
if (pEntClicked->GetName() == "music_off")
{
GetAudioManager()->StopMusic();
}
if (pEntClicked->GetName() == "log")
{
RemoveFocusIfNeeded(pEntClicked->GetParent());
SlideScreen(pEntClicked->GetParent(), false);
LogMenuCreate(pEntClicked->GetParent()->GetParent());
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
}
if (pEntClicked->GetName() == "Back")
{
//slide it off the screen and then kill the whole menu tree
RemoveFocusIfNeeded(pEntClicked->GetParent());
SlideScreen(pEntClicked->GetParent(), false);
AddFocusIfNeeded(pEntClicked->GetParent()->GetParent());
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
}
if (pEntClicked->GetName() == "AddStrength")
{
//slide it off the screen and then kill the whole menu tree
DinkModStrength(1);
}
if (pEntClicked->GetName() == "AddDefense")
{
//slide it off the screen and then kill the whole menu tree
DinkModDefense(1);
}
if (pEntClicked->GetName() == "AddMagic")
{
//slide it off the screen and then kill the whole menu tree
DinkModMagic(1);
}
if (pEntClicked->GetName() == "AddLife")
{
//slide it off the screen and then kill the whole menu tree
DinkModLifeMax(10);
}
if (pEntClicked->GetName() == "FillLife")
{
//slide it off the screen and then kill the whole menu tree
DinkFillLife();
}
if (pEntClicked->GetName() == "AddGold")
{
//slide it off the screen and then kill the whole menu tree
DinkModGold(100);
}
if (pEntClicked->GetName() == "empty_cache")
{
DinkUnloadGraphicsCache();
LogMsg("Cache emptied");
}
if (pEntClicked->GetName() == "AddBow")
{
//slide it off the screen and then kill the whole menu tree
DinkAddBow();
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
Entity * DebugMenuCreate(Entity *pParentEnt)
{
//Entity *pBG = CreateOverlayEntity(pParentEnt, "DebugMenu", "interface/generic_bg.rttex", 0,0);
Entity *pBG = CreateOverlayRectEntity(pParentEnt, CL_Vec2f(0,0), GetScreenSize(), MAKE_RGBA(0,0,0,140));
AddFocusIfNeeded(pBG);
Entity *pButtonEntity;
float x = iPhoneMapX(30);
float y = iPhoneMapY(30);
float ySpacer = iPhoneMapY(40);
pButtonEntity = CreateTextButtonEntity(pBG, "FPS", x, y, "Toggle FPS Display"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
//pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
if (GetApp()->GetCheatsEnabled())
{
pButtonEntity = CreateTextButtonEntity(pBG, "empty_cache", x, y, "Empty graphic cache"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
}
pButtonEntity = CreateTextButtonEntity(pBG, "log", x, y, "View log"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "Back", x, y, "Back"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
//pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
AddHotKeyToButton(pButtonEntity, VIRTUAL_KEY_BACK);
if (GetApp()->GetCheatsEnabled())
{
//buttons on right
x = iPhoneMapX(200);
y = iPhoneMapY(30);
pButtonEntity = CreateTextButtonEntity(pBG, "AddStrength", x, y, "Increase Strength"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "AddDefense", x, y, "Increase Defense"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "AddMagic", x, y, "Increase Magic"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "AddLife", x, y, "Increase Life"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "FillLife", x, y, "Refill Life"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "AddGold", x, y, "Add 100 Gold"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
pButtonEntity = CreateTextButtonEntity(pBG, "AddBow", x, y, "Add Bow"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&DebugMenuOnSelect);
}
SlideScreen(pBG, true, 500);
return pBG;
}

7
source/GUI/DebugMenu.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef DebugMenu_h__
#define DebugMenu_h__
#include "App.h"
Entity * DebugMenuCreate(Entity *pParentEnt);
#endif // DebugMenu_h__

114
source/GUI/EnterURLMenu.cpp Normal file
View file

@ -0,0 +1,114 @@
#include "PlatformPrecomp.h"
#include "EnterURLMenu.h"
#include "Entity/EntityUtils.h"
#include "DMODMenu.h"
#include "DMODInstallMenu.h"
#include "dink/dink.h"
#include "PopUpMenu.h"
void EnterURLMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
Entity *pMenu = pEntClicked->GetParent();
//LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[0].Print().c_str());
if (pEntClicked->GetName() == "Back")
{
//slide it off the screen and then kill the whole menu tree
pEntClicked->GetParent()->RemoveComponentByName("FocusInput");
DisableAllButtonsEntity(pMenu);
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
DMODMenuCreate(pEntClicked->GetParent()->GetParent(), true);
}
if (pEntClicked->GetName() == "Continue")
{
string name = GetEntityRoot()->GetEntityByName("name_input_box")->GetComponentByName("InputTextRender")->GetVar("text")->GetString();
DisableAllButtonsEntity(pMenu);
GetApp()->GetVar("dmod_download_url")->Set(name); //save it to our database so we can remember the default
LogMsg("Read %s for the name", GetApp()->GetVar("name")->GetString().c_str());
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
DMODInstallMenuCreate(pEntClicked->GetParent()->GetParent(), GetApp()->GetVar("dmod_download_url")->GetString(), GetDMODRootPath() );
}
if (pEntClicked->GetName() == "paste")
{
string text = GetClipboardText();
if (!text.empty())
{
GetEntityRoot()->GetEntityByName("name_input_box")->GetComponentByName("InputTextRender")->GetVar("text")->Set(""); //clear it first
GetMessageManager()->SendGUI(MESSAGE_TYPE_GUI_PASTE, Variant(text), 0);
} else
{
//kill the keyboard
GetEntityRoot()->GetEntityByName("name_input_box")->GetComponentByName("InputTextRender")->GetFunction("CloseKeyboard")->sig_function(NULL);
PopUpCreate(pMenu, "Paste buffer is currently empty.", "", "cancel", "Continue", "", "", false);
}
}
}
Entity * EnterURLMenuCreate(Entity *pParentEnt)
{
Entity *pBG = CreateOverlayEntity(pParentEnt, "EnterURLMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
AddFocusIfNeeded(pBG);
Entity *pButtonEntity;
CL_Vec2f vTextAreaPos = iPhoneMap(25,40);
CL_Vec2f vTextAreaBounds = iPhoneMap(384,234);
string title = "`$Add-On Download from URL";
pButtonEntity = CreateTextLabelEntity(pBG, "title", vTextAreaPos.x, vTextAreaPos.y, title);
pButtonEntity->GetComponentByName("TextRender")->GetVar("font")->Set(uint32(FONT_LARGE));
pButtonEntity->GetVar("scale2d")->Set(CL_Vec2f(0.6f, 0.6f));
vTextAreaPos.y += iPhoneMapY(25);
string msg = "Enter a URL to a .dmod file to download and install. (example: http://rtsoft.com/NewQuest.dmod )";
switch (GetEmulatedPlatformID())
{
case PLATFORM_ID_WINDOWS:
msg = "Enter a URL to a .dmod file to download and install. (example: http://rtsoft.com/NewQuest.dmod ) Use Ctrl-V to paste from the clipboard.";
break;
}
Entity *pText = CreateTextBoxEntity(pBG, "text", vTextAreaPos, vTextAreaBounds, msg);
pButtonEntity = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(25), iPhoneMapY(284), "Back", false);
pButtonEntity->GetFunction("OnButtonSelected")->sig_function.connect(&EnterURLMenuOnSelect);
AddHotKeyToButton(pButtonEntity, VIRTUAL_KEY_BACK);
//the continue button
pButtonEntity = CreateTextButtonEntity(pBG, "Continue", iPhoneMapX(356), iPhoneMapY(284), "Continue", false);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&EnterURLMenuOnSelect);
//create button for pasting
if (GetEmulatedPlatformID() != PLATFORM_ID_WEBOS)
{
pButtonEntity = CreateTextButtonEntity(pBG, "paste", vTextAreaPos.x, vTextAreaPos.y+iPhoneMapX(80), "[tap here to paste]");
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&EnterURLMenuOnSelect);
}
//create input box
pButtonEntity = CreateInputTextEntity(pBG, "name_input_box", vTextAreaPos.x, vTextAreaPos.y+iPhoneMapX(49), GetApp()->GetShared()->GetVarWithDefault("dmod_download_url", string(""))->GetString(),
iPhoneMapX(450), 0);
pButtonEntity->GetComponentByName("InputTextRender")->GetVar("inputLengthMax")->Set(uint32(255));
pButtonEntity->GetComponentByName("InputTextRender")->GetVar("filtering")->Set(uint32(InputTextRenderComponent::FILTERING_LOOSE));
pButtonEntity->GetComponentByName("InputTextRender")->GetVar("inputType")->Set(uint32(InputTextRenderComponent::INPUT_TYPE_URL));
//pButtonEntity->GetComponentByName("InputTextRender")->GetVar("font")->Set(uint32(FONT_LARGE));
//a way to get our CreateTextBox function called in 500 seconds, but not called if the entity doesn't exist at that time
SlideScreen(pBG, true);
return pBG;
}

16
source/GUI/EnterURLMenu.h Normal file
View file

@ -0,0 +1,16 @@
// ***************************************************************
// EnterURLMenu - Creation date: 01/5/2010
// ------------------------------------------------------------
// Robinson Technologies Copyright (C) 2010 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef EnterURLMenu_h__
#define EnterURLMenu_h__
#include "App.h"
Entity * EnterURLMenuCreate(Entity *pParentEnt);
#endif // EnterURLMenu_h__

View file

@ -0,0 +1,28 @@
#include "PlatformPrecomp.h"
#include "ExpiredMenu.h"
#include "App.h"
#include "Entity/EntityUtils.h"
#include "Entity/CustomInputComponent.h"
void ExpiredMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
//LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
}
Entity * ExpiredMenuCreate(Entity *pParentEnt)
{
Entity *pBG = CreateOverlayEntity(pParentEnt, "ExpiredMenu", "interface/main_bg.rttex", 0,0);
AddFocusIfNeeded(pBG);
//for android, so the back key (or escape on windows) will quit out of the game
EntityComponent *pComp = pBG->AddComponent(new CustomInputComponent);
//tell the component which key has to be hit for it to be activated
pComp->GetFunction("OnActivated")->sig_function.connect(1, boost::bind(&App::OnExitApp, GetApp(), _1));
pComp->GetVar("keycode")->Set(uint32(VIRTUAL_KEY_BACK));
CreateTextLabelEntity(pBG, "text", 20, 100, "This beta has expired.\n\nPlease visit www.codedojo.com to see if there\nis a new one.");
return pBG;
}

5
source/GUI/ExpiredMenu.h Normal file
View file

@ -0,0 +1,5 @@
#ifndef ExpiredMenu_h__
#define ExpiredMenu_h__
class Entity;
Entity * ExpiredMenuCreate(Entity *pParentEnt);
#endif // ExpiredMenu_h__

1389
source/GUI/GameMenu.cpp Normal file

File diff suppressed because it is too large Load diff

16
source/GUI/GameMenu.h Normal file
View file

@ -0,0 +1,16 @@
#ifndef Game_h__
#define Game_h__
#include "App.h"
Entity * GameCreate(Entity *pParentEnt, int gameIDToLoad, string stateToLoad, string msgToShow = "");
void KillControls(float fadeTimeMS = 300);
void BuildControls(float fadeTimeMS = 300);
void UpdateControlsGUIIfNeeded();
void ShowQuickMessage(string msg);
void GameOnSelect(VariantList *pVList);
CL_Vec2f FlipXIfNeeded(CL_Vec2f vPos);
float FlipXIfNeeded(float x);
bool IsInFlingMode();
#endif // Game_h__

127
source/GUI/LoadMenu.cpp Normal file
View file

@ -0,0 +1,127 @@
#include "PlatformPrecomp.h"
#include "LoadMenu.h"
#include "Entity/EntityUtils.h"
#include "MainMenu.h"
#include "dink/dink.h"
#include "GameMenu.h"
#define C_SAVE_GAME_COUNT 10
void LoadMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity", pEntClicked->GetName().c_str());
if (pEntClicked->GetName() == "Back")
{
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
MainMenuCreate(pEntClicked->GetParent()->GetParent());
//LoadMenuCreate(GetParent()
}
int num = atol(pEntClicked->GetName().c_str());
if (num > 0)
{
//let's load this sucka
DisableAllButtonsEntity(pEntClicked->GetParent());
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
if (num == 10)
{
string fName = GetSavePath()+"dink/"+"autosave.dat";
GameCreate(pEntClicked->GetParent()->GetParent(), 0, fName);
} else
{
GameCreate(pEntClicked->GetParent()->GetParent(), num, "");
}
}
GetEntityRoot()->PrintTreeAsText(); //useful for Loading
}
void SetupLoadButton(Entity *pParent, int x, float *pY, int gameID)
{
gameID++; //it's 1 based, not 0 based
const float ySpacer = 46;
if (gameID > 5) x += 200;
char stTemp[256];
char stFormatted[256];
string clickKey = ""; //none
int gameTime;
if (gameID == 10)
{
string autoSave = DinkGetSavePath() + "autosave.dat";
if (!FileExists(autoSave))
{
sprintf(stFormatted, "Auto Save - None yet", gameID);
} else
{
gameTime = 0;
string description = "Unknown";
VariantDB db;
bool bFileExisted = false;
if (db.Load(DinkGetSavePath()+"autosavedb.dat", &bFileExisted, false) && bFileExisted )
{
gameTime = db.GetVar("minutes")->GetUINT32();
description = db.GetVar("description")->GetString();
}
sprintf(stFormatted, "Auto Save - %d:%02d - %s", (gameTime / 60), gameTime - ((gameTime / 60) * 60), description.c_str());
clickKey = toString(gameID);
}
} else
if (load_game_small(gameID, stTemp, &gameTime))
{
sprintf(stFormatted, "Slot %d - %d:%02d - %s", gameID, (gameTime / 60), gameTime - ((gameTime / 60) * 60) , stTemp);
clickKey = toString(gameID);
} else
{
sprintf(stFormatted, "Slot %d - Empty", gameID);
}
string butText = stFormatted;
Entity * pButtonEntity = CreateTextButtonEntity(pParent, clickKey, iPhoneMapX(x), iPhoneMapY(*pY), butText, false); *pY += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&LoadMenuOnSelect);
//pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
}
Entity * LoadMenuCreate(Entity *pParentEnt)
{
Entity *pBG = CreateOverlayEntity(pParentEnt, "LoadMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
AddFocusIfNeeded(pBG, true);
Entity *pButtonEntity;
float x = 80;
float yStart = 40;
float y = yStart;
float ySpacer = 50;
for (int i=0; i < C_SAVE_GAME_COUNT; i++)
{
if (i == 5) y = yStart;
SetupLoadButton(pBG, x, &y, i);
}
pButtonEntity = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(x), iPhoneMapY(y), "Back"); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&LoadMenuOnSelect);
//pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SlideScreen(pBG, true, 500);
return pBG;
}

7
source/GUI/LoadMenu.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef LoadMenu_h__
#define LoadMenu_h__
#include "App.h"
Entity * LoadMenuCreate(Entity *pParentEnt);
#endif // LoadMenu_h__

98
source/GUI/LogMenu.cpp Normal file
View file

@ -0,0 +1,98 @@
#include "PlatformPrecomp.h"
#include "LogMenu.h"
#include "Entity/EntityUtils.h"
#include "dink/dink.h"
#include "MainMenu.h"
void LogEnd(Entity *pMenu)
{
//slide it off the screen and then kill the whole menu tree
RemoveFocusIfNeeded(pMenu);
//SlideScreen(pEntClicked->GetParent(), false);
AddFocusIfNeeded(pMenu->GetParent());
FadeOutEntity(pMenu, true, 499);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
}
void LogMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity", pEntClicked->GetName().c_str());
Entity *pMenu = GetEntityRoot()->GetEntityByName("LogMenu");
if (pEntClicked->GetName() == "Back")
{
LogEnd(pMenu);
}
GetEntityRoot()->PrintTreeAsText(); //useful for Log
}
void LogAddScrollContent(Entity *pParent)
{
pParent = pParent->GetEntityByName("scroll_child");
float x = iPhoneMapX(5);
float y = 0;
CL_Vec2f vTextBoxPos(iPhoneMapX(20),y);
CL_Vec2f vTextBounds(iPhoneMapX(434), iPhoneMapY(200));
string msg = GetBaseApp()->GetConsole()->GetAsSingleString();
CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, msg, 0.7f);
VariantList vList(pParent->GetParent());
ResizeScrollBounds(&vList);
}
Entity * LogMenuCreate(Entity *pParentEnt)
{
Entity *pBG = CreateOverlayRectEntity(pParentEnt, CL_Vec2f(0,0), GetScreenSize(), MAKE_RGBA(0,0,0,140));
pBG->SetName("LogMenu");
AddFocusIfNeeded(pBG, true);
Entity *pButtonEntity;
//setup a scrolling window
CL_Vec2f vTextAreaPos = CL_Vec2f(0,0);
float offsetFromBottom = iPhoneMapY(30);
CL_Vec2f vTextAreaBounds = GetScreenSize()-CL_Vec2f(15,offsetFromBottom);
Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);
EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position
pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255));
Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
pScrollComp->GetVar("fingerTracking")->Set(uint32(1));
EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
//Entity *pOverlay = CreateOverlayEntity(pBG, "", ReplaceWithDeviceNameInFileName("interface/iphone/bg_stone_overlay.rttex"), 0, GetScreenSizeYf());
//SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
LogAddScrollContent(pBG);
VariantList vList(CL_Vec2f(0.0f, 1.0f));
pScrollComp->GetFunction("SetProgress")->sig_function(&vList); //scroll to the end
pButtonEntity = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(35), iPhoneMapY(300), "CONTINUE", false);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&LogMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
AddHotKeyToButton(pButtonEntity, VIRTUAL_KEY_BACK);
FadeInEntity(pBG, true);
return pBG;
}

8
source/GUI/LogMenu.h Normal file
View file

@ -0,0 +1,8 @@
#ifndef LogMenu_h__
#define LogMenu_h__
#include "App.h"
Entity * LogMenuCreate(Entity *pParentEnt);
#endif // LogMenu_h__

601
source/GUI/MainMenu.cpp Normal file
View file

@ -0,0 +1,601 @@
#include "PlatformPrecomp.h"
#include "MainMenu.h"
#include "Entity/EntityUtils.h"
#include "DebugMenu.h"
#include "GameMenu.h"
#include "LoadMenu.h"
#include "dink/dink.h"
#include "DMODMenu.h"
#include "PauseMenu.h"
#include "DMODInstallMenu.h"
#include "PopUpMenu.h"
#include "OptionsMenu.h"
#include "AboutMenu.h"
#include "FileSystem/StreamingInstance.h"
#include "Entity/CustomInputComponent.h"
#include "Entity/HTTPComponent.h"
bool g_bMainMenuFirstTime = true;
bool g_bDidVersionCheck = false;
Entity * VersionShowScoreMessage(Entity *pMenu, string msg);
void ReloadMainMenu(VariantList *pVList)
{
MainMenuCreate(pVList->Get(0).GetEntity());
}
void OnVersionDownloadError(VariantList *pVList)
{
NetHTTP::eError e = (NetHTTP::eError)pVList->m_variant[1].GetUINT32();
string msg = "`4Unable to check for updates. (" + toString(e) + ")";
if (e == NetHTTP::ERROR_COMMUNICATION_TIMEOUT)
{
msg = "`4Unable to check for updates. (timed out)";
}
Entity *pMenu = pVList->m_variant[0].GetComponent()->GetParent();
VersionShowScoreMessage(pMenu, msg);
//kill current menu
GetMessageManager()->CallEntityFunction(pMenu, 1000, "OnDelete", NULL);
//reload the main menu in a bit
VariantList vList(pMenu->GetParent());
GetMessageManager()->CallStaticFunction(ReloadMainMenu, 1000, &vList, TIMER_SYSTEM);
}
Entity * VersionShowScoreMessage(Entity *pMenu, string msg)
{
Entity *pInfo = pMenu->GetEntityByName("Info");
if (pInfo)
{
pInfo->GetComponentByName("TextRender")->GetVar("text")->Set(msg);
pInfo->RemoveComponentByName("Typer"); // a thing that types stuff
}
else
{
pInfo = CreateTextLabelEntity(pMenu, "Info", iPhoneMapX(130), iPhoneMapY(220), msg);
}
return pInfo;
}
void OnVersionDownloadHTTPFinish(VariantList *pVList)
{
Entity *pMenu = pVList->m_variant[0].GetComponent()->GetParent();
TextScanner t((char*)pVList->m_variant[1].GetString().c_str());
string line;
LogMsg(t.GetAll().c_str());
// ShowScoreMessage(pMenu, t.GetParmString("msg",1));
//GetApp()->GetVar("score_msg")->Set(t.GetParmString("msg",1));
string key = PlatformIDAsString(GetEmulatedPlatformID());
#ifdef RT_IS_BETA
key += "_beta";
#endif
vector<string> lines;
for (int i = 0; i < t.GetLineCount(); i++)
{
lines = StringTokenize(t.GetLine(i), "|");
if (lines.size() > 2 && lines[0] == key)
{
VersionShowScoreMessage(pMenu, "");
float version = StringToFloat(lines[1]);
if (version > GetApp()->GetVersion() + 0.001f) //the extra for an epsilon to flight floating point weirdness, trust me
{
PopUpCreate(pMenu, "New version detected! Download it now?", lines[2],
"cancel_update", "`wCancel", "url_update", "`wDownload", true);
return;
}
}
}
VersionShowScoreMessage(pMenu, "No new updates found.");
//kill current menu
GetMessageManager()->CallEntityFunction(pMenu, 1000, "OnDelete", NULL);
//reload the main menu in a bit
VariantList vList(pMenu->GetParent());
GetMessageManager()->CallStaticFunction(ReloadMainMenu, 1000, &vList, TIMER_SYSTEM);
}
void MainMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
if (pEntClicked->GetName() == "New")
{
DisableAllButtonsEntity(pEntClicked->GetParent());
InitDinkPaths(GetBaseAppPath(), "dink", "");
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
GameCreate(pEntClicked->GetParent()->GetParent(), 0, "");
GetApp()->GetVar("showViewHint")->Set(uint32(0)); //so this won't be shown here
}
if (pEntClicked->GetName() == "Load")
{
DisableAllButtonsEntity(pEntClicked->GetParent());
InitDinkPaths(GetBaseAppPath(), "dink", "");
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
LoadMenuCreate(pEntClicked->GetParent()->GetParent());
}
if (pEntClicked->GetName() == "Continue")
{
DisableAllButtonsEntity(pEntClicked->GetParent());
InitDinkPaths(GetBaseAppPath(), "dink", "");
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
GameCreate(pEntClicked->GetParent()->GetParent(), 0, GetSavePath()+"dink/"+string("continue_state.dat"));
}
if (pEntClicked->GetName() == "Debug")
{
//overlay the debug menu over this one
pEntClicked->GetParent()->RemoveComponentByName("FocusInput");
DebugMenuCreate(pEntClicked->GetParent());
}
if (pEntClicked->GetName() == "Add-ons")
{
DisableAllButtonsEntity(pEntClicked->GetParent());
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
// DMODInstallMenuCreate(pEntClicked->GetParent()->GetParent(), "files.dinknetwork.com/three_amulets-v1_1.dmod", "");
DMODMenuCreate(pEntClicked->GetParent()->GetParent());
}
if (pEntClicked->GetName() == "Options")
{
//DisableAllButtonsEntity(pEntClicked->GetParent());
pEntClicked->GetParent()->RemoveComponentByName("FocusInput");
pEntClicked->GetParent()->RemoveComponentByName("FocusUpdate");
//SlideScreen(pEntClicked->GetParent(), false);
//GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
OptionsMenuCreate(pEntClicked->GetParent());
}
if (pEntClicked->GetName() == "About")
{
DisableAllButtonsEntity(pEntClicked->GetParent());
//RemoveFocusIfNeeded(pEntClicked->GetParent()); //slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
AboutMenuCreate(pEntClicked->GetParent()->GetParent());
}
if (pEntClicked->GetName() == "rtsoftlogo")
{
PopUpCreate(pEntClicked->GetParent(), "Would you like to visit `wrtsoft.com``?", "http://www.rtsoft.com/iphone",
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
string GetNextDMODToInstall()
{
//if (!GetApp()->CanDownloadDMODS()) return ""; //ignore it
vector<string> files = GetFilesAtPath(GetSavePath());
//LogMsg("listing files");
for (unsigned int i=0; i < files.size(); i++)
{
//LogMsg(files[i].c_str());
if (GetFileExtension(files[i]) == "dmod")
{
return files[i];
}
}
return "";
}
void MainOnStartLoading(VariantList *pVList)
{
Entity *pBG = pVList->m_variant[0].GetEntity();
string fileName = pVList->m_variant[1].GetString();
DisableAllButtonsEntity(pBG);
SlideScreen(pBG, false);
GetMessageManager()->CallEntityFunction(pBG, 500, "OnDelete", NULL);
string fName = GetNextDMODToInstall();
if (!fName.empty())
{
DMODInstallMenuCreate(pBG->GetParent(), "", GetDMODRootPath(), GetSavePath()+fName);
} else
{
GameCreate(pBG->GetParent(), 0, fileName, "Continuing last game...");
}
}
void ImportSaveFileIfApplicable(string fName)
{
if (GetFileExtension(fName) != "dat") return;
if (fName == "save.dat") return; //it's not this one
if (fName == "state.dat") return; //it's not this one
if (fName == "continue_state.dat") return; //it's not this one
if (fName == "autosave.dat") return; //it's not this one
if (fName == "autosavedb.dat") return; //it's not this one
if (fName == "quicksave.dat") return; //it's not this one
if (fName == "quickload.dat") return; //it's not this one
//check for any dmod name specified after a _
size_t index = fName.find_last_of('_');
size_t periodPos = fName.find_last_of('.');
if (periodPos == string::npos || GetFileExtension(fName) != "dat") return;
string dmodName = "";
if (index != string::npos)
{
//yeah, it has one
dmodName = fName.substr(index+1, periodPos-(index+1));
}
//ok, ready to copy it. But figure out where, and what the filename should be
string destPath = GetSavePath()+"dink/";
string destFile = fName;
//modify if needed for a dmod
if (!dmodName.empty())
{
destPath = GetDMODRootPath()+dmodName+"/";
destFile = fName.substr(0, index);
destFile += fName.substr(periodPos, fName.size()-periodPos);
}
LogMsg("Importing %s to %s", (GetSavePath()+fName).c_str(), (destPath+destFile).c_str());
GetFileManager()->Copy(GetSavePath()+fName, destPath+destFile, false);
RemoveFile(GetSavePath()+fName, false);
}
void CheckForImportedSavedGames()
{
if (!GetEmulatedPlatformID() == PLATFORM_ID_IOS) return;
vector<string> files = GetFilesAtPath(GetSavePath());
for (uint32 i=0; i < files.size(); i++)
{
ImportSaveFileIfApplicable(files[i]);
}
}
void MainMenuContinueLast(VariantList *pVList)
{
Entity *pBG = pVList->Get(0).GetEntity();
pBG->GetFunction("OnStartLoading")->sig_function.connect(&MainOnStartLoading);
VariantList vList(pBG, GetSavePath()+string("state.dat"));
GetMessageManager()->CallEntityFunction(pBG, 1000, "OnStartLoading", &vList);
g_bMainMenuFirstTime = false;
LogMsg("Continuing");
}
void MainMenuContinueLastNewStyle(VariantList *pVList)
{
Entity *pBG = pVList->Get(0).GetEntity();
pBG->GetFunction("OnStartLoading")->sig_function.connect(&MainOnStartLoading);
VariantList vList(pBG, ReadLastPathSaved()+string("continue_state.dat"));
GetMessageManager()->CallEntityFunction(pBG, 1000, "OnStartLoading", &vList);
g_bMainMenuFirstTime = false;
WriteLastPathSaved("");
LogMsg("Contining");
}
void MainMenuCancelLast(VariantList *pVList)
{
Entity *pMenu = pVList->Get(0).GetEntity();
WriteLastPathSaved("");
RemoveFile(GetSavePath()+"state.dat", false);
//kill current menu
GetMessageManager()->CallEntityFunction(pMenu, 0, "OnDelete", NULL);
//reload the main menu
MainMenuCreate(pMenu->GetParent());
}
void CheckForNewVersion(Entity *pMenu)
{
pMenu->RemoveComponentByName("HTTP"); //just in case it already exists
//get the internet stuff going
EntityComponent *pComp = pMenu->AddComponent(new HTTPComponent);
VariantList vPostData;
vPostData.m_variant[0].Set("version");
vPostData.m_variant[1].Set(toString(GetApp()->GetVersion()));
pComp->GetFunction("AddPostData")->sig_function(&vPostData);
vPostData.m_variant[0].Set("build");
vPostData.m_variant[1].Set(toString(GetApp()->GetBuild()));
pComp->GetFunction("AddPostData")->sig_function(&vPostData);
vPostData.m_variant[0].Set("platform");
vPostData.m_variant[1].Set(toString(GetEmulatedPlatformID()));
pComp->GetFunction("AddPostData")->sig_function(&vPostData);
VariantList v;
string url;
uint32 port;
GetApp()->GetServerInfo(url, port);
v.m_variant[0].Set(url);
v.m_variant[1].Set(port);
v.m_variant[2].Set("dink/versions.php");
pComp->GetFunction("OnError")->sig_function.connect(&OnVersionDownloadError);
pComp->GetFunction("OnFinish")->sig_function.connect(&OnVersionDownloadHTTPFinish);
pComp->GetFunction("Init")->sig_function(&v);
Entity *pEnt = VersionShowScoreMessage(pMenu, "`6");
EntityComponent *pTyper = pEnt->AddComponent(new TyperComponent);
pTyper->GetVar("text")->Set("Checking rtsoft.com for updates...");
pTyper->GetVar("speedMS")->Set(uint32(50));
}
Entity * MainMenuCreate( Entity *pParentEnt, bool bFadeIn )
{
CheckForImportedSavedGames();
GetApp()->GetVar("showViewHint")->Set(uint32(1)); //show that one tip
Entity *pBG = CreateOverlayEntity(pParentEnt, "MainMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
OverlayRenderComponent *pOverlay = (OverlayRenderComponent*) pBG->GetComponentByName("OverlayRender");
if (!pOverlay->GetSurfaceAnim())
{
LogMsg("Can't find media. If running from Visual Studio, make sure you set the active dir to ../bin first!");
#ifdef WINAPI
MessageBox(NULL, "Can't find media. If running from Visual Studio, make sure you set the active dir to ../bin and have run media/update_media.bat first!", "Woah nelly!" , 0);
#endif
}
//Entity *pBG = pParentEnt->AddEntity(new Entity);
GetBaseApp()->ClearError();
AddFocusIfNeeded(pBG, true);
pBG->GetFunction("ContinueLast")->sig_function.connect(&MainMenuContinueLast);
pBG->GetFunction("ContinueLastNewStyle")->sig_function.connect(&MainMenuContinueLastNewStyle);
pBG->GetFunction("CancelLast")->sig_function.connect(&MainMenuCancelLast);
Entity *pButtonEntity;
float x = 50;
float yStart = 200;
float y = yStart;
float ySpacer = 55;
eFont fontID = FONT_LARGE;
float fontScale = 1;
float fireAnimY = 240;
CL_Vec2f vRtsoftLogoPt = CL_Vec2f(402, 149);
CL_Vec2f vNewButPt = CL_Vec2f(26, 199);
CL_Vec2f vLoadButPt = CL_Vec2f(135, 199);
CL_Vec2f vAddonButPt = CL_Vec2f(26, 245);
CL_Vec2f vContinueButPt = CL_Vec2f(246, 198);
CL_Vec2f vAboutButPt = CL_Vec2f(251, 245);
CL_Vec2f vOptionsButPt = CL_Vec2f(360, 246);
if (IsIPADSize)
{
vNewButPt = CL_Vec2f(0, 468);
vLoadButPt = CL_Vec2f(256, 468);
fireAnimY = GetScreenSizeYf()-256;
vRtsoftLogoPt = CL_Vec2f(830, 370);
vAddonButPt = CL_Vec2f(13, 565);
vContinueButPt = CL_Vec2f(525, 468);
vAboutButPt = CL_Vec2f(525, 565);
vOptionsButPt = CL_Vec2f(748, 565);
} else if (IsIphone4Size)
{
vNewButPt = CL_Vec2f(66, 364);
vLoadButPt = CL_Vec2f(277, 362);
fireAnimY = GetScreenSizeYf()-160;
vRtsoftLogoPt = CL_Vec2f(775, 262);
vAddonButPt = CL_Vec2f(67, 453);
vContinueButPt = CL_Vec2f(498, 364 );
vAboutButPt = CL_Vec2f(512, 454);
vOptionsButPt = CL_Vec2f(716, 455);
}
#ifdef RT_IS_BETA
Entity *pText = CreateTextLabelEntity(pBG, "text", GetScreenSizeXf()/2, GetScreenSizeYf()-20,
"`wBeta Version("+GetApp()->GetVersionString()+")");
SetAlignmentEntity(pText, ALIGNMENT_CENTER);
#endif
if (!g_bDidVersionCheck && IsDesktop())
{
g_bDidVersionCheck = true;
CheckForNewVersion(pBG);
return pBG;
}
Entity *pEntDinkLogo = CreateOverlayEntity(pBG, "dinklogo", ReplaceWithDeviceNameInFileName("interface/iphone/logo_dink.rttex"), 0, 0);
pButtonEntity = CreateOverlayEntity(pBG, "flameAnim", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_anim_fire.rttex"), 0, fireAnimY);
SetupAnimEntity(pButtonEntity, 1, 4, 0, 0);
AnimateEntity(pButtonEntity, 0, 3, 125, InterpolateComponent::ON_FINISH_REPEAT, 0);
//for android, so the back key (or escape on windows/OSX) will quit out of the game
EntityComponent *pComp = pBG->AddComponent(new CustomInputComponent);
//tell the component which key has to be hit for it to be activated
pComp->GetFunction("OnActivated")->sig_function.connect(1, boost::bind(&App::OnExitApp, GetApp(), _1));
pComp->GetVar("keycode")->Set(uint32(VIRTUAL_KEY_BACK));
pButtonEntity = CreateOverlayButtonEntity(pBG, "rtsoftlogo", ReplaceWithDeviceNameInFileName("interface/iphone/logo_rtsoft.rttex"), vRtsoftLogoPt.x, vRtsoftLogoPt.y);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0, 0, 0, -10)); //no padding, it overlaps other buttons..
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
FadeInEntity(pButtonEntity, false, 300, 1000);
if ( ! GetNextDMODToInstall().empty())
{
pBG->GetFunction("OnStartLoading")->sig_function.connect(&MainOnStartLoading);
VariantList vList(pBG, string(""));
GetMessageManager()->CallEntityFunction(pBG, 1000, "OnStartLoading", &vList);
} else
{
if (FileExists(GetSavePath()+"state.dat"))
{
PopUpCreate(pBG, "Continue your last session?", "", "CancelLast", "Cancel", "ContinueLast", "Continue", true);
return pBG;
} else if (!ReadLastPathSaved().empty())
{
PopUpCreate(pBG, "Continue your last session?", "", "CancelLast", "Cancel", "ContinueLastNewStyle", "Continue", true);
return pBG;
} else
{
if (g_bMainMenuFirstTime)
{
#ifdef RT_MOGA_ENABLED
ShowTextMessage("Moga enabled test version - not for distribution");
#endif
PlayMenuMusic();
}
ZoomToPositionFromThisOffsetEntity(pEntDinkLogo, CL_Vec2f(0, -300), 2000, INTERPOLATE_EASE_TO, 5);
pButtonEntity = CreateOverlayButtonEntity(pBG, "New", ReplaceWithDeviceNameInFileName("interface/iphone/main_but_new.rttex"), vNewButPt.x, vNewButPt.y);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0,0,0,0));
FadeInEntity(pButtonEntity, false, 500, 100);
//SetupTextEntity(pButtonEntity, fontID, fontScale);
pButtonEntity = CreateOverlayButtonEntity(pBG, "Add-ons", ReplaceWithDeviceNameInFileName("interface/iphone/main_but_addon10.rttex"), vAddonButPt.x, vAddonButPt.y);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
//SetupTextEntity(pButtonEntity, fontID, fontScale);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0,0,0,0));
FadeInEntity(pButtonEntity, false, 500, 1000);
pButtonEntity = CreateOverlayButtonEntity(pBG, "Load", ReplaceWithDeviceNameInFileName("interface/iphone/main_but_load.rttex"), vLoadButPt.x, vLoadButPt.y);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
//SetupTextEntity(pButtonEntity, fontID, fontScale);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0,0,0,0));
FadeInEntity(pButtonEntity, false, 500, 400);
pButtonEntity = CreateOverlayButtonEntity(pBG, "Continue", ReplaceWithDeviceNameInFileName("interface/iphone/main_but_continue.rttex"), vContinueButPt.x, vContinueButPt.y);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0,0,0,0));
FadeInEntity(pButtonEntity, false, 500, 700);
if (!FileExists(GetSavePath()+"dink/"+string("continue_state.dat")))
{
pButtonEntity->GetVar("color")->Set(MAKE_RGBA(100,100,100,255));
DisableAllButtonsEntity(pButtonEntity, false);
}
pButtonEntity = CreateOverlayButtonEntity(pBG, "About", ReplaceWithDeviceNameInFileName("interface/iphone/main_but_about.rttex"), vAboutButPt.x, vAboutButPt.y);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0,0,0,0));
FadeInEntity(pButtonEntity, false, 500, 1300);
pButtonEntity = CreateOverlayButtonEntity(pBG, "Options", ReplaceWithDeviceNameInFileName("interface/iphone/main_but_options.rttex"), vOptionsButPt.x, vOptionsButPt.y);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
SetTouchPaddingEntity(pButtonEntity, CL_Rectf(0,0,0,0));
FadeInEntity(pButtonEntity, false, 500, 1500);
DestroyUnusedTextures();
}
//pButtonEntity = CreateTextButtonEntity(pBG, "Debug", x, y, "Debug and MP3 Music"); y += ySpacer;
//pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&MainMenuOnSelect);
//pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
}
if (bFadeIn)
{
FadeInEntity(pBG, true, 500, 0);
} else
{
if (g_bMainMenuFirstTime)
{
g_bMainMenuFirstTime = false;
} else
{
SlideScreen(pBG, true);
}
}
return pBG;
}
Entity * AddTitle( Entity *pEnt, string title)
{
Entity *pTitle;
float titleHeight = 25;
float scale = 1;
float x = 480/2;
pTitle = CreateTextLabelEntity(pEnt, "Title", x, titleHeight, title);
pTitle->GetVar("scale2d")->Set(CL_Vec2f(scale, scale));
pTitle->GetComponentByName("TextRender")->GetVar("font")->Set(uint32(FONT_LARGE));
EntityRetinaRemapIfNeeded(pTitle, true, false, true);
pTitle->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
return pTitle;
}

9
source/GUI/MainMenu.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef MainMenu_h__
#define MainMenu_h__
#include "App.h"
#define BACK_BUTTON_Y 293
Entity * MainMenuCreate(Entity *pParentEnt, bool bFadeIn = false);
Entity * AddTitle( Entity *pEnt, string title);
#endif // MainMenu_h__

552
source/GUI/OptionsMenu.cpp Normal file
View file

@ -0,0 +1,552 @@
#include "PlatformPrecomp.h"
#include "OptionsMenu.h"
#include "Entity/EntityUtils.h"
#include "App.h"
#include "../dink/Dink.h"
#include "Entity/SliderComponent.h"
#include "MainMenu.h"
#include "PauseMenu.h"
#include "GameMenu.h"
#include "Gamepad/GamepadManager.h"
#include "PopUpMenu.h"
#ifdef PLATFORM_IOS
#include "Gamepad/GamepadProvider60Beat.h"
#endif
#include "Gamepad/GamepadProvideriCade.h"
void UpdateOptionsGUI();
void OptionsMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
Entity *pMenu = pEntClicked->GetParent();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
if (pEntClicked->GetName() == "music_0")
{
GetApp()->GetShared()->GetVar("musicDisabled")->Set(uint32(1));
GetAudioManager()->SetMusicEnabled(0);
}
if (pEntClicked->GetName() == "music_1")
{
GetApp()->GetShared()->GetVar("musicDisabled")->Set(uint32(0));
GetAudioManager()->SetMusicEnabled(1);
}
if (pEntClicked->GetName() == "toggle_fullscreen")
{
GetBaseApp()->OnFullscreenToggleRequest();
//if you wanted to set a specific size instead:
//GetBaseApp()->SetVideoMode(200, 200, false);
}
if (pEntClicked->GetName() == "vid_small")
{
GetBaseApp()->SetVideoMode(640, 480, false);
}
if (pEntClicked->GetName() == "vid_med")
{
GetBaseApp()->SetVideoMode(1024, 768, false);
}
if (pEntClicked->GetName() == "vid_big")
{
GetBaseApp()->SetVideoMode(1280, 960, false);
}
if (pEntClicked->GetName() == "controls_0")
{
GetApp()->GetShared()->GetVar("controlStyle")->Set(uint32(CONTROLS_JOYPAD));
}
if (pEntClicked->GetName() == "controls_1")
{
GetApp()->GetShared()->GetVar("controlStyle")->Set(uint32(CONTROLS_DRAG_ANYWHERE));
}
if (pEntClicked->GetName() == "controls_2")
{
GetApp()->GetShared()->GetVar("controlStyle")->Set(uint32(CONTROLS_FLING));
}
if (pEntClicked->GetName() == "buttons_0")
{
GetApp()->GetShared()->GetVar("buttons")->Set(uint32(0));
}
if (pEntClicked->GetName() == "buttons_1")
{
GetApp()->GetShared()->GetVar("buttons")->Set(uint32(1));
}
if (pEntClicked->GetName() == "fps_limit_0")
{
GetApp()->GetShared()->GetVar("fpsLimit")->Set(uint32(VIDEO_FPS_LIMIT_ON));
GetApp()->UpdateVideoSettings();
}
if (pEntClicked->GetName() == "fps_limit_1")
{
GetApp()->GetShared()->GetVar("fpsLimit")->Set(uint32(VIDEO_FPS_LIMIT_OFF));
GetApp()->UpdateVideoSettings();
}
if (pEntClicked->GetName() == "smoothing_0")
{
GetApp()->GetShared()->GetVar("smoothing")->Set(uint32(1));
GetApp()->UpdateVideoSettings();
DinkUnloadUnusedGraphicsByUsageTime(0); //unload anything not used in the last second
DinkReInitSurfacesAfterVideoChange();
DinkOnForeground();
}
if (pEntClicked->GetName() == "smoothing_1")
{
GetApp()->GetShared()->GetVar("smoothing")->Set(uint32(0));
GetApp()->UpdateVideoSettings();
DinkUnloadUnusedGraphicsByUsageTime(0); //unload anything not used in the last second
DinkReInitSurfacesAfterVideoChange();
DinkOnForeground();
}
if (pEntClicked->GetName() == "check_stretch")
{
bool bChecked = IsCheckboxChecked(pEntClicked);
GetApp()->GetVar("check_stretch")->Set(uint32(bChecked));
GetApp()->UpdateVideoSettings();
DinkUnloadUnusedGraphicsByUsageTime(0); //unload anything not used in the last second
DinkReInitSurfacesAfterVideoChange();
DinkOnForeground();
}
if (pEntClicked->GetName() == "sbeat_ad")
{
string url = "http://www.60beat.com/?Click=326";
PopUpCreate(pEntClicked->GetParent()->GetParent()->GetParent(), "Would you like to visit 60beat's webpage and learn more about their gamepad?", url,
"cancel", "`wCancel", "url", "`wLaunch", true);
return;
}
if (pEntClicked->GetName() == "check_icade")
{
bool bChecked = IsCheckboxChecked(pEntClicked);
GetApp()->GetVar("check_icade")->Set(uint32(bChecked));
GetGamepadManager()->RemoveProviderByName("iCade");
GetApp()->RemoveAndroidKeyboardKeys();
if (bChecked)
{
GetApp()->AddIcadeProvider();
GetApp()->RemoveAndAttachAllAvailableGamepads();
} else
{
GetApp()->AddDroidKeyboardKeys();
//GetBaseApp()->SetAllowScreenDimming(true);
}
}
#ifdef PLATFORM_IOS
/*
if (pEntClicked->GetName() == "check_60beat")
{
bool bChecked = IsCheckboxChecked(pEntClicked);
GetApp()->GetVar("check_60beat")->Set(uint32(bChecked));
GetGamepadManager()->RemoveProviderByName("60Beat");
if (bChecked)
{
GetGamepadManager()->AddProvider(new GamepadProvider60Beat);
GetBaseApp()->SetAllowScreenDimming(false);
GetApp()->RemoveAndAttachAllAvailableGamepads();
} else
{
//GetBaseApp()->SetAllowScreenDimming(true);
}
}
*/
#endif
if (pEntClicked->GetName() == "Back")
{
RemoveFocusIfNeeded(pMenu);
ZoomToPositionEntity(pMenu, CL_Vec2f(GetScreenSizeXf(),0), 500); //slide up
KillEntity(pMenu, 500);
AddFocusIfNeeded(pMenu->GetParent(), true, 500);
}
if (pEntClicked->GetName() == "sound_1")
{
GetApp()->GetShared()->GetVar("sound")->Set(uint32(1));
GetAudioManager()->SetSoundEnabled(true);
//restart music if applicable
bool bMusicDisabled = GetApp()->GetShared()->GetVar("musicDisabled")->GetUINT32() != 0;
if (GetDinkGameState() == DINK_GAME_STATE_PLAYING)
{
} else
{
PlayMenuMusic();
}
UpdateOptionsGUI();
return;
}
if (pEntClicked->GetName() == "sound_0")
{
GetApp()->GetShared()->GetVar("sound")->Set(uint32(0));
GetAudioManager()->SetSoundEnabled(false);
GetAudioManager()->StopMusic();
UpdateOptionsGUI();
return;
}
if (pEntClicked->GetName() == "FPS")
{
GetBaseApp()->SetFPSVisible(!GetBaseApp()->GetFPSVisible());
return;
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
void OnProgressChangedMusic(Variant *pDataObject)
{
float musicVol = pDataObject->GetFloat();
GetApp()->GetVar("music_vol")->Set(musicVol);
//LogMsg("Music vol changed to %.2f", musicVol);
GetAudioManager()->SetMusicVol(musicVol);
}
void OnProgressChangedGUI(Variant *pDataObject)
{
float guiTrans = pDataObject->GetFloat();
GetApp()->GetVar("gui_transparency")->Set(guiTrans);
UpdateOptionsGUI();
}
void UpdateOptionsGUI()
{
float alpha = GetApp()->GetVar("gui_transparency")->GetFloat();
Entity *inventoryIcon = GetEntityRoot()->GetEntityByName("options_inventory");
if (inventoryIcon)
{
inventoryIcon->GetVar("alpha")->Set( alpha);
}
bool bSound = GetApp()->GetShared()->GetVar("sound")->GetUINT32() != 0;
if (bSound)
{
//enable the music slider
}
}
void OptionsMenuAddScrollContent(Entity *pParent)
{
pParent = pParent->GetEntityByName("scroll_child");
pParent->RemoveAllEntities();
Entity *pBG = pParent;
Entity *pEnt;
float y = iPhoneMapY(70);
float startX = iPhoneMapX(28);
float offsetX = iPhoneMapX(0);
float spacerX = iPhoneMapX(46);
float spacerY = iPhoneMapY(40);
float columnX = 140;
eFont fontID = FONT_SMALL;
//title at the top
pEnt = CreateTextLabelEntity(pBG, "title", GetScreenSizeXf()/2, iPhoneMapY(40), "Options");
SetupTextEntity(pEnt, FONT_LARGE);
SetAlignmentEntity(pEnt, ALIGNMENT_CENTER);
if (IsDesktop())
{
pEnt = CreateTextButtonEntity(pBG, "toggle_fullscreen", startX, y, "Toggle fullscreen (or Alt-Enter)");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
y += spacerY;
pEnt = CreateTextButtonEntity(pBG, "vid_small", startX, y, "640X480");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
pEnt = CreateTextButtonEntity(pBG, "vid_med", startX+350, y, "1024X768");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
pEnt = CreateTextButtonEntity(pBG, "vid_big", startX+700, y, "1280X960");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
y += spacerY;
}
//control method
if (GetApp()->GetUsingTouchScreen())
{
pEnt = CreateTextLabelEntity(pBG, "", startX, y, "Controls:");
SetupTextEntity(pEnt,fontID);
offsetX = iPhoneMapX(columnX);
pEnt = CreateTextButtonEntity(pBG, "controls_0", offsetX, y, "Virtual Joypad", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
float smallSpacerX = spacerX;
if (IsIPADSize)
{
smallSpacerX = 34;
}
offsetX += pEnt->GetVar("size2d")->GetVector2().x + smallSpacerX;
pEnt = CreateTextButtonEntity(pBG, "controls_1", offsetX, y, "Drag Anywhere", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + smallSpacerX;
if (IsIPADSize)
{
pEnt = CreateTextButtonEntity(pBG, "controls_2", offsetX, y, "Fling Mode", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + smallSpacerX;
}
uint32 controlsID = GetApp()->GetVar("controlStyle")->GetUINT32();
SetupLightBarSelect(pBG, "controls_", controlsID, MAKE_RGBA(190, 0, 35, 255));
y += spacerY;
y += spacerY;
/*
if (GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
bool bUse60Beat = GetApp()->GetVar("check_60beat")->GetUINT32() != 0;
pEnt = CreateCheckbox(pBG, "check_60beat", "Use 60beat® GamePad", startX, y, bUse60Beat, FONT_SMALL, 1.0f);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
//add the image to the right
CL_Sizef vCheckBoxSizeWithText = MeasureEntityAndChildren(pEnt).get_size();
offsetX = startX + vCheckBoxSizeWithText.width+iPhoneMapX(20);
Entity *pAd = CreateOverlayButtonEntity(pBG, "sbeat_ad", "interface/sixtybeat_ad.rttex", offsetX, y+vCheckBoxSizeWithText.height/2);
pAd->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
SetAlignmentEntity(pAd, ALIGNMENT_LEFT_CENTER);
//We don't want it too big, scale it down if needed
EntityScaleiPad(pAd, true);
y += GetSize2DEntity(pAd).y;
//y += spacerY;
}
*/
//********* icade option
string bName = "iCade Controller Mode";
if (GetEmulatedPlatformID() == PLATFORM_ID_IOS)
{
//bName = "Bluetooth Arcade Stick Mode";
}
bool bUseicade = GetApp()->GetVar("check_icade")->GetUINT32() != 0;
pEnt = CreateCheckbox(pBG, "check_icade", "Use "+bName, startX, y, bUseicade, FONT_SMALL, 1.0f);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
y += GetSize2DEntity(pEnt).y;
y += spacerY;
pEnt = CreateTextLabelEntity(pBG, "", startX, y, "GUI Icons:");
SetupTextEntity(pEnt,fontID);
offsetX = iPhoneMapX(columnX);
pEnt = CreateTextButtonEntity(pBG, "buttons_0", offsetX, y, "Right side", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
pEnt = CreateTextButtonEntity(pBG, "buttons_1", offsetX, y, "Left side", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
uint32 buttons = GetApp()->GetVar("buttons")->GetUINT32();
SetupLightBarSelect(pBG, "buttons_", buttons, MAKE_RGBA(190, 0, 35, 255));
y += spacerY;
}
bool bStretchToFit = GetApp()->GetVar("check_stretch")->GetUINT32() != 0;
pEnt = CreateCheckbox(pBG, "check_stretch", "Force screen stretching (ignore aspect ratio)", startX, y, bStretchToFit, FONT_SMALL, 1.0f);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
y += GetSize2DEntity(pEnt).y;
y += spacerY;
//fps limit
pEnt = CreateTextLabelEntity(pBG, "", startX, y, "FPS lock:");
SetupTextEntity(pEnt,fontID);
offsetX = iPhoneMapX(columnX);
pEnt = CreateTextButtonEntity(pBG, "fps_limit_0", offsetX, y, "On", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
pEnt = CreateTextButtonEntity(pBG, "fps_limit_1", offsetX, y, "Off", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
uint32 videoFPS = GetApp()->GetVar("fpsLimit")->GetUINT32();
SetupLightBarSelect(pBG, "fps_limit_", videoFPS, MAKE_RGBA(190, 0, 35, 255));
if (GetPlatformID() != PLATFORM_ID_IOS)
{
y += spacerY;
//audio on/off button
pEnt = CreateTextLabelEntity(pBG, "", startX, y, "Audio:");
SetupTextEntity(pEnt,fontID);
offsetX = iPhoneMapX(columnX);
pEnt = CreateTextButtonEntity(pBG, "sound_1", offsetX, y, "On", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
pEnt = CreateTextButtonEntity(pBG, "sound_0", offsetX, y, "Off", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
bool bSound = GetApp()->GetShared()->GetVar("sound")->GetUINT32() != 0;
SetupLightBarSelect(pBG, "sound_", bSound, MAKE_RGBA(190, 0, 35, 255));
}
//music vol slider
y += spacerY+iPhoneMapY2X(26);
EntityComponent *pSliderComp = CreateSlider(pBG, startX, y, iPhoneMapX(360), "interface/slider_button.rttex", "Min", "Music volume", "Max");
pSliderComp->GetVar("progress")->Set( GetApp()->GetVar("music_vol")->GetFloat());
pSliderComp->GetVar("progress")->GetSigOnChanged()->connect(&OnProgressChangedMusic);
//transparency slider
if (GetApp()->GetUsingTouchScreen())
{
y += spacerY+iPhoneMapY2X(36);
pSliderComp = CreateSlider(pBG, startX, y, iPhoneMapX(360), "interface/slider_button.rttex", "Min", "Game Interface Visibility", "Max");
//a thing to visually show them how much alpha they've set it too
Entity *pChest = CreateOverlayEntity(pBG, "options_inventory", ReplaceWithLargeInFileName("interface/iphone/button_inventory.rttex"), startX+iPhoneMapX(363), y-iPhoneMapY(34));
SetAlignmentEntity(pChest, ALIGNMENT_UPPER_LEFT);
UpdateOptionsGUI();
pSliderComp->GetVar("progress")->Set( GetApp()->GetVar("gui_transparency")->GetFloat());
pSliderComp->GetVar("progress")->GetSigOnChanged()->connect(&OnProgressChangedGUI);
y += spacerY;
} else
{
y += spacerY;
}
//if (GetPlatformID() != PLATFORM_ID_IOS)
{
//smoothing
pEnt = CreateTextLabelEntity(pBG, "", startX, y, "Pic smoothing:");
SetupTextEntity(pEnt,fontID);
offsetX = iPhoneMapX(columnX);
pEnt = CreateTextButtonEntity(pBG, "smoothing_0", offsetX, y, "On", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
pEnt = CreateTextButtonEntity(pBG, "smoothing_1", offsetX, y, "Off", false);
SetupTextEntity(pEnt,fontID);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(OptionsMenuOnSelect);
offsetX += pEnt->GetVar("size2d")->GetVector2().x + spacerX;
uint32 smoothing = !GetApp()->GetVar("smoothing")->GetUINT32();
SetupLightBarSelect(pBG, "smoothing_", smoothing, MAKE_RGBA(190, 0, 35, 255));
//show fps
y += spacerY;
pEnt = CreateTextButtonEntity(pBG, "FPS",startX, y, "Toggle FPS Display");
pEnt->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
}
VariantList vList(pParent->GetParent());
ResizeScrollBounds(&vList);
}
Entity * OptionsMenuCreate( Entity *pParentEnt)
{
Entity *pBG = CreateOverlayEntity(pParentEnt, "OptionsMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
AddFocusIfNeeded(pBG, true, 500);
//add the header
CL_Vec2f vTextAreaPos = iPhoneMap(2,10);
float offsetFromBottom = iPhoneMapY(42);
float offsetFromRight = iPhoneMapY(0);
CL_Vec2f vTextAreaBounds = (GetScreenSize()- CL_Vec2f(offsetFromRight,offsetFromBottom))-vTextAreaPos;
Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
pScroll->GetVar("pos2d")->Set(vTextAreaPos);
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);
EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position
//pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255));
Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
pScrollComp->GetVar("fingerTracking")->Set(uint32(1));
/*
//too slow/broken on Android, we'll do it another way
EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
*/
Entity *pOverlay = CreateOverlayEntity(pBG, "", ReplaceWithDeviceNameInFileName("interface/iphone/bg_stone_overlay.rttex"), 0, GetScreenSizeYf());
SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
OptionsMenuAddScrollContent(pBG);
// ZoomFromPositionEntity(pBG, CL_Vec2f(0, -GetScreenSizeYf()), 500);
//the continue button
Entity *pEnt;
//pEnt = CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 320), MAKE_RGBA(0,0,0,100));
eFont fontID = FONT_SMALL;
pEnt = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(5), iPhoneMapY(BACK_BUTTON_Y), "Back", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&OptionsMenuOnSelect);
SetupTextEntity(pEnt, fontID);
AddHotKeyToButton(pEnt, VIRTUAL_KEY_BACK);
ZoomFromPositionEntity(pBG, CL_Vec2f( GetScreenSizeXf(),0), 500);
return pBG;
}

9
source/GUI/OptionsMenu.h Normal file
View file

@ -0,0 +1,9 @@
#ifndef OptionsMenu_h__
#define OptionsMenu_h__
#include "App.h"
Entity * OptionsMenuCreate(Entity *pParentEnt);
#endif // OptionsMenu_h__

View file

@ -0,0 +1,39 @@
#include "ParticleTestMenu.h"
#include "Entity/EntityUtils.h"
#include "MainMenu.h"
#include "Component/ParticleTestComponent.h"
void ParticleTestOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
if (pEntClicked->GetName() == "Back")
{
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
MainMenuCreate(pEntClicked->GetParent()->GetParent());
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
Entity * ParticleTestCreate(Entity *pParentEnt)
{
Entity *pBG = CreateOverlayEntity(pParentEnt, "ParticleTest", "interface/generic_bg.rttex", 0,0);
AddFocusIfNeeded(pBG);
Entity *pParticleEnt = pBG->AddEntity(new Entity(new ParticleTestComponent));
Entity *pButtonEntity;
pButtonEntity = CreateTextButtonEntity(pBG, "Back", 240, 290, "Back");
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&ParticleTestOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SlideScreen(pBG, true);
return pBG;
}

View file

@ -0,0 +1,7 @@
#ifndef ParticleTest_h__
#define ParticleTest_h__
#include "App.h"
Entity * ParticleTestCreate(Entity *pParentEnt);
#endif // ParticleTest_h__

421
source/GUI/PauseMenu.cpp Normal file
View file

@ -0,0 +1,421 @@
#include "PlatformPrecomp.h"
#include "PauseMenu.h"
#include "Entity/EntityUtils.h"
#include "dink/dink.h"
#include "MainMenu.h"
#include "DebugMenu.h"
#include "GameMenu.h"
#include "DMODMenu.h"
#include "OptionsMenu.h"
#include "PopUpMenu.h"
#include "Entity/SelectButtonWithCustomInputComponent.h"
void PlayMenuMusic()
{
GetAudioManager()->Play("dink/sound/3.ogg", true, true, true);
}
Entity * DinkQuitGame()
{
SetDinkGameState(DINK_GAME_STATE_NOT_PLAYING);
Entity *pMenu = GetEntityRoot()->GetEntityByName("GameMenu");
assert(pMenu);
if (!pMenu) return NULL;
GetBaseApp()->SetGameTickPause(false);
//AddFocusIfNeeded(pMenu);
SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
Entity *pFinalMenu = NULL;
if (g_dglo.m_dmodGameDir.empty())
{
pFinalMenu = MainMenuCreate(pMenu->GetParent(), true);
} else
{
pFinalMenu = DMODMenuCreate(pMenu->GetParent(), true);
}
PlayMenuMusic();
return pFinalMenu;
}
Entity * DinkRestartGame()
{
SetDinkGameState(DINK_GAME_STATE_NOT_PLAYING);
Entity *pMenu = GetEntityRoot()->GetEntityByName("GameMenu");
assert(pMenu);
if (!pMenu) return NULL;
GetBaseApp()->SetGameTickPause(false);
AddFocusIfNeeded(pMenu);
string dmodDirAndPath = RemoveTrailingBackslash(g_dglo.m_dmodGamePathWithDir);
LogMsg("Restarting dmod %s", dmodDirAndPath.c_str());
InitDinkPaths(GetBaseAppPath(), "dink", dmodDirAndPath);
//SlideScreen(pMenu, false);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
Entity *pFinalMenu = NULL;
GameCreate(pMenu->GetParent(), 0, "", "Restarting...");
/*
if (g_dglo.m_dmodGameDir.empty())
{
pFinalMenu = MainMenuCreate(pMenu->GetParent(), true);
} else
{
pFinalMenu = DMODMenuCreate(pMenu->GetParent(), true);
}
PlayMenuMusic();
*/
return pFinalMenu;
}
void PauseEnd(Entity *pMenu)
{
//slide it off the screen and then kill the whole menu tree
RemoveFocusIfNeeded(pMenu);
DisableAllButtonsEntity(pMenu);
//SlideScreen(pEntClicked->GetParent(), false);
AddFocusIfNeeded(pMenu->GetParent());
FadeOutEntity(pMenu, true, 499);
GetMessageManager()->CallEntityFunction(pMenu, 500, "OnDelete", NULL);
GetBaseApp()->SetGameTickPause(false);
}
void PrepareForPopup(Entity *pMainMenuEnt, VariantList *pVList)
{
SendFakeInputMessageToEntity(GetEntityRoot(), MESSAGE_TYPE_GUI_CLICK_END, pVList->m_variant[0].GetVector2()); //otherwise the menu may never get the touch release message
pMainMenuEnt->RemoveComponentByName("FocusInput");
pMainMenuEnt->RemoveComponentByName("FocusUpdate");
GetMessageManager()->RemoveComponentByName(pMainMenuEnt, 500, "FocusRender");
}
void UpdatePauseButtons(Entity *pMenu)
{
Entity *pEnt = pMenu->GetEntityByName("QuickLoad");
if (!pEnt)
{
assert(0);
return;
}
unsigned int color = MAKE_RGBA(255,255,255,255);
if (!FileExists(DinkGetSavePath()+"quicksave.dat"))
{
//we'll, let's make it look not highlighted
color = MAKE_RGBA(255,255,255,100);
}
MorphToColorEntity(pEnt, false, 500, color, 0);
}
void PauseMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity", pEntClicked->GetName().c_str());
Entity *pMenu = GetEntityRoot()->GetEntityByName("PauseMenu");
if (pEntClicked->GetName() == "Back")
{
GetAudioManager()->Play("audio/pause_close.wav");
PauseEnd(pMenu);
}
if (pEntClicked->GetName() == "OldOptions")
{
PauseEnd(pMenu);
g_dglo.m_dirInput[DINK_INPUT_BUTTON5] = true;
g_dglo.m_dirInputFinished[DINK_INPUT_BUTTON5] = true;
}
if (pEntClicked->GetName() == "Map")
{
PauseEnd(pMenu);
g_dglo.m_dirInput[DINK_INPUT_BUTTON6] = true;
g_dglo.m_dirInputFinished[DINK_INPUT_BUTTON6] = true;
}
if (pEntClicked->GetName() == "Keyboard")
{
PauseEnd(pMenu);
g_dglo.m_bFullKeyboardActive = true;
}
if (pEntClicked->GetName() == "Quit")
{
//slide it off the screen and then kill the whole menu tree
RemoveFocusIfNeeded(pMenu);
SaveState(g_dglo.m_savePath+"continue_state.dat");
WriteLastPathSaved("");
//kill our state.dat if it existed, not needed now, this can exist if an iphone goes into suspend, but then is resumed
RemoveFile(GetSavePath()+"state.dat", false);
//SlideScreen(pEntClicked->GetParent()->GetParent(), false);
DinkQuitGame();
}
if (pEntClicked->GetName() == "Debug")
{
//overlay the debug menu over this one
pMenu->RemoveComponentByName("FocusInput");
DebugMenuCreate(pMenu);
}
if (pEntClicked->GetName() == "Options")
{
//overlay the debug menu over this one
PrepareForPopup(pMenu, pVList);
OptionsMenuCreate(pMenu);
}
if (pEntClicked->GetName() == "empty_cache")
{
DinkUnloadGraphicsCache();
LogMsg("Cache emptied");
}
if (pEntClicked->GetName() == "QuickSave")
{
SaveStateWithExtra();
UpdatePauseButtons(pMenu);
PauseEnd(pMenu);
}
if (pEntClicked->GetName() == "QuickLoad")
{
LogMsg("loading state");
string fName = DinkGetSavePath()+"quicksave.dat";
if (FileExists(fName))
{
bool bSuccess = LoadState(fName, true);
if (!bSuccess)
{
RemoveFile(fName, false);
GetAudioManager()->Play("audio/buzzer2.wav");
PopUpCreate(pMenu, "Error loading save state. Probably an older version, sorry.", "", "cancel", "Continue", "", "", true);
} else
{
LoadStateWithExtra();
PauseEnd(pMenu);
}
} else
{
//disabled, play buzzer sound
GetAudioManager()->Play("audio/buzzer2.wav");
}
UpdatePauseButtons(pMenu);
}
GetEntityRoot()->PrintTreeAsText(); //useful for Pause
}
void OnPauseArcadeInput(VariantList *pVList)
{
int vKey = pVList->Get(0).GetUINT32();
bool bIsDown = pVList->Get(1).GetUINT32() != 0;
//LogMsg("GameMenuArcade: Key %d, down is %d", vKey, int(bIsDown));
Entity *pQuickSaveEnt = GetEntityRoot()->GetEntityByName("QuickSave");
Entity *pQuickLoadEnt = GetEntityRoot()->GetEntityByName("QuickLoad");
if (!EntityHasInputFocus(GetEntityRoot()->GetEntityByName("PauseMenu")))
{
return;
}
if (!bIsDown)
{
switch (vKey)
{
case VIRTUAL_KEY_DIR_LEFT:
BobEntityStop(pQuickSaveEnt);
break;
case VIRTUAL_KEY_DIR_RIGHT:
BobEntityStop(pQuickLoadEnt);
break;
}
}
int bobAmount =iPadMapY(40);
int bobCycleMS = 300;
if (bIsDown)
{
switch (vKey)
{
case VIRTUAL_KEY_DIR_LEFT:
BobEntity(pQuickSaveEnt, bobAmount, 0, bobCycleMS);
break;
case VIRTUAL_KEY_DIR_RIGHT:
BobEntity(pQuickLoadEnt, bobAmount, 0, bobCycleMS);
break;
case VIRTUAL_KEY_GAME_FIRE:
case VIRTUAL_KEY_GAME_INVENTORY:
case VIRTUAL_KEY_GAME_TALK:
if ( IsEntityBobbing(pQuickSaveEnt) )
{
FakeClickAnEntity(pQuickSaveEnt);
} else if (IsEntityBobbing(pQuickLoadEnt) )
{
FakeClickAnEntity(pQuickLoadEnt);
} else
{
GetAudioManager()->Play("audio/buzzer2.wav");
}
break;
default: ;
}
}
}
Entity * PauseMenuCreate(Entity *pParentEnt)
{
//Entity *pBG = pParentEnt->AddEntity(new Entity("PauseMenu"));
Entity * pBG = CreateOverlayRectEntity(pParentEnt, CL_Vec2f(0,0), GetScreenSize(), MAKE_RGBA(0,0,0,140));
pBG->SetName("PauseMenu");
//so we can snag gamepad messages too:
GetBaseApp()->m_sig_arcade_input.connect(pBG->GetFunction("OnArcadeInput")->sig_function);
pBG->GetShared()->GetFunction("OnArcadeInput")->sig_function.connect(&OnPauseArcadeInput);
Entity * pBackdrop = CreateOverlayRectEntity(pBG, CL_Vec2f(0,0), CL_Vec2f(0,0), MAKE_RGBA(0,0,0,140));
Entity *pTextBG = pBG->AddEntity(new Entity("PauseTextBG"));
GetAudioManager()->Play("audio/pause_open.wav");
pBackdrop->GetVar("pos2d")->Set(GetScreenSize()/2);
pTextBG->GetVar("pos2d")->Set(GetScreenSize()/2+CL_Vec2f(0,iPhoneMapY(-30)));
GetBaseApp()->SetGameTickPause(true);
AddFocusIfNeeded(pBG, true);
KillControls();
g_dglo.m_bLastFullKeyboardActive = false;
Entity *pButtonEntity;
float x = 0;
float y = iPhoneMapX(-70);
float ySpacer = iPhoneMapY(40);
eFont fontID = FONT_SMALL;
float fontScale = 1;
pButtonEntity = CreateTextButtonEntity(pBG , "Debug", iPhoneMapX(440), iPhoneMapY(20), "Cheats", false);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
//pButtonEntity->GetVar("color")->Set(MAKE_RGBA(0,0,0,0));
//quick save/load buttons first
pButtonEntity = CreateOverlayButtonEntity(pBG , "QuickSave", ReplaceWithLargeInFileName("interface/iphone/button_quicksave.rttex"), iPhoneMapX(85), GetScreenSizeYf()/2);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
pButtonEntity = CreateOverlayButtonEntity(pBG , "QuickLoad", ReplaceWithLargeInFileName("interface/iphone/button_quickload.rttex"), iPhoneMapX(395), GetScreenSizeYf()/2);
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
UpdatePauseButtons(pBG);
pButtonEntity = CreateTextButtonEntity(pTextBG, "Map", x, y, "VIEW MAP", false); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pButtonEntity, fontID, fontScale);
if (!DinkCanRunScriptNow())
{
pButtonEntity->GetVar("color")->Set(MAKE_RGBA(255,255,255,50));
}
pButtonEntity = CreateTextButtonEntity(pTextBG, "OldOptions", x, y, "DINK MENU", false); y += ySpacer;
pButtonEntity->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pButtonEntity, fontID, fontScale);
if (!DinkCanRunScriptNow())
{
pButtonEntity->GetVar("color")->Set(MAKE_RGBA(255,255,255,50));
}
if (GetApp()->GetUsingTouchScreen())
{
pButtonEntity = CreateTextButtonEntity(pTextBG, "Keyboard", x, y, "FULL KEYBOARD", false); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pButtonEntity, fontID,fontScale);
}
pButtonEntity = CreateTextButtonEntity(pTextBG, "Quit", x, y, "QUIT", false); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pButtonEntity, fontID, fontScale);
pButtonEntity = CreateTextButtonEntity(pTextBG, "Options", x, y, "OPTIONS", false); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pButtonEntity, fontID,fontScale);
pButtonEntity = CreateTextButtonEntity(pTextBG, "Back", x, y, "CONTINUE", false); y += ySpacer;
pButtonEntity->GetShared()->GetFunction("OnButtonSelected")->sig_function.connect(&PauseMenuOnSelect);
pButtonEntity->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
SetupTextEntity(pButtonEntity, fontID, fontScale);
SetButtonClickSound(pButtonEntity, ""); //no sound
EntityComponent *pKeys = AddHotKeyToButton(pButtonEntity, VIRTUAL_KEY_BACK);
//work around problem of it instantly closing
pKeys->GetVar("disabled")->Set(uint32(1));
GetMessageManager()->SetComponentVariable(pKeys, 500, "disabled", uint32(0)); //enable it again
/*
pKeys = AddHotKeyToButton(pButtonEntity, VIRTUAL_KEY_PROPERTIES);
//work around problem of it instantly closing
pKeys->GetVar("disabled")->Set(uint32(1));
GetMessageManager()->SetComponentVariable(pKeys, 1, "disabled", uint32(0)); //enable it again
*/
CL_Rectf size = MeasureEntityAndChildren(pTextBG);
size.expand(iPhoneMapY(27));
pBackdrop->GetVar("size2d")->Set(CL_Vec2f(size.get_width(), size.get_height()));
pBackdrop->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
FadeInEntity(pBG, true, 450);
return pBG;
}

10
source/GUI/PauseMenu.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef PauseMenu_h__
#define PauseMenu_h__
#include "App.h"
Entity * PauseMenuCreate(Entity *pParentEnt);
Entity * DinkQuitGame(); //kills dink and loads the appropriate last menu and returns a pointer to it
void PlayMenuMusic();
Entity * DinkRestartGame();
#endif // PauseMenu_h__

251
source/GUI/PopUpMenu.cpp Normal file
View file

@ -0,0 +1,251 @@
#include "PlatformPrecomp.h"
#include "PopUpMenu.h"
#include "Entity/EntityUtils.h"
#include "App.h"
Entity * PopUpRestoreFocusToOriginalMenu(Entity *pEntClicked)
{
Entity *pFinishMenu = GetEntityRoot()->GetEntityByName(pEntClicked->GetParent()->GetParent()->GetVar("finishMenuName")->GetString());
assert(pFinishMenu);
if (pFinishMenu)
{
if (pEntClicked->GetParent()->GetParent()->GetVar("requireMoveMessages")->GetUINT32() == 1)
{
AddFocusIfNeeded(pFinishMenu, true, 0);
} else
{
pFinishMenu->AddComponent(new FocusInputComponent);
}
}
return pFinishMenu;
}
void ReloadMainMenu(VariantList *pVList);
//general purpose pop up menu, I've hardcoded various behaviors here, it knows what to do based on the button name
void PopUpMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
FadeOutEntity(pEntClicked->GetParent()->GetParent(), true, 300);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent()->GetParent(), 500, "OnDelete", NULL);
DisableAllButtonsEntity(pEntClicked->GetParent()->GetParent());
Entity *pDarken = GetEntityRoot()->GetEntityByName("pop_up_darken");
FadeScreen(pDarken, 0, 0, 400, true);
KillEntity(pDarken, 400);
pDarken->SetName("");
//set the game pause state back to whatever it was originally
GetApp()->SetGameTickPause(pEntClicked->GetParent()->GetParent()->GetVar("gamePaused")->GetUINT32() != 0);
if (pEntClicked->GetName() == "url")
{
LogMsg("Launch url: %s", pEntClicked->GetVar("url")->GetString().c_str());
LaunchURL(pEntClicked->GetVar("url")->GetString());
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
} else if (pEntClicked->GetName() == "url_update")
{
LogMsg("Launch url: %s", pEntClicked->GetVar("url")->GetString().c_str());
LaunchURL(pEntClicked->GetVar("url")->GetString());
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
//kill current menu
//GetMessageManager()->CallEntityFunction(pFinishMenu, 200, "OnDelete", NULL);
PopUpCreate(pFinishMenu, "Please close the game and install the new version!", "", "cancel", "", "", "", true);
}
else
/*
if (pEntClicked->GetName() == "music_disable")
{
//add control back
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
GetApp()->GetShared()->GetVar("musicDisabled")->Set(uint32(1));
GetAudioManager()->SetMusicEnabled(false);
string msg = "Music disabled. You can re-enable it from the `wOptions`` menu later.";
PopUpCreate(pFinishMenu, msg, "", "cancel", "Continue", "", "", true);
GetAudioManager()->Play(GetApp()->GetMainMenuMusic(), true, true); //because music is disabled this won't play, but it will remember this if
//we enable music again so we still want it
} else
if (pEntClicked->GetName() == "music_on")
{
//add control back
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
GetAudioManager()->Play(GetApp()->GetMainMenuMusic(), true, true);
} else
if (pEntClicked->GetName() == "quit_game")
{
Entity *pGameMenu = GetEntityRoot()->GetEntityByName("GameMenu");
//GetApp()->SetGameType(GAME_TYPE_NONE);
//slide it off the screen and then kill the whole menu tree
SlideScreen(pGameMenu, false, 500, 10);
GetMessageManager()->CallEntityFunction(pGameMenu, 900, "OnDelete", NULL);
//SummaryMenuCreate(pGameMenu->GetParent());
GetBaseApp()->SetGameTickPause(false);
} else
*/
if (pEntClicked->GetName() == "cancel")
{
//add control back
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
}if (pEntClicked->GetName() == "cancel_update")
{
//add control back
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
//kill current menu
GetMessageManager()->CallEntityFunction(pFinishMenu, 100, "OnDelete", NULL);
VariantList vList(pFinishMenu->GetParent());
GetMessageManager()->CallStaticFunction(ReloadMainMenu, 200, &vList, TIMER_SYSTEM);
}
else
if (pEntClicked->GetName() == "reset")
{
//add control back
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
GetAudioManager()->Play("audio/tip_start.wav");
//GetHighScoreManager()->ResetLocalScores();
//belay that order, show another pop up...
PopUpCreate(pFinishMenu, "Local high scores have been reset.", "", "cancel", "Continue", "", "", true);
} else
{
//unhandled
Entity *pFinishMenu = PopUpRestoreFocusToOriginalMenu(pEntClicked);
//call this function on the original guy, just in case they want to do something with it
VariantList vList(pFinishMenu, pEntClicked->GetName());
pFinishMenu->GetFunction(pEntClicked->GetName())->sig_function(&vList);
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
void PopUpCreate(Entity *pEnt, string msg, string url, string button1Action, string button1Label, string button2Action, string button2Label,
bool bRequireMoveMessages, string button3Action, string button3Label)
{
pEnt->RemoveComponentByName("FocusInput");
bool bGamePaused = GetBaseApp()->GetGameTickPause();
GetBaseApp()->SetGameTickPause(true);
// GetMessageManager()->RemoveComponentByName(pEnt, 201, "FocusInput"); //hack that works around a problem of pending FocusInput messages coming in
//remember where we should give focus to later
string parentName = pEnt->GetName();
assert(!parentName.empty());
//let's build our own menu right on the GUI branch of the tree
pEnt = GetEntityRoot()->GetEntityByName("GUI");
Entity *pDarken = pEnt->AddEntity(new Entity("pop_up_darken"));
pDarken->AddComponent(new FocusRenderComponent);
pDarken->AddComponent(new FocusUpdateComponent);
FadeScreen(pDarken, 0, 0.7, 400, false); //fade the whole GUI
//add our prompt
Entity *pBG = CreateOverlayEntity(pEnt, "pop_up", ReplaceWithLargeInFileName("interface/iphone/pop_up.rttex"), 0,0);
//Ok, at this point we can check the image dimensions and center it based on the bitmap size itself
pBG->GetVar("pos2d")->Set( (GetScreenSize()/2) - pBG->GetVar("size2d")->GetVector2()/2);
// pBG->AddComponent(new FocusInputComponent);
pBG->GetVar("finishMenuName")->Set(parentName);
if (bRequireMoveMessages)
{
pBG->GetVar("requireMoveMessages")->Set(uint32(1));
}
AddFocusIfNeeded(pBG);
CL_Vec2f vTextArea = pBG->GetVar("size2d")->GetVector2();
float padding = 30;
vTextArea.x -= iPhoneMapX2X(padding*2);
//add our msg and word wrap it
Entity *pText = CreateTextBoxEntity(pBG, "pop_up_text", (pBG->GetVar("size2d")->GetVector2()/2)+CL_Vec2f(0, iPhoneMapY2X(-17)), vTextArea, msg);
SetAlignmentEntity(pText, ALIGNMENT_CENTER);
float textHeight = pText->GetVar("size2d")->GetVector2().y;
FadeInEntity(pBG, true, 300);
//pText->GetVar("color")->Set(MAKE_RGBA(203,177,137,255));
pBG->GetVar("gamePaused")->Set(uint32(bGamePaused != 0)); //remember this for later
Entity *pButton = NULL;
CL_Vec2f vButtonSize;
Entity *pLabel;
Entity *pButton1, *pButton2;
float buttonHeight = iPhoneMapY2X(120);
if (textHeight > iPhoneMapY2X(50))
{
//well, we need more space for this much text. Move the buttons down a bit.
buttonHeight = iPhoneMapY2X(135);
}
//add the buttons
pButton = CreateOverlayEntity(pBG, "button1", ReplaceWithLargeInFileName("interface/iphone/pop_up_button.rttex"), iPhoneMapX2X(21), buttonHeight);
pButton1 = pButton;
vButtonSize = pButton->GetVar("size2d")->GetVector2();
//add the text label
pLabel = CreateTextButtonEntity(pButton, button1Action, vButtonSize.x/2, vButtonSize.y/2, "`w"+button1Label, false);
pLabel->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
pLabel->GetFunction("OnButtonSelected")->sig_function.connect(&PopUpMenuOnSelect);
pLabel->GetVar("url")->Set(url); //just in case we want to know this later, store it in the button itself
FadeInEntity(pButton, true, 300, 250);
if (button2Label.empty())
{
//we only have one button? Fine, center it.
pButton->GetVar("pos2d")->Set(iPhoneMapX(88), buttonHeight);
} else
{
pButton = CreateOverlayEntity(pBG, "button2", ReplaceWithLargeInFileName("interface/iphone/pop_up_button.rttex"), iPhoneMapY2X(180), buttonHeight);
pButton2 = pButton;
vButtonSize = pButton->GetVar("size2d")->GetVector2();
//add the text label
pLabel = CreateTextButtonEntity(pButton, button2Action, vButtonSize.x/2, vButtonSize.y/2, "`w"+button2Label, false);
pLabel->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
pLabel->GetFunction("OnButtonSelected")->sig_function.connect(&PopUpMenuOnSelect);
pLabel->GetVar("url")->Set(url); //just in case we want to know this later, store it in the button itself
FadeInEntity(pButton, true, 300, 350);
if (button3Label.empty())
{
//we only have two buttons? fine. Done then
} else
{
pButton1->GetVar("pos2d")->Set(iPhoneMapX2X(20), buttonHeight);
pButton2->GetVar("pos2d")->Set(iPhoneMapX2X(180), buttonHeight);
//move stuff around and add a third button
pButton = CreateOverlayEntity(pBG, "button2", ReplaceWithLargeInFileName("interface/iphone/pop_up_button.rttex"), iPhoneMapX2X(100), buttonHeight);
vButtonSize = pButton->GetVar("size2d")->GetVector2();
//add the text label
pLabel = CreateTextButtonEntity(pButton, button3Action, vButtonSize.x/2, vButtonSize.y/2, "`w"+button3Label, false);
pLabel->GetVar("alignment")->Set(uint32(ALIGNMENT_CENTER));
pLabel->GetFunction("OnButtonSelected")->sig_function.connect(&PopUpMenuOnSelect);
pLabel->GetVar("url")->Set(url); //just in case we want to know this later, store it in the button itself
FadeInEntity(pButton, true, 300, 450);
}
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}

7
source/GUI/PopUpMenu.h Normal file
View file

@ -0,0 +1,7 @@
#ifndef PopUpMenu_h__
#define PopUpMenu_h__
#include "PlatformSetup.h"
class Entity;
void PopUpCreate(Entity *pEnt, string msg, string url, string button1Action, string button1Label, string button2Action , string button2Label,
bool bRequireMoveMessages, string button3Action= "", string button3Label="");
#endif // PopUpMenu_h__

122
source/GUI/QuickTipMenu.cpp Normal file
View file

@ -0,0 +1,122 @@
#include "PlatformPrecomp.h"
#include "QuickTipMenu.h"
#include "App.h"
#include "Entity/EntityUtils.h"
#include "Entity/SelectButtonWithCustomInputComponent.h"
void QuickTipMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
DisableAllButtonsEntity(pEntClicked->GetParent());
GetAudioManager()->Play("audio/tip_end.wav");
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
Entity *pDarken = GetEntityRoot()->GetEntityByName("pop_up_darken");
FadeScreen(pDarken, 0, 0, 400, true);
KillEntity(pDarken, 400);
pDarken->SetName("");
//set the game pause state back to whatever it was originally
GetApp()->SetGameTickPause(pEntClicked->GetParent()->GetParent()->GetVar("gamePaused")->GetUINT32() != 0);
if (pEntClicked->GetName() == "continue")
{
//slide it off the screen and then kill the whole menu tree
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
Entity *pFinishMenu = GetEntityRoot()->GetEntityByName(pEntClicked->GetParent()->GetVar("finishMenuName")->GetString());
assert(pFinishMenu);
if (pFinishMenu)
{
if (pEntClicked->GetParent()->GetVar("requireMoveMessages")->GetUINT32() == 1)
{
AddFocusIfNeeded(pFinishMenu, true, 100);
} else
{
AddFocusIfNeeded(pFinishMenu, false, 100);
}
}
return;
}
}
Entity * CreateQuickTipFirstTimeOnly(Entity *pParentEnt, string tipFileName, bool bRequireMoveMessages)
{
//we access the app database to make sure this is only shown once
string key = "tip_"+tipFileName;
#ifdef _DEBUG
//cheat to always show quicktips
GetApp()->GetShared()->DeleteVarsStartingWith("tip_"); //for testing
#endif
if (GetApp()->GetShared()->GetVarIfExists(key))
{
return NULL; //already showed this I guess
}
//mark it as shown
GetApp()->GetVar(key)->Set("shown");
return CreateQuickTip(pParentEnt, tipFileName, bRequireMoveMessages);
}
Entity * CreateQuickTip(Entity *pParentEnt, string tipFileName, bool bRequireMoveMessages)
{
tipFileName = ReplaceWithLargeInFileNameAndOSSpecific(tipFileName);
pParentEnt->RemoveComponentByName("FocusInput");
bool bGamePaused = GetBaseApp()->GetGameTickPause();
GetBaseApp()->SetGameTickPause(true);
Entity *pEnt;
//let's build our own menu right on the GUI branch of the tree
pEnt = GetEntityRoot()->GetEntityByName("GUI");
Entity *pDarken = pEnt->AddEntity(new Entity("pop_up_darken"));
pDarken->AddComponent(new FocusRenderComponent);
pDarken->AddComponent(new FocusUpdateComponent);
FadeScreen(pDarken, 0, 0.5, 400, false); //fade the whole GUI
Entity *pBG = CreateOverlayEntity(GetEntityRoot()->GetEntityByName("GUI"), "QuickTipMenu", "", 0,0);
SurfaceAnim *pSurf = new SurfaceAnim;
pSurf->LoadFile(tipFileName);
OverlayRenderComponent *pOverlay = (OverlayRenderComponent*) pBG->GetComponentByName("OverlayRender");
pOverlay->SetSurface(pSurf, true);
if (bRequireMoveMessages)
{
pBG->GetVar("requireMoveMessages")->Set(uint32(1));
}
CL_Vec2f vSize = pBG->GetVar("size2d")->GetVector2();
pBG->GetVar("pos2d")->Set( (GetScreenSize()/2) - (vSize/2) );
pBG->GetVar("gamePaused")->Set(uint32(bGamePaused != 0)); //remember this for later
string parentName = pParentEnt->GetName();
assert(!parentName.empty());
pBG->GetVar("finishMenuName")->Set(parentName);
AddFocusIfNeeded(pBG, false, 1000); //don't allow input for a bit so they don't accidentally dismiss the tip
Entity *pButtonEntity;
//back button
pButtonEntity = CreateButtonHotspot(pBG, "continue", CL_Vec2f(0,0), GetScreenSize());
GetMessageManager()->AddComponent(pButtonEntity, 1000, new SelectButtonWithCustomInputComponent);
//pButtonEntity = CreateOverlayButtonEntity(pBG, "continue", "interface/quicktips/tip_continue.rttex", 178, 184);
pButtonEntity->GetFunction("OnButtonSelected")->sig_function.connect(&QuickTipMenuOnSelect);
SlideScreen(pBG, true);
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
//FadeInEntity(pBG, true, 300);
GetAudioManager()->Play("audio/tip_start.wav");
return pBG;
}

View file

@ -0,0 +1,8 @@
#ifndef QuickTipMenu_h__
#define QuickTipMenu_h__
#include "PlatformSetup.h"
class Entity;
Entity * CreateQuickTipFirstTimeOnly(Entity *pParentEnt, string tipFileName, bool bRequireMoveMessages);
Entity * CreateQuickTip(Entity *pParentEnt, string tipFileName, bool bRequireMoveMessages);
#endif // QuickTipMenu_h__

127
source/GUI/ReadTextMenu.cpp Normal file
View file

@ -0,0 +1,127 @@
#include "PlatformPrecomp.h"
#include "ReadTextMenu.h"
#include "MainMenu.h"
#include "GameMenu.h"
#include "Entity/EntityUtils.h"
#include "dink/dink.h"
#include "PopUpMenu.h"
#include "util/TextScanner.h"
#include "DMODMenu.h"
void ReadTextMenuAddScrollContent(Entity *pParent, TextScanner &t);
void ReadTextMenuOnSelect(VariantList *pVList) //0=vec2 point of click, 1=entity sent from
{
Entity *pEntClicked = pVList->m_variant[1].GetEntity();
LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[1].Print().c_str());
Entity *pMenu = GetEntityRoot()->GetEntityByName("ReadTextMenu");
//LogMsg("Clicked %s entity at %s", pEntClicked->GetName().c_str(),pVList->m_variant[0].Print().c_str());
if (pEntClicked->GetName() == "Back")
{
DisableAllButtonsEntity(pMenu);
SlideScreen(pEntClicked->GetParent(), false);
GetMessageManager()->CallEntityFunction(pEntClicked->GetParent(), 500, "OnDelete", NULL);
DMODMenuCreate(pEntClicked->GetParent()->GetParent(), true);
return;
}
GetEntityRoot()->PrintTreeAsText(); //useful for debugging
}
void ReadTextMenuAddScrollContent(Entity *pParent)
{
TextScanner t(pParent->GetVar("textfile")->GetString(), false);
pParent = pParent->GetEntityByName("scroll_child");
pParent->RemoveAllEntities();
float x = 5;
float y = 0;
//Entity *pEnt;
CL_Vec2f vTextBoxPos(iPhoneMapX(20),iPhoneMapY(y));
CL_Vec2f vTextBounds(iPhoneMapX(434), iPhoneMapY(200));
CreateTextBoxEntity(pParent, "", vTextBoxPos, vTextBounds, t.GetAll());
VariantList vList(pParent->GetParent());
ResizeScrollBounds(&vList);
}
void ReadTextOnPostIntroTransition(VariantList *pVList)
{
Entity *pBG = pVList->Get(0).GetEntity();
ReadTextMenuAddScrollContent(pBG);
}
Entity * ReadTextMenuCreate( Entity *pParentEnt, string fileName, string prettyFileName )
{
GetBaseApp()->ClearError();
Entity *pBG = NULL;
pBG = CreateOverlayEntity(pParentEnt, "ReadTextMenu", ReplaceWithDeviceNameInFileName("interface/iphone/bkgd_stone.rttex"), 0,0);
AddFocusIfNeeded(pBG, true, 500);
pBG->AddComponent(new FocusRenderComponent);
pBG->GetVar("textfile")->Set(fileName);
CL_Vec2f vTextAreaPos = iPhoneMap(2,10);
float offsetFromBottom = iPhoneMapY(42);
float offsetFromRight = iPhoneMapY(0);
CL_Vec2f vTextAreaBounds = (GetScreenSize()- CL_Vec2f(offsetFromRight,offsetFromBottom))-vTextAreaPos;
Entity *pScroll = pBG->AddEntity(new Entity("scroll"));
pScroll->GetVar("pos2d")->Set(vTextAreaPos);
pScroll->GetVar("size2d")->Set(vTextAreaBounds);
pScroll->AddComponent(new TouchHandlerComponent);
Entity *pLabel = CreateTextLabelEntity(pBG, "Reading "+prettyFileName, GetScreenSizeXf()/2, GetScreenSizeYf()/2, "Updating add-on ReadText list...");
SetAlignmentEntity(pLabel, ALIGNMENT_CENTER);
FadeOutAndKillEntity(pLabel, true, 300, 501);
EntityComponent *pFilter = pScroll->AddComponent(new FilterInputComponent);
EntityComponent *pScrollComp = pScroll->AddComponent(new ScrollComponent);
EntityComponent *pScrollBarComp = pScroll->AddComponent(new ScrollBarRenderComponent); //also let's add a visual way to see the scroller position
//pScroll->GetVar("color")->Set(MAKE_RGBA(61,155, 193, 255));
Entity *pScrollChild = pScroll->AddEntity(new Entity("scroll_child"));
pScrollComp->GetVar("fingerTracking")->Set(uint32(1));
//EntityComponent *pClip = pScroll->AddComponent(new RenderClipComponent);
//pClip->GetVar("clipMode")->Set(uint32(RenderClipComponent::CLIP_MODE_BOTTOM));
Entity *pOverlay = CreateOverlayEntity(pBG, "", ReplaceWithDeviceNameInFileName("interface/iphone/bg_stone_overlay.rttex"), 0, GetScreenSizeYf());
SetAlignmentEntity(pOverlay, ALIGNMENT_DOWN_LEFT);
// ZoomFromPositionEntity(pBG, CL_Vec2f(0, -GetScreenSizeYf()), 500);
//the continue button
Entity *pEnt;
//pEnt = CreateOverlayRectEntity(pBG, CL_Rectf(0, GetScreenSizeYf()-offsetFromBottom, GetScreenSizeXf(), 320), MAKE_RGBA(0,0,0,100));
eFont fontID = FONT_SMALL;
pEnt = CreateTextButtonEntity(pBG, "Back", iPhoneMapX(40), iPhoneMapY(BACK_BUTTON_Y), "Back", false);
pEnt->GetFunction("OnButtonSelected")->sig_function.connect(&ReadTextMenuOnSelect);
SetupTextEntity(pEnt, fontID);
AddHotKeyToButton(pEnt, VIRTUAL_KEY_BACK);
SlideScreen(pBG, true, 500);
pBG->GetFunction("OnPostIntroTransition")->sig_function.connect(&ReadTextOnPostIntroTransition);
VariantList vList(pBG, string(""));
GetMessageManager()->CallEntityFunction(pBG, 500, "OnPostIntroTransition", &vList);
return pBG;
}

View file

@ -0,0 +1,7 @@
#ifndef ReadTextMenu_h__
#define ReadTextMenu_h__
#include "BaseApp.h"
Entity * ReadTextMenuCreate( Entity *pParentEnt, string fileName, string prettyFileName );
#endif // ReadTextMenu_h__

View file

@ -0,0 +1,122 @@
#include "StackUtils.h"
#include <tchar.h>
#include <stdio.h>
// For more info about "PreventSetUnhandledExceptionFilter" see:
// "SetUnhandledExceptionFilter" and VC8
// http://blog.kalmbachnet.de/?postid=75
// and
// Unhandled exceptions in VC8 and above… for x86 and x64
// http://blog.kalmbach-software.de/2008/04/02/unhandled-exceptions-in-vc8-and-above-for-x86-and-x64/
// Even better: http://blog.kalmbach-software.de/2013/05/23/improvedpreventsetunhandledexceptionfilter/
class StackWalkerToConsole : public StackWalker
{
protected:
virtual void OnOutput(LPCSTR szText)
{
LogMsg(szText);
}
};
#if defined _M_X64 || defined _M_IX86
static BOOL PreventSetUnhandledExceptionFilter()
{
HMODULE hKernel32 = LoadLibrary(_T("kernel32.dll"));
if (hKernel32 == NULL) return FALSE;
void *pOrgEntry = GetProcAddress(hKernel32, "SetUnhandledExceptionFilter");
if (pOrgEntry == NULL) return FALSE;
#ifdef _M_IX86
// Code for x86:
// 33 C0 xor eax,eax
// C2 04 00 ret 4
unsigned char szExecute[] = { 0x33, 0xC0, 0xC2, 0x04, 0x00 };
#elif _M_X64
// 33 C0 xor eax,eax
// C3 ret
unsigned char szExecute[] = { 0x33, 0xC0, 0xC3 };
#else
#error "The following code only works for x86 and x64!"
#endif
DWORD dwOldProtect = 0;
BOOL bProt = VirtualProtect(pOrgEntry, sizeof(szExecute),
PAGE_EXECUTE_READWRITE, &dwOldProtect);
SIZE_T bytesWritten = 0;
BOOL bRet = WriteProcessMemory(GetCurrentProcess(),
pOrgEntry, szExecute, sizeof(szExecute), &bytesWritten);
if ((bProt != FALSE) && (dwOldProtect != PAGE_EXECUTE_READWRITE))
{
DWORD dwBuf;
VirtualProtect(pOrgEntry, sizeof(szExecute), dwOldProtect, &dwBuf);
}
return bRet;
}
#else
#pragma message("This code works only for x86 and x64!")
#endif
static BOOL s_bUnhandledExeptionFilterSet = FALSE;
static LONG __stdcall CrashHandlerExceptionFilter(EXCEPTION_POINTERS* pExPtrs)
{
#ifdef _M_IX86
if (pExPtrs->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)
{
static char MyStack[1024 * 128]; // be sure that we have enought space...
// it assumes that DS and SS are the same!!! (this is the case for Win32)
// change the stack only if the selectors are the same (this is the case for Win32)
//__asm push offset MyStack[1024*128];
//__asm pop esp;
__asm mov eax, offset MyStack[1024 * 128];
__asm mov esp, eax;
}
#endif
LogMsg("DINK CRASHED! STACK TRACE BELOW");
LogMsg("---------------------------------------------------------");
StackWalkerToConsole sw; // output to console
sw.ShowCallstack(GetCurrentThread(), pExPtrs->ContextRecord);
LogMsg("---------------------------------------------------------");
TCHAR lString[500];
_stprintf_s(lString,
_T("Dink crashed! Info on where it crashed was written to %slog.txt. If you're a tester, give Seth that file so he can fix it!"),
GetBaseAppPath().c_str()
);
FatalAppExit(-1, lString);
return EXCEPTION_CONTINUE_SEARCH;
}
void InitUnhandledExceptionFilter()
{
/*
TCHAR szModName[_MAX_PATH];
if (GetModuleFileName(NULL, szModName, sizeof(szModName) / sizeof(TCHAR)) != 0)
{
_tcscpy_s(s_szExceptionLogFileName, szModName);
_tcscat_s(s_szExceptionLogFileName, _T(".exp.log"));
}
*/
if (s_bUnhandledExeptionFilterSet == FALSE)
{
// set global exception handler (for handling all unhandled exceptions)
SetUnhandledExceptionFilter(CrashHandlerExceptionFilter);
#if defined _M_X64 || defined _M_IX86
PreventSetUnhandledExceptionFilter();
#endif
s_bUnhandledExeptionFilterSet = TRUE;
}
}

View file

@ -0,0 +1,5 @@
#pragma once
#include <PlatformSetup.h>
#include "StackWalker.h"
void InitUnhandledExceptionFilter();

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,219 @@
/**********************************************************************
*
* StackWalker.h
*
*
*
* LICENSE (http://www.opensource.org/licenses/bsd-license.php)
*
* Copyright (c) 2005-2009, Jochen Kalmbach
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of Jochen Kalmbach nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* **********************************************************************/
// #pragma once is supported starting with _MCS_VER 1000,
// so we need not to check the version (because we only support _MSC_VER >= 1100)!
#pragma once
#include <windows.h>
#if _MSC_VER >= 1900
#pragma warning(disable : 4091)
#endif
// special defines for VC5/6 (if no actual PSDK is installed):
#if _MSC_VER < 1300
typedef unsigned __int64 DWORD64, *PDWORD64;
#if defined(_WIN64)
typedef unsigned __int64 SIZE_T, *PSIZE_T;
#else
typedef unsigned long SIZE_T, *PSIZE_T;
#endif
#endif // _MSC_VER < 1300
class StackWalkerInternal; // forward
class StackWalker
{
public:
typedef enum StackWalkOptions
{
// No addition info will be retrived
// (only the address is available)
RetrieveNone = 0,
// Try to get the symbol-name
RetrieveSymbol = 1,
// Try to get the line for this symbol
RetrieveLine = 2,
// Try to retrieve the module-infos
RetrieveModuleInfo = 4,
// Also retrieve the version for the DLL/EXE
RetrieveFileVersion = 8,
// Contains all the abouve
RetrieveVerbose = 0xF,
// Generate a "good" symbol-search-path
SymBuildPath = 0x10,
// Also use the public Microsoft-Symbol-Server
SymUseSymSrv = 0x20,
// Contains all the abouve "Sym"-options
SymAll = 0x30,
// Contains all options (default)
OptionsAll = 0x3F
} StackWalkOptions;
StackWalker(
int options = RetrieveLine, // 'int' is by design, to combine the enum-flags
//int options = OptionsAll, // 'int' is by design, to combine the enum-flags
LPCSTR szSymPath = NULL,
DWORD dwProcessId = GetCurrentProcessId(),
HANDLE hProcess = GetCurrentProcess()
);
StackWalker(DWORD dwProcessId, HANDLE hProcess);
virtual ~StackWalker();
typedef BOOL (__stdcall *PReadProcessMemoryRoutine)(
HANDLE hProcess,
DWORD64 qwBaseAddress,
PVOID lpBuffer,
DWORD nSize,
LPDWORD lpNumberOfBytesRead,
LPVOID pUserData // optional data, which was passed in "ShowCallstack"
);
BOOL LoadModules();
BOOL ShowCallstack(
HANDLE hThread = GetCurrentThread(),
const CONTEXT *context = NULL,
PReadProcessMemoryRoutine readMemoryFunction = NULL,
LPVOID pUserData = NULL // optional to identify some data in the 'readMemoryFunction'-callback
);
#if _MSC_VER >= 1300
// due to some reasons, the "STACKWALK_MAX_NAMELEN" must be declared as "public"
// in older compilers in order to use it... starting with VC7 we can declare it as "protected"
protected:
#endif
enum { STACKWALK_MAX_NAMELEN = 1024 }; // max name length for found symbols
protected:
// Entry for each Callstack-Entry
typedef struct CallstackEntry
{
DWORD64 offset; // if 0, we have no valid entry
CHAR name[STACKWALK_MAX_NAMELEN];
CHAR undName[STACKWALK_MAX_NAMELEN];
CHAR undFullName[STACKWALK_MAX_NAMELEN];
DWORD64 offsetFromSmybol;
DWORD offsetFromLine;
DWORD lineNumber;
CHAR lineFileName[STACKWALK_MAX_NAMELEN];
DWORD symType;
LPCSTR symTypeString;
CHAR moduleName[STACKWALK_MAX_NAMELEN];
DWORD64 baseOfImage;
CHAR loadedImageName[STACKWALK_MAX_NAMELEN];
} CallstackEntry;
typedef enum CallstackEntryType {firstEntry, nextEntry, lastEntry};
virtual void OnSymInit(LPCSTR szSearchPath, DWORD symOptions, LPCSTR szUserName);
virtual void OnLoadModule(LPCSTR img, LPCSTR mod, DWORD64 baseAddr, DWORD size, DWORD result, LPCSTR symType, LPCSTR pdbName, ULONGLONG fileVersion);
virtual void OnCallstackEntry(CallstackEntryType eType, CallstackEntry &entry);
virtual void OnDbgHelpErr(LPCSTR szFuncName, DWORD gle, DWORD64 addr);
virtual void OnOutput(LPCSTR szText);
StackWalkerInternal *m_sw;
HANDLE m_hProcess;
DWORD m_dwProcessId;
BOOL m_modulesLoaded;
LPSTR m_szSymPath;
int m_options;
int m_MaxRecursionCount;
static BOOL __stdcall myReadProcMem(HANDLE hProcess, DWORD64 qwBaseAddress, PVOID lpBuffer, DWORD nSize, LPDWORD lpNumberOfBytesRead);
friend StackWalkerInternal;
}; // class StackWalker
// The "ugly" assembler-implementation is needed for systems before XP
// If you have a new PSDK and you only compile for XP and later, then you can use
// the "RtlCaptureContext"
// Currently there is no define which determines the PSDK-Version...
// So we just use the compiler-version (and assumes that the PSDK is
// the one which was installed by the VS-IDE)
// INFO: If you want, you can use the RtlCaptureContext if you only target XP and later...
// But I currently use it in x64/IA64 environments...
//#if defined(_M_IX86) && (_WIN32_WINNT <= 0x0500) && (_MSC_VER < 1400)
#if defined(_M_IX86)
#ifdef CURRENT_THREAD_VIA_EXCEPTION
// TODO: The following is not a "good" implementation,
// because the callstack is only valid in the "__except" block...
#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \
do { \
memset(&c, 0, sizeof(CONTEXT)); \
EXCEPTION_POINTERS *pExp = NULL; \
__try { \
throw 0; \
} __except( ( (pExp = GetExceptionInformation()) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_EXECUTE_HANDLER)) {} \
if (pExp != NULL) \
memcpy(&c, pExp->ContextRecord, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
} while(0);
#else
// The following should be enough for walking the callstack...
#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \
do { \
memset(&c, 0, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
__asm call x \
__asm x: pop eax \
__asm mov c.Eip, eax \
__asm mov c.Ebp, ebp \
__asm mov c.Esp, esp \
} while(0);
#endif
#else
// The following is defined for x86 (XP and higher), x64 and IA64:
#define GET_CURRENT_CONTEXT_STACKWALKER_CODEPLEX(c, contextFlags) \
do { \
memset(&c, 0, sizeof(CONTEXT)); \
c.ContextFlags = contextFlags; \
RtlCaptureContext(&c); \
} while(0);
#endif

236
source/dink/FFReader.cpp Normal file
View file

@ -0,0 +1,236 @@
#include "PlatformPrecomp.h"
#include "FFReader.h"
FFReader::FFReader()
{
m_fp = NULL;
}
FFReader::~FFReader()
{
Kill();
}
void FFReader::Kill()
{
if (m_fp)
{
fclose(m_fp);
m_fp = NULL;
}
m_fileHeader.clear();
m_bUsingBaseDinkFF = false;
m_error = ERROR_NONE;
}
int FFReader::GetFFRecordIndexFromFileName(const string &fName)
{
assert(m_fp);
for (unsigned int i=0; i < m_fileHeader.size(); i++)
{
if (strcmp(fName.c_str(), m_fileHeader[i].name) == 0)
return i;
}
return -1;
}
bool FFReader::DoesFileExist( const string &fName )
{
//LogMsg("Checking for %s", (m_basePath+fName).c_str());
if (m_fp)
{
if (GetFFRecordIndexFromFileName(fName) != -1) return true;
}
if (!m_dmodGamePath.empty())
{
if (FileExists(m_dmodGamePath+m_basePath+fName)) return true;
}
if (!FileExists(m_gamePath+m_basePath+fName))
{
//LogMsg("Can't find %s", (m_basePath+fName).c_str());
return false;
}
return true;
}
void FFReader::Init( const string &gamePath, const string &dmodGamePath, const string &basePath, bool bUsingDinkPak )
{
if (m_basePath == basePath && m_dmodGamePath == dmodGamePath)
{
//optimization, detect when we don't have to reload this
return;
}
Kill();
m_dmodBasePath = basePath;
if (!bUsingDinkPak)
{
m_gamePath = GetBaseAppPath()+gamePath;
m_basePath = basePath;
} else
{
//using dink.pak
m_basePath = gamePath+basePath;
}
m_dmodGamePath = dmodGamePath;
//first scan for an .ff file
assert(!m_fp);
if (!dmodGamePath.empty())
{
m_fp = fopen((m_dmodGamePath+m_dmodBasePath+"dir.ff").c_str(), "rb");
}
if (!m_fp)
{
m_fp = fopen((m_gamePath+m_basePath+"dir.ff").c_str(), "rb");
if (m_fp)
{
m_bUsingBaseDinkFF = true;
}
}
if (!m_fp) return; //no ff to scan in this case
int totalFiles;
FFFileInfo f;
fread(&totalFiles, sizeof(int), 1, m_fp);
for (int i=0; i < totalFiles; i++)
{
fread(&f, sizeof(f), 1, m_fp);
assert(strlen(f.name) < 13);
ToLowerCase(f.name);
m_fileHeader.push_back(f);
}
//LogMsg("FFScanning %s, %d entries", basePath.c_str(), m_fileHeader.size());
}
int FFReader::GetNextFFIndex(int index)
{
if (m_fileHeader[index+1].offset != 0)
{
return index+1;
}
assert(index+2 < m_fileHeader.size() );
return index+2;
}
void FFReader::SetError(eErrorType error)
{
m_error = error;
if (error == ERROR_LOW_MEM)
{
GetBaseApp()->SetLastError(BaseApp::ERROR_MEM);
}
}
byte * FFReader::LoadFFIntoMemory(int index, int *pSizeOut)
{
int byteSize = m_fileHeader[GetNextFFIndex(index)].offset-m_fileHeader[index].offset;
if (pSizeOut) *pSizeOut = byteSize;
fseek(m_fp, m_fileHeader[index].offset, SEEK_SET);
byte *pMem = new byte[byteSize+1]; //extra one for a null we're going to attach
#ifdef _DEBUG
/*
if (Random(60) == 1)
{
//fake a memory error
SAFE_DELETE_ARRAY(pMem);
}
*/
#endif
if (!pMem)
{
LogError("Out of mem!");
SetError(ERROR_LOW_MEM);
return NULL;
}
pMem[byteSize] = 0; //ending null, useful if we loaded a text file
fread(pMem, byteSize, 1, m_fp);
return pMem;
}
byte * FFReader::LoadFileIntoMemory( string const &fName, int *pSizeOut )
{
#ifdef _DEBUG
//LogMsg("loading for %s", (m_basePath+fName).c_str());
#endif
int len;
byte *pBuff = NULL;
if (m_fp)
{
if (m_bUsingBaseDinkFF && !m_dmodGamePath.empty())
{
//you know what? Let's do a last minute try in the dmod dir as well.
if (FileExists(m_dmodGamePath+m_dmodBasePath+fName))
{
//pBuff = LoadFileIntoMemoryBasic(m_dmodGamePath+m_basePath+fName, &len, false, false);
pBuff = GetFileManager()->Get(m_dmodGamePath+m_dmodBasePath+fName, &len, false);
if (!pBuff) SetError(ERROR_LOW_MEM);
return pBuff;
}
}
int index = GetFFRecordIndexFromFileName(fName);
if (index != -1)
{
//we found it!
return LoadFFIntoMemory(index, pSizeOut);
}
} else
{
if (!m_dmodGamePath.empty())
{
if (FileExists(m_dmodGamePath+m_dmodBasePath+fName))
{
//pBuff = LoadFileIntoMemoryBasic(m_dmodGamePath+m_basePath+fName, &len, false, false);
pBuff = GetFileManager()->Get(m_dmodGamePath+m_dmodBasePath+fName, &len,false);
if (!pBuff) SetError(ERROR_LOW_MEM);
return pBuff;
}
}
//pBuff = LoadFileIntoMemoryBasic(m_gamePath+m_basePath+fName, &len, false, false);
pBuff = GetFileManager()->Get(m_gamePath+m_basePath+fName,&len, false);
if (len == UINT_MAX) SetError(ERROR_LOW_MEM);
return pBuff;
}
return NULL;
}

60
source/dink/FFReader.h Normal file
View file

@ -0,0 +1,60 @@
// ***************************************************************
// FFReader - Creation date: 12/31/2009
// -------------------------------------------------------------
// Robinson Technologies Copyright (C) 2009 - All Rights Reserved
//
// ***************************************************************
// Programmer(s): Seth A. Robinson (seth@rtsoft.com)
// ***************************************************************
#ifndef FFReader_h__
#define FFReader_h__
#include "BaseApp.h"
#pragma pack(push, 1)
struct FFFileInfo
{
int offset;
char name[13];
};
#pragma pack(pop)
class FFReader
{
public:
enum eErrorType
{
ERROR_NONE,
ERROR_LOW_MEM
};
FFReader();
virtual ~FFReader();
bool DoesFileExist(const string &fName);
void Init( const string &gamePath, const string &dmodGamePath, const string &baseDir, bool bUsingDinkPak);
byte * LoadFileIntoMemory(string const &fName, int *pSizeout); //you need to delete [] what this gives you on your own
eErrorType GetLastError() {return m_error;}
private:
void Kill();
int GetFFRecordIndexFromFileName(const string &fName);
byte * LoadFFIntoMemory(int index, int *pSizeOut);
int GetNextFFIndex(int index);
void SetError(eErrorType error);
string m_gamePath;
string m_dmodGamePath;
string m_basePath;
FILE *m_fp;
bool m_bUsingBaseDinkFF;
eErrorType m_error;
string m_dmodBasePath;
vector<FFFileInfo> m_fileHeader;
};
#endif // FFReader_h__

View file

@ -0,0 +1,38 @@
#include "PlatformPrecomp.h"
#include "ScriptAccelerator.h"
#include "util/MiscUtils.h"
ScriptAccelerator::ScriptAccelerator()
{
}
ScriptAccelerator::~ScriptAccelerator()
{
}
void ScriptAccelerator::Kill()
{
m_data.clear();
}
void ScriptAccelerator::AddPosition(string label, int current)
{
label = ToUpperCaseString(label);
m_data[label] = ScriptPosition(current);
}
ScriptPosition * ScriptAccelerator::GetPositionByName( string label )
{
label = ToUpperCaseString(label);
ScriptMap::iterator itor = m_data.find(label);
if (itor != m_data.end())
{
//bingo!
return &(itor->second);
}
return NULL;
}

Some files were not shown because too many files have changed in this diff Show more