예제 #1
0
파일: mentat.c 프로젝트: damajor/play-dune
void async_GUI_Mentat_LoopOpen() {
	asyncMentatLoop.dirty = false;
	asyncMentatLoop.textTick = 0;
	asyncMentatLoop.textDelay = 0;

	asyncMentatLoop.old07AE = Widget_SetCurrentWidget(8);
	asyncMentatLoop.oldScreenID = GFX_Screen_SetActive(4);

	asyncMentatLoop.wsa = NULL;

	if (asyncMentatLoop.wsaFilename != NULL) {
		asyncMentatLoop.wsa = WSA_LoadFile(asyncMentatLoop.wsaFilename, GFX_Screen_Get_ByIndex(3), GFX_Screen_GetSize_ByIndex(3), false);
	}

	asyncMentatLoop.step = 0;
	if (asyncMentatLoop.wsa == NULL) {
		Widget_PaintCurrentWidget();
		asyncMentatLoop.step = 1;
	}

	GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x31);

	asyncMentatLoop.descLines = GUI_SplitText(asyncMentatLoop.pictureDetails, (g_curWidgetWidth << 3) + 10, '\0');

	GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x32);

	asyncMentatLoop.textLines = GUI_Mentat_SplitText(asyncMentatLoop.text, 304);

	asyncMentatLoop.mentatSpeakingMode = 2;
	asyncMentatLoop.lines = 0;
	asyncMentatLoop.frame = 0;
	g_timerTimeout = 0;
	asyncMentatLoop.descTick = g_timerGUI + 30;

	Input_History_Clear();

	asyncMentatLoop.textDone = false;
	asyncMentatLoop.done = false;
	asyncMentatLoop.result = 0;
}
예제 #2
0
파일: mentat.c 프로젝트: gnaghi/OpenDUNE
uint16 GUI_Mentat_Loop(const char *wsaFilename, char *pictureDetails, char *text, bool arg12, Widget *w)
{
    Screen oldScreenID;
    uint16 old07AE;
    void *wsa;
    uint16 descLines;
    bool dirty;
    bool done;
    bool textDone;
    uint16 frame;
    uint32 descTick;
    uint16 mentatSpeakingMode;
    uint16 result;
    uint32 textTick;
    uint32 textDelay;
    uint16 lines;
    uint16 textLines;
    uint16 step;

    dirty = false;
    textTick = 0;
    textDelay = 0;

    old07AE = Widget_SetCurrentWidget(8);
    oldScreenID = GFX_Screen_SetActive(SCREEN_2);

    wsa = NULL;

    if (wsaFilename != NULL) {
        wsa = WSA_LoadFile(wsaFilename, GFX_Screen_Get_ByIndex(SCREEN_1), GFX_Screen_GetSize_ByIndex(SCREEN_1), false);
    }

    step = 0;
    if (wsa == NULL) {
        Widget_PaintCurrentWidget();
        step = 1;
    }

    GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x31);

    descLines = GUI_SplitText(pictureDetails, (g_curWidgetWidth << 3) + 10, '\0');

    GUI_DrawText_Wrapper(NULL, 0, 0, 0, 0, 0x32);

    textLines = GUI_Mentat_SplitText(text, 304);

    mentatSpeakingMode = 2;
    lines = 0;
    frame = 0;
    g_timerTimeout = 0;
    descTick = g_timerGUI + 30;

    Input_History_Clear();

    textDone = false;
    result = 0;
    for (done = false; !done; sleepIdle()) {
        uint16 key;

        GFX_Screen_SetActive(SCREEN_0);

        key = GUI_Widget_HandleEvents(w);

        GUI_PaletteAnimate();

        if (key != 0) {
            if ((key & 0x800) == 0) {
                if (w != NULL) {
                    if ((key & 0x8000) != 0 && result == 0) result = key;
                } else {
                    if (textDone) result = key;
                }
            } else {
                key = 0;
            }
        }

        switch (step) {
        case 0:
            if (key == 0) break;
            step = 1;
        /* FALL-THROUGH */

        case 1:
            if (key != 0) {
                if (result != 0) {
                    step = 5;
                    break;
                }
                lines = descLines;
                dirty = true;
            } else {
                if (g_timerGUI > descTick) {
                    descTick = g_timerGUI + 15;
                    lines++;
                    dirty = true;
                }
            }

            if (lines < descLines && lines <= 12) break;

            step = (text != NULL) ? 2 : 4;
            lines = descLines;
            break;

        case 2:
            GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40);
            GUI_Screen_Copy(0, 0, 0, 160, SCREEN_WIDTH / 8, 40, SCREEN_0, SCREEN_2);
            GUI_Mouse_Show_InRegion();

            step = 3;
            key = 1;
        /* FALL-THROUGH */

        case 3:
            if (mentatSpeakingMode == 2 && textTick < g_timerGUI) key = 1;

            if ((key != 0 && textDone) || result != 0) {
                GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40);
                GUI_Screen_Copy(0, 160, 0, 0, SCREEN_WIDTH / 8, 40, SCREEN_2, SCREEN_0);
                GUI_Mouse_Show_InRegion();

                step = 4;
                mentatSpeakingMode = 0;
                break;
            }

            if (key != 0) {
                GUI_Screen_Copy(0, 160, 0, 0, SCREEN_WIDTH / 8, 40, SCREEN_2, SCREEN_2);

                if (textLines-- != 0) {
                    GFX_Screen_SetActive(SCREEN_2);
                    GUI_DrawText_Wrapper(text, 4, 1, g_curWidgetFGColourBlink, 0, 0x32);
                    mentatSpeakingMode = 1;
                    textDelay = (uint32)strlen(text) * 4;
                    textTick = g_timerGUI + textDelay;

                    if (textLines != 0) {
                        while (*text++ != '\0') {}
                    } else {
                        textDone = true;
                    }

                    GFX_Screen_SetActive(SCREEN_0);
                }

                GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40);
                GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, 40, SCREEN_2, SCREEN_0);
                GUI_Mouse_Show_InRegion();
                break;
            }

            if (mentatSpeakingMode == 0 || textTick > g_timerGUI) break;

            mentatSpeakingMode = 2;
            textTick += textDelay + textDelay / 2;
            break;

        case 4:
            if (result != 0 || w == NULL) step = 5;
            break;

        case 5:
            dirty = true;
            done = true;
            break;

        default:
            break;
        }

        GUI_Mentat_Animation(mentatSpeakingMode);

        if (wsa != NULL && g_timerTimeout == 0) {
            g_timerTimeout = 7;

            do {
                if (step == 0 && frame > 4) step = 1;

                if (!WSA_DisplayFrame(wsa, frame++, g_curWidgetXBase << 3, g_curWidgetYBase, SCREEN_2)) {
                    if (step == 0) step = 1;

                    if (arg12 != 0) {
                        frame = 0;
                    } else {
                        WSA_Unload(wsa);
                        wsa = NULL;
                    }
                }
            } while (frame == 0);
            dirty = true;
        }

        if (!dirty) continue;

        GUI_Mentat_DrawInfo(pictureDetails, (g_curWidgetXBase << 3) + 5, g_curWidgetYBase + 3, 8, 0, lines, 0x31);

        GUI_DrawSprite(SCREEN_2, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0);
        GUI_Mouse_Hide_InWidget(g_curWidgetIndex);
        GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_2, SCREEN_0);
        GUI_Mouse_Show_InWidget();
        dirty = false;
    }

    if (wsa != NULL) WSA_Unload(wsa);

    GFX_Screen_SetActive(SCREEN_2);
    GUI_DrawSprite(SCREEN_2, g_sprites[397 + g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0);
    GUI_Mouse_Hide_InWidget(g_curWidgetIndex);
    GUI_Screen_Copy(g_curWidgetXBase, g_curWidgetYBase, g_curWidgetXBase, g_curWidgetYBase, g_curWidgetWidth, g_curWidgetHeight, SCREEN_2, SCREEN_0);
    GUI_Mouse_Show_InWidget();
    Widget_SetCurrentWidget(old07AE);
    GFX_Screen_SetActive(oldScreenID);

    Input_History_Clear();

    return result;
}
예제 #3
0
파일: editbox.c 프로젝트: 166MMX/OpenDUNE
/**
 * Show an EditBox and handles the input.
 * @param text The text to edit. Uses the pointer to make the modifications.
 * @param maxLength The maximum length of the text.
 * @param unknown1 Unknown.
 * @param w The widget this editbox is attached to.
 * @param tickProc The function to call every tick, for animation etc.
 * @param unknown4 Unknown.
 * @return Unknown.
 */
uint16 GUI_EditBox(char *text, uint16 maxLength, uint16 unknown1, Widget *w, uint16 (*tickProc)(void), uint16 unknown4)
{
	Screen oldScreenID;
	uint16 oldValue_07AE_0000;
	uint16 positionX;
	uint16 maxWidth;
	uint16 textWidth;
	uint16 textLength;
	uint16 returnValue;
	char *t;

	/* Initialize */
	{
		Input_Flags_SetBits(INPUT_FLAG_NO_TRANSLATE);
		Input_Flags_ClearBits(INPUT_FLAG_UNKNOWN_2000);

		oldScreenID = GFX_Screen_SetActive(SCREEN_0);

		oldValue_07AE_0000 = Widget_SetCurrentWidget(unknown1);

		returnValue = 0x0;
	}

	positionX = g_curWidgetXBase << 3;

	textWidth = 0;
	textLength = 0;
	maxWidth = (g_curWidgetWidth << 3) - Font_GetCharWidth('W') - 1;
	t = text;

	/* Calculate the length and width of the current string */
	for (; *t != '\0'; t++) {
		textWidth += Font_GetCharWidth(*t);
		textLength++;

		if (textWidth >= maxWidth) break;
	}
	*t = '\0';

	if ((unknown4 & 0x1) != 0) {
		unknown4 |= 0x4;
	}

	GUI_Mouse_Hide_Safe();

	if ((unknown4 & 0x4) != 0) Widget_PaintCurrentWidget();

	GUI_DrawText_Wrapper(text, positionX, g_curWidgetYBase, g_curWidgetFGColourBlink, g_curWidgetFGColourNormal, 0);

	GUI_EditBox_BlinkCursor(positionX + textWidth, false);

	GUI_Mouse_Show_Safe();

	for (;; sleepIdle()) {
		uint16 keyWidth;
		uint16 key;

		if (tickProc != NULL) {
			returnValue = tickProc();
			if (returnValue != 0) break;
		}

		key = GUI_Widget_HandleEvents(w);

		GUI_EditBox_BlinkCursor(positionX + textWidth, false);

		if (key == 0x0) continue;

		if ((key & 0x8000) != 0) {
			returnValue = key;
			break;
		}
		if (key == 0x2B) {
			returnValue = 0x2B;
			break;
		}
		if (key == 0x6E) {
			*t = '\0';
			returnValue = 0x6B;
			break;
		}

		/* Handle backspace */
		if (key == 0x0F) {
			if (textLength == 0) continue;

			GUI_EditBox_BlinkCursor(positionX + textWidth, true);

			textWidth -= Font_GetCharWidth(*(t - 1));
			textLength--;
			*(--t) = '\0';

			GUI_EditBox_BlinkCursor(positionX + textWidth, false);
			continue;
		}

		key = Input_Keyboard_HandleKeys(key) & 0xFF;

		/* Names can't start with a space, and should be alpha-numeric */
		if ((key == 0x20 && textLength == 0) || key < 0x20 || key > 0x7E) continue;

		keyWidth = Font_GetCharWidth(key & 0xFF);

		if (textWidth + keyWidth >= maxWidth || textLength >= maxLength) continue;

		/* Add char to the text */
		*t = key & 0xFF;
		*(++t) = '\0';
		textLength++;

		GUI_Mouse_Hide_Safe();

		GUI_EditBox_BlinkCursor(positionX + textWidth, true);

		/* Draw new character */
		GUI_DrawText_Wrapper(text + textLength - 1, positionX + textWidth, g_curWidgetYBase, g_curWidgetFGColourBlink, g_curWidgetFGColourNormal, 0x020);

		GUI_Mouse_Show_Safe();

		textWidth += keyWidth;

		GUI_EditBox_BlinkCursor(positionX + textWidth, false);
	}

	/* Deinitialize */
	{
		Input_Flags_ClearBits(INPUT_FLAG_NO_TRANSLATE);
		Input_Flags_SetBits(INPUT_FLAG_UNKNOWN_2000);

		Widget_SetCurrentWidget(oldValue_07AE_0000);

		GFX_Screen_SetActive(oldScreenID);
	}

	return returnValue;
}