Jump to content

[Computercraft] Hilfööö! Oder: tausend Augen sehen besser als 2


Corona

Empfohlene Beiträge

Tja, ich sollte wirklich für ein Forum nur für mich anfragen, wo ich dann meine CC bezogenen Problemchen reinklatsche.

So. folgendes läuft nicht ganz sauber; Ich bin gerade dabei ein Programm zu schreiben, was höchst Geheim ist. Streng Geheim. Und dafür möchte ich ein Hauptmenü machen.

Weil es relativ anstrengend ist, Buttonvariablen solange anzupassen, bis es gutaussieht (editieren, anschauen, wieder editieren) dachte ich, ich machs mir einfach, und mach eine minianwendung, die mit zwei rechtsklicks auf dem Bildschirm den Button dementsprechend dimensioniert.

So jetzt habe ich in meiner hastigen Weise und meinem unglaublich überschaubaren Code (normalerweise ists schöner, aber ich brauch das Teil ja nur einmal) keinen Plan, was hierbei der Fehler ist. (BILDER IM ANHANG)

Ich will trotzdem dass das geht. Isso, innerer Drang, also wenn mir ein paar versierte LUA-Gurus helfen könnten wärs super (: (Nurn Witz, jeder soll seinen Senf dazugeben, es muss nur funktionieren!!!!)

Code für den Definer:


os.loadAPI(shell.dir().."/api/screen")

os.loadAPI(shell.dir().."/api/monitor")

screen.cls()

local tab = {}

print("Please klick with your cursor on 2 Edge Points where you want the button to be!")

local evn,btn,xIns1,yIns1=os.pullEvent("mouse_click")

strx1 = "x1="..xIns1

stry1 = "y1="..yIns1

table.insert(tab,strx1)

table.insert(tab,stry1)

--paintutils.drawPixel(xIns1,yIns1,colors.red)

local evn,btn,xIns2,yIns2=os.pullEvent("mouse_click")

strx2 = "x2="..xIns2

stry2 = "y2="..yIns2

strcol = "color=colors.red"

strtxt = "text=\"A Button\""

table.insert(tab,strx2)

table.insert(tab,stry2)

table.insert(tab,strcol)

table.insert(tab,strtxt)

if not fs.exists(shell.dir().."/definedButton") then

  local fh = fs.open(shell.dir().."/definedButton","w")

  fh.close()

end

local fh = fs.open(shell.dir().."/definedButton","a")

local str = "{"

for i=1,#tab do

  print(tab[i])

  str = str..tab[i]

  if i ~= #tab then

    str = str..","

  end

end

str = str.."}"

--print(str)

fh.writeLine(str)

fh.close()

--paintutils.drawPixel(xIns2,yIns2,colors.red)

screen.drawButton(tab)

Code für die API, mit der ich den Button zeichne:


--(C) Corona 2013

--DO NOT STEAL THIS CODE!!!

function drawButton(button)

  xStart=button["x1"]

  xEnd=button["x2"]

  yStart=button["y1"]

  yEnd=button["y2"]

  fillColor=button["color"]

  x=xEnd-xStart

  y=yEnd-yStart

  textCentery=(yStart+y/2)

  textCenterx=((xStart+(x/2))-(string.len(button["text"])/2))

  --print("")

  --print("Putting Text at y-Coordinates:"..textCentery)

  --print("Putting Text at x-Coordinates:"..textCenterx)

  --print("Drawing x:"..x)

  --print("Drawing y:"..y)

  --print("Draw Color:"..button["color"])

  term.setCursorPos(xStart,yStart)

  term.setBackgroundColor(fillColor)

  for j=1,y do

    for i=1,x do

        term.write(" ")

    end  

  term.setCursorPos(xStart,yStart+j)

  end

  term.setCursorPos(textCenterx,textCentery)

  term.write(button["text"])

  term.setBackgroundColor(colors.black)

end


function drawBox(area)

  x1 = area["x1"]

  x2 = area["x2"]

  y1 = area["y1"]

  y2 = area["y2"]

  color = area["color"]

  xSpan = x2-x1

  ySpan = y2-y1

  cornerCount = 1

  --print("xSpan:"..xSpan)

  --print("ySpan:"..ySpan)

  --print("Color:"..color)

  term.setCursorPos(x1,y1)

  for j=1,ySpan do

    for i=1,xSpan do

      if (cornerCount == 1) or (cornerCount == ySpan) or (i == 1) or (i == xSpan) then

        term.setBackgroundColor(color)

        term.write(" ")

      else

        local tx,ty = term.getCursorPos()

        term.setCursorPos(tx+1,ty)

      end

    end

    cornerCount = cornerCount+1

    term.setCursorPos(x1,y1+j)

  end

end


function pressed(object,x,y)

  if (object["x1"]-1<x) and (object["x2"]-1>x) and (object["y1"]-1<y) and (object["y2"]-1>y) then

    return true

  else

    return false

  end

end


function cls()

  term.setBackgroundColor(colors.black)

  term.clear()

  term.setCursorPos(1,1)

end


function getFocus(area)

  term.setCursorPos(area["x1"]+1,area["y1"]+1)

end

post-673-0-83325200-1388377352_thumb.png

Link zu diesem Kommentar
Auf anderen Seiten teilen

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...
B
B