コード例 #1
0
ファイル: Mentat.cs プロジェクト: n-stefan/SharpDune
    /*
     * Handle clicks on the Mentat widget.
     * @return True, always.
     */
    internal static bool GUI_Widget_Mentat_Click(CWidget _)
    {
        g_cursorSpriteID = 0;

        Sprites_SetMouseSprite(0, 0, g_sprites[0]);

        Sound_Output_Feedback(0xFFFE);

        Driver_Voice_Play(null, 0xFF);

        Music_Play(g_table_houseInfo[(int)g_playerHouseID].musicBriefing);

        Sprites_UnloadTiles();

        Timer_SetTimer(TimerType.TIMER_GAME, false);

        GUI_Mentat_ShowHelpList(false);

        Timer_SetTimer(TimerType.TIMER_GAME, true);

        Driver_Sound_Play(1, 0xFF);

        Sprites_LoadTiles();

        g_textDisplayNeedsUpdate = true;

        GUI_DrawInterfaceAndRadar(Screen.NO0);

        Music_Play((ushort)(Tools_RandomLCG_Range(0, 5) + 8));

        return(true);
    }
コード例 #2
0
ファイル: Mentat.cs プロジェクト: n-stefan/SharpDune
    /*
     * Show the Mentat screen.
     * @param spriteBuffer The buffer of the strings.
     * @param wsaFilename The WSA to show.
     * @param w The widgets to handle. Can be NULL for no widgets.
     * @return Return value of GUI_Widget_HandleEvents() or f__B4DA_0AB8_002A_AAB2() (latter when no widgets).
     */
    internal static ushort GUI_Mentat_Show(string stringBuffer, string wsaFilename, CWidget w)
    {
        ushort ret;

        Sprites_UnloadTiles();

        GUI_Mentat_Display(wsaFilename, (byte)g_playerHouseID);

        GFX_Screen_SetActive(Screen.NO1);

        Widget_SetAndPaintCurrentWidget(8);

        if (wsaFilename != null)
        {
            /*WSAObject*/
            (WSAHeader header, Array <byte> buffer)wsa;

            wsa = WSA_LoadFile(wsaFilename, GFX_Screen_Get_ByIndex(Screen.NO2), GFX_Screen_GetSize_ByIndex(Screen.NO2), false);
            WSA_DisplayFrame(wsa, 0, (ushort)(g_curWidgetXBase * 8), g_curWidgetYBase, Screen.NO1);
            WSA_Unload(wsa);
        }

        GUI_DrawSprite(Screen.NO1, g_sprites[397 + (int)g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0);
        GFX_Screen_SetActive(Screen.NO0);

        GUI_Mouse_Hide_Safe();
        GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, (short)SCREEN_HEIGHT, Screen.NO1, Screen.NO0);
        GUI_Mouse_Show_Safe();

        GUI_SetPaletteAnimated(g_palette1, 15);

        ret = GUI_Mentat_Loop(wsaFilename, null, stringBuffer, true, null);

        if (w != null)
        {
            do
            {
                GUI_Widget_DrawAll(w);
                ret = GUI_Widget_HandleEvents(w);

                GUI_PaletteAnimate();
                GUI_Mentat_Animation(0);

                SleepIdle();
            } while ((ret & 0x8000) == 0);
        }

        Input_History_Clear();

        if (w != null)
        {
            /* reset palette and tiles */
            Load_Palette_Mercenaries();
            Sprites_LoadTiles();
        }

        return(ret);
    }
コード例 #3
0
ファイル: Mentat.cs プロジェクト: n-stefan/SharpDune
    /*
     * Handles Click event for list in mentat window.
     *
     * @param w The widget.
     */
    static bool GUI_Mentat_List_Click(CWidget w)
    {
        ushort  index;
        CWidget w2;

        index = (ushort)(s_selectedHelpSubject + 3);

        if (w.index != index)
        {
            w2 = GUI_Widget_Get_ByIndex(g_widgetMentatTail, index);

            GUI_Widget_MakeNormal(w, false);
            GUI_Widget_MakeNormal(w2, false);

            if (w2.stringID == 0x31)
            {
                w2.fgColourDown   = 15;
                w2.fgColourNormal = 15;

                GUI_Widget_Draw(w2);
            }

            if (w.stringID == 0x31)
            {
                w.fgColourDown   = 8;
                w.fgColourNormal = 8;

                GUI_Widget_Draw(w);
            }

            s_selectedHelpSubject = (ushort)(w.index - 3);
            return(true);
        }

        if ((w.state.buttonState & 0x11) == 0 && !s_selectMentatHelp)
        {
            return(true);
        }

        if (w.stringID != 0x31)
        {
            return(true);
        }

        GUI_Widget_MakeNormal(w, false);

        GUI_Mentat_ShowHelp();

        GUI_Mentat_Draw(true);

        Input_HandleInput(0x841);
        Input_HandleInput(0x842);
        return(false);
    }
コード例 #4
0
ファイル: WidgetClick.cs プロジェクト: n-stefan/SharpDune
    /*
     * Handles Click event for unit commands button.
     *
     * @param w The widget.
     * @return True, always.
     */
    internal static bool GUI_Widget_TextButton_Click(CWidget w)
    {
        UnitInfo   ui;
        ActionInfo ai;

        ushort[]   actions;
        ActionType action;
        CUnit      u;
        //ushort found;
        ActionType unitAction;

        u  = g_unitSelected;
        ui = g_table_unitInfo[u.o.type];

        actions = ui.o.actionsPlayer;
        if (Unit_GetHouseID(u) != (byte)g_playerHouseID && u.o.type != (byte)UnitType.UNIT_HARVESTER)
        {
            actions = g_table_actionsAI;
        }

        action = (ActionType)actions[w.index - 8];
        if (g_dune2_enhanced)
        {
            if (Input_Test(0x2c) != 0 || Input_Test(0x39) != 0)
            {   /* LSHIFT or RSHIFT is pressed */
                if (action == ActionType.ACTION_GUARD)
                {
                    action = ActionType.ACTION_AREA_GUARD;                                      /* AREA GUARD instead of GUARD */
                }
                else if (action == ActionType.ACTION_ATTACK)
                {
                    action = ActionType.ACTION_AMBUSH;                                          /* AMBUSH instead of ATTACK */
                }
            }
            Debug.WriteLine($"DEBUG: GUI_Widget_TextButton_Click({w} index={w.index}) action={action}");
        }

        unitAction = (ActionType)u.nextActionID;
        if (unitAction == ActionType.ACTION_INVALID)
        {
            unitAction = (ActionType)u.actionID;
        }

        if (u.deviated != 0)
        {
            Unit_Deviation_Decrease(u, 5);
            if (u.deviated == 0)
            {
                GUI_Widget_MakeNormal(w, false);
                return(true);
            }
        }

        GUI_Widget_MakeSelected(w, false);

        ai = g_table_actionInfo[(int)action];

        if (ai.selectionType != g_selectionType)
        {
            g_unitActive   = g_unitSelected;
            g_activeAction = (ushort)action;
            GUI_ChangeSelectionType(ai.selectionType);

            return(true);
        }

        Object_Script_Variable4_Clear(u.o);
        u.targetAttack = 0;
        u.targetMove   = 0;
        u.route[0]     = 0xFF;

        Unit_SetAction(u, action);

        if (ui.movementType == (ushort)MovementType.MOVEMENT_FOOT)
        {
            Sound_StartSound(ai.soundID);
        }

        if (unitAction == action)
        {
            return(true);
        }

        var index = Array.FindIndex(actions[..4], a => a == (ushort)unitAction);
コード例 #5
0
ファイル: EditBox.cs プロジェクト: n-stefan/SharpDune
    /*
     * 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 widgetID the widget in which the EditBox is displayed.
     * @param w The widget this editbox is attached to (for input events).
     * @param tickProc The function to call every tick, for animation etc.
     * @param paint Flag indicating if the widget need to be repainted.
     * @return Key code / Button press code.
     */
    internal static ushort GUI_EditBox(ref string text, ushort maxLength, ushort widgetID, CWidget w, Func <ushort> tickProc, bool paint)
    {
        Screen oldScreenID;
        ushort oldWidgetID;
        ushort positionX;
        ushort maxWidth;
        ushort textWidth;
        ushort textLength;
        ushort returnValue;
        var    t = new StringBuilder();

        /* Initialize */
        {
            Input_Flags_SetBits((ushort)InputFlagsEnum.INPUT_FLAG_NO_TRANSLATE);
            Input_Flags_ClearBits((ushort)InputFlagsEnum.INPUT_FLAG_UNKNOWN_2000);

            oldScreenID = GFX_Screen_SetActive(Screen.NO0);

            oldWidgetID = Widget_SetCurrentWidget(widgetID);

            returnValue = 0x0;
        }

        positionX = (ushort)(g_curWidgetXBase << 3);

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

        /* Calculate the length and width of the current string */
        for (var i = 0; i < t.Length; i++)
        {
            textWidth += Font_GetCharWidth(t[i]);
            textLength++;

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

        GUI_Mouse_Hide_Safe();

        if (paint)
        {
            Widget_PaintCurrentWidget();
        }

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

        GUI_EditBox_BlinkCursor((ushort)(positionX + textWidth), false);

        GUI_Mouse_Show_Safe();

        for (; ; SleepIdle())
        {
            ushort keyWidth;
            ushort key;

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

            key = GUI_Widget_HandleEvents(w);

            GUI_EditBox_BlinkCursor((ushort)(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((ushort)(positionX + textWidth), true);

                textWidth -= Font_GetCharWidth(t[^ 1]);
コード例 #6
0
ファイル: Mentat.cs プロジェクト: n-stefan/SharpDune
    internal static ushort GUI_Mentat_Loop(string wsaFilename, string pictureDetails, string text, bool loopAnimation, CWidget w)
    {
        Screen oldScreenID;
        ushort oldWidgetID;

        /*WSAObject*/
        (WSAHeader header, Array <byte> buffer)wsa;
        ushort descLines;
        bool   dirty;
        bool   done;
        bool   textDone;
        ushort frame;
        uint   descTick;
        ushort mentatSpeakingMode;
        ushort result;
        uint   textTick;
        uint   textDelay;
        ushort lines;
        ushort step;
        var    partsPointer = 0;

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

        oldWidgetID = Widget_SetCurrentWidget(8);
        oldScreenID = GFX_Screen_SetActive(Screen.NO2);

        wsa = (null, null);

        if (wsaFilename != null)
        {
            wsa = WSA_LoadFile(wsaFilename, GFX_Screen_Get_ByIndex(Screen.NO1), GFX_Screen_GetSize_ByIndex(Screen.NO1), false);
        }

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

        GUI_DrawText_Wrapper(null, 0, 0, 0, 0, 0x31);

        descLines = GUI_SplitText(ref pictureDetails, (ushort)((g_curWidgetWidth << 3) + 10), '\r');

        GUI_DrawText_Wrapper(null, 0, 0, 0, 0, 0x32);

        var parts /*(parts, textLines)*/ = GUI_Mentat_SplitText(text, 304);
        var textLines = parts?.Length ?? 0;

        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())
        {
            ushort key;

            GFX_Screen_SetActive(Screen.NO0);

            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:
            case 1:
                if (step == 0)
                {
                    if (key == 0)
                    {
                        break;
                    }
                    step = 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  = (ushort)((parts?[partsPointer] /*text*/ != null) ? 2 : 4);
                lines = descLines;
                break;

            case 2:
            case 3:
                if (step == 2)
                {
                    GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40);
                    GUI_Screen_Copy(0, 0, 0, 160, SCREEN_WIDTH / 8, 40, Screen.NO0, Screen.NO2);
                    GUI_Mouse_Show_InRegion();

                    step = 3;
                    key  = 1;
                }

                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.NO2, Screen.NO0);
                    GUI_Mouse_Show_InRegion();

                    step = 4;
                    mentatSpeakingMode = 0;
                    break;
                }

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

                    if (textLines-- != 0)
                    {
                        GFX_Screen_SetActive(Screen.NO2);
                        GUI_DrawText_Wrapper(parts[partsPointer] /*text*/, 4, 1, g_curWidgetFGColourBlink, 0, 0x32);
                        mentatSpeakingMode = 1;
                        textDelay          = (uint)(parts[partsPointer] /*text*/.Length * 4);
                        textTick           = g_timerGUI + textDelay;

                        //int textPointer = 0;
                        if (textLines != 0)
                        {
                            partsPointer++;
                            //while (text[textPointer++] != '\r') {}
                        }
                        else
                        {
                            textDone = true;
                        }

                        GFX_Screen_SetActive(Screen.NO0);
                    }

                    GUI_Mouse_Hide_InRegion(0, 0, SCREEN_WIDTH, 40);
                    GUI_Screen_Copy(0, 0, 0, 0, SCREEN_WIDTH / 8, 40, Screen.NO2, Screen.NO0);
                    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, null) && g_timerTimeout == 0)
            {
                g_timerTimeout = 7;

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

                    if (!WSA_DisplayFrame(wsa, frame++, (ushort)(g_curWidgetXBase << 3), g_curWidgetYBase, Screen.NO2))
                    {
                        if (step == 0)
                        {
                            step = 1;
                        }

                        if (loopAnimation)
                        {
                            frame = 0;
                        }
                        else
                        {
                            WSA_Unload(wsa);
                            wsa = (null, null);
                        }
                    }
                } while (frame == 0);
                dirty = true;
            }

            if (!dirty)
            {
                continue;
            }

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

            GUI_DrawSprite(Screen.NO2, g_sprites[397 + (byte)g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0);
            GUI_Mouse_Hide_InWidget(g_curWidgetIndex);
            GUI_Screen_Copy((short)g_curWidgetXBase, (short)g_curWidgetYBase, (short)g_curWidgetXBase, (short)g_curWidgetYBase, (short)g_curWidgetWidth, (short)g_curWidgetHeight, Screen.NO2, Screen.NO0);
            GUI_Mouse_Show_InWidget();
            dirty = false;
        }

        if (wsa != (null, null))
        {
            WSA_Unload(wsa);
        }

        GFX_Screen_SetActive(Screen.NO2);
        GUI_DrawSprite(Screen.NO2, g_sprites[397 + (byte)g_playerHouseID * 15], g_shoulderLeft, g_shoulderTop, 0, 0);
        GUI_Mouse_Hide_InWidget(g_curWidgetIndex);
        GUI_Screen_Copy((short)g_curWidgetXBase, (short)g_curWidgetYBase, (short)g_curWidgetXBase, (short)g_curWidgetYBase, (short)g_curWidgetWidth, (short)g_curWidgetHeight, Screen.NO2, Screen.NO0);
        GUI_Mouse_Show_InWidget();
        Widget_SetCurrentWidget(oldWidgetID);
        GFX_Screen_SetActive(oldScreenID);

        Input_History_Clear();

        return(result);
    }
コード例 #7
0
ファイル: Mentat.cs プロジェクト: n-stefan/SharpDune
 static void GUI_Mentat_ScrollBar_Draw(CWidget w)
 {
     GUI_Mentat_SelectHelpSubject((short)(GUI_Get_Scrollbar_Position(w) - s_topHelpList));
     GUI_Mentat_Draw(false);
 }
コード例 #8
0
ファイル: Mentat.cs プロジェクト: n-stefan/SharpDune
    static readonly string empty = string.Empty; //char[2]
    /* Create the widgets of the mentat help screen. */
    static void GUI_Mentat_Create_HelpScreen_Widgets()
    {
        ushort ypos;

        CWidget[] w;
        int       i;

        if (g_widgetMentatScrollbar != null)
        {
            GUI_Widget_Free_WithScrollbar(g_widgetMentatScrollbar);
            g_widgetMentatScrollbar = null;
        }

        g_widgetMentatScrollUp   = null; //free(g_widgetMentatScrollUp);
        g_widgetMentatScrollDown = null; //free(g_widgetMentatScrollDown);

        g_widgetMentatTail = null;
        ypos = 8;

        //w = (Widget[])Gfx.GFX_Screen_Get_ByIndex(Screen.NO2);

        w = new CWidget[13];

        for (i = 0; i < 13; i++)
        {
            w[i] = new CWidget
            {
                index = (ushort)(i + 2)
            }; //memset(w, 0, 13 * sizeof(Widget));

            //memset(&w->flags, 0, sizeof(w->flags));
            w[i].flags.buttonFilterLeft  = 9;
            w[i].flags.buttonFilterRight = 1;

            w[i].clickProc = GUI_Mentat_List_Click;

            w[i].drawParameterDown.text     = empty;
            w[i].drawParameterSelected.text = empty;
            w[i].drawParameterNormal.text   = empty;

            w[i].drawModeNormal = (byte)DrawMode.DRAW_MODE_TEXT;

            //memset(&w->state, 0, sizeof(w->state));

            w[i].offsetX  = 24;
            w[i].offsetY  = (short)ypos;
            w[i].width    = 0x88;
            w[i].height   = 8;
            w[i].parentID = 8;

            g_widgetMentatTail = g_widgetMentatTail != null?GUI_Widget_Link(g_widgetMentatTail, w[i]) : w[i];

            ypos += 8;
            //w++;
        }

        GUI_Widget_MakeInvisible(g_widgetMentatTail);
        GUI_Widget_MakeInvisible(w[i - 1]);

        g_widgetMentatScrollbar = GUI_Widget_Allocate_WithScrollbar(15, 8, 168, 24, 8, 72, GUI_Mentat_ScrollBar_Draw);

        g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatScrollbar);

        g_widgetMentatScrollDown           = GUI_Widget_AllocateScrollBtn(16, 0, 168, 96, g_sprites[385], g_sprites[386], GUI_Widget_Get_ByIndex(g_widgetMentatTail, 15), true);
        g_widgetMentatScrollDown.shortcut  = 0;
        g_widgetMentatScrollDown.shortcut2 = 0;
        g_widgetMentatScrollDown.parentID  = 8;
        g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatScrollDown);

        g_widgetMentatScrollUp           = GUI_Widget_AllocateScrollBtn(17, 0, 168, 16, g_sprites[383], g_sprites[384], GUI_Widget_Get_ByIndex(g_widgetMentatTail, 15), false);
        g_widgetMentatScrollUp.shortcut  = 0;
        g_widgetMentatScrollUp.shortcut2 = 0;
        g_widgetMentatScrollUp.parentID  = 8;
        g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatScrollUp);

        g_widgetMentatTail = GUI_Widget_Link(g_widgetMentatTail, g_widgetMentatFirst);

        GUI_Widget_Draw(g_widgetMentatFirst);
    }
コード例 #9
0
ファイル: WidgetDraw.cs プロジェクト: n-stefan/SharpDune
    /*
     * Draw the panel on the right side of the screen, with the actions of the
     *  selected item.
     *
     * @param forceDraw Wether to draw the panel even if nothing changed.
     */
    internal static void GUI_Widget_ActionPanel_Draw(bool forceDraw)
    {
        StructureInfo si;
        ObjectInfo    oi;
        UnitInfo      ui;
        ushort        actionType;
        Screen        oldScreenID;
        ushort        oldWidgetID;
        bool          isNotPlayerOwned;
        CObject       o;
        CUnit         u;
        CStructure    s;
        CHouse        h;
        var           buttons = new CWidget[4];
        CWidget       widget24 = null, widget28 = null, widget2C = null, widget30 = null, widget34 = null;

        o = null;
        u = null;
        s = null;
        h = null;

        oi = null;
        si = null;
        isNotPlayerOwned = false;

        actionType = GUI_Widget_ActionPanel_GetActionType(forceDraw);

        switch (actionType)
        {
        case 2:
        {         /* Unit */
            u  = g_unitSelected;
            ui = g_table_unitInfo[u.o.type];

            o  = u.o;
            oi = ui.o;

            isNotPlayerOwned = (byte)g_playerHouseID != Unit_GetHouseID(u);

            h = House_Get_ByIndex(u.o.houseID);
        }
        break;

        case 3:
        {         /* Structure */
            s  = Structure_Get_ByPackedTile(g_selectionPosition);
            si = g_table_structureInfo[s.o.type];

            o  = s.o;
            oi = si.o;

            isNotPlayerOwned = (byte)g_playerHouseID != s.o.houseID;

            h = House_Get_ByIndex(s.o.houseID);

            if (s.upgradeTimeLeft == 0 && Structure_IsUpgradable(s))
            {
                s.upgradeTimeLeft = 100;
            }
            GUI_UpdateProductionStringID();
        }
        break;

        case 7:
        {         /* Placement */
            si = g_table_structureInfo[g_structureActiveType];

            o  = null;
            oi = si.o;

            isNotPlayerOwned = false;

            h = House_Get_ByIndex((byte)g_playerHouseID);
        }
        break;

        case 8:
        {         /* House Missile */
            u  = g_unitHouseMissile;
            ui = g_table_unitInfo[u.o.type];

            o  = u.o;
            oi = ui.o;

            isNotPlayerOwned = (byte)g_playerHouseID != Unit_GetHouseID(u);

            h = House_Get_ByIndex((byte)g_playerHouseID);
        }
        break;

        case 4:     /* Attack */
        case 5:     /* Movement */
        case 6:     /* Harvest */
        default:    /* Default */
            break;
        }

        oldScreenID = Screen.ACTIVE;
        oldWidgetID = g_curWidgetIndex;

        if (actionType != 0)
        {
            var w = g_widgetLinkedListHead;
            int i;

            oldScreenID = GFX_Screen_SetActive(Screen.NO1);
            oldWidgetID = Widget_SetCurrentWidget(6);

            widget30 = GUI_Widget_Get_ByIndex(w, 7);
            GUI_Widget_MakeInvisible(widget30);

            widget24 = GUI_Widget_Get_ByIndex(w, 4);
            GUI_Widget_MakeInvisible(widget24);

            widget28 = GUI_Widget_Get_ByIndex(w, 6);
            GUI_Widget_MakeInvisible(widget28);

            widget2C = GUI_Widget_Get_ByIndex(w, 5);
            GUI_Widget_MakeInvisible(widget2C);

            widget34 = GUI_Widget_Get_ByIndex(w, 3);
            GUI_Widget_MakeInvisible(widget34);

            /* Create the 4 buttons */
            for (i = 0; i < 4; i++)
            {
                buttons[i] = GUI_Widget_Get_ByIndex(w, (ushort)(i + 8));
                GUI_Widget_MakeInvisible(buttons[i]);
            }

            GUI_Widget_DrawBorder(g_curWidgetIndex, 0, false /*0*/);
        }

        if (actionType > 1)
        {
            var    stringID = (ushort)Text.STR_NULL;
            ushort spriteID = 0xFFFF;

            switch (actionType)
            {
            case 4: stringID = (ushort)Text.STR_TARGET; break;   /* Attack */

            case 5: stringID = (ushort)Text.STR_MOVEMENT; break; /* Movement */

            case 6: stringID = (ushort)Text.STR_HARVEST; break;  /* Harvest */

            case 2:                                              /* Unit */
            case 3:                                              /* Structure */
            case 7:                                              /* Placement */
            case 8:                                              /* House Missile */
                stringID = oi.stringID_abbrev;
                break;

            default: break;
            }

            if (stringID != (ushort)Text.STR_NULL)
            {
                GUI_DrawText_Wrapper(String_Get_ByIndex(stringID), 288, 43, 29, 0, 0x111);
            }

            switch (actionType)
            {
            case 3:     /* Structure */
            case 2:     /* Unit */
            case 7:     /* Placement */
                if (actionType == 3)
                {
                    if (oi.flags.factory && !isNotPlayerOwned)
                    {
                        GUI_Widget_MakeVisible(widget28);
                        break;
                    }
                }
                spriteID = oi.spriteID;
                break;

            case 5:     /* Movement */
            case 6:     /* Harvest */
                spriteID = 0x1D;
                break;

            case 4:     /* Attack */
                spriteID = 0x1C;
                break;

            case 8:     /* House Missile */
                spriteID = 0x1E;
                break;

            default:
                spriteID = 0xFFFF;
                break;
            }

            if (spriteID != 0xFFFF)
            {
                GUI_DrawSprite(Screen.ACTIVE, g_sprites[spriteID], 258, 51, 0, 0);
            }

            /* Unit / Structure */
            if (actionType is 2 or 3)
            {
                GUI_DrawProgressbar(o.hitpoints, oi.hitpoints);
                GUI_DrawSprite(Screen.ACTIVE, g_sprites[27], 292, 60, 0, 0);
                GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_DMG), 296, 65, 29, 0, 0x11);
            }

            if (!isNotPlayerOwned || g_debugGame)
            {
                switch (actionType)
                {
                case 2:     /* Unit */
                {
                    ushort[] actions;
                    ushort   actionCurrent;
                    int      i;

                    GUI_Widget_MakeVisible(widget34);

                    actionCurrent = (u.nextActionID != (byte)ActionType.ACTION_INVALID) ? u.nextActionID : u.actionID;

                    actions = oi.actionsPlayer;
                    if (isNotPlayerOwned && o.type != (byte)UnitType.UNIT_HARVESTER)
                    {
                        actions = g_table_actionsAI;
                    }

                    for (i = 0; i < 4; i++)
                    {
                        buttons[i].stringID = g_table_actionInfo[actions[i]].stringID;
                        buttons[i].shortcut = GUI_Widget_GetShortcut((byte)String_Get_ByIndex(buttons[i].stringID)[0]);

                        if (g_config.language == (byte)Language.FRENCH)
                        {
                            if (buttons[i].stringID == (ushort)Text.STR_MOVE)
                            {
                                buttons[i].shortcut2 = 0x27;                                                        /* L key */
                            }
                            else if (buttons[i].stringID == (ushort)Text.STR_RETURN)
                            {
                                buttons[i].shortcut2 = 0x13;                                                                /* E key */
                            }
                        }
                        else if (g_config.language == (byte)Language.GERMAN)
                        {
                            if (buttons[i].stringID == (ushort)Text.STR_GUARD)
                            {
                                buttons[i].shortcut2 = 0x17;                                                        /* U key */
                            }
                        }

                        GUI_Widget_MakeVisible(buttons[i]);

                        if (actions[i] == actionCurrent)
                        {
                            GUI_Widget_MakeSelected(buttons[i], false);
                        }
                        else
                        {
                            GUI_Widget_MakeNormal(buttons[i], false);
                        }
                    }
                }
                break;

                case 3:     /* Structure */
                {
                    GUI_Widget_MakeVisible(widget34);

                    if (o.flags.upgrading)
                    {
                        widget24.stringID = (ushort)Text.STR_UPGRADING;

                        GUI_Widget_MakeVisible(widget24);
                        GUI_Widget_MakeSelected(widget24, false);
                    }
                    else if (o.hitpoints != oi.hitpoints)
                    {
                        if (o.flags.repairing)
                        {
                            widget24.stringID = (ushort)Text.STR_REPAIRING;

                            GUI_Widget_MakeVisible(widget24);
                            GUI_Widget_MakeSelected(widget24, false);
                        }
                        else
                        {
                            widget24.stringID = (ushort)Text.STR_REPAIR;

                            GUI_Widget_MakeVisible(widget24);
                            GUI_Widget_MakeNormal(widget24, false);
                        }
                    }
                    else if (s.upgradeTimeLeft != 0)
                    {
                        widget24.stringID = (ushort)Text.STR_UPGRADE;

                        GUI_Widget_MakeVisible(widget24);
                        GUI_Widget_MakeNormal(widget24, false);
                    }

                    if (o.type != (byte)StructureType.STRUCTURE_STARPORT)
                    {
                        if (oi.flags.factory || (o.type == (byte)StructureType.STRUCTURE_PALACE && s.countDown == 0))
                        {
                            GUI_Widget_MakeVisible(widget2C);
                            GUI_Widget_Draw(widget2C);
                        }
                    }

                    switch (o.type)
                    {
                    case (byte)StructureType.STRUCTURE_SLAB_1x1: break;

                    case (byte)StructureType.STRUCTURE_SLAB_2x2: break;

                    case (byte)StructureType.STRUCTURE_PALACE: break;

                    case (byte)StructureType.STRUCTURE_LIGHT_VEHICLE: break;

                    case (byte)StructureType.STRUCTURE_HEAVY_VEHICLE: break;

                    case (byte)StructureType.STRUCTURE_HIGH_TECH: break;

                    case (byte)StructureType.STRUCTURE_HOUSE_OF_IX: break;

                    case (byte)StructureType.STRUCTURE_WOR_TROOPER: break;

                    case (byte)StructureType.STRUCTURE_CONSTRUCTION_YARD: break;

                    case (byte)StructureType.STRUCTURE_BARRACKS: break;

                    case (byte)StructureType.STRUCTURE_WALL: break;

                    case (byte)StructureType.STRUCTURE_TURRET: break;

                    case (byte)StructureType.STRUCTURE_ROCKET_TURRET: break;

                    case (byte)StructureType.STRUCTURE_REPAIR:
                    {
                        ushort percent;
                        ushort steps;
                        CUnit  u2;

                        u2 = Structure_GetLinkedUnit(s);
                        if (u2 == null)
                        {
                            break;
                        }

                        GUI_DrawSprite(Screen.ACTIVE, g_sprites[g_table_unitInfo[u2.o.type].o.spriteID], 260, 89, 0, 0);

                        steps   = (ushort)(g_table_unitInfo[u2.o.type].o.buildTime / 4);
                        percent = (ushort)((steps - (s.countDown >> 8)) * 100 / steps);

                        GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_D_DONE), 258, 116, 29, 0, 0x11, percent);
                    }
                    break;

                    case (byte)StructureType.STRUCTURE_WINDTRAP:
                    {
                        var powerOutput  = (ushort)(o.hitpoints * -si.powerUsage / oi.hitpoints);
                        var powerAverage = (ushort)((h.windtrapCount == 0) ? 0 : h.powerUsage / h.windtrapCount);

                        GUI_DrawLine(261, 95, 312, 95, 16);
                        GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_POWER_INFONEEDEDOUTPUT), 258, 88, 29, 0, 0x11);
                        GUI_DrawText_Wrapper("{0, 3}", 292, (short)(g_fontCurrent.height * 2 + 80), 29, 0, 0x11, powerAverage);
                        GUI_DrawText_Wrapper("{0, 3}", 292, (short)(g_fontCurrent.height * 3 + 80), (byte)((powerOutput >= powerAverage) ? 29 : 6), 0, 0x11, powerOutput);
                    }
                    break;

                    case (byte)StructureType.STRUCTURE_STARPORT:
                    {
                        if (h.starportLinkedID != 0xFFFF)
                        {
                            GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_FRIGATEARRIVAL_INTMINUS_D), 258, 88, 29, 0, 0x11, h.starportTimeLeft);
                        }
                        else
                        {
                            GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_FRIGATE_INORBIT_ANDAWAITINGORDER), 258, 88, 29, 0, 0x11);
                        }
                    }
                    break;

                    case (byte)StructureType.STRUCTURE_REFINERY:
                    case (byte)StructureType.STRUCTURE_SILO:
                    {
                        ushort creditsStored;

                        creditsStored = (ushort)(h.credits * si.creditsStorage / h.creditsStorage);
                        if (h.credits > h.creditsStorage)
                        {
                            creditsStored = si.creditsStorage;
                        }

                        GUI_DrawLine(261, 95, 312, 95, 16);
                        GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_SPICEHOLDS_4DMAX_4D), 258, 88, 29, 0, 0x11, creditsStored, (si.creditsStorage <= 1000) ? si.creditsStorage : 1000);
                    }
                    break;

                    case (byte)StructureType.STRUCTURE_OUTPOST:
                    {
                        GUI_DrawLine(261, 95, 312, 95, 16);
                        GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_RADAR_SCANFRIEND_2DENEMY_2D), 258, 88, 29, 0, 0x11, h.unitCountAllied, h.unitCountEnemy);
                    }
                    break;
                    }
                }
                break;

                case 4:     /* Attack */
                    GUI_Widget_MakeVisible(widget30);
                    GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_SELECTTARGET), 259, 76, g_curWidgetFGColourBlink, 0, 0x11);
                    break;

                case 5:     /* Movement */
                    GUI_Widget_MakeVisible(widget30);
                    GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_SELECTDESTINATION), 259, 76, g_curWidgetFGColourBlink, 0, 0x11);
                    break;

                case 6:     /* Harvest */
                    GUI_Widget_MakeVisible(widget30);
                    GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_SELECTPLACE_TOHARVEST), 259, 76, g_curWidgetFGColourBlink, 0, 0x11);
                    break;

                case 7:     /* Placement */
                    GUI_Widget_MakeVisible(widget30);
                    GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_SELECTLOCATION_TOBUILD), 259, 84, g_curWidgetFGColourBlink, 0, 0x11);
                    break;

                case 8:     /* House Missile */
                {
                    var count = (short)(g_houseMissileCountdown - 1);
                    if (count <= 0)
                    {
                        count = 0;
                    }

                    GUI_DrawText_Wrapper(String_Get_ByIndex(Text.STR_PICK_TARGETTMINUS_D), 259, 84, g_curWidgetFGColourBlink, 0, 0x11, count);
                }
                break;

                default:
                    break;
                }
            }
        }

        if (actionType != 0)
        {
            GUI_Mouse_Hide_InWidget(6);
            GUI_Screen_Copy((short)g_curWidgetXBase, (short)g_curWidgetYBase, (short)g_curWidgetXBase, (short)g_curWidgetYBase, (short)g_curWidgetWidth, (short)g_curWidgetHeight, Screen.ACTIVE, Screen.NO0);
            GUI_Mouse_Show_InWidget();
        }

        if (actionType > 1)
        {
            Widget_SetCurrentWidget(oldWidgetID);
            GFX_Screen_SetActive(oldScreenID);
        }
    }