home *** CD-ROM | disk | FTP | other *** search
- /* ScummC
- * Copyright (C) 2007 Alban Bedel, Gerrit Karius
- *
- * 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
- #include <scummVars6.s>
- #include "common.sch"
- #include "dialog.sch"
- #include "verbs.sch"
-
-
- room Dialog {
-
- //
- // Dialogs stuff
- //
-
- // Reset the dialog list
- script dialogClear(int kill) {
- int i;
- char* j;
- if(dialogList) {
- if(kill) {
- for(i = 0 ; i < numDialog ; i++) {
- // Undim can't work on array members directly.
- // Hopefully the compiler can hide that out one day.
- j = dialogList[i];
- undim(j);
- }
- }
- undim(dialogList);
- dialogList = 0;
- }
- numDialog = numActiveDialog = 0;
- }
-
- // Add an entry to the dialog list
- script dialogAdd(char* str) {
- if(numDialog >= MAX_DIALOG_SENTENCE) {
- dbgPrint("Too many sentences, can't add another one.");
- return;
- }
- unless(dialogList)
- dimInt(dialogList,MAX_DIALOG_SENTENCE);
- dialogList[numDialog] = str;
- numDialog++;
- if(str) numActiveDialog++;
- }
-
- // Remove an entry, if kill is not zero undim the string too
- script dialogRemove(int idx, int kill) {
- int i;
- if(idx < 0 || idx >= numDialog) {
- dbgPrint("Dialog index out of range: %i{idx}, can't remove.");
- return;
- }
- if(dialogList[idx]) {
- numActiveDialog--;
- // Remove the string from the array
- if(kill)
- undim(dialogList[idx]);
- dialogList[idx] = 0;
- }
- // shift the res
- for(i = idx+1 ; i < numDialog ; i++)
- dialogList[i-1] = dialogList[i];
- numDialog--;
- }
-
- script showDialog() {
- int i,v,d,first,last,firstSentence,lastSentence;
-
- first = last = -1;
- firstSentence = lastSentence = -1;
- // switch the charset
- initCharset(ResRoom::dialogCharset);
- // Dialog lines
- v = 0;
- for(i = 0 ; i < numDialog ; i++) {
- unless(dialogList[i]) continue;
- if(firstSentence < 0) firstSentence = i;
- lastSentence = i;
- if(v < dialogOffset || v >= dialogOffset+MAX_DIALOG_LINES) {
- v++;
- continue;
- }
- if(first < 0) first = i;
- last = i;
- setCurrentVerb(dialogVerb0 + d);
- initVerb();
- setVerbNameString(dialogList[i]);
- setVerbXY(12,145+11*d);
- setVerbColor(dialogColor);
- setVerbHiColor(dialogHiColor);
- setVerbOn();
- redrawVerb();
- v++, d++;
- }
- for( ; d < MAX_DIALOG_LINES ; d++) {
- setCurrentVerb(dialogVerb0 + d);
- setVerbOff();
- redrawVerb();
- }
- dbgPrint("Sentence: %i{firstSentence} %i{lastSentence}");
- dbgPrint("Shown: %i{first} %i{last}");
-
- // Up arrow
- setCurrentVerb(dialogUp);
- if(first > firstSentence) {
- initVerb();
- setVerbName("\x03");
- setVerbXY(2,145);
- setVerbColor(dialogColor);
- setVerbHiColor(dialogHiColor);
- setVerbOn();
- redrawVerb();
- } else {
- setVerbOff();
- redrawVerb();
- }
- // Down arrow
- setCurrentVerb(dialogDown);
- if(last < lastSentence) {
- initVerb();
- setVerbName("\x02");
- setVerbXY(2,145+4*11);
- setVerbColor(dialogColor);
- setVerbHiColor(dialogHiColor);
- setVerbOn();
- redrawVerb();
- } else {
- setVerbOff();
- redrawVerb();
- }
-
- initCharset(ResRoom::chtest);
-
- }
-
- script dialogInputHandler(int area,int cmd, int btn) {
- int i,v,d;
-
- dbgPrintBegin();
- dbgPrint("Area=%i{area} cmd=%i{cmd} button=%i{btn}");
- dbgPrintEnd();
-
- egoPrintBegin();
- egoPrintOverhead();
- actorPrintEnd();
-
- if(area == 4) { // area 4 is the keyboard
- ResRoom::keyboardHandler(cmd);
- return;
- }
-
- if(cmd == dialogUp || cmd == dialogDown) {
- dialogOffset += (cmd == dialogUp ? -1 : 1)*MAX_DIALOG_LINES/2;
- if(dialogOffset > numActiveDialog-MAX_DIALOG_LINES)
- dialogOffset = numActiveDialog-MAX_DIALOG_LINES;
- if(dialogOffset < 0) dialogOffset = 0;
- dbgPrint("Dialog offset: %i{dialogOffset}");
- showDialog();
- return;
- }
-
- if(cmd < dialogVerb0 || cmd > dialogVerb4)
- return;
-
- // Find the selected sentence
- for(i = 0 ; i < numDialog ; i++) {
- unless(dialogList[i]) continue;
- if(v < dialogOffset || v >= dialogOffset+MAX_DIALOG_LINES) {
- v++;
- continue;
- }
- if(d == cmd-dialogVerb0) break;
- v++, d++;
- }
-
- selectedSentence = i;
- }
-
- // Start a dialog
- script dialogStart(int color, int hiColor) {
- int i;
- selectedSentence = -1;
- dialogOffset = 0;
- if(numDialog < 1) {
- dbgPrint("No dialog was setup, nothing to show.");
- selectedSentence = -2;
- return;
- }
- // Hide the normal verbs/inventory
- Verbs::showVerbs(0);
- // Show our stuff
- // setup the verbs
- dialogColor = color ? color : VERB_COLOR;
- dialogHiColor = hiColor ? hiColor : VERB_HI_COLOR;
- showDialog();
- // Kill the mouseWatch
- if(isScriptRunning(ResRoom::mouseWatch))
- stopScript(ResRoom::mouseWatch);
- // Set the dialog input handler
- VAR_VERB_SCRIPT = dialogInputHandler;
- }
-
- script dialogHide() {
- int i;
- for(i = 0 ; i < MAX_DIALOG_LINES ; i++) {
- setCurrentVerb(dialogVerb0 + i);
- setVerbOff();
- redrawVerb();
- }
- setCurrentVerb(dialogUp);
- setVerbOff();
- redrawVerb();
- setCurrentVerb(dialogDown);
- setVerbOff();
- redrawVerb();
- }
-
- script dialogEnd() {
- dialogHide();
- Verbs::showVerbs(1);
- VAR_VERB_SCRIPT = ResRoom::inputHandler;
- // Restart the mouse watching thread
- ResRoom::mouseWatch();
- }
-
-
- }
-