1 Star 0 Fork 0

weimingtom2000/onscripter_en_fork2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ONScripterLabel_command.cpp 121.07 KB
一键复制 编辑 原始数据 按行查看 历史
weimingtom2000 提交于 2020-06-14 15:20 . v6
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436
/* -*- C++ -*-
*
* ONScripterLabel_command.cpp - Command executer of ONScripter-EN
*
* Copyright (c) 2001-2011 Ogapee. All rights reserved.
* (original ONScripter, of which this is a fork).
*
* ogapee@aqua.dti2.ne.jp
*
* Copyright (c) 2007-2011 "Uncle" Mion Sonozaki
*
* UncleMion@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Modified by Haeleth, autumn 2006, to remove unnecessary diagnostics and support ADOS properly.
// Modified by Mion, March 2008, to update from
// Ogapee's 20080121 release source code.
// Modified by Mion, April 2009, to update from
// Ogapee's 20090331 release source code.
// Modified by Mion, November 2009, to update from
// Ogapee's 20091115 release source code.
#ifdef _MSC_VER
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#endif
#include "ONScripterLabel.h"
#include "version.h"
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#ifdef WIN32
#include <direct.h>
#include <windows.h>
#include "SDL_syswm.h"
#endif
#ifdef MACOSX
#include "cocoa_url.h"
#include "cocoa_encoding.h"
#include "cocoa_alertbox.h"
#endif
#ifdef LINUX
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#endif
#ifdef _MSC_VER
#define snprintf _snprintf
#endif
#define DEFAULT_CURSOR_WAIT ":l/3,160,2;cursor0.bmp"
#define DEFAULT_CURSOR_NEWPAGE ":l/3,160,2;cursor1.bmp"
#define CONTINUOUS_PLAY
extern SDL_TimerID timer_bgmfade_id;
extern "C" Uint32 bgmfadeCallback( Uint32 interval, void *param );
int ONScripterLabel::yesnoboxCommand()
{
//Mion: Currently we only support dialog boxes on Windows and Mac OS X.
// Any ideas on making dialog boxes for Linux etc.?
#if !defined(MACOSX) && !(defined(WIN32) && defined(USE_MESSAGEBOX))
if (!answer_dialog_with_yes_ok)
return RET_NOMATCH;
#endif
bool is_yesnobox = false;
if (script_h.isName( "yesnobox" )){
fprintf(stderr,"yesnobox: ");
is_yesnobox = true;
}
else if (script_h.isName( "okcancelbox" ))
fprintf(stderr,"okcancelbox: ");
script_h.readVariable();
script_h.pushVariable();
const char *buf = script_h.readStr();
char *msg = new char[strlen(buf)+1];
sprintf(msg,"%s",buf);
const char *title = script_h.readStr();
int res = 1;
if(!answer_dialog_with_yes_ok) {
//The OS X dialog box routines are crashing when in fullscreen mode,
//so let's switch to windowed mode just in case
menu_windowCommand();
#if defined(MACOSX)
bool selectedYes;
if(is_yesnobox) {
selectedYes = ONSCocoa::choicebox(title, msg, "Yes", "No", ONSCocoa::ENC_SJIS);
} else {
selectedYes = ONSCocoa::choicebox(title, msg, "OK", "Cancel", ONSCocoa::ENC_SJIS);
}
res = selectedYes ? 1 : 0;
#elif defined(WIN32) && defined(USE_MESSAGEBOX)
UINT mb_type = MB_OKCANCEL;
if (is_yesnobox)
mb_type = MB_YESNO;
HWND pwin = NULL;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWMInfo(&info) == 1)
pwin = info.window;
res = MessageBox(pwin, msg, title, mb_type);
res = ((res == IDYES) || (res == IDOK)) ? 1 : 0;
#endif
}
script_h.setInt( &script_h.pushed_variable, res );
fprintf(stderr,"Got dialog '%s': '%s', returned value of %d\n",
title, msg, res);
delete[] msg;
return RET_CONTINUE;
}
int ONScripterLabel::waveCommand()
{
wave_play_loop_flag = false;
if (script_h.isName( "waveloop" ))
wave_play_loop_flag = true;
wavestopCommand();
setStr(&wave_file_name, script_h.readStr());
playSound(wave_file_name, SOUND_WAVE|SOUND_OGG, wave_play_loop_flag, MIX_WAVE_CHANNEL);
return RET_CONTINUE;
}
int ONScripterLabel::wavestopCommand()
{
setStr( &wave_file_name, NULL );
return RET_CONTINUE;
}
int ONScripterLabel::waittimerCommand()
{
int count = script_h.readInt() + internal_timer - SDL_GetTicks();
if (count < 0) count = 0;
event_mode = WAIT_TIMER_MODE;
waitEvent( count );
return RET_CONTINUE;
}
int ONScripterLabel::waitCommand()
{
//using insani's skippable wait concept (modified)
int count = script_h.readInt();
if( (skip_mode & (SKIP_NORMAL | SKIP_TO_WAIT)) || ctrl_pressed_status ) {
//Mion: instead of skipping entirely, let's do a shortened wait (safer)
if (count > 100) {
count = count / 10;
} else if (count > 10) {
count = 10;
}
}
if (count < 0) count = 0;
event_mode = WAIT_TIMER_MODE | WAIT_SLEEP_MODE;
waitEvent( count );
return RET_CONTINUE;
}
int ONScripterLabel::vspCommand()
{
leaveTextDisplayMode();
bool vsp2_flag = false;
if (script_h.isName("vsp2")) vsp2_flag = true;
int no = script_h.readInt();
int v = script_h.readInt();
if (vsp2_flag){
sprite2_info[ no ].visible = (v==1)?true:false;
dirty_rect.add( sprite2_info[no].bounding_rect );
}
else {
sprite_info[ no ].visible = (v==1)?true:false;
dirty_rect.add( sprite_info[no].pos );
if ((v==0) && sprite_info[ no ].is_animatable){
sprite_info[ no ].current_cell = 0;
sprite_info[ no ].direction = 1;
}
}
return RET_CONTINUE;
}
int ONScripterLabel::voicevolCommand()
{
voice_volume = script_h.readInt();
channelvolumes[0] = voice_volume;
return RET_CONTINUE;
}
int ONScripterLabel::vCommand()
{
char buf[256];
sprintf(buf, "voice%c%s.wav", DELIMITER, script_h.getStringBuffer()+1);
playSound(buf, SOUND_WAVE|SOUND_OGG, false, MIX_WAVE_CHANNEL);
return RET_CONTINUE;
}
int ONScripterLabel::trapCommand()
{
if ( script_h.isName( "lr_trap" ) ){
trap_mode = TRAP_LEFT_CLICK | TRAP_RIGHT_CLICK;
}
else if ( script_h.isName( "r_trap" ) ){
trap_mode = TRAP_RIGHT_CLICK;
}
else if ( script_h.isName( "trap" ) ){
trap_mode = TRAP_LEFT_CLICK;
}
else{
printf("trapCommand: cmd [%s] not recognized\n", script_h.getStringBuffer() );
trap_mode = TRAP_NONE;
return RET_CONTINUE;
}
if ( script_h.compareString("off") ){
script_h.readName();
trap_mode = TRAP_NONE;
return RET_CONTINUE;
}
const char *buf = script_h.readLabel();
if ( buf[0] == '*' ){
setStr(&trap_dest, buf+1);
}
else{
printf("trapCommand: [%s] is not supported\n", buf );
}
return RET_CONTINUE;
}
int ONScripterLabel::transbtnCommand()
{
transbtn_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::textspeeddefaultCommand()
{
sentence_font.wait_time = -1;
return RET_CONTINUE;
}
int ONScripterLabel::textspeedCommand()
{
sentence_font.wait_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::textshowCommand()
{
dirty_rect.fill( screen_width, screen_height );
refresh_window_text_mode = REFRESH_NORMAL_MODE | REFRESH_WINDOW_MODE | REFRESH_TEXT_MODE;
if (!setEffect(&window_effect, true, false))
while(doEffect(&window_effect, false));
return RET_CONTINUE;
}
int ONScripterLabel::textonCommand()
{
if (windowchip_sprite_no >= 0)
sprite_info[windowchip_sprite_no].visible = true;
enterTextDisplayMode();
text_on_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::textoffCommand()
{
if (windowchip_sprite_no >= 0)
sprite_info[windowchip_sprite_no].visible = false;
leaveTextDisplayMode(true);
refreshSurface(backup_surface, NULL, REFRESH_NORMAL_MODE);
text_on_flag = false;
return RET_CONTINUE;
}
int ONScripterLabel::texthideCommand()
{
dirty_rect.fill( screen_width, screen_height );
refresh_window_text_mode = REFRESH_NORMAL_MODE | REFRESH_WINDOW_MODE;
if (!setEffect(&window_effect, true, true))
while(doEffect(&window_effect, false));
return RET_CONTINUE;
}
int ONScripterLabel::textexbtnCommand()
{
int txtbtn_no = script_h.readInt();
const char *buf = script_h.readStr();
TextButtonInfoLink *info = text_button_info.next;
TextButtonInfoLink *found = NULL;
while (info) {
if (info->no == txtbtn_no)
found = info;
info = info->next;
}
if (found) {
ButtonLink *button = found->button;
while (button) {
button->exbtn_ctl = new char[ strlen( buf ) + 1 ];
strcpy( button->exbtn_ctl, buf );
button = button->same;
}
}
is_exbtn_enabled = true;
return RET_CONTINUE;
}
int ONScripterLabel::textclearCommand()
{
newPage( false );
return RET_CONTINUE;
}
int ONScripterLabel::textbtnstartCommand()
{
txtbtn_start_num = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::textbtnoffCommand()
{
txtbtn_show = false;
return RET_CONTINUE;
}
int ONScripterLabel::texecCommand()
{
if ( textgosub_clickstr_state == CLICK_NEWPAGE ){
newPage( true );
clickstr_state = CLICK_NONE;
}
else if ( textgosub_clickstr_state == CLICK_WAITEOL ){
if ( !sentence_font.isLineEmpty() && !new_line_skip_flag ){
indent_offset = 0;
line_enter_status = 0;
current_page->add( 0x0a );
sentence_font.newLine();
}
}
return RET_CONTINUE;
}
int ONScripterLabel::tateyokoCommand()
{
int mode = script_h.readInt();
//don't perform this command while in a textgosub
bool in_textgosub = false;
if (textgosub_label) {
NestInfo *tmp_nest = last_nest_info;
while (tmp_nest) {
if (tmp_nest->textgosub_flag) {
in_textgosub = true;
break;
}
tmp_nest = tmp_nest->previous;
}
}
if (!in_textgosub)
sentence_font.setTateyokoMode( mode );
else
fprintf(stderr, "tateyoko: in textgosub, ignoring\n");
return RET_CONTINUE;
}
int ONScripterLabel::talCommand()
{
leaveTextDisplayMode();
char loc = script_h.readName()[0];
int no = -1, trans = 0;
if ( loc == 'l' ) no = 0;
else if ( loc == 'c' ) no = 1;
else if ( loc == 'r' ) no = 2;
if (no >= 0){
trans = script_h.readInt();
if (trans > 256) trans = 256;
else if (trans < 0 ) trans = 0;
tachi_info[ no ].trans = trans;
dirty_rect.add( tachi_info[ no ].pos );
}
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripterLabel::tablegotoCommand()
{
int count = 0;
int no = script_h.readInt();
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
const char *buf = script_h.readLabel();
if ( count++ == no ){
setCurrentLabel( buf+1 );
break;
}
}
return RET_CONTINUE;
}
int ONScripterLabel::systemcallCommand()
{
system_menu_mode = getSystemCallNo( script_h.readName() );
//if (!rgosub_label)
executeSystemCall();
system_menu_mode = SYSTEM_NULL;
return RET_CONTINUE;
}
int ONScripterLabel::strspCommand()
{
leaveTextDisplayMode();
bool v=true;
if ( script_h.isName( "strsph" ) )
v = false;
int sprite_no = script_h.readInt();
AnimationInfo *ai = &sprite_info[sprite_no];
if ( ai->visible )
dirty_rect.add( ai->pos );
ai->remove();
setStr(&ai->file_name, script_h.readStr());
Fontinfo fi;
fi.is_newline_accepted = true;
ai->orig_pos.x = script_h.readInt();
ai->orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(ai);
fi.num_xy[0] = script_h.readInt();
fi.num_xy[1] = script_h.readInt();
fi.font_size_xy[0] = script_h.readInt();
fi.font_size_xy[1] = script_h.readInt();
fi.pitch_xy[0] = script_h.readInt() + fi.font_size_xy[0];
fi.pitch_xy[1] = script_h.readInt() + fi.font_size_xy[1];
fi.is_bold = script_h.readInt()?true:false;
fi.is_shadow = script_h.readInt()?true:false;
char *buffer = script_h.getNext();
while(script_h.getEndStatus() & ScriptHandler::END_COMMA){
ai->num_of_cells++;
script_h.readStr();
}
if (ai->num_of_cells == 0){
ai->num_of_cells = 1;
ai->color_list = new uchar3[ai->num_of_cells];
ai->color_list[0][0] = ai->color_list[0][1] = ai->color_list[0][2] = 0xff;
}
else{
ai->color_list = new uchar3[ai->num_of_cells];
script_h.setCurrent(buffer);
for (int i=0 ; i<ai->num_of_cells ; i++)
readColor(&ai->color_list[i], readColorStr());
}
ai->trans_mode = AnimationInfo::TRANS_STRING;
ai->trans = 256;
ai->visible = v;
ai->is_single_line = false;
ai->is_tight_region = false;
setupAnimationInfo(ai, &fi);
if ( ai->visible )
dirty_rect.add( ai->pos );
return RET_CONTINUE;
}
int ONScripterLabel::stopCommand()
{
wavestopCommand();
//NScr doesn't stop loopbgm w/this cmd
return mp3stopCommand();
}
int ONScripterLabel::sp_rgb_gradationCommand()
{
leaveTextDisplayMode();
int no = script_h.readInt();
int upper_r = script_h.readInt();
int upper_g = script_h.readInt();
int upper_b = script_h.readInt();
int lower_r = script_h.readInt();
int lower_g = script_h.readInt();
int lower_b = script_h.readInt();
ONSBuf key_r = script_h.readInt();
ONSBuf key_g = script_h.readInt();
ONSBuf key_b = script_h.readInt();
Uint32 alpha = script_h.readInt();
AnimationInfo *si;
if (no == -1) si = &sentence_font_info;
else si = &sprite_info[no];
SDL_Surface *surface = si->image_surface;
if (surface == NULL) return RET_CONTINUE;
SDL_PixelFormat *fmt = SDL_Surface_get_format(surface);
ONSBuf key_mask = (key_r >> fmt->Rloss) << fmt->Rshift |
(key_g >> fmt->Gloss) << fmt->Gshift |
(key_b >> fmt->Bloss) << fmt->Bshift;
ONSBuf rgb_mask = fmt->Rmask | fmt->Gmask | fmt->Bmask;
SDL_LockSurface(surface);
// check upper and lower bound
int i, j;
int upper_bound=0, lower_bound=0;
bool is_key_found = false;
for (i=0 ; i<SDL_Surface_get_h(surface) ; i++){
ONSBuf *buf = (ONSBuf *)SDL_Surface_get_pixels(surface) + SDL_Surface_get_w(surface) * i;
for (j=0 ; j < SDL_Surface_get_w(surface) ; j++, buf++){
if ((*buf & rgb_mask) == key_mask){
if (is_key_found == false){
is_key_found = true;
upper_bound = lower_bound = i;
}
else{
lower_bound = i;
}
break;
}
}
}
// replace pixels of the key-color with the specified color in gradation
for (i=upper_bound ; i<=lower_bound ; i++){
ONSBuf *buf = (ONSBuf *)SDL_Surface_get_pixels(surface) + SDL_Surface_get_w(surface) * i;
#ifdef BPP16
unsigned char *alphap = si->alpha_buf + SDL_Surface_get_w(surface) * i;
#else
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
unsigned char *alphap = (unsigned char *)buf + 3;
#else
unsigned char *alphap = (unsigned char *)buf;
#endif
#endif
Uint32 color = alpha << SDL_Surface_get_format(surface)->Ashift;
if (upper_bound != lower_bound){
color |= (((lower_r - upper_r) * (i-upper_bound) / (lower_bound - upper_bound) + upper_r) >> fmt->Rloss) << fmt->Rshift;
color |= (((lower_g - upper_g) * (i-upper_bound) / (lower_bound - upper_bound) + upper_g) >> fmt->Gloss) << fmt->Gshift;
color |= (((lower_b - upper_b) * (i-upper_bound) / (lower_bound - upper_bound) + upper_b) >> fmt->Bloss) << fmt->Bshift;
}
else{
color |= (upper_r >> fmt->Rloss) << fmt->Rshift;
color |= (upper_g >> fmt->Gloss) << fmt->Gshift;
color |= (upper_b >> fmt->Bloss) << fmt->Bshift;
}
for (j=0 ; j < SDL_Surface_get_w(surface) ; j++, buf++){
if ((*buf & rgb_mask) == key_mask){
*buf = color;
*alphap = alpha;
}
#ifdef BPP16
alphap++;
#else
alphap += 4;
#endif
}
}
SDL_UnlockSurface(surface);
if ( si->visible )
dirty_rect.add( si->pos );
return RET_CONTINUE;
}
int ONScripterLabel::spstrCommand()
{
decodeExbtnControl( script_h.readStr() );
return RET_CONTINUE;
}
int ONScripterLabel::spreloadCommand()
{
leaveTextDisplayMode();
int no = script_h.readInt();
AnimationInfo *si;
if (no == -1) si = &sentence_font_info;
else si = &sprite_info[no];
parseTaggedString( si );
setupAnimationInfo( si );
if ( si->visible )
dirty_rect.add( si->pos );
return RET_CONTINUE;
}
int ONScripterLabel::splitCommand()
{
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
char delimiter = script_h.readStr()[0];
char *token = new char[strlen(save_buf)+1];
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
unsigned int c=0;
while(save_buf[c] != delimiter && save_buf[c] != '\0'){
if (IS_TWO_BYTE(save_buf[c]))
c += 2;
else
c++;
}
memcpy( token, save_buf, c );
token[c] = '\0';
script_h.readVariable();
if ( script_h.current_variable.type & ScriptHandler::VAR_INT ||
script_h.current_variable.type & ScriptHandler::VAR_ARRAY ){
script_h.setInt( &script_h.current_variable, atoi(token) );
}
else if ( script_h.current_variable.type & ScriptHandler::VAR_STR ){
setStr( &script_h.getVariableData(script_h.current_variable.var_no).str, token );
}
save_buf += c;
if (save_buf[0] != '\0') save_buf++;
}
delete[] token;
return RET_CONTINUE;
}
int ONScripterLabel::spclclkCommand()
{
if ( !force_button_shortcut_flag )
spclclk_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::spbtnCommand()
{
bool cellcheck_flag = false;
if ( script_h.isName( "cellcheckspbtn" ) )
cellcheck_flag = true;
int sprite_no = script_h.readInt();
int no = script_h.readInt();
if ( cellcheck_flag ){
if ( sprite_info[ sprite_no ].num_of_cells < 2 ) return RET_CONTINUE;
}
else{
if ( sprite_info[ sprite_no ].num_of_cells == 0 ) return RET_CONTINUE;
}
ButtonLink *button = new ButtonLink();
root_button_link.insert( button );
button->button_type = ButtonLink::SPRITE_BUTTON;
button->sprite_no = sprite_no;
button->no = no;
if ( sprite_info[ sprite_no ].image_surface ||
sprite_info[ sprite_no ].trans_mode == AnimationInfo::TRANS_STRING )
{
button->image_rect = button->select_rect = sprite_info[ sprite_no ].pos;
}
return RET_CONTINUE;
}
int ONScripterLabel::skipoffCommand()
{
skip_mode &= ~SKIP_NORMAL;
return RET_CONTINUE;
}
#ifdef LINUX
int tryToLaunch(const char* command, const char* target)
{
if (!command || !target) return -1;
pid_t child = vfork();
if (child == -1) {
// Parent, failed
fprintf(stderr, "Could not open `%s': fork error: %s\n",
target, strerror(errno));
return 0;
}
else if (child) {
// Parent, success
int status;
waitpid(child, &status, 0);
if (WIFEXITED(status)) return WEXITSTATUS(status);
return -1;
}
else {
// Child
execlp(command, command, target, (char*) NULL);
_exit(255);
}
}
#endif
int ONScripterLabel::shellCommand()
{
#ifdef WIN32
const char *url = script_h.readStr();
HMODULE shdll = LoadLibrary("shell32");
if (shdll) {
typedef HINSTANCE (WINAPI *SHELLEXECUTE)(HWND, LPCSTR, LPCSTR, LPCSTR,
LPCSTR, int);
SHELLEXECUTE shexec =
SHELLEXECUTE(GetProcAddress(shdll, "ShellExecuteA"));
if (shexec) {
shexec(NULL, "open", url, NULL, NULL, SW_SHOW);
}
FreeLibrary(shdll);
}
#elif defined MACOSX
ONSCocoa::open_url(script_h.readStr(), ONSCocoa::ENC_SJIS);
#elif defined LINUX
// Linux/BSD/other Unixes don't provide standard APIs for this
// kind of thing, but there are various things we can try.
const char *url = script_h.readStr();
int status;
// First up is xdg-open, the freedesktop solution that's becoming
// standard in the Linux world, at least.
//
status = tryToLaunch("xdg-open", url);
switch (status) {
case 0: // Success
return RET_CONTINUE;
case 2: // File not found
fprintf(stderr, "Failed to open %s: xdg-error reports that it doesn't "
"exist\n", url);
return RET_CONTINUE;
case 255: // execlp() failed (e.g. xdg-open not present)
// Don't say anything.
break;
case 1: // Syntax error
case 3: // Required tool missing
case 4: // Action failed
case -1: // child didn't exit normally
default: // unknown problem
fprintf(stderr, "Open URL with xdg-open failed with status %d\n",
status);
}
// Failing that, try $BROWSER, or give up.
const char* browser = getenv("BROWSER");
if (browser) {
char* cmd = new char[strlen(browser) + strlen(url) + 8];
sprintf(cmd, "\"%s\" '%s' &", browser, url);
if (system(cmd) != 0)
fprintf(stderr, "Couldn't launch web browser `%s': check your "
"BROWSER setting.\n", browser);
delete[] cmd;
}
else {
fputs("Could not determine which web browser to use. "
"Please set BROWSER appropriately.\n", stderr);
}
#else
fprintf(stderr, "[shell] command not supported for this OS\n");
#endif
return RET_CONTINUE;
}
int ONScripterLabel::sevolCommand()
{
se_volume = script_h.readInt();
for ( int i=1 ; i<ONS_MIX_CHANNELS ; i++ ) {
channelvolumes[i] = se_volume;
}
return RET_CONTINUE;
}
void ONScripterLabel::setwindowCore()
{
sentence_font.ttf_font = NULL;
sentence_font.top_xy[0] = script_h.readInt();
sentence_font.top_xy[1] = script_h.readInt();
sentence_font.num_xy[0] = script_h.readInt();
sentence_font.num_xy[1] = script_h.readInt();
sentence_font.font_size_xy[0] = script_h.readInt();
sentence_font.font_size_xy[1] = script_h.readInt();
sentence_font.pitch_xy[0] = script_h.readInt() + sentence_font.font_size_xy[0];
sentence_font.pitch_xy[1] = script_h.readInt() + sentence_font.font_size_xy[1];
sentence_font.wait_time = script_h.readInt();
sentence_font.is_bold = script_h.readInt()?true:false;
sentence_font.is_shadow = script_h.readInt()?true:false;
bool is_color = false;
const char *buf;
if (allow_color_type_only) {
buf = script_h.readColor(&is_color);
if (!is_color)
buf = script_h.readStr();
} else {
buf = script_h.readStr();
if ( buf[0] == '#' ) is_color = true;
}
dirty_rect.add( sentence_font_info.pos );
if ( is_color ){
sentence_font.is_transparent = true;
readColor( &sentence_font.window_color, buf );
sentence_font_info.orig_pos.x = script_h.readInt();
sentence_font_info.orig_pos.y = script_h.readInt();
sentence_font_info.orig_pos.w = script_h.readInt() - sentence_font_info.orig_pos.x + 1;
sentence_font_info.orig_pos.h = script_h.readInt() - sentence_font_info.orig_pos.y + 1;
UpdateAnimPosStretchXY(&sentence_font_info);
UpdateAnimPosStretchWH(&sentence_font_info);
}
else{
sentence_font.is_transparent = false;
sentence_font_info.setImageName( buf );
parseTaggedString( &sentence_font_info );
#ifdef RCA_SCALE
setupAnimationInfo( &sentence_font_info, NULL, scr_stretch_x, scr_stretch_y );
#else
setupAnimationInfo( &sentence_font_info );
#endif
sentence_font_info.orig_pos.x = script_h.readInt();
sentence_font_info.orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(&sentence_font_info);
sentence_font.window_color[0] = sentence_font.window_color[1] = sentence_font.window_color[2] = 0xff;
}
#ifdef RCA_SCALE
// Scale and reposition window size if screen is bigger than game
if (scr_stretch_x > 1.0) {
sentence_font.top_xy[0] = sentence_font.top_xy[0] * scr_stretch_x + 0.5;
# if 1
// Either increase number of characters on screen
sentence_font.num_xy[0] = sentence_font.num_xy[0] * scr_stretch_x + 0.5;
# else
// Or increase font size
sentence_font.pitch_xy[0] = sentence_font.pitch_xy[0] * scr_stretch_x + 0.5;
sentence_font.font_size_xy[0] = sentence_font.font_size_xy[0] * scr_stretch_x + 0.5;
# endif
}
if (scr_stretch_y > 1.0) {
sentence_font.top_xy[1] = sentence_font.top_xy[1] * scr_stretch_y + 0.5;
# if 1
// Either increase number of characters on screen
sentence_font.num_xy[1] = sentence_font.num_xy[1] * scr_stretch_y + 0.5;
# else
// Or increase font size
sentence_font.pitch_xy[1] = sentence_font.pitch_xy[1] * scr_stretch_y + 0.5;
sentence_font.font_size_xy[1] = sentence_font.font_size_xy[1] * scr_stretch_y + 0.5;
# endif
}
#endif //RCA_SCALE
}
int ONScripterLabel::setwindow3Command()
{
setwindowCore();
display_mode = DISPLAY_MODE_NORMAL;
flush( refreshMode(), &sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripterLabel::setwindow2Command()
{
bool is_color = false;
const char *buf;
if (allow_color_type_only) {
buf = script_h.readColor(&is_color);
if (!is_color)
buf = script_h.readStr();
} else {
buf = script_h.readStr();
if ( buf[0] == '#' ) is_color = true;
}
if ( is_color ){
sentence_font.is_transparent = true;
readColor( &sentence_font.window_color, buf );
}
else{
sentence_font.is_transparent = false;
sentence_font_info.setImageName( buf );
parseTaggedString( &sentence_font_info );
setupAnimationInfo( &sentence_font_info );
}
repaintCommand();
return RET_CONTINUE;
}
int ONScripterLabel::setwindowCommand()
{
setwindowCore();
lookbackflushCommand();
indent_offset = 0;
line_enter_status = 0;
page_enter_status = 0;
display_mode = DISPLAY_MODE_NORMAL;
flush( refreshMode(), &sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripterLabel::seteffectspeedCommand()
{
int no = script_h.readInt();
effectspeed = EFFECTSPEED_NORMAL;
if (no == 1)
effectspeed = EFFECTSPEED_QUICKER;
else if (no == 2)
effectspeed = EFFECTSPEED_INSTANT;
return RET_CONTINUE;
}
int ONScripterLabel::setcursorCommand()
{
bool abs_flag;
if ( script_h.isName( "abssetcursor" ) ){
abs_flag = true;
}
else{
abs_flag = false;
}
int no = script_h.readInt();
script_h.readStr();
const char* buf = script_h.saveStringBuffer();
int x = script_h.readInt();
int y = script_h.readInt();
loadCursor( no, buf, x, y, abs_flag );
return RET_CONTINUE;
}
int ONScripterLabel::selectCommand()
{
enterTextDisplayMode();
int select_mode = SELECT_GOTO_MODE;
SelectLink *last_select_link;
if ( script_h.isName( "selnum" ) )
select_mode = SELECT_NUM_MODE;
else if ( script_h.isName( "selgosub" ) )
select_mode = SELECT_GOSUB_MODE;
else if ( script_h.isName( "select" ) )
select_mode = SELECT_GOTO_MODE;
else if ( script_h.isName( "csel" ) )
select_mode = SELECT_CSEL_MODE;
if ( select_mode == SELECT_NUM_MODE ){
script_h.readVariable();
script_h.pushVariable();
}
bool comma_flag = true;
if ( select_mode == SELECT_CSEL_MODE ){
saveoffCommand();
}
shortcut_mouse_line = -1;
int xy[2];
xy[0] = sentence_font.xy[0];
xy[1] = sentence_font.xy[1];
if ( selectvoice_file_name[SELECTVOICE_OPEN] )
playSound(selectvoice_file_name[SELECTVOICE_OPEN],
SOUND_WAVE|SOUND_OGG, false, MIX_WAVE_CHANNEL );
last_select_link = &root_select_link;
while(1){
if ( script_h.getNext()[0] != 0x0a && comma_flag == true ){
const char *buf = script_h.readStr();
comma_flag = (script_h.getEndStatus() & ScriptHandler::END_COMMA);
if ( select_mode != SELECT_NUM_MODE && !comma_flag )
errorAndExit( "select: missing comma." );
// Text part
SelectLink *slink = new SelectLink();
setStr( &slink->text, buf );
//printf("Select text %s\n", slink->text);
// Label part
if (select_mode != SELECT_NUM_MODE){
script_h.readLabel();
setStr( &slink->label, script_h.getStringBuffer()+1 );
//printf("Select label %s\n", slink->label );
}
last_select_link->next = slink;
last_select_link = last_select_link->next;
comma_flag = (script_h.getEndStatus() & ScriptHandler::END_COMMA);
//printf("2 comma %d %c %x\n", comma_flag, script_h.getCurrent()[0], script_h.getCurrent()[0]);
}
else if (script_h.getNext()[0] == 0x0a){
//printf("comma %d\n", comma_flag);
char *buf = script_h.getNext() + 1; // consume eol
while ( *buf == ' ' || *buf == '\t' ) buf++;
if (comma_flag && *buf == ',')
errorAndExit( "select: double comma." );
bool comma2_flag = false;
if (*buf == ','){
comma2_flag = true;
buf++;
while ( *buf == ' ' || *buf == '\t' ) buf++;
}
script_h.setCurrent(buf);
if (*buf == 0x0a){
comma_flag |= comma2_flag;
continue;
}
if (!comma_flag && !comma2_flag){
select_label_info.next_script = buf;
//printf("select: stop at the end of line\n");
break;
}
//printf("continue\n");
comma_flag = true;
}
else{ // if select ends at the middle of the line
select_label_info.next_script = script_h.getNext();
//printf("select: stop at the middle of the line\n");
break;
}
}
if ( select_mode != SELECT_CSEL_MODE ){
last_select_link = root_select_link.next;
int counter = 1;
while( last_select_link ){
if ( *last_select_link->text ){
ButtonLink *button = getSelectableSentence( last_select_link->text, &sentence_font );
root_button_link.insert( button );
button->no = counter;
}
counter++;
last_select_link = last_select_link->next;
}
}
if ( select_mode == SELECT_CSEL_MODE ){
setCurrentLabel( "customsel" );
return RET_CONTINUE;
}
skip_mode &= ~SKIP_NORMAL;
automode_flag = false;
sentence_font.xy[0] = xy[0];
sentence_font.xy[1] = xy[1];
flush( refreshMode() );
refreshMouseOverButton();
bool actual_rmode = rmode_flag;
rmode_flag = false;
event_mode = WAIT_TEXT_MODE | WAIT_BUTTON_MODE | WAIT_TIMER_MODE;
do {
waitEvent(-1);
} while ( !current_button_state.valid_flag ||
(current_button_state.button <= 0) );
rmode_flag = actual_rmode;
if ( selectvoice_file_name[SELECTVOICE_SELECT] )
playSound(selectvoice_file_name[SELECTVOICE_SELECT],
SOUND_WAVE|SOUND_OGG, false, MIX_WAVE_CHANNEL );
deleteButtonLink();
int counter = 1;
last_select_link = root_select_link.next;
while ( last_select_link ){
if ( current_button_state.button == counter++ ) break;
last_select_link = last_select_link->next;
}
if ( select_mode == SELECT_GOTO_MODE ){
setCurrentLabel( last_select_link->label );
}
else if ( select_mode == SELECT_GOSUB_MODE ){
gosubReal( last_select_link->label, select_label_info.next_script );
}
else{ // selnum
script_h.setInt( &script_h.pushed_variable, current_button_state.button - 1 );
current_label_info = script_h.getLabelByAddress( select_label_info.next_script );
current_line = script_h.getLineByAddress( select_label_info.next_script );
script_h.setCurrent( select_label_info.next_script );
}
deleteSelectLink();
newPage( true );
return RET_CONTINUE;
}
int ONScripterLabel::savetimeCommand()
{
int no = script_h.readInt();
SaveFileInfo info;
searchSaveFile( info, no );
script_h.readVariable();
if ( !info.valid ){
script_h.setInt( &script_h.current_variable, 0 );
for ( int i=0 ; i<3 ; i++ )
script_h.readVariable();
return RET_CONTINUE;
}
script_h.setInt( &script_h.current_variable, info.month );
script_h.readInt();
script_h.setInt( &script_h.current_variable, info.day );
script_h.readInt();
script_h.setInt( &script_h.current_variable, info.hour );
script_h.readInt();
script_h.setInt( &script_h.current_variable, info.minute );
return RET_CONTINUE;
}
int ONScripterLabel::savescreenshotCommand()
{
if ( script_h.isName( "savescreenshot" ) ){
}
else if ( script_h.isName( "savescreenshot2" ) ){
}
const char *buf = script_h.readStr();
char filename[4096];
const char *ext = strrchr( buf, '.' );
if ( ext && (!strcmp( ext+1, "BMP" ) || !strcmp( ext+1, "bmp" ) ) ){
sprintf( filename, "%s%s", script_h.save_path, buf );
int last_delim = 0;
for ( unsigned int i=0 ; i<strlen( filename ) ; i++ ) {
if ( filename[i] == '/' || filename[i] == '\\' ) {
filename[i] = DELIMITER;
last_delim = i;
}
}
if (last_delim) {
filename[last_delim] = 0;
mkdir(filename
#ifndef WIN32
, 0755
#endif
);
filename[last_delim] = DELIMITER;
}
if ( screenshot_surface == NULL ) {
printf("savescreenshot: no screenshot buffer, creating a blank 1x1 surface.\n");
screenshot_surface = SDL_CreateRGBSurface( SDL_SWSURFACE, 1, 1, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
}
SDL_SaveBMP( screenshot_surface, filename );
}
else
printf("savescreenshot: file %s is not supported.\n", buf );
return RET_CONTINUE;
}
int ONScripterLabel::saveonCommand()
{
saveon_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::saveoffCommand()
{
saveon_flag = false;
return RET_CONTINUE;
}
int ONScripterLabel::savegameCommand()
{
bool savegame2_flag = false;
if ( script_h.isName( "savegame2" ) )
savegame2_flag = true;
int no = script_h.readInt();
const char* savestr = NULL;
if (savegame2_flag)
savestr = script_h.readStr();
if ( no < 0 )
errorAndExit("savegame: save number is less than 0.");
else
saveSaveFile( no, savestr );
return RET_CONTINUE;
}
int ONScripterLabel::savefileexistCommand()
{
script_h.readInt();
script_h.pushVariable();
int no = script_h.readInt();
SaveFileInfo info;
searchSaveFile( info, no );
script_h.setInt( &script_h.pushed_variable, (info.valid==true)?1:0 );
return RET_CONTINUE;
}
int ONScripterLabel::rndCommand()
{
int upper, lower;
if ( script_h.isName( "rnd2" ) ){
script_h.readInt();
script_h.pushVariable();
lower = script_h.readInt();
upper = script_h.readInt();
}
else{
script_h.readInt();
script_h.pushVariable();
lower = 0;
upper = script_h.readInt() - 1;
}
script_h.setInt( &script_h.pushed_variable, lower + (int)( (double)(upper-lower+1)*rand()/(RAND_MAX+1.0)) );
return RET_CONTINUE;
}
int ONScripterLabel::rmodeCommand()
{
if ( script_h.readInt() == 1 ) rmode_flag = true;
else rmode_flag = false;
return RET_CONTINUE;
}
int ONScripterLabel::resettimerCommand()
{
internal_timer = SDL_GetTicks();
return RET_CONTINUE;
}
int ONScripterLabel::resetCommand()
{
//clear out the event queue
SDL_Event event;
while( SDL_PollEvent( &event ) )
if (event.type == SDL_QUIT) endCommand();
int fadeout = mp3fadeout_duration;
mp3fadeout_duration = 0; //don't use fadeout during a reset
int effect = window_effect.effect;
int duration = window_effect.duration;
window_effect.effect = 1; //don't use window effect during a reset
window_effect.duration = 0;
resetSub();
window_effect.effect = effect;
window_effect.duration = duration;
//reopen the audio mixer with default settings, if needed
mp3fadeout_duration = fadeout;
clearCurrentPage();
string_buffer_offset = 0;
setCurrentLabel( "start" );
saveSaveFile(-1);
return RET_CONTINUE;
}
int ONScripterLabel::repaintCommand()
{
dirty_rect.fill( screen_width, screen_height );
flush( refreshMode() );
return RET_CONTINUE;
}
int ONScripterLabel::quakeCommand()
{
int quake_type;
if ( script_h.isName( "quakey" ) ){
quake_type = 0;
}
else if ( script_h.isName( "quakex" ) ){
quake_type = 1;
}
else{
quake_type = 2;
}
tmp_effect.no = script_h.readInt();
tmp_effect.duration = script_h.readInt();
//insani's skippable quake
if ( ctrl_pressed_status )
{
dirty_rect.fill( screen_width, screen_height );
SDL_BlitSurface( accumulation_surface, NULL, effect_dst_surface, NULL );
event_mode = IDLE_EVENT_MODE;
return RET_CONTINUE;
}
if ( tmp_effect.duration < tmp_effect.no * 4 ) tmp_effect.duration = tmp_effect.no * 4;
tmp_effect.effect = CUSTOM_EFFECT_NO + quake_type;
dirty_rect.fill( screen_width, screen_height );
SDL_BlitSurface( accumulation_surface, NULL, effect_dst_surface, NULL );
if (setEffect(&tmp_effect, true, true)) return RET_CONTINUE;
while (doEffect(&tmp_effect));
return RET_CONTINUE;
}
int ONScripterLabel::puttextCommand()
{
enterTextDisplayMode(false);
script_h.readStr();
string_buffer_offset = 0;
if (script_h.getEndStatus() & ScriptHandler::END_1BYTE_CHAR)
string_buffer_offset = 1; // skip the heading `
while(processText());
processEOT();
return RET_CONTINUE;
}
int ONScripterLabel::prnumclearCommand()
{
if (system_menu_mode == SYSTEM_NULL)
leaveTextDisplayMode();
for ( int i=0 ; i<MAX_PARAM_NUM ; i++ ) {
if ( prnum_info[i] ) {
dirty_rect.add( prnum_info[i]->pos );
delete prnum_info[i];
prnum_info[i] = NULL;
}
}
return RET_CONTINUE;
}
int ONScripterLabel::prnumCommand()
{
leaveTextDisplayMode();
int no = script_h.readInt();
if ( prnum_info[no] ){
dirty_rect.add( prnum_info[no]->pos );
delete prnum_info[no];
}
prnum_info[no] = new AnimationInfo();
prnum_info[no]->trans_mode = AnimationInfo::TRANS_STRING;
prnum_info[no]->num_of_cells = 1;
prnum_info[no]->setCell(0);
prnum_info[no]->color_list = new uchar3[ prnum_info[no]->num_of_cells ];
prnum_info[no]->param = script_h.readInt();
prnum_info[no]->orig_pos.x = script_h.readInt();
prnum_info[no]->orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(prnum_info[no]);
prnum_info[no]->font_size_xy[0] = script_h.readInt();
prnum_info[no]->font_size_xy[1] = script_h.readInt();
const char *buf = readColorStr();
readColor( &prnum_info[no]->color_list[0], buf );
char num_buf[7];
// Use fullwidth digits
script_h.getStringFromInteger( num_buf, prnum_info[no]->param, 3, false, true );
setStr( &prnum_info[no]->file_name, num_buf );
setupAnimationInfo( prnum_info[no] );
dirty_rect.add( prnum_info[no]->pos );
return RET_CONTINUE;
}
int ONScripterLabel::printCommand()
{
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripterLabel::playstopCommand()
{
stopBGM( false );
return RET_CONTINUE;
}
int ONScripterLabel::playCommand()
{
bool loop_flag = true;
if ( script_h.isName( "playonce" ) )
loop_flag = false;
const char *buf = script_h.readStr();
if ( buf[0] == '*' ){
cd_play_loop_flag = loop_flag;
int new_cd_track = atoi( buf + 1 );
#ifdef CONTINUOUS_PLAY
if ( current_cd_track != new_cd_track ) {
#endif
stopBGM( false );
current_cd_track = new_cd_track;
playCDAudio();
#ifdef CONTINUOUS_PLAY
}
#endif
}
else{ // play MIDI
stopBGM( false );
setStr(&seqmusic_file_name, buf);
seqmusic_play_loop_flag = loop_flag;
if (playSound(seqmusic_file_name, SOUND_SEQMUSIC, seqmusic_play_loop_flag) != SOUND_SEQMUSIC){
fprintf(stderr, "can't play sequenced music file %s\n", seqmusic_file_name);
}
}
return RET_CONTINUE;
}
int ONScripterLabel::ofscopyCommand()
{
SDL_BlitSurface( screen_surface, NULL, accumulation_surface, NULL );
return RET_CONTINUE;
}
int ONScripterLabel::negaCommand()
{
nega_mode = script_h.readInt();
dirty_rect.fill( screen_width, screen_height );
return RET_CONTINUE;
}
int ONScripterLabel::mvCommand()
{
char buf[256];
sprintf(buf, "voice%c%s.mp3", DELIMITER, script_h.getStringBuffer()+2);
setStr(&music_file_name, buf);
//don't bother with playback or fadeins if there's no audio
if ( !audio_open_flag ) return RET_CONTINUE;
int tmp = music_volume;
if (mp3fadein_duration > 0) {
music_volume = 0;
}
playSound(buf, SOUND_MP3, false, MIX_BGM_CHANNEL);
if (mp3fadein_duration > 0) {
// do a bgm fadein
music_volume = tmp;
mp3fade_start = SDL_GetTicks();
timer_bgmfade_id = SDL_AddTimer(20, bgmfadeCallback,
(void*)&timer_bgmfade_id);
event_mode = WAIT_TIMER_MODE;
waitEvent(-1);
}
return RET_CONTINUE;
}
int ONScripterLabel::mspCommand()
{
leaveTextDisplayMode();
bool msp2_flag = false;
if (script_h.isName("msp2")) msp2_flag = true;
int no = script_h.readInt();
AnimationInfo *si=NULL;
if (msp2_flag) {
si = &sprite2_info[no];
dirty_rect.add( si->bounding_rect );
}
else{
si = &sprite_info[no];
dirty_rect.add( si->pos );
}
int dx = script_h.readInt();
int dy = script_h.readInt();
si->orig_pos.x += dx;
si->orig_pos.y += dy;
UpdateAnimPosStretchXY(si);
if (msp2_flag){
si->scale_x += script_h.readInt();
si->scale_y += script_h.readInt();
si->rot += script_h.readInt();
si->calcAffineMatrix();
dirty_rect.add( si->bounding_rect );
}
else{
dirty_rect.add( si->pos );
}
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
si->trans += script_h.readInt();
if ( si->trans > 256 ) si->trans = 256;
else if ( si->trans < 0 ) si->trans = 0;
if ( si->is_animatable ) advanceAnimPhase();
return RET_CONTINUE;
}
int ONScripterLabel::mp3volCommand()
{
music_volume = script_h.readInt();
setCurMusicVolume(music_volume);
return RET_CONTINUE;
}
int ONScripterLabel::mp3stopCommand()
{
if (playingMusic() && (mp3fadeout_duration > 0) &&
(system_menu_mode == SYSTEM_NULL)) {
// do a bgm fadeout
mp3fade_start = SDL_GetTicks();
timer_bgmfade_id = SDL_AddTimer(20, bgmfadeCallback, 0);
event_mode |= WAIT_TIMER_MODE;
waitEvent(-1);
}
stopBGM( false );
return RET_CONTINUE;
}
//Mion: integrating mp3fadeout as it's supposed to work.
int ONScripterLabel::mp3fadeoutCommand()
{
mp3fadeout_duration = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::mp3fadeinCommand()
{
mp3fadein_duration = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::mp3Command()
{
bool loop_flag = false;
if ( script_h.isName( "mp3save" ) ){
mp3save_flag = true;
}
else if ( script_h.isName( "bgmonce" ) ){
mp3save_flag = false;
}
else if ( script_h.isName( "mp3loop" ) ||
script_h.isName( "bgm" ) ){
mp3save_flag = true;
loop_flag = true;
}
else{
mp3save_flag = false;
}
mp3stopCommand();
music_play_loop_flag = loop_flag;
const char *buf = script_h.readStr();
if (buf[0] != '\0'){
int tmp = music_volume;
setStr(&music_file_name, buf);
//don't bother with playback or fadeins if there's no audio
if ( !audio_open_flag ) return RET_CONTINUE;
if (mp3fadein_duration > 0) {
music_volume = 0;
}
playSound(music_file_name,
SOUND_WAVE | SOUND_OGG_STREAMING | SOUND_MP3 | SOUND_SEQMUSIC,
music_play_loop_flag, MIX_BGM_CHANNEL);
music_volume = tmp;
if (mp3fadein_duration > 0) {
// do a bgm fadein
mp3fade_start = SDL_GetTicks();
timer_bgmfade_id = SDL_AddTimer(20, bgmfadeCallback,
(void*)&timer_bgmfade_id);
event_mode = WAIT_TIMER_MODE;
waitEvent(-1);
}
}
return RET_CONTINUE;
}
int ONScripterLabel::movieCommand()
{
bool mpegplay_flag = false;
if ( script_h.isName( "mpegplay" ) ){
mpegplay_flag = true;
} else {
if ( script_h.compareString( "stop" ) ){
script_h.readName();
return RET_CONTINUE;
}
}
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
if (mpegplay_flag) {
movie_loop_flag = false;
movie_click_flag = (script_h.readInt()==1)?true:false;
if (playMPEG( save_buf, false )) endCommand();
return RET_CONTINUE;
}
movie_click_flag = false;
movie_loop_flag = false;
bool async_flag = false;
bool pos_flag = false;
int x=0,y=0,w=0,h=0;
while( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
const char *param = script_h.readName();
if ( strcmp(param, "click") == 0 )
movie_click_flag = true;
else if ( strcmp(param, "loop") == 0 )
movie_loop_flag = true;
else if ( strcmp(param, "async") == 0 )
async_flag = true;
else if ( strcmp(param, "pos") == 0 ) {
pos_flag = true;
x = ExpandPos(script_h.readInt());
y = ExpandPos(script_h.readInt());
w = ExpandPos(script_h.readInt());
h = ExpandPos(script_h.readInt());
}
}
if (playMPEG( save_buf, async_flag, pos_flag, x, y, w, h )) endCommand();
return RET_CONTINUE;
}
int ONScripterLabel::movemousecursorCommand()
{
int x = StretchPosX(script_h.readInt());
int y = StretchPosY(script_h.readInt());
//SDL_WarpMouse( x, y );
return RET_CONTINUE;
}
int ONScripterLabel::mousemodeCommand()
{
int no = script_h.readInt();
if (no == 0) {
; //SDL_ShowCursor(SDL_DISABLE);
} else {
; //SDL_ShowCursor(SDL_ENABLE);
}
return RET_CONTINUE;
}
int ONScripterLabel::monocroCommand()
{
leaveTextDisplayMode();
if ( script_h.compareString( "off" ) ){
script_h.readName();
monocro_flag = false;
}
else{
monocro_flag = true;
readColor( &monocro_color, readColorStr() );
for (int i=0 ; i<256 ; i++){
monocro_color_lut[i][0] = (monocro_color[0] * i) >> 8;
monocro_color_lut[i][1] = (monocro_color[1] * i) >> 8;
monocro_color_lut[i][2] = (monocro_color[2] * i) >> 8;
}
}
dirty_rect.fill( screen_width, screen_height );
return RET_CONTINUE;
}
int ONScripterLabel::minimizewindowCommand()
{
return RET_CONTINUE;
}
int ONScripterLabel::mesboxCommand()
{
const char *buf = script_h.readStr();
char *msg = new char[strlen(buf)+1];
sprintf(msg,"%s",buf);
const char *title = script_h.readStr();
#if defined(MACOSX)
//The OS X dialog box routines are crashing when in fullscreen mode,
//so let's switch to windowed mode just in case
menu_windowCommand();
ONSCocoa::alertbox(title, msg);
#elif defined(WIN32) && defined(USE_MESSAGEBOX)
menu_windowCommand();
HWND pwin = NULL;
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (SDL_GetWMInfo(&info) == 1)
pwin = info.window;
MessageBox(pwin, msg, title, MB_OK);
#endif
fprintf(stderr,"Got message box '%s': '%s'\n", title, msg);
delete[] msg;
return RET_CONTINUE;
}
int ONScripterLabel::menu_windowCommand()
{
if ( fullscreen_mode ){
fullscreen_mode = false;
}
return RET_CONTINUE;
}
int ONScripterLabel::menu_waveonCommand()
{
volume_on_flag = true;
printf("menu_waveon: setting main volume to on\n");
return RET_CONTINUE;
}
int ONScripterLabel::menu_waveoffCommand()
{
volume_on_flag = false;
printf("menu_waveoff: setting main volume to off\n");
return RET_CONTINUE;
}
int ONScripterLabel::menu_fullCommand()
{
if ( !fullscreen_mode ){
}
return RET_CONTINUE;
}
int ONScripterLabel::menu_click_pageCommand()
{
skip_mode |= SKIP_TO_EOP;
printf("menu_click_page: enabling page-at-once mode\n");
return RET_CONTINUE;
}
int ONScripterLabel::menu_click_defCommand()
{
skip_mode &= ~SKIP_TO_EOP;
printf("menu_click_def: disabling page-at-once mode\n");
return RET_CONTINUE;
}
int ONScripterLabel::menu_automodeCommand()
{
automode_flag = true;
skip_mode &= ~SKIP_NORMAL;
printf("menu_automode: change to automode\n");
return RET_CONTINUE;
}
int ONScripterLabel::lsp2Command()
{
leaveTextDisplayMode();
bool v=true;
if ( script_h.isName( "lsph2" ) || script_h.isName( "lsph2add" ) ||
script_h.isName( "lsph2sub" ) )
v = false;
int blend_mode = AnimationInfo::BLEND_NORMAL;
if ( script_h.isName( "lsp2add" ) || script_h.isName( "lsph2add" ) )
blend_mode = AnimationInfo::BLEND_ADD;
else if ( script_h.isName( "lsp2sub" ) || script_h.isName( "lsph2sub" ) )
blend_mode = AnimationInfo::BLEND_SUB;
int no = script_h.readInt();
if ( sprite2_info[no].visible )
dirty_rect.add( sprite2_info[no].bounding_rect );
sprite2_info[ no ].visible = v;
sprite2_info[ no ].blending_mode = blend_mode;
const char *buf = script_h.readStr();
sprite2_info[ no ].setImageName( buf );
sprite2_info[ no ].orig_pos.x = script_h.readInt();
sprite2_info[ no ].orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(&sprite2_info[ no ]);
sprite2_info[ no ].scale_x = script_h.readInt();
sprite2_info[ no ].scale_y = script_h.readInt();
sprite2_info[ no ].rot = script_h.readInt();
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
sprite2_info[ no ].trans = script_h.readInt();
else
sprite2_info[ no ].trans = 256;
parseTaggedString( &sprite2_info[ no ] );
#ifdef RCA_SCALE
setupAnimationInfo( &sprite2_info[ no ], NULL, scr_stretch_x, scr_stretch_y );
#else
setupAnimationInfo( &sprite2_info[ no ] );
#endif
sprite2_info[ no ].calcAffineMatrix();
if ( sprite2_info[no].visible )
dirty_rect.add( sprite2_info[no].bounding_rect );
sprite2_info[ no ].is_animatable = false; //extended sprites don't animate
return RET_CONTINUE;
}
int ONScripterLabel::lspCommand()
{
leaveTextDisplayMode();
bool v=true;
if ( script_h.isName( "lsph" ) )
v = false;
int no = script_h.readInt();
if ( sprite_info[no].visible )
dirty_rect.add( sprite_info[no].pos );
const char *buf = script_h.readStr();
sprite_info[ no ].setImageName( buf );
parseTaggedString( &sprite_info[ no ] );
if (sprite_info[ no ].stale_image) {
//see if the same sprite has been loaded recently
int x = last_loaded_sprite_ind;
for (int i=0; i<SPRITE_NUM_LAST_LOADS; i++) {
if (last_loaded_sprite[x] < 0) continue;
AnimationInfo *anim = &sprite_info[ last_loaded_sprite[x] ];
if (!anim->stale_image &&
sameImageTag(*anim, sprite_info[ no ])) {
sprite_info[ no ].deepcopy(*anim);
sprite_info[ no ].current_cell = 0;
sprite_info[ no ].direction = 1;
sprite_info[ no ].stale_image = false;
break;
}
x += SPRITE_NUM_LAST_LOADS - 1;
x %= SPRITE_NUM_LAST_LOADS;
}
}
sprite_info[ no ].visible = v;
sprite_info[ no ].orig_pos.x = script_h.readInt();
sprite_info[ no ].orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(&sprite_info[ no ]);
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
sprite_info[ no ].trans = script_h.readInt();
else
sprite_info[ no ].trans = 256;
#ifdef RCA_SCALE
setupAnimationInfo( &sprite_info[ no ], NULL, scr_stretch_x, scr_stretch_y );
#else
setupAnimationInfo( &sprite_info[ no ] );
#endif
++last_loaded_sprite_ind %= SPRITE_NUM_LAST_LOADS;
last_loaded_sprite[last_loaded_sprite_ind] = no;
if ( sprite_info[no].visible )
dirty_rect.add( sprite_info[no].pos );
if ( sprite_info[ no ].is_animatable ) advanceAnimPhase();
return RET_CONTINUE;
}
int ONScripterLabel::loopbgmstopCommand()
{
setStr(&loop_bgm_name[0], NULL);
return RET_CONTINUE;
}
int ONScripterLabel::loopbgmCommand()
{
const char *buf = script_h.readStr();
setStr( &loop_bgm_name[0], buf );
buf = script_h.readStr();
setStr( &loop_bgm_name[1], buf );
playSound(loop_bgm_name[1],
SOUND_PRELOAD|SOUND_WAVE|SOUND_OGG, false, MIX_LOOPBGM_CHANNEL1);
playSound(loop_bgm_name[0],
SOUND_WAVE|SOUND_OGG, false, MIX_LOOPBGM_CHANNEL0);
return RET_CONTINUE;
}
int ONScripterLabel::lookbackflushCommand()
{
current_page = current_page->next;
for ( int i=0 ; i<max_page_list-1 ; i++ ){
current_page->text_count = 0;
current_page = current_page->next;
}
clearCurrentPage();
start_page = current_page;
return RET_CONTINUE;
}
int ONScripterLabel::lookbackbuttonCommand()
{
for ( int i=0 ; i<4 ; i++ ){
const char *buf = script_h.readStr();
setStr( &lookback_info[i].image_name, buf );
parseTaggedString( &lookback_info[i] );
setupAnimationInfo( &lookback_info[i] );
}
return RET_CONTINUE;
}
int ONScripterLabel::logspCommand()
{
leaveTextDisplayMode();
bool logsp2_flag = false;
if ( script_h.isName( "logsp2" ) )
logsp2_flag = true;
int sprite_no = script_h.readInt();
AnimationInfo &si = sprite_info[sprite_no];
if ( si.visible ) dirty_rect.add( si.pos );
si.remove();
setStr( &si.file_name, script_h.readStr() );
si.orig_pos.x = script_h.readInt();
si.orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(&si);
si.trans_mode = AnimationInfo::TRANS_STRING;
if (logsp2_flag){
si.font_size_xy[0] = script_h.readInt();
si.font_size_xy[1] = script_h.readInt();
si.font_pitch = script_h.readInt() + si.font_size_xy[0];
script_h.readInt(); // dummy read for y pitch
}
else{
si.font_size_xy[0] = sentence_font.font_size_xy[0];
si.font_size_xy[1] = sentence_font.font_size_xy[1];
si.font_pitch = sentence_font.pitch_xy[0];
}
char *current = script_h.getNext();
int num = 0;
while(script_h.getEndStatus() & ScriptHandler::END_COMMA){
script_h.readStr();
num++;
}
script_h.setCurrent(current);
if (num == 0){
si.num_of_cells = 1;
si.color_list = new uchar3[ si.num_of_cells ];
readColor( &si.color_list[0], "#ffffff" );
}
else{
si.num_of_cells = num;
si.color_list = new uchar3[ si.num_of_cells ];
for (int i=0 ; i<num ; i++){
readColor( &si.color_list[i], readColorStr() );
}
}
si.is_single_line = false;
si.is_tight_region = false;
si.is_ruby_drawable = true;
si.skip_whitespace = false;
sentence_font.is_newline_accepted = true;
#ifdef RCA_SCALE
setupAnimationInfo( &si, NULL, scr_stretch_x, scr_stretch_y );
#else
setupAnimationInfo( &si );
#endif
sentence_font.is_newline_accepted = false;
si.visible = true;
dirty_rect.add( si.pos );
return RET_CONTINUE;
}
int ONScripterLabel::locateCommand()
{
int x = script_h.readInt();
int y = script_h.readInt();
//Mion: correcting the ons-en old style of locate, which depended
// on finding the movements from the current position to
// a new screen position, which could vary depending on the current
// window settings - better to use absolutes
// Also should account for possible vertical text and
// -1 (i.e. unchanged) x or y values
int cur_xy[2];
cur_xy[0] = sentence_font.xy[0];
cur_xy[1] = sentence_font.xy[1];
bool tateyoko = (sentence_font.getTateyokoMode() == Fontinfo::TATE_MODE);
sentence_font.clear();
if (y >= 0) {
current_page->add(ScriptHandler::TEXT_FF); //reset to "top of page"
if (tateyoko)
cur_xy[0] = sentence_font.xy[0] - 2 * y;
else
cur_xy[1] = sentence_font.xy[1] + 2 * y;
}
char downchar = ScriptHandler::TEXT_VTAB;
if (x >= 0) {
current_page->add(ScriptHandler::TEXT_CR); //reset to "start of line"
downchar = ScriptHandler::TEXT_LF;
if (tateyoko)
cur_xy[1] = sentence_font.xy[1] + 2 * x;
else
cur_xy[0] = sentence_font.xy[0] + 2 * x;
}
for (int i=0; i<y*2; i+=2){
current_page->add(downchar);
}
#ifdef _MSC_VER
{
#endif
for (int i=0; i<x*2; i+=2){
//a TAB is like adding a single space, but strippable in "gettext"
current_page->add(ScriptHandler::TEXT_TAB);
current_page->add(ScriptHandler::TEXT_TAB);
}
#ifdef _MSC_VER
}
#endif
sentence_font.xy[0] = cur_xy[0];
sentence_font.xy[1] = cur_xy[1];
return RET_CONTINUE;
}
int ONScripterLabel::loadgameCommand()
{
int no = script_h.readInt();
if ( no < 0 )
errorAndExit( "loadgame: save number is less than 0." );
int fadeout = mp3fadeout_duration;
mp3fadeout_duration = 0; //don't use fadeout during a load
if ( !loadSaveFile( no ) ){
dirty_rect.fill( screen_width, screen_height );
flush( refreshMode() );
saveon_flag = true;
internal_saveon_flag = true;
skip_mode &= ~SKIP_NORMAL;
automode_flag = false;
deleteButtonLink();
deleteSelectLink();
key_pressed_flag = false;
text_on_flag = false;
indent_offset = 0;
line_enter_status = 0;
page_enter_status = 0;
string_buffer_offset = 0;
break_flag = false;
refreshMouseOverButton();
if (loadgosub_label)
gosubReal( loadgosub_label, script_h.getCurrent() );
}
mp3fadeout_duration = fadeout;
return RET_CONTINUE;
}
int ONScripterLabel::linkcolorCommand()
{
const char *buf;
buf = readColorStr();
readColor( &linkcolor[0], buf );
buf = readColorStr();
readColor( &linkcolor[1], buf );
return RET_CONTINUE;
}
int ONScripterLabel::ldCommand()
{
leaveTextDisplayMode();
char loc = script_h.readName()[0];
int no = -1;
if (loc == 'l') no = 0;
else if (loc == 'c') no = 1;
else if (loc == 'r') no = 2;
const char *buf = NULL;
if (no >= 0){
buf = script_h.readStr();
if ( tachi_info[ no ].image_surface )
dirty_rect.add( tachi_info[ no ].pos );
tachi_info[ no ].setImageName( buf );
parseTaggedString( &tachi_info[ no ] );
#ifdef RCA_SCALE
if (scr_stretch_y > 1.0) {
// RCA: Stretch characters to screen size.
// Note stretches are with Y-scale, so they don't get distorted
setupAnimationInfo( &tachi_info[ no ], NULL, scr_stretch_y, scr_stretch_y );
} else
#endif
setupAnimationInfo( &tachi_info[ no ] );
if ( tachi_info[ no ].image_surface ){
tachi_info[ no ].visible = true;
//start with "orig_pos" at the center-bottom, for easier scaling
tachi_info[ no ].orig_pos.x = humanpos[no];
tachi_info[ no ].orig_pos.y = underline_value + 1;
UpdateAnimPosStretchXY(&tachi_info[ no ]);
tachi_info[ no ].pos.x -= tachi_info[ no ].pos.w / 2;
tachi_info[ no ].pos.y -= tachi_info[ no ].pos.h;
if (!disable_rescale_flag){
tachi_info[ no ].orig_pos.x -= tachi_info[ no ].orig_pos.w / 2;
tachi_info[ no ].orig_pos.y -= tachi_info[ no ].orig_pos.h;
} else {
tachi_info[ no ].orig_pos.x -= ContractPos(tachi_info[ no ].orig_pos.w) / 2;
tachi_info[ no ].orig_pos.y -= ContractPos(tachi_info[ no ].orig_pos.h);
}
dirty_rect.add( tachi_info[ no ].pos );
}
}
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripterLabel::layermessageCommand()
{
int no = script_h.readInt();
const char *message = script_h.readStr();
#ifdef NO_LAYER_EFFECTS
printf("layermessage: layer effect support not available (%d,'%s')\n",
no, message);
#else
LayerInfo *tmp = layer_info;
while (tmp) {
if ( tmp->num == no ) break;
tmp = tmp->next;
}
if (tmp) {
getret_str = tmp->handler->message(message, getret_int);
//printf("layermessage returned: '%s', %d\n", getret_str, getret_int);
}
#endif // ndef NO_LAYER_EFFECTS
return RET_CONTINUE;
}
int ONScripterLabel::languageCommand()
{
const char* which = script_h.readName();
if ( strcmp(which, "japanese") == 0 ){
script_h.preferred_script = ScriptHandler::JAPANESE_SCRIPT;
}
else if ( strcmp(which, "english") == 0 ){
script_h.preferred_script = ScriptHandler::LATIN_SCRIPT;
}
else {
snprintf(script_h.errbuf, MAX_ERRBUF_LEN,
"language: unknown language '%s'", which);
errorAndExit(script_h.errbuf, "valid options are 'japanese' and 'english'");
}
return RET_CONTINUE;
}
int ONScripterLabel::jumpfCommand()
{
char *buf = script_h.getNext();
while(*buf != '\0' && *buf != '~') buf++;
if (*buf == '~') buf++;
script_h.setCurrent(buf);
current_label_info = script_h.getLabelByAddress(buf);
current_line = script_h.getLineByAddress(buf);
return RET_CONTINUE;
}
int ONScripterLabel::jumpbCommand()
{
script_h.setCurrent( last_tilde.next_script );
current_label_info = script_h.getLabelByAddress( last_tilde.next_script );
current_line = script_h.getLineByAddress( last_tilde.next_script );
return RET_CONTINUE;
}
int ONScripterLabel::ispageCommand()
{
script_h.readInt();
if ( textgosub_clickstr_state == CLICK_NEWPAGE )
script_h.setInt( &script_h.current_variable, 1 );
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripterLabel::isfullCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, fullscreen_mode?1:0 );
return RET_CONTINUE;
}
int ONScripterLabel::isskipCommand()
{
script_h.readInt();
if ( automode_flag )
script_h.setInt( &script_h.current_variable, 2 );
else if ( skip_mode & SKIP_NORMAL )
script_h.setInt( &script_h.current_variable, 1 );
else if ( ctrl_pressed_status )
script_h.setInt( &script_h.current_variable, 3 );
else if ( skip_mode & SKIP_TO_EOP )
script_h.setInt( &script_h.current_variable, 4 );
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripterLabel::isdownCommand()
{
script_h.readInt();
if ( current_button_state.down_flag )
script_h.setInt( &script_h.current_variable, 1 );
else
script_h.setInt( &script_h.current_variable, 0 );
return RET_CONTINUE;
}
int ONScripterLabel::inputCommand()
{
script_h.readStr();
if ( script_h.current_variable.type != ScriptHandler::VAR_STR )
errorAndExit( "input: no string variable." );
int no = script_h.current_variable.var_no;
script_h.readStr(); // description
const char *buf = script_h.readStr(); // default value
setStr( &script_h.getVariableData(no).str, buf );
printf( "*** inputCommand(): $%d is set to the default value: %s\n",
no, buf );
script_h.readInt(); // maxlen
script_h.readInt(); // widechar flag
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
script_h.readInt(); // window width
script_h.readInt(); // window height
script_h.readInt(); // text box width
script_h.readInt(); // text box height
}
return RET_CONTINUE;
}
int ONScripterLabel::indentCommand()
{
indent_offset = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::humanorderCommand()
{
leaveTextDisplayMode();
const char *buf = script_h.readStr();
int i;
for (i=0 ; i<3 ; i++){
if (buf[i] == 'l') human_order[i] = 0;
else if (buf[i] == 'c') human_order[i] = 1;
else if (buf[i] == 'r') human_order[i] = 2;
else human_order[i] = -1;
}
for ( i=0 ; i<3 ; i++ )
dirty_rect.add( tachi_info[i].pos );
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripterLabel::getzxcCommand()
{
getzxc_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getvoicevolCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, voice_volume );
return RET_CONTINUE;
}
int ONScripterLabel::getversionCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, NSC_VERSION );
return RET_CONTINUE;
}
int ONScripterLabel::gettimerCommand()
{
bool gettimer_flag=false;
if ( script_h.isName( "gettimer" ) ){
gettimer_flag = true;
}
else if ( script_h.isName( "getbtntimer" ) ){
}
script_h.readInt();
if ( gettimer_flag ){
script_h.setInt( &script_h.current_variable, SDL_GetTicks() - internal_timer );
}
else{
script_h.setInt( &script_h.current_variable, btnwait_time );
}
return RET_CONTINUE;
}
int ONScripterLabel::gettextbtnstrCommand()
{
script_h.readVariable();
script_h.pushVariable();
int txtbtn_no = script_h.readInt();
TextButtonInfoLink *info = text_button_info.next;
TextButtonInfoLink *found = NULL;
while (info) {
if (info->no == txtbtn_no)
found = info;
info = info->next;
}
if (found)
setStr(&script_h.getVariableData( script_h.pushed_variable.var_no ).str, found->text);
else
setStr(&script_h.getVariableData( script_h.pushed_variable.var_no ).str, NULL);
return RET_CONTINUE;
}
int ONScripterLabel::gettextCommand()
{
script_h.readVariable();
script_h.pushVariable();
int page_no = 0;
Page *page = current_page;
if (script_h.isName( "getlogtext" )) {
page_no = script_h.readInt();
while(page != start_page && page_no > 0){
page_no--;
page = page->previous;
}
}
if (page_no > 0)
setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, NULL );
else {
//extract control characters from the page text
char *buf = new char[ page->text_count + 1 ];
int i, j;
for ( i=0, j=0 ; i<page->text_count ; i++ ){
if (page->text[i] == ScriptHandler::LEFT_PAREN)
buf[j++] = '(';
else if (page->text[i] == ScriptHandler::RIGHT_PAREN)
buf[j++] = ')';
else if ((unsigned char)page->text[i] >= 0x20)
buf[j++] = page->text[i];
//don't put any control characters into the string
}
buf[j] = '\0';
setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, buf );
delete[] buf;
}
return RET_CONTINUE;
}
int ONScripterLabel::gettaglogCommand()
{
script_h.readVariable();
script_h.pushVariable();
int page_no = script_h.readInt();
int page_origin = 0;
if (set_tag_page_origin_to_1) page_origin = 1;
Page *page = current_page;
while(page != start_page && page_no > page_origin){
page_no--;
page = page->previous;
}
if (page->tag)
setStr(&script_h.getVariableData( script_h.pushed_variable.var_no ).str, page->tag);
else
setStr(&script_h.getVariableData( script_h.pushed_variable.var_no ).str, NULL);
return RET_CONTINUE;
}
int ONScripterLabel::gettagCommand()
{
if ( !last_nest_info->previous || last_nest_info->nest_mode != NestInfo::LABEL )
errorAndExit( "gettag: not in a subroutine, i.e. pretextgosub" );
char *buf = current_page->tag;
int end_status;
do{
script_h.readVariable();
end_status = script_h.getEndStatus();
script_h.pushVariable();
if ( script_h.pushed_variable.type & ScriptHandler::VAR_INT ||
script_h.pushed_variable.type & ScriptHandler::VAR_ARRAY ){
if (buf)
script_h.setInt( &script_h.pushed_variable, script_h.parseInt(&buf));
else
script_h.setInt( &script_h.pushed_variable, 0);
}
else if ( script_h.pushed_variable.type & ScriptHandler::VAR_STR ){
if (buf){
const char *buf_start = buf;
bool in_1byte_mode = false;
while((in_1byte_mode || *buf != '/') && *buf != 0){
if (*buf == '`') {
in_1byte_mode = !in_1byte_mode;
buf++;
} else if (IS_TWO_BYTE(*buf))
buf += 2;
else
buf++;
}
setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, buf_start, buf-buf_start );
}
else{
setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, NULL);
}
}
if (buf && *buf == '/')
buf++;
else
buf = NULL;
}
while(end_status & ScriptHandler::END_COMMA);
return RET_CONTINUE;
}
int ONScripterLabel::gettabCommand()
{
gettab_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getspsizeCommand()
{
int no = script_h.readInt();
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].orig_pos.w );
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].orig_pos.h );
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA ){
script_h.readVariable();
script_h.setInt( &script_h.current_variable, sprite_info[no].num_of_cells );
}
return RET_CONTINUE;
}
int ONScripterLabel::getspmodeCommand()
{
script_h.readVariable();
script_h.pushVariable();
int no = script_h.readInt();
script_h.setInt( &script_h.pushed_variable, sprite_info[no].visible?1:0 );
return RET_CONTINUE;
}
int ONScripterLabel::getskipoffCommand()
{
getskipoff_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getsevolCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, se_volume );
return RET_CONTINUE;
}
int ONScripterLabel::getscreenshotCommand()
{
int w = script_h.readInt();
int h = script_h.readInt();
if (disable_rescale_flag) {
w = ExpandPos(w);
h = ExpandPos(h);
}
if ( w == 0 ) w = 1;
if ( h == 0 ) h = 1;
if ( screenshot_surface &&
(SDL_Surface_get_w(screenshot_surface) != w ||
SDL_Surface_get_h(screenshot_surface) != h )){
SDL_FreeSurface( screenshot_surface );
screenshot_surface = NULL;
}
if ( screenshot_surface == NULL )
screenshot_surface = SDL_CreateRGBSurface( SDL_SWSURFACE, w, h, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 );
SDL_Surface *surface = SDL_ConvertSurface( screen_surface, SDL_Surface_get_format(image_surface), SDL_SWSURFACE );
AnimationInfo::resizeSurface( surface, screenshot_surface );
SDL_FreeSurface( surface );
return RET_CONTINUE;
}
int ONScripterLabel::getsavestrCommand()
{
script_h.readVariable();
if ( script_h.current_variable.type != ScriptHandler::VAR_STR )
errorAndExit( "getsavestr: no string variable" );
int var_no = script_h.current_variable.var_no;
int no = script_h.readInt();
char *savestr = NULL;
char *tmpstr = NULL;
int slen = 0;
if (loadSaveFile(no, false) == 0) {
//grab the savestr, if any
readStr( &tmpstr );
if (tmpstr) {
savestr = tmpstr;
slen = strlen(savestr);
if ((savestr[0] == '"') && (savestr[slen-2] == '"') &&
(savestr[slen-1] == '*')) {
savestr[slen-2] = 0;
++savestr;
slen = strlen(savestr);
}
}
} else
printf("getsavestr: couldn't read save slot %d\n", no);
if (savestr)
setStr(&script_h.getVariableData( var_no ).str, savestr);
else
setStr(&script_h.getVariableData( var_no ).str, "");
//printf("getsavestr: got '%s'\n", script_h.getVariableData( var_no ).str);
if (tmpstr) delete[] tmpstr;
return RET_CONTINUE;
}
int ONScripterLabel::getpageupCommand()
{
getpageup_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getpageCommand()
{
getpageup_flag = true;
getpagedown_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getretCommand()
{
script_h.readVariable();
if ( script_h.current_variable.type == ScriptHandler::VAR_INT ||
script_h.current_variable.type == ScriptHandler::VAR_ARRAY ){
script_h.setInt( &script_h.current_variable, getret_int );
}
else if ( script_h.current_variable.type == ScriptHandler::VAR_STR ){
int no = script_h.current_variable.var_no;
setStr( &script_h.getVariableData(no).str, getret_str );
}
else errorAndExit( "getret: no variable." );
return RET_CONTINUE;
}
int ONScripterLabel::getregCommand()
{
script_h.readVariable();
if ( script_h.current_variable.type != ScriptHandler::VAR_STR )
errorAndExit( "getreg: no string variable." );
int no = script_h.current_variable.var_no;
const char *buf = script_h.readStr();
char path[256], key[256];
strcpy( path, buf );
buf = script_h.readStr();
strcpy( key, buf );
printf(" reading Registry file for [%s] %s\n", path, key );
FILE *fp;
if ( ( fp = fopen( registry_file, "r" ) ) == NULL ){
fprintf( stderr, "Cannot open file [%s]\n", registry_file );
return RET_CONTINUE;
}
char reg_buf[256], reg_buf2[256];
bool found_flag = false;
while( fgets( reg_buf, 256, fp) && !found_flag ){
if ( reg_buf[0] == '[' ){
unsigned int c=0;
while ( reg_buf[c] != ']' && reg_buf[c] != '\0' ) c++;
if ( !strncmp( reg_buf + 1, path, (c-1>strlen(path))?(c-1):strlen(path) ) ){
while( fgets( reg_buf2, 256, fp) ){
script_h.pushCurrent( reg_buf2 );
buf = script_h.readStr();
if ( strncmp( buf,
key,
(strlen(buf)>strlen(key))?strlen(buf):strlen(key) ) ){
script_h.popCurrent();
continue;
}
if ( !script_h.compareString("=") ){
script_h.popCurrent();
continue;
}
script_h.setCurrent(script_h.getNext()+1);
buf = script_h.readStr();
setStr( &script_h.getVariableData(no).str, buf );
script_h.popCurrent();
printf(" $%d = %s\n", no, script_h.getVariableData(no).str );
found_flag = true;
break;
}
}
}
}
if ( !found_flag ) fprintf( stderr, " The key is not found.\n" );
fclose(fp);
return RET_CONTINUE;
}
int ONScripterLabel::getmp3volCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, music_volume );
return RET_CONTINUE;
}
int ONScripterLabel::getmouseposCommand()
{
script_h.readInt();
script_h.setInt( &script_h.current_variable, ContractPos(current_button_state.x) );
script_h.readInt();
script_h.setInt( &script_h.current_variable, ContractPos(current_button_state.y) );
return RET_CONTINUE;
}
int ONScripterLabel::getmouseoverCommand()
{
getmouseover_flag = true;
getmouseover_min = script_h.readInt();
getmouseover_max = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::getmclickCommand()
{
getmclick_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getlogCommand()
{
script_h.readVariable();
script_h.pushVariable();
int page_no = script_h.readInt();
Page *page = current_page;
while(page != start_page && page_no > 0){
page_no--;
page = page->previous;
}
if (page_no > 0)
setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, NULL );
else
setStr( &script_h.getVariableData( script_h.pushed_variable.var_no ).str, page->text, page->text_count );
return RET_CONTINUE;
}
int ONScripterLabel::getinsertCommand()
{
getinsert_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getfunctionCommand()
{
getfunction_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getenterCommand()
{
if ( !force_button_shortcut_flag )
getenter_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getcursorposCommand()
{
if ( script_h.isName( "getcursorpos2" ) ){
script_h.readInt();
script_h.setInt( &script_h.current_variable, last_textpos_xy[0] );
script_h.readInt();
script_h.setInt( &script_h.current_variable, last_textpos_xy[1] );
} else {
int xy_bak[2], line_offset_xy_bak[2];
xy_bak[0] = sentence_font.xy[0];
xy_bak[1] = sentence_font.xy[1];
line_offset_xy_bak[0] = sentence_font.line_offset_xy[0];
line_offset_xy_bak[1] = sentence_font.line_offset_xy[1];
if ( script_h.isName( "getnextline" ) ){
sentence_font.newLine();
}
script_h.readInt();
//script_h.setInt( &script_h.current_variable, sentence_font.x() );
#ifdef RCA_SCALE
if (scr_stretch_x > 1.0)
script_h.setInt( &script_h.current_variable, (sentence_font.x()-sentence_font.ruby_offset_xy[0]) / scr_stretch_x + 0.5);
else
#endif
script_h.setInt( &script_h.current_variable, sentence_font.x()-sentence_font.ruby_offset_xy[0] ); // workaround for possibly a bug in the original
script_h.readInt();
//script_h.setInt( &script_h.current_variable, sentence_font.y() );
#ifdef RCA_SCALE
if (scr_stretch_y > 1.0)
script_h.setInt( &script_h.current_variable, (sentence_font.y()-sentence_font.ruby_offset_xy[1]) / scr_stretch_y + 0.5);
else
#endif
script_h.setInt( &script_h.current_variable, sentence_font.y()-sentence_font.ruby_offset_xy[1] ); // workaround for possibly a bug in the original
sentence_font.xy[0] = xy_bak[0];
sentence_font.xy[1] = xy_bak[1];
sentence_font.line_offset_xy[0] = line_offset_xy_bak[0];
sentence_font.line_offset_xy[1] = line_offset_xy_bak[1];
}
return RET_CONTINUE;
}
int ONScripterLabel::getcursorCommand()
{
if ( !force_button_shortcut_flag )
getcursor_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::getcselstrCommand()
{
script_h.readVariable();
script_h.pushVariable();
int csel_no = script_h.readInt();
int counter = 0;
SelectLink *link = root_select_link.next;
while (link){
if (csel_no == counter++) break;
link = link->next;
}
if (!link) errorAndExit("getcselstr: no select link");
setStr(&script_h.getVariableData( script_h.pushed_variable.var_no ).str, link->text);
return RET_CONTINUE;
}
int ONScripterLabel::getcselnumCommand()
{
int count = 0;
SelectLink *link = root_select_link.next;
while ( link ) {
count++;
link = link->next;
}
script_h.readInt();
script_h.setInt( &script_h.current_variable, count );
return RET_CONTINUE;
}
int ONScripterLabel::gameCommand()
{
int i;
current_mode = NORMAL_MODE;
effectspeed = EFFECTSPEED_NORMAL;
/* ---------------------------------------- */
if ( !lookback_info[0].image_surface ){
setStr( &lookback_info[0].image_name, DEFAULT_LOOKBACK_NAME0 );
parseTaggedString( &lookback_info[0] );
setupAnimationInfo( &lookback_info[0] );
}
if ( !lookback_info[1].image_surface ){
setStr( &lookback_info[1].image_name, DEFAULT_LOOKBACK_NAME1 );
parseTaggedString( &lookback_info[1] );
setupAnimationInfo( &lookback_info[1] );
}
if ( !lookback_info[2].image_surface ){
setStr( &lookback_info[2].image_name, DEFAULT_LOOKBACK_NAME2 );
parseTaggedString( &lookback_info[2] );
setupAnimationInfo( &lookback_info[2] );
}
if ( !lookback_info[3].image_surface ){
setStr( &lookback_info[3].image_name, DEFAULT_LOOKBACK_NAME3 );
parseTaggedString( &lookback_info[3] );
setupAnimationInfo( &lookback_info[3] );
}
/* ---------------------------------------- */
/* Load default cursor */
loadCursor( CURSOR_WAIT_NO, DEFAULT_CURSOR_WAIT, 0, 0 );
loadCursor( CURSOR_NEWPAGE_NO, DEFAULT_CURSOR_NEWPAGE, 0, 0 );
/* ---------------------------------------- */
/* Initialize text buffer */
page_list = new Page[max_page_list];
for ( i=0 ; i<max_page_list-1 ; i++ ){
page_list[i].next = &page_list[i+1];
page_list[i+1].previous = &page_list[i];
}
page_list[0].previous = &page_list[max_page_list-1];
page_list[max_page_list-1].next = &page_list[0];
start_page = current_page = &page_list[0];
clearCurrentPage();
/* ---------------------------------------- */
/* Initialize local variables */
for ( i=0 ; i<script_h.global_variable_border ; i++ )
script_h.getVariableData(i).reset(false);
setCurrentLabel( "start" );
saveSaveFile(-1);
return RET_CONTINUE;
}
int ONScripterLabel::flushoutCommand()
{
//Mion: flushout special effect
// not quite the same as NScr's, but looks good
// does a "flushout" in 30 stages while fading to white
tmp_effect.duration = script_h.readInt();
tmp_effect.effect = CUSTOM_EFFECT_NO + 3;
dirty_rect.fill( screen_width, screen_height );
if (setEffect(&tmp_effect, false, false)) return RET_CONTINUE;
setStr( &bg_info.file_name, "white" );
createBackground();
SDL_BlitSurface( bg_info.image_surface, NULL, effect_dst_surface, NULL );
SDL_BlitSurface( accumulation_surface, NULL, effect_tmp_surface, NULL );
while (doEffect(&tmp_effect));
return RET_CONTINUE;
}
int ONScripterLabel::fileexistCommand()
{
script_h.readInt();
script_h.pushVariable();
const char *buf = script_h.readStr();
int found = (script_h.cBR->getFileLength(buf)>0)?1:0;
if (!found) {
char fn[4096];
sprintf(fn, "%s%s", script_h.save_path, buf);
char* si = fn;
do {
if (IS_TWO_BYTE(*si)) si++;
else if ( (*si == '\\') || (*si == '/') ) *si = DELIMITER;
} while (*(++si));
#if MSC_VER < 1200
FILE* fp = fopen(fn, "rb"); // FIXME: failing even when file exists?!
#else
FILE* fp = std::fopen(fn, "rb"); // FIXME: failing even when file exists?!
#endif
//printf("Seek %s, fp = %s, ", fn, fp ? "yes" : "no");
if (fp) {
found = 1;
fclose(fp);
//puts("found\n");
}
//else printf(" fail (%s)\n", strerror(errno));
}
script_h.setInt( &script_h.pushed_variable, found );
return RET_CONTINUE;
}
int ONScripterLabel::exec_dllCommand()
{
const char *buf = script_h.readStr();
char dll_name[256];
unsigned int c=0;
while(buf[c] && (buf[c] != '/')){
dll_name[c] = buf[c];
c++;
}
dll_name[c] = '\0';
printf(" reading %s for %s\n", dll_file, dll_name );
FILE *fp;
if ( ( fp = fopen( dll_file, "r" ) ) == NULL ){
fprintf( stderr, "Cannot open file [%s]\n", dll_file );
return RET_CONTINUE;
}
char dll_buf[256], dll_buf2[256];
bool found_flag = false;
while( fgets( dll_buf, 256, fp) && !found_flag ){
if ( dll_buf[0] == '[' ){
c=0;
while ( dll_buf[c] != ']' && dll_buf[c] != '\0' ) c++;
if ( !strncmp( dll_buf + 1, dll_name, (c-1>strlen(dll_name))?(c-1):strlen(dll_name) ) ){
found_flag = true;
while( fgets( dll_buf2, 256, fp) ){
c=0;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
if ( !strncmp( &dll_buf2[c], "str", 3 ) ){
c+=3;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
if ( dll_buf2[c] != '=' ) continue;
c++;
while ( dll_buf2[c] != '"' ) c++;
unsigned int c2 = ++c;
while ( dll_buf2[c2] != '"' && dll_buf2[c2] != '\0' ) c2++;
dll_buf2[c2] = '\0';
setStr( &getret_str, &dll_buf2[c] );
printf(" getret_str = %s\n", getret_str );
}
else if ( !strncmp( &dll_buf2[c], "ret", 3 ) ){
c+=3;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
if ( dll_buf2[c] != '=' ) continue;
c++;
while ( dll_buf2[c] == ' ' || dll_buf2[c] == '\t' ) c++;
getret_int = atoi( &dll_buf2[c] );
printf(" getret_int = %d\n", getret_int );
}
else if ( dll_buf2[c] == '[' )
break;
}
}
}
}
if ( !found_flag ) fprintf( stderr, " The DLL is not found in %s.\n", dll_file );
fclose( fp );
return RET_CONTINUE;
}
int ONScripterLabel::exbtnCommand()
{
int sprite_no=-1, no=0;
ButtonLink *button;
if ( script_h.isName( "exbtn_d" ) ){
button = &exbtn_d_button_link;
if ( button->exbtn_ctl ) delete[] button->exbtn_ctl;
}
else{
bool cellcheck_flag = false;
if ( script_h.isName( "cellcheckexbtn" ) )
cellcheck_flag = true;
sprite_no = script_h.readInt();
no = script_h.readInt();
if ( (cellcheck_flag && (sprite_info[ sprite_no ].num_of_cells < 2)) ||
(!cellcheck_flag && (sprite_info[ sprite_no ].num_of_cells == 0)) ){
script_h.readStr();
return RET_CONTINUE;
}
button = new ButtonLink();
root_button_link.insert( button );
}
is_exbtn_enabled = true;
const char *buf = script_h.readStr();
button->button_type = ButtonLink::EX_SPRITE_BUTTON;
button->sprite_no = sprite_no;
button->no = no;
button->exbtn_ctl = new char[ strlen( buf ) + 1 ];
strcpy( button->exbtn_ctl, buf );
if ( sprite_no >= 0 &&
( sprite_info[ sprite_no ].image_surface ||
sprite_info[ sprite_no ].trans_mode == AnimationInfo::TRANS_STRING ) )
{
button->image_rect = button->select_rect = sprite_info[ sprite_no ].pos;
}
return RET_CONTINUE;
}
int ONScripterLabel::erasetextwindowCommand()
{
erase_text_window_mode = script_h.readInt();
did_leavetext = false;
dirty_rect.add( sentence_font_info.pos );
return RET_CONTINUE;
}
int ONScripterLabel::erasetextbtnCommand()
{
if (!txtbtn_visible) return RET_CONTINUE;
TextButtonInfoLink *info = text_button_info.next;
while (info) {
ButtonLink *cur_button_link = info->button;
while (cur_button_link) {
cur_button_link->show_flag = 1;
cur_button_link->anim[0]->visible = true;
cur_button_link->anim[0]->setCell(0);
dirty_rect.add( cur_button_link->image_rect );
cur_button_link = cur_button_link->same;
}
info = info->next;
}
flush( refreshMode() );
return RET_CONTINUE;
}
int ONScripterLabel::endCommand()
{
printf("Quitting...\n");
quit();
exit(0);
return RET_CONTINUE; // dummy
}
int ONScripterLabel::effectskipCommand()
{
if (script_h.readInt() == 0)
effectskip_flag = false;
else
effectskip_flag = true;
return RET_CONTINUE;
}
int ONScripterLabel::dwavestopCommand()
{
int ch = script_h.readInt();
//Mion - ogapee2008: avoid dwavestop outside array
if (ch < 0) ch = 0;
else if (ch >= ONS_MIX_CHANNELS) ch = ONS_MIX_CHANNELS-1;
if ((ch == 0) && bgmdownmode_flag)
setCurMusicVolume( music_volume );
return RET_CONTINUE;
}
int ONScripterLabel::dwaveCommand()
{
int play_mode = WAVE_PLAY;
bool loop_flag = false;
if ( script_h.isName( "dwaveloop" ) ){
loop_flag = true;
}
else if ( script_h.isName( "dwaveload" ) ){
play_mode = WAVE_PRELOAD;
}
else if ( script_h.isName( "dwaveplayloop" ) ){
play_mode = WAVE_PLAY_LOADED;
loop_flag = true;
}
else if ( script_h.isName( "dwaveplay" ) ){
play_mode = WAVE_PLAY_LOADED;
loop_flag = false;
}
int ch = script_h.readInt();
if (ch < 0) ch = 0;
else if (ch >= ONS_MIX_CHANNELS) ch = ONS_MIX_CHANNELS-1;
if (play_mode == WAVE_PLAY_LOADED){
}
else{
const char *buf = script_h.readStr();
int fmt = SOUND_WAVE|SOUND_OGG;
if (play_mode == WAVE_PRELOAD) fmt |= SOUND_PRELOAD;
playSound(buf, fmt, loop_flag, ch);
}
if ((ch == 0) && bgmdownmode_flag)
setCurMusicVolume( music_volume );
return RET_CONTINUE;
}
int ONScripterLabel::dvCommand()
{
char buf[256];
sprintf(buf, "voice%c%s.wav", DELIMITER, script_h.getStringBuffer()+2);
playSound(buf, SOUND_WAVE|SOUND_OGG, false, 0);
return RET_CONTINUE;
}
int ONScripterLabel::drawtextCommand()
{
SDL_Rect clip = {0, 0, SDL_Surface_get_w(accumulation_surface), SDL_Surface_get_h(accumulation_surface)};
text_info.blendOnSurface( accumulation_surface, 0, 0, clip );
return RET_CONTINUE;
}
int ONScripterLabel::drawsp3Command()
{
int sprite_no = script_h.readInt();
int cell_no = script_h.readInt();
int alpha = script_h.readInt();
int x = StretchPosX(script_h.readInt());
int y = StretchPosY(script_h.readInt());
AnimationInfo &si = sprite_info[sprite_no];
int old_cell_no = si.current_cell;
si.setCell(cell_no);
si.mat[0][0] = script_h.readInt();
si.mat[0][1] = script_h.readInt();
si.mat[1][0] = script_h.readInt();
si.mat[1][1] = script_h.readInt();
int denom = (si.mat[0][0]*si.mat[1][1]-si.mat[0][1]*si.mat[1][0])/1000;
if (denom != 0){
si.inv_mat[0][0] = si.mat[1][1] * 1000 / denom;
si.inv_mat[0][1] = -si.mat[0][1] * 1000 / denom;
si.inv_mat[1][0] = -si.mat[1][0] * 1000 / denom;
si.inv_mat[1][1] = si.mat[0][0] * 1000 / denom;
}
SDL_Rect clip = {0, 0, SDL_Surface_get_w(screen_surface), SDL_Surface_get_h(screen_surface)};
si.blendOnSurface2( accumulation_surface, x, y, clip, alpha );
si.setCell(old_cell_no);
return RET_CONTINUE;
}
int ONScripterLabel::drawsp2Command()
{
int sprite_no = script_h.readInt();
int cell_no = script_h.readInt();
int alpha = script_h.readInt();
AnimationInfo si = sprite_info[sprite_no];
si.orig_pos.x = script_h.readInt();
si.orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(&si);
si.scale_x = script_h.readInt();
si.scale_y = script_h.readInt();
si.rot = script_h.readInt();
si.calcAffineMatrix();
si.setCell(cell_no);
SDL_Rect clip = {0, 0, SDL_Surface_get_w(screen_surface), SDL_Surface_get_h(screen_surface)};
si.blendOnSurface2( accumulation_surface, si.pos.x, si.pos.y, clip, alpha );
return RET_CONTINUE;
}
int ONScripterLabel::drawspCommand()
{
int sprite_no = script_h.readInt();
int cell_no = script_h.readInt();
int alpha = script_h.readInt();
int x = StretchPosX(script_h.readInt());;
int y = StretchPosY(script_h.readInt());;
AnimationInfo &si = sprite_info[sprite_no];
int old_cell_no = si.current_cell;
si.setCell(cell_no);
SDL_Rect clip = {0, 0, SDL_Surface_get_w(accumulation_surface), SDL_Surface_get_h(accumulation_surface)};
si.blendOnSurface( accumulation_surface, x, y, clip, alpha );
si.setCell(old_cell_no);
return RET_CONTINUE;
}
int ONScripterLabel::drawfillCommand()
{
int r = script_h.readInt();
int g = script_h.readInt();
int b = script_h.readInt();
SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( SDL_Surface_get_format(accumulation_surface), r, g, b, 0xff) );
return RET_CONTINUE;
}
int ONScripterLabel::drawclearCommand()
{
SDL_FillRect( accumulation_surface, NULL, SDL_MapRGBA( SDL_Surface_get_format(accumulation_surface), 0, 0, 0, 0xff) );
return RET_CONTINUE;
}
int ONScripterLabel::drawbgCommand()
{
SDL_Rect clip = {0, 0, SDL_Surface_get_w(accumulation_surface), SDL_Surface_get_h(accumulation_surface)};
bg_info.blendOnSurface( accumulation_surface, bg_info.pos.x, bg_info.pos.y, clip );
return RET_CONTINUE;
}
int ONScripterLabel::drawbg2Command()
{
AnimationInfo bi = bg_info;
bi.orig_pos.x = script_h.readInt();
bi.orig_pos.y = script_h.readInt();
UpdateAnimPosXY(&bi);
bi.scale_x = script_h.readInt();
bi.scale_y = script_h.readInt();
bi.rot = script_h.readInt();
bi.calcAffineMatrix();
SDL_Rect clip = {0, 0, SDL_Surface_get_w(screen_surface), SDL_Surface_get_h(screen_surface)};
bi.blendOnSurface2( accumulation_surface, bi.pos.x, bi.pos.y,
clip, 256 );
return RET_CONTINUE;
}
int ONScripterLabel::drawCommand()
{
SDL_Rect rect = {0, 0, screen_width, screen_height};
flushDirect( rect, REFRESH_NONE_MODE );
dirty_rect.clear();
return RET_CONTINUE;
}
int ONScripterLabel::deletescreenshotCommand()
{
if ( screenshot_surface ) {
SDL_FreeSurface( screenshot_surface );
screenshot_surface = NULL;
}
return RET_CONTINUE;
}
int ONScripterLabel::delayCommand()
{
int t = script_h.readInt();
//Mion: use a shorter delay during skip mode
if( (skip_mode & (SKIP_NORMAL | SKIP_TO_WAIT)) || ctrl_pressed_status ) {
t = 0;
}
event_mode = WAIT_TIMER_MODE | WAIT_INPUT_MODE;
waitEvent( t );
return RET_CONTINUE;
}
int ONScripterLabel::defineresetCommand()
{
//clear out the event queue
SDL_Event event;
while( SDL_PollEvent( &event ) )
if (event.type == SDL_QUIT) endCommand();
script_h.reset();
ScriptParser::reset();
reset();
//reopen the audio mixer with default settings, if needed
setCurrentLabel( "define" );
return RET_CONTINUE;
}
int ONScripterLabel::cspCommand()
{
leaveTextDisplayMode();
bool csp2_flag = false;
if (script_h.isName("csp2")) csp2_flag = true;
int no = script_h.readInt();
AnimationInfo *si = NULL;
int num = 0;
if (csp2_flag) {
num = MAX_SPRITE2_NUM;
si = sprite2_info;
}
else{
num = MAX_SPRITE_NUM;
si = sprite_info;
}
if ( no == -1 )
for ( int i=0 ; i<num ; i++ ){
if ( si[i].visible ){
if (csp2_flag)
dirty_rect.add( si[i].bounding_rect );
else
dirty_rect.add( si[i].pos );
}
if ( si[i].image_name ){
si[i].orig_pos.x = -1000;
si[i].orig_pos.y = -1000;
#ifndef RCA_SCALE
si[i].pos.x = ExpandPos(-1000);
si[i].pos.y = ExpandPos(-1000);
#else
si[i].pos.x = ExpandPos(-10000);
si[i].pos.y = ExpandPos(-10000);
#endif
}
if (!csp2_flag) root_button_link.removeSprite(i);
si[i].remove();
}
else if (no >= 0 && no < MAX_SPRITE_NUM){
if ( si[no].visible ) {
if (csp2_flag)
dirty_rect.add( si[no].bounding_rect );
else
dirty_rect.add( si[no].pos );
}
if (!csp2_flag) root_button_link.removeSprite(no);
si[no].remove();
}
return RET_CONTINUE;
}
int ONScripterLabel::cselgotoCommand()
{
int csel_no = script_h.readInt();
int counter = 0;
SelectLink *link = root_select_link.next;
while( link ){
if ( csel_no == counter++ ) break;
link = link->next;
}
if ( !link ) errorAndExit( "cselgoto: no select link" );
setCurrentLabel( link->label );
deleteSelectLink();
newPage( true );
return RET_CONTINUE;
}
int ONScripterLabel::cselbtnCommand()
{
int csel_no = script_h.readInt();
int button_no = script_h.readInt();
Fontinfo csel_info = sentence_font;
csel_info.setRubyOnFlag(false);
csel_info.top_xy[0] = script_h.readInt();
csel_info.top_xy[1] = script_h.readInt();
int counter = 0;
SelectLink *link = root_select_link.next;
while ( link ){
if ( csel_no == counter++ ) break;
link = link->next;
}
if ( link == NULL || link->text == NULL || *link->text == '\0' )
return RET_CONTINUE;
csel_info.setLineArea( strlen(link->text)/2+1 );
csel_info.clear();
ButtonLink *button = getSelectableSentence( link->text, &csel_info );
root_button_link.insert( button );
button->no = button_no;
button->sprite_no = csel_no;
sentence_font.ttf_font = csel_info.ttf_font;
return RET_CONTINUE;
}
int ONScripterLabel::clickCommand()
{
bool lrclick_flag = false;
if ( script_h.isName( "lrclick" ) ) lrclick_flag = true;
//Mion: NScr doesn't stop skip-to-choice mode for a "click" command
if (skip_mode & SKIP_NORMAL)
return RET_CONTINUE;
skip_mode &= ~SKIP_TO_WAIT;
key_pressed_flag = false;
clickstr_state = CLICK_WAIT;
event_mode = WAIT_TIMER_MODE | WAIT_INPUT_MODE;
if (lrclick_flag) event_mode |= WAIT_RCLICK_MODE;
waitEvent(-1);
clickstr_state = CLICK_NONE;
if (lrclick_flag)
getret_int = (current_button_state.button == -1) ? 0 : 1;
return RET_CONTINUE;
}
int ONScripterLabel::clCommand()
{
leaveTextDisplayMode();
char loc = script_h.readName()[0];
if ( loc == 'l' || loc == 'a' ){
dirty_rect.add( tachi_info[0].pos );
tachi_info[0].remove();
}
if ( loc == 'c' || loc == 'a' ){
dirty_rect.add( tachi_info[1].pos );
tachi_info[1].remove();
}
if ( loc == 'r' || loc == 'a' ){
dirty_rect.add( tachi_info[2].pos );
tachi_info[2].remove();
}
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
while (doEffect(el));
return RET_CONTINUE;
}
int ONScripterLabel::chvolCommand()
{
int ch = script_h.readInt();
//Mion - ogapee2008: avoid access outside array bounds
if (ch < 0) ch = 0;
else if (ch >= ONS_MIX_CHANNELS) ch = ONS_MIX_CHANNELS-1;
int vol = script_h.readInt();
channelvolumes[ch] = vol;
return RET_CONTINUE;
}
int ONScripterLabel::checkpageCommand()
{
script_h.readVariable();
script_h.pushVariable();
if ( script_h.pushed_variable.type != ScriptHandler::VAR_INT &&
script_h.pushed_variable.type != ScriptHandler::VAR_ARRAY )
errorAndExit( "checkpage: no integer variable." );
int page_no = script_h.readInt();
Page *page = current_page;
while(page != start_page && page_no > 0){
page_no--;
page = page->previous;
}
if (page_no > 0)
script_h.setInt( &script_h.pushed_variable, 0 );
else
script_h.setInt( &script_h.pushed_variable, 1 );
return RET_CONTINUE;
}
int ONScripterLabel::checkkeyCommand()
{
script_h.readVariable();
script_h.pushVariable();
if ( script_h.pushed_variable.type != ScriptHandler::VAR_INT &&
script_h.pushed_variable.type != ScriptHandler::VAR_ARRAY )
errorAndExit( "checkpage: no integer variable." );
const char* buf = script_h.readStr();
if (!buf || (*buf == '\0')) {
script_h.setInt( &script_h.pushed_variable, 0 );
return RET_CONTINUE;
}
char* keystr = new char[strlen(buf)+1];
for (unsigned int i=0; i<strlen(keystr); i++)
keystr[i] = toupper(buf[i]);
keystr[strlen(buf)] = '\0';
int ret = 1;
if (strlen(keystr) == 1){
if ((last_keypress >= SDLK_0) && (last_keypress <= SDLK_9))
ret = (last_keypress - SDLK_0) - (*keystr - '0');
else if ((last_keypress >= SDLK_a) && (last_keypress <= SDLK_z))
ret = (last_keypress - SDLK_a) - (*keystr - 'A');
}
if (ret != 0){
switch (last_keypress){
default:
ret = 1; break;
case SDLK_RCTRL:
case SDLK_LCTRL:
ret = strcmp(keystr, "CTRL"); break;
case SDLK_RSHIFT:
case SDLK_LSHIFT:
ret = strcmp(keystr, "SHIFT"); break;
case SDLK_RETURN:
ret = strcmp(keystr, "RETURN");
if (ret != 0)
ret = strcmp(keystr, "ENTER");
break;
case SDLK_SPACE:
ret = strcmp(keystr, " ");
if (ret != 0)
ret = strcmp(keystr, "SPACE");
break;
case SDLK_PAGEUP:
ret = strcmp(keystr, "PAGEUP"); break;
case SDLK_PAGEDOWN:
ret = strcmp(keystr, "PAGEDOWN"); break;
case SDLK_UP:
ret = strcmp(keystr, "UP"); break;
case SDLK_DOWN:
ret = strcmp(keystr, "DOWN"); break;
case SDLK_LEFT:
ret = strcmp(keystr, "LEFT"); break;
case SDLK_RIGHT:
ret = strcmp(keystr, "RIGHT"); break;
case SDLK_F1: ret = strcmp(keystr, "F1"); break;
case SDLK_F2: ret = strcmp(keystr, "F2"); break;
case SDLK_F3: ret = strcmp(keystr, "F3"); break;
case SDLK_F4: ret = strcmp(keystr, "F4"); break;
case SDLK_F5: ret = strcmp(keystr, "F5"); break;
case SDLK_F6: ret = strcmp(keystr, "F6"); break;
case SDLK_F7: ret = strcmp(keystr, "F7"); break;
case SDLK_F8: ret = strcmp(keystr, "F8"); break;
case SDLK_F9: ret = strcmp(keystr, "F9"); break;
case SDLK_F10: ret = strcmp(keystr, "F10"); break;
case SDLK_F11: ret = strcmp(keystr, "F11"); break;
case SDLK_F12: ret = strcmp(keystr, "F12"); break;
}
}
if (ret == 0) printf("checkkey: got key %s\n", keystr);
script_h.setInt( &script_h.pushed_variable, (ret == 0) ? 1 : 0 );
delete[] keystr;
return RET_CONTINUE;
}
int ONScripterLabel::cellCommand()
{
int sprite_no = script_h.readInt();
int no = script_h.readInt();
sprite_info[sprite_no].setCell(no);
dirty_rect.add( sprite_info[sprite_no].pos );
return RET_CONTINUE;
}
int ONScripterLabel::captionCommand()
{
const char* buf = script_h.readStr();
size_t len = strlen(buf);
char *buf2 = new char[len*2+3];
char *buf1 = new char[len+1];
strcpy(buf1, buf);
DirectReader::convertFromSJISToUTF8(buf2, buf1);
delete[] buf1;
setStr( &wm_title_string, buf2 );
setStr( &wm_icon_string, buf2 );
delete[] buf2;
//printf("caption (utf8): '%s'\n", wm_title_string);
#if 1
//FIXME:???
setStr( &wm_title_string, buf );
#endif
SDL_WM_SetCaption( wm_title_string, wm_icon_string );
#ifdef WIN32
//convert from UTF-8 to Wide (Unicode) and thence to system ANSI
len = MultiByteToWideChar(CP_UTF8, 0, wm_title_string, -1, NULL, 0);
wchar_t *u16_tmp = new wchar_t[len];
MultiByteToWideChar(CP_UTF8, 0, wm_title_string, -1, u16_tmp, len);
len = WideCharToMultiByte(CP_ACP, 0, u16_tmp, -1, NULL, 0, NULL, NULL);
char *cvt = new char[len+1];
WideCharToMultiByte(CP_ACP, 0, u16_tmp, -1, cvt, len, NULL, NULL);
delete[] u16_tmp;
//set the window caption directly
SDL_SysWMinfo info;
SDL_GetWMInfo(&info);
SendMessageA(info.window, WM_SETTEXT, 0, (LPARAM)cvt);
delete[] cvt;
#endif //WIN32
return RET_CONTINUE;
}
int ONScripterLabel::btnwaitCommand()
{
bool del_flag=false, textbtn_flag=false;
bool remove_window_flag = !( (erase_text_window_mode == 0) ||
btnnowindowerase_flag );
if ( script_h.isName( "btnwait2" ) ){
}
else if ( script_h.isName( "btnwait" ) ){
del_flag = true;
}
else if ( script_h.isName( "textbtnwait" ) ){
textbtn_flag = true;
remove_window_flag = false;
}
if (remove_window_flag)
leaveTextDisplayMode(remove_window_flag);
script_h.readInt();
bool skip_flag = (skip_mode & SKIP_NORMAL) || ctrl_pressed_status ||
((skip_mode & SKIP_TO_EOP) &&
( (clickstr_state == CLICK_WAIT) ||
(textgosub_label &&
( (textgosub_clickstr_state == CLICK_WAIT) ||
(textgosub_clickstr_state == CLICK_WAITEOL) )) ));
current_button_state.reset();
last_keypress = KEYPRESS_NULL;
btnwaitTop:
long button_timer_start = SDL_GetTicks(); //set here so btnwait is correct
if ( !( skip_flag && textbtn_flag ) ) {
shortcut_mouse_line = 0;
skip_mode &= ~SKIP_NORMAL;
if (txtbtn_show) txtbtn_visible = true;
if (is_exbtn_enabled && exbtn_d_button_link.exbtn_ctl){
SDL_Rect check_src_rect = {0, 0, screen_width, screen_height};
decodeExbtnControl( exbtn_d_button_link.exbtn_ctl, &check_src_rect );
}
ButtonLink *p_button_link = root_button_link.next;
while( p_button_link ){
ButtonLink *cur_button_link = p_button_link;
while (cur_button_link) {
cur_button_link->show_flag = 0;
if ( cur_button_link->button_type == ButtonLink::SPRITE_BUTTON ||
cur_button_link->button_type == ButtonLink::EX_SPRITE_BUTTON ){
sprite_info[ cur_button_link->sprite_no ].visible = true;
sprite_info[ cur_button_link->sprite_no ].setCell(0);
}
else if ( cur_button_link->button_type == ButtonLink::TMP_SPRITE_BUTTON ){
cur_button_link->show_flag = 1;
sprite_info[ cur_button_link->sprite_no ].setCell(0);
}
else if ( cur_button_link->button_type == ButtonLink::TEXT_BUTTON ){
if (txtbtn_visible)
cur_button_link->show_flag = 1;
sprite_info[ cur_button_link->sprite_no ].setCell(0);
}
else if ( cur_button_link->anim[1] != NULL ){
cur_button_link->show_flag = 2;
}
dirty_rect.add( cur_button_link->image_rect );
cur_button_link = cur_button_link->same;
}
p_button_link = p_button_link->next;
}
flush( refreshMode() );
event_mode = WAIT_BUTTON_MODE;
refreshMouseOverButton();
int t = -1;
if ( btntime_value > 0 ){
if ( btntime2_flag )
event_mode |= WAIT_VOICE_MODE;
t = btntime_value;
}
button_timer_start = SDL_GetTicks();
if ( textbtn_flag ){
event_mode |= WAIT_TEXTBTN_MODE;
if ( btntime_value == 0 ){
if ( automode_flag ){
event_mode |= WAIT_VOICE_MODE;
if ( automode_time < 0 ){
if (t == -1 || t > -automode_time * num_chars_in_sentence)
t = -automode_time * num_chars_in_sentence;
}
else{
if (t == -1 || t > automode_time)
t = automode_time;
}
}
else if ( (autoclick_time > 0) &&
(t == -1 || t > autoclick_time))
t = autoclick_time;
}
}
if (t <= 0) t = -1;
event_mode |= WAIT_TIMER_MODE;
if (waitEvent(t)) {
return RET_CONTINUE;
}
}
btnwait_time = SDL_GetTicks() - button_timer_start;
num_chars_in_sentence = 0;
if ( skip_flag && textbtn_flag ){
//do a wait to catch possible 'ctrl' release
waitEvent(0);
if (!current_button_state.valid_flag)
current_button_state.set(0);
}
if (!current_button_state.valid_flag) {
goto btnwaitTop;
}
script_h.setInt( &script_h.current_variable, current_button_state.button );
if ( current_button_state.button >= 1 && del_flag ){
btndef_info.remove();
deleteButtonLink();
}
event_mode = IDLE_EVENT_MODE;
disableGetButtonFlag();
ButtonLink *p_button_link = root_button_link.next;
while( p_button_link ){
ButtonLink *cur_button_link = p_button_link;
while (cur_button_link) {
cur_button_link->show_flag = 0;
cur_button_link = cur_button_link->same;
}
p_button_link = p_button_link->next;
}
flush( refreshMode() );
return RET_CONTINUE;
}
int ONScripterLabel::btntimeCommand()
{
if ( script_h.isName( "btntime2" ) )
btntime2_flag = true;
else
btntime2_flag = false;
btntime_value = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::btndownCommand()
{
btndown_flag = (script_h.readInt()==1)?true:false;
return RET_CONTINUE;
}
int ONScripterLabel::btndefCommand()
{
if (script_h.compareString("clear")){
script_h.readName();
}
else{
const char *buf = script_h.readStr();
btndef_info.remove();
if ( buf[0] != '\0' ){
btndef_info.setImageName( buf );
parseTaggedString( &btndef_info );
btndef_info.trans_mode = AnimationInfo::TRANS_COPY;
#ifdef RCA_SCALE
setupAnimationInfo( &btndef_info, NULL, scr_stretch_x, scr_stretch_y );
#else
setupAnimationInfo( &btndef_info );
#endif
SDL_SetAlpha( btndef_info.image_surface, DEFAULT_BLIT_FLAG, SDL_ALPHA_OPAQUE );
}
}
btntime_value = 0;
deleteButtonLink();
current_button_state.reset();
last_keypress = KEYPRESS_NULL;
processTextButtonInfo();
disableGetButtonFlag();
return RET_CONTINUE;
}
int ONScripterLabel::btnareaCommand()
{
btnarea_flag = true;
btnarea_pos = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::btnCommand()
{
SDL_Rect src_rect;
ButtonLink *button = new ButtonLink();
button->no = script_h.readInt();
button->image_rect.x = StretchPosX(script_h.readInt());
button->image_rect.y = StretchPosY(script_h.readInt());
button->image_rect.w = StretchPosX(script_h.readInt());
button->image_rect.h = StretchPosY(script_h.readInt());
button->select_rect = button->image_rect;
src_rect.x = StretchPosX(script_h.readInt());
src_rect.y = StretchPosY(script_h.readInt());
if (!btndef_info.image_surface){
button->image_rect.w = 0;
button->image_rect.h = 0;
}
if (btndef_info.image_surface &&
src_rect.x + button->image_rect.w > SDL_Surface_get_w(btndef_info.image_surface)){
button->image_rect.w = SDL_Surface_get_w(btndef_info.image_surface) - src_rect.x;
}
if (btndef_info.image_surface &&
src_rect.y + button->image_rect.h > SDL_Surface_get_h(btndef_info.image_surface)){
button->image_rect.h = SDL_Surface_get_h(btndef_info.image_surface) - src_rect.y;
}
src_rect.w = button->image_rect.w;
src_rect.h = button->image_rect.h;
button->anim[0] = new AnimationInfo();
button->anim[0]->num_of_cells = 1;
button->anim[0]->trans_mode = AnimationInfo::TRANS_COPY;
button->anim[0]->pos.x = button->image_rect.x;
button->anim[0]->pos.y = button->image_rect.y;
if (btndef_info.image_surface) {
button->anim[0]->allocImage( button->image_rect.w, button->image_rect.h );
button->anim[0]->copySurface( btndef_info.image_surface, &src_rect );
}
root_button_link.insert( button );
return RET_CONTINUE;
}
int ONScripterLabel::brCommand()
{
sentence_font.newLine();
current_page->add( 0x0a );
return RET_CONTINUE;
}
int ONScripterLabel::bltCommand()
{
int dx,dy,dw,dh;
int sx,sy,sw,sh;
dx = StretchPosX(script_h.readInt());
dy = StretchPosY(script_h.readInt());
dw = StretchPosX(script_h.readInt());
dh = StretchPosY(script_h.readInt());
sx = StretchPosX(script_h.readInt());
sy = StretchPosY(script_h.readInt());
sw = StretchPosX(script_h.readInt());
sh = StretchPosY(script_h.readInt());
if (btndef_info.image_surface == NULL) return RET_CONTINUE;
if (dw == 0 || dh == 0 || sw == 0 || sh == 0) return RET_CONTINUE;
if ( sw == dw && sw > 0 && sh == dh && sh > 0 ){
SDL_Rect src_rect = {sx,sy,sw,sh};
SDL_Rect dst_rect = {dx,dy,dw,dh};
SDL_BlitSurface( btndef_info.image_surface, &src_rect, screen_surface, &dst_rect );
SDL_UpdateRect( screen_surface, dst_rect.x, dst_rect.y, dst_rect.w, dst_rect.h );
dirty_rect.clear();
}
else{
SDL_LockSurface(accumulation_surface);
SDL_LockSurface(btndef_info.image_surface);
ONSBuf *dst_buf = (ONSBuf*)SDL_Surface_get_pixels(accumulation_surface);
ONSBuf *src_buf = (ONSBuf*)SDL_Surface_get_pixels(btndef_info.image_surface);
#ifdef BPP16
int dst_width = SDL_Surface_get_pitch(accumulation_surface) / 2;
int src_width = SDL_Surface_get_pitch(btndef_info.image_surface) / 2;
#else
int dst_width = SDL_Surface_get_pitch(accumulation_surface) / 4;
int src_width = SDL_Surface_get_pitch(btndef_info.image_surface) / 4;
#endif
int start_y = dy, end_y = dy+dh;
if (dh < 0){
start_y = dy+dh;
end_y = dy;
}
if (start_y < 0) start_y = 0;
if (end_y > screen_height) end_y = screen_height;
int start_x = dx, end_x = dx+dw;
if (dw < 0){
start_x = dx+dw;
end_x = dx;
}
if (start_x < 0) start_x = 0;
if (end_x >= screen_width) end_x = screen_width;
dst_buf += start_y*dst_width;
for (int i=start_y ; i<end_y ; i++){
int y = sy+sh*(i-dy)/dh;
for (int j=start_x ; j<end_x ; j++){
int x = sx+sw*(j-dx)/dw;
if (x<0 || x>= SDL_Surface_get_w(btndef_info.image_surface) ||
y<0 || y>= SDL_Surface_get_h(btndef_info.image_surface))
*(dst_buf+j) = 0;
else
*(dst_buf+j) = *(src_buf+y*src_width+x);
}
dst_buf += dst_width;
}
SDL_UnlockSurface(btndef_info.image_surface);
SDL_UnlockSurface(accumulation_surface);
SDL_Rect dst_rect = {start_x, start_y, end_x-start_x, end_y-start_y};
flushDirect( (SDL_Rect&)dst_rect, REFRESH_NONE_MODE );
}
return RET_CONTINUE;
}
int ONScripterLabel::bgmdownmodeCommand()
{
bgmdownmode_flag = (script_h.readInt() != 0);
return RET_CONTINUE;
}
int ONScripterLabel::bgcopyCommand()
{
SDL_BlitSurface( screen_surface, NULL, accumulation_surface, NULL );
bg_info.num_of_cells = 1;
bg_info.trans_mode = AnimationInfo::TRANS_COPY;
bg_info.pos.x = 0;
bg_info.pos.y = 0;
bg_info.copySurface( accumulation_surface, NULL );
return RET_CONTINUE;
}
int ONScripterLabel::bgCommand()
{
//Mion: prefer removing textwindow for bg change effects even during skip;
//but don't remove text window if erasetextwindow == 0
leaveTextDisplayMode((erase_text_window_mode != 0));
const char *buf;
if (script_h.compareString("white")){
buf = "white";
script_h.readName();
}
else if (script_h.compareString("black")){
buf = "black";
script_h.readName();
}
else{
if (allow_color_type_only) {
bool is_color = false;
buf = script_h.readColor(&is_color);
if (!is_color)
buf = script_h.readStr();
} else {
buf = script_h.readStr();
}
}
for ( int i=0 ; i<3 ; i++ )
tachi_info[i].remove();
bg_info.remove();
setStr( &bg_info.file_name, buf );
createBackground();
dirty_rect.fill( screen_width, screen_height );
EffectLink *el = parseEffect(true);
if (setEffect(el, true, true)) return RET_CONTINUE;
#if 1 //TODO:
while (doEffect(el));
#endif
return RET_CONTINUE;
}
int ONScripterLabel::barclearCommand()
{
if (system_menu_mode == SYSTEM_NULL)
leaveTextDisplayMode();
for ( int i=0 ; i<MAX_PARAM_NUM ; i++ ) {
if ( bar_info[i] ) {
dirty_rect.add( bar_info[i]->pos );
delete bar_info[i];
bar_info[i] = NULL;
}
}
return RET_CONTINUE;
}
int ONScripterLabel::barCommand()
{
int no = script_h.readInt();
if ( bar_info[no] ){
dirty_rect.add( bar_info[no]->pos );
bar_info[no]->remove();
}
else{
bar_info[no] = new AnimationInfo();
}
bar_info[no]->trans_mode = AnimationInfo::TRANS_COPY;
bar_info[no]->num_of_cells = 1;
bar_info[no]->param = script_h.readInt();
bar_info[no]->orig_pos.x = script_h.readInt();
bar_info[no]->orig_pos.y = script_h.readInt();
UpdateAnimPosXY(bar_info[no]);
bar_info[no]->max_width = script_h.readInt();
bar_info[no]->orig_pos.h = script_h.readInt();
bar_info[no]->pos.h = ExpandPos(bar_info[no]->orig_pos.h);
bar_info[no]->max_param = script_h.readInt();
const char *buf = readColorStr();
readColor( &bar_info[no]->color, buf );
int w = ExpandPos(bar_info[no]->max_width) * bar_info[no]->param / bar_info[no]->max_param;
if ( bar_info[no]->max_width > 0 && w > 0 ){
bar_info[no]->pos.w = w;
bar_info[no]->allocImage( bar_info[no]->pos.w, bar_info[no]->pos.h );
bar_info[no]->fill( bar_info[no]->color[0], bar_info[no]->color[1], bar_info[no]->color[2], 0xff );
dirty_rect.add( bar_info[no]->pos );
}
return RET_CONTINUE;
}
int ONScripterLabel::aviCommand()
{
script_h.readStr();
const char *save_buf = script_h.saveStringBuffer();
bool click_flag = (script_h.readInt()==1)?true:false;
stopBGM( false );
if (playAVI( save_buf, click_flag )) endCommand();
return RET_CONTINUE;
}
int ONScripterLabel::automode_timeCommand()
{
automode_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::autoclickCommand()
{
autoclick_time = script_h.readInt();
return RET_CONTINUE;
}
int ONScripterLabel::amspCommand()
{
leaveTextDisplayMode();
bool amsp2_flag = false;
if (script_h.isName("amsp2")) amsp2_flag = true;
int no = script_h.readInt();
AnimationInfo *si=NULL;
if (amsp2_flag){
si = &sprite2_info[no];
dirty_rect.add( si->bounding_rect );
}
else{
si = &sprite_info[no];
dirty_rect.add( si->pos );
}
si->orig_pos.x = script_h.readInt();
si->orig_pos.y = script_h.readInt();
UpdateAnimPosStretchXY(si);
if (amsp2_flag){
si->scale_x = script_h.readInt();
si->scale_y = script_h.readInt();
si->rot = script_h.readInt();
si->calcAffineMatrix();
dirty_rect.add( si->bounding_rect );
}
else{
dirty_rect.add( si->pos );
}
if ( script_h.getEndStatus() & ScriptHandler::END_COMMA )
si->trans = script_h.readInt();
if ( si->trans > 256 ) si->trans = 256;
else if ( si->trans < 0 ) si->trans = 0;
if ( si->is_animatable ) advanceAnimPhase();
return RET_CONTINUE;
}
int ONScripterLabel::allsp2resumeCommand()
{
all_sprite2_hide_flag = false;
for ( int i=0 ; i<MAX_SPRITE2_NUM ; i++ ){
if ( sprite2_info[i].visible )
dirty_rect.add( sprite2_info[i].bounding_rect );
}
return RET_CONTINUE;
}
int ONScripterLabel::allspresumeCommand()
{
all_sprite_hide_flag = false;
for ( int i=0 ; i<MAX_SPRITE_NUM ; i++ ){
if ( sprite_info[i].visible )
dirty_rect.add( sprite_info[i].pos );
}
return RET_CONTINUE;
}
int ONScripterLabel::allsp2hideCommand()
{
all_sprite2_hide_flag = true;
for ( int i=0 ; i<MAX_SPRITE2_NUM ; i++ ){
if ( sprite2_info[i].visible )
dirty_rect.add( sprite2_info[i].bounding_rect );
}
return RET_CONTINUE;
}
int ONScripterLabel::allsphideCommand()
{
all_sprite_hide_flag = true;
for ( int i=0 ; i<MAX_SPRITE_NUM ; i++ ){
if ( sprite_info[i].visible )
dirty_rect.add( sprite_info[i].pos );
}
return RET_CONTINUE;
}
// Haeleth: Stub out some commands to suppress unwanted debug messages
int ONScripterLabel::insertmenuCommand()
{
script_h.skipToken();
return RET_CONTINUE;
}
int ONScripterLabel::resetmenuCommand()
{
script_h.skipToken();
return RET_CONTINUE;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/weimingtom2000/onscripter_en_fork2.git
git@gitee.com:weimingtom2000/onscripter_en_fork2.git
weimingtom2000
onscripter_en_fork2
onscripter_en_fork2
master

搜索帮助