You are the OS

Discuss GUI programming with the RapaGUI plugin here
Post Reply
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

You are the OS

Post by GMKai »

I have attempted to recreate this:
https://drfreckles42.itch.io/youre-the-os

My GUI:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
    <application>
        <window id="mywindow" title="YouAreTheOS">
        <vgroup>
          <vgroup id="MainGroup" hide="false">
            <hgroup>
                <rectangle/>
                <choice id="Difficulty">
                 <item>Easy</item>
                 <item>Normal</item>
                 <item>Hard</item>
                </choice>
                <rectangle/>
               <button id="play">Play</button>
               <rectangle/>
            </hgroup>
            <vgroup>    
               <hline/>
               <button id="score">HighScore</button>
               <rectangle/>
            </vgroup>
          </vgroup>
          <vgroup id="Game" hide="true">
            <!--CPU-Slots-->
            <hgroup id="cpuslots">            
             <button id="Core1" height="64" width="64">Core1</button>
             <button id="Core2" height="64" width="64">Core2</button>
             <button id="Core3" height="64" width="64">Core3</button>
             <button id="Core4" height="64" width="64">Core4</button>
            </hgroup>
            <!--Tasks-->
            <scrollgroup id="tasks" horiz="true">
             <rectangle/>
            </scrollgroup>
            <button id="Return" hide="true">Return</button>
            <rectangle/>
          </vgroup>
          <vgroup id="HighScore" hide="true">
               <rectangle/>
               <choice id="ScoreDifficulty">
                 <item>Easy</item>
                 <item>Normal</item>
                 <item>Hard</item>
                </choice>
                <rectangle/>
                <listview>
                   <column title="Player">
                      <item>Entry 1</item>
                      <item>Entry 2</item>
                      <item>Entry 3</item>
                   </column>
                   <column title="Score">
                      <item>Entry 1</item>
                      <item>Entry 2</item>
                      <item>Entry 3</item>
                   </column>        
                </listview>
                <rectangle/>
               <button id="ok">OK</button>
          </vgroup>
          <!--Status-->
          <statusbar>
            <item id="first">Welcome to my application</item>
            <item id="second"/>
            <item id="third"/>
          </statusbar>
        </vgroup>    
        </window>
    </application>
My Code:

Code: Select all

@REQUIRE "RapaGUI"
@APPTITLE "YouAreTheOS"
@APPVERSION "$VER: YouAreTheOS 1.0 (02.12.23)"
@APPCOPYRIGHT "Copyright ©2023, Kai Stegemann"
@APPAUTHOR "Kai Stegemann"
@APPDESCRIPTION "Small Game to educate task scheduling"

Global intervaltiming = 950
Global corecount      = 4
Global tasklist = CreateList()

function p_TaskToPool(id)
    moai.DoMethod("tasks", "initchange")
    moai.DoMethod("tasks", "append", id)
    moai.DoMethod("tasks", "exitchange", false)
EndFunction


function p_TaskFromPool(id)
    moai.DoMethod("tasks", "initchange")
    moai.DoMethod("tasks", "remove", id)
    moai.DoMethod("tasks", "exitchange", false)
EndFunction

Function p_CreateTask()
    DebugPrint("p_CreateTask")
    Local id = RndStrong(#INTEGER,65536)
    id = ToString(id)
    DebugPrint("ID: "..id)
    Local xml$ = "<button id=\""..id.."\" height=\"64\" width=\"64\">"..id.."</button>"
    moai.CreateObject(xml$, "mywindow") 
    p_TaskToPool(id)
    InsertItem(tasklist,id)    
EndFunction

Function p_InspectCore(id)
   DebugPrint("p_InspectCore")
   Local text$ = moai.get(id,"text")
   If(StartsWith(text$, "Core"))
     ;Core is already empty
     Return()
   Else
     ;give task to pool
     p_TaskToPool(text$)
     ;rename Core 
     moai.set(id,"text",id)  
   EndIf()
EndFunction

Function p_FillCoreWithTask(taskid)
   DebugPrint("p_FillCoreWithTask")
   DebugPrint(taskid)
   Local coreid = 0
   ;find available core
   For Local i = 1 To corecount
       Local moaid = "Core"..i
       Local text$ = moai.get(moaid,"text")
       If(StartsWith(text$,"Core"))
         ;Core is available
         ;place task here
         moai.set(moaid,"text",taskid)
         ;remove task from pool
         p_TaskFromPool(taskid)
         ;end loop
         Break()
       EndIf()             
   Next
EndFunction


Function p_RedrawTasks()
    ;age taks in pool
    ;proceed tasks in core
    
    Return()
EndFunction


Function p_EventFunc(msg)
    ForEach(msg, DebugPrint)
    Switch msg.ID 
        Case "play":
           moai.set("MainGroup","hide",true)
           moai.set("HighScore","hide",true)   
           moai.set("Game","hide",false)    
           moai.set("first","text","CurrentScore")
           moai.set("second","text","0") 
           moai.set("third","text","0") 
           SetInterval(1,p_CreateTask,intervaltiming)
           SetInterval(2,p_RedrawTasks,40)        
        Case "ok":
           moai.set("MainGroup","hide",false)
           moai.set("HighScore","hide",true) 
           moai.set("Game","hide",true)           
        Case "score":
           moai.set("HighScore","hide",false) 
           moai.set("MainGroup","hide",true)
           moai.set("Game","hide",true)
        Case "Core1":
           p_InspectCore(msg.id)
        Case "Core2":
           p_InspectCore(msg.id)
        Case "Core3":
           p_InspectCore(msg.id)
        Case "Core4":
           p_InspectCore(msg.id)        
        Default:
           ;place given id to available cpu slot
           p_FillCoreWithTask(msg.id)
    EndSwitch

EndFunction

InstallEventHandler({RapaGUI = p_EventFunc})

moai.CreateApp(FileToString("YouAreTheOS.xml"))

Repeat
    WaitEvent
Forever

Request for comments:

The tasks are buttons. Is there a way to attach the state of the task to a button? Some kind of Traffic light, or background colour?

The current project freezes after some tasks are created.

The placement of the waiting tasks feels dirty. How can infinite tasks be organized to eat up less space?
User avatar
airsoftsoftwair
Posts: 5446
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: You are the OS

Post by airsoftsoftwair »

GMKai wrote: Wed Dec 13, 2023 12:36 pm The tasks are buttons. Is there a way to attach the state of the task to a button? Some kind of Traffic light, or background colour?
Not really possible because Button.Icon has an applicability of just "I" so you won't be able to change a button's icon. On AmigaOS it could easily be done, though, by using MUI Royale and just using the \33A text formatting code.
plouf
Posts: 473
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: You are the OS

Post by plouf »

since its not possible, if you are satisfied with black only "icons" maybe you can create a custon font with the "icons"as characters and use this..
Christos
p-OS
Posts: 167
Joined: Mon Nov 01, 2010 11:56 pm

Re: You are the OS

Post by p-OS »

Actually MUi does not have a real Button class.

Every Object based on Area.mui or any subclass of it can be made a Button. Even a group.

One has to set MUIA_InputMode to MUIV_InputMode_RelVerify and a notifcytion trigge to MUIA_Pressed.

Normal Buttons in MUI are actually TextObjects:

(C Code:)

Code: Select all

okbutton = TextObject,
           MUIA_Frame        , MUIV_Frame_Button,
           MUIA_InputMode    , MUIV_InputMode_RelVerify,
           MUIA_Text_Contents, "OK"
Thus you could create Group of TextObject and HollywoodArea Class and set the Group to be a Button.
GMKai
Posts: 140
Joined: Mon Feb 15, 2010 10:58 am

Re: You are the OS

Post by GMKai »

I am happy to go with Royale.

For now I try to hack the state with Area.BackgroundRGB.

I will let you know what strikes next...
Post Reply